Improve Env Manager Interface
- Add to spec !config, !extras, !description fields as default values - Allow to pass in EnvManager.create spec and optional parameters to replace config, extras and description - Schema validation is now only in one place which is great - Add config field to envs table (and change all corresponding places in db.api) - Update all tests - Add cached_data property which can be used when you don't need to refresh data - Traceback & dates are now returened as string which allows to perform serialization operations (for all EnvManager commands) Change-Id: I9cb7f1ef55ef5d82c9860720c52a1a48f05b2c7c
This commit is contained in:
parent
2480e5da0e
commit
2a8ce50373
@ -13,7 +13,8 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import sys
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from rally.common import logging
|
||||
from rally.env import platform
|
||||
@ -145,21 +146,28 @@ class OpenStack(platform.Platform):
|
||||
osclients.Clients(
|
||||
self.platform_data["admin"]).verified_keystone()
|
||||
except Exception:
|
||||
d = copy.deepcopy(self.platform_data["admin"])
|
||||
d["password"] = "***"
|
||||
return {
|
||||
"available": False,
|
||||
"message": ("Bad admin creds: %s"
|
||||
% self.platform_data["admin"]),
|
||||
"traceback": list(sys.exc_info())
|
||||
"message": (
|
||||
"Bad admin creds: \n%s"
|
||||
% json.dumps(d, indent=2, sort_keys=True)),
|
||||
"traceback": traceback.format_exc()
|
||||
}
|
||||
|
||||
for user in self.platform_data["users"]:
|
||||
try:
|
||||
osclients.Clients(user).keystone()
|
||||
except Exception:
|
||||
d = copy.deepcopy(user)
|
||||
d["password"] = "***"
|
||||
return {
|
||||
"available": False,
|
||||
"message": ("Bad user creds: %s" % user),
|
||||
"traceback": list(sys.exc_info())
|
||||
"message": (
|
||||
"Bad user creds: \n%s"
|
||||
% json.dumps(d, indent=2, sort_keys=True)),
|
||||
"traceback": traceback.format_exc()
|
||||
}
|
||||
|
||||
return {"available": True}
|
||||
@ -168,9 +176,10 @@ class OpenStack(platform.Platform):
|
||||
"""Return information about cloud as dict."""
|
||||
active_user = (self.platform_data["admin"] or
|
||||
self.platform_data["users"][0])
|
||||
services = osclients.Clients(active_user).services()
|
||||
return {
|
||||
"info": {
|
||||
"services": osclients.Clients(active_user).list_services()
|
||||
"services": services
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
|
||||
from rally.env import platform
|
||||
@ -160,35 +162,47 @@ class ExistingPlatformTestCase(test_platform.PlatformBaseTestCase):
|
||||
@mock.patch("rally.plugins.openstack.osclients.Clients")
|
||||
def test_check_failed_admin(self, mock_clients):
|
||||
mock_clients.return_value.verified_keystone.side_effect = Exception
|
||||
pdata = {"admin": mock.MagicMock()}
|
||||
pdata = {"admin": {"username": "balbab", "password": "12345"}}
|
||||
result = existing.OpenStack({}, platform_data=pdata).check_health()
|
||||
self._check_health_schema(result)
|
||||
self.assertEqual(
|
||||
{"available": False,
|
||||
"message": "Bad admin creds: %s" % pdata["admin"],
|
||||
"traceback": [Exception, mock.ANY, mock.ANY]},
|
||||
"message":
|
||||
"Bad admin creds: \n%s"
|
||||
% json.dumps({"username": "balbab", "password": "***"},
|
||||
indent=2, sort_keys=True),
|
||||
"traceback": mock.ANY},
|
||||
result)
|
||||
self.assertIn("Traceback (most recent call last)", result["traceback"])
|
||||
|
||||
@mock.patch("rally.plugins.openstack.osclients.Clients")
|
||||
def test_check_failed_users(self, mock_clients):
|
||||
mock_clients.return_value.keystone.side_effect = Exception
|
||||
pdata = {"admin": None, "users": [mock.MagicMock()]}
|
||||
pdata = {"admin": None,
|
||||
"users": [{"username": "balbab", "password": "12345"}]}
|
||||
result = existing.OpenStack({}, platform_data=pdata).check_health()
|
||||
self._check_health_schema(result)
|
||||
self.assertEqual(
|
||||
{"available": False,
|
||||
"message": "Bad user creds: %s" % pdata["users"][0],
|
||||
"traceback": [Exception, mock.ANY, mock.ANY]},
|
||||
"message":
|
||||
"Bad user creds: \n%s"
|
||||
% json.dumps({"username": "balbab", "password": "***"},
|
||||
indent=2, sort_keys=True),
|
||||
"traceback": mock.ANY},
|
||||
result)
|
||||
self.assertIn("Traceback (most recent call last)", result["traceback"])
|
||||
|
||||
@mock.patch("rally.plugins.openstack.osclients.Clients")
|
||||
def test_info(self, mock_clients):
|
||||
mock_clients.return_value.list_services.return_value = ["a", "b"]
|
||||
p = existing.OpenStack({},
|
||||
platform_data={"admin": None, "users": ["u1"]})
|
||||
mock_clients.return_value.services.return_value = ["a", "b"]
|
||||
platform_data = {
|
||||
"admin": None,
|
||||
"users": [{"username": "u1", "password": "123"}]
|
||||
}
|
||||
p = existing.OpenStack({}, platform_data=platform_data)
|
||||
|
||||
result = p.info()
|
||||
mock_clients.assert_called_once_with("u1")
|
||||
mock_clients.return_value.list_services.assert_called_once_with()
|
||||
mock_clients.assert_called_once_with(platform_data["users"][0])
|
||||
mock_clients.return_value.services.assert_called_once_with()
|
||||
self.assertEqual({"info": {"services": ["a", "b"]}}, result)
|
||||
self._check_info_schema(result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user