[validators] Port validators to use context object
Change-Id: I74d46d0c4573ebb1ca33c0322d3d945ed89cd968
This commit is contained in:
parent
ada57e6704
commit
c94ee57621
@ -24,7 +24,7 @@ from rally.task import context
|
|||||||
class CheckOpenStackAPIVersionsValidator(validation.Validator):
|
class CheckOpenStackAPIVersionsValidator(validation.Validator):
|
||||||
"""Additional validation for api_versions context"""
|
"""Additional validation for api_versions context"""
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
for client in plugin_cfg:
|
for client in plugin_cfg:
|
||||||
client_cls = osclients.OSClient.get(client)
|
client_cls = osclients.OSClient.get(client)
|
||||||
try:
|
try:
|
||||||
|
@ -29,7 +29,7 @@ class CheckCleanupResourcesValidator(validation.Validator):
|
|||||||
super(CheckCleanupResourcesValidator, self).__init__()
|
super(CheckCleanupResourcesValidator, self).__init__()
|
||||||
self.admin_required = admin_required
|
self.admin_required = admin_required
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
missing = set(plugin_cfg)
|
missing = set(plugin_cfg)
|
||||||
missing -= manager.list_resource_names(
|
missing -= manager.list_resource_names(
|
||||||
admin_required=self.admin_required)
|
admin_required=self.admin_required)
|
||||||
|
@ -99,7 +99,7 @@ class ValidCommandValidator(validators.FileExistsValidator):
|
|||||||
"Unexpected command parameters: %s" % ", ".join(
|
"Unexpected command parameters: %s" % ", ".join(
|
||||||
unexpected_keys))
|
unexpected_keys))
|
||||||
|
|
||||||
def validate(self, config, credentials, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
command = config.get("args", {}).get(self.param_name)
|
command = config.get("args", {}).get(self.param_name)
|
||||||
if command is None and not self.required:
|
if command is None and not self.required:
|
||||||
return
|
return
|
||||||
|
@ -48,7 +48,7 @@ class ImageExistsValidator(validation.Validator):
|
|||||||
self.param_name = param_name
|
self.param_name = param_name
|
||||||
self.nullable = nullable
|
self.nullable = nullable
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
|
||||||
image_args = config.get("args", {}).get(self.param_name)
|
image_args = config.get("args", {}).get(self.param_name)
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ class ImageExistsValidator(validation.Validator):
|
|||||||
"regex" in image_args and match):
|
"regex" in image_args and match):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
for user in credentials["openstack"]["users"]:
|
for user in context["users"]:
|
||||||
clients = user.get("credential", {}).clients()
|
clients = user["credential"].clients()
|
||||||
image_id = openstack_types.GlanceImage.transform(
|
image_id = openstack_types.GlanceImage.transform(
|
||||||
clients=clients, resource_config=image_args)
|
clients=clients, resource_config=image_args)
|
||||||
clients.glance().images.get(image_id)
|
clients.glance().images.get(image_id)
|
||||||
@ -91,15 +91,14 @@ class ExternalNetworkExistsValidator(validation.Validator):
|
|||||||
super(ExternalNetworkExistsValidator, self).__init__()
|
super(ExternalNetworkExistsValidator, self).__init__()
|
||||||
self.param_name = param_name
|
self.param_name = param_name
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
|
||||||
ext_network = config.get("args", {}).get(self.param_name)
|
ext_network = config.get("args", {}).get(self.param_name)
|
||||||
if not ext_network:
|
if not ext_network:
|
||||||
return
|
return
|
||||||
|
|
||||||
users = credentials["openstack"]["users"]
|
|
||||||
result = []
|
result = []
|
||||||
for user in users:
|
for user in context["users"]:
|
||||||
creds = user["credential"]
|
creds = user["credential"]
|
||||||
|
|
||||||
networks = creds.clients().neutron().list_networks()["networks"]
|
networks = creds.clients().neutron().list_networks()["networks"]
|
||||||
@ -139,8 +138,8 @@ class RequiredNeutronExtensionsValidator(validation.Validator):
|
|||||||
self.req_ext = [extensions]
|
self.req_ext = [extensions]
|
||||||
self.req_ext.extend(args)
|
self.req_ext.extend(args)
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
clients = credentials["openstack"]["users"][0]["credential"].clients()
|
clients = context["users"][0]["credential"].clients()
|
||||||
extensions = clients.neutron().list_extensions()["extensions"]
|
extensions = clients.neutron().list_extensions()["extensions"]
|
||||||
aliases = [x["alias"] for x in extensions]
|
aliases = [x["alias"] for x in extensions]
|
||||||
for extension in self.req_ext:
|
for extension in self.req_ext:
|
||||||
@ -190,11 +189,10 @@ class FlavorExistsValidator(validation.Validator):
|
|||||||
pass
|
pass
|
||||||
self.fail("Flavor '%s' not found" % flavor_value)
|
self.fail("Flavor '%s' not found" % flavor_value)
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
# flavors do not depend on user or tenant, so checking for one user
|
# flavors do not depend on user or tenant, so checking for one user
|
||||||
# should be enough
|
# should be enough
|
||||||
user = credentials["openstack"]["users"][0]
|
clients = context["users"][0]["credential"].clients()
|
||||||
clients = user["credential"].clients()
|
|
||||||
self._get_validated_flavor(config=config,
|
self._get_validated_flavor(config=config,
|
||||||
clients=clients,
|
clients=clients,
|
||||||
param_name=self.param_name)
|
param_name=self.param_name)
|
||||||
@ -265,10 +263,10 @@ class ImageValidOnFlavorValidator(FlavorExistsValidator):
|
|||||||
except (glance_exc.HTTPNotFound, exceptions.InvalidScenarioArgument):
|
except (glance_exc.HTTPNotFound, exceptions.InvalidScenarioArgument):
|
||||||
self.fail("Image '%s' not found" % image_args)
|
self.fail("Image '%s' not found" % image_args)
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
|
||||||
flavor = None
|
flavor = None
|
||||||
for user in credentials["openstack"]["users"]:
|
for user in context["users"]:
|
||||||
clients = user["credential"].clients()
|
clients = user["credential"].clients()
|
||||||
|
|
||||||
if not flavor:
|
if not flavor:
|
||||||
@ -335,7 +333,7 @@ class RequiredClientsValidator(validation.Validator):
|
|||||||
"Client for {0} is not installed. To install it run "
|
"Client for {0} is not installed. To install it run "
|
||||||
"`pip install python-{0}client`".format(client_component))
|
"`pip install python-{0}client`".format(client_component))
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
LOG.warning("The validator 'required_clients' is deprecated since "
|
LOG.warning("The validator 'required_clients' is deprecated since "
|
||||||
"Rally 0.10.0. If you are interested in it, please "
|
"Rally 0.10.0. If you are interested in it, please "
|
||||||
"contact Rally team via E-mail, IRC or Gitter (see "
|
"contact Rally team via E-mail, IRC or Gitter (see "
|
||||||
@ -343,10 +341,10 @@ class RequiredClientsValidator(validation.Validator):
|
|||||||
"/index.html#where-can-i-discuss-and-propose-changes for "
|
"/index.html#where-can-i-discuss-and-propose-changes for "
|
||||||
"more details).")
|
"more details).")
|
||||||
if self.options.get("admin", False):
|
if self.options.get("admin", False):
|
||||||
clients = credentials["openstack"]["admin"].clients()
|
clients = context["admin"]["credential"].clients()
|
||||||
self._check_component(clients)
|
self._check_component(clients)
|
||||||
else:
|
else:
|
||||||
for user in credentials["openstack"]["users"]:
|
for user in context["users"]:
|
||||||
clients = user["credential"].clients()
|
clients = user["credential"].clients()
|
||||||
self._check_component(clients)
|
self._check_component(clients)
|
||||||
break
|
break
|
||||||
@ -376,9 +374,9 @@ class RequiredServicesValidator(validation.Validator):
|
|||||||
self.services = [services]
|
self.services = [services]
|
||||||
self.services.extend(args)
|
self.services.extend(args)
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
creds = (credentials["openstack"].get("admin")
|
creds = (context.get("admin", {}).get("credential", None)
|
||||||
or credentials["openstack"]["users"][0]["credential"])
|
or context["users"][0]["credential"])
|
||||||
|
|
||||||
available_services = creds.clients().services().values()
|
available_services = creds.clients().services().values()
|
||||||
if consts.Service.NOVA_NET in self.services:
|
if consts.Service.NOVA_NET in self.services:
|
||||||
@ -425,7 +423,7 @@ class ValidateHeatTemplateValidator(validation.Validator):
|
|||||||
self.params = [params]
|
self.params = [params]
|
||||||
self.params.extend(args)
|
self.params.extend(args)
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
|
||||||
for param_name in self.params:
|
for param_name in self.params:
|
||||||
template_path = config.get("args", {}).get(param_name)
|
template_path = config.get("args", {}).get(param_name)
|
||||||
@ -440,7 +438,7 @@ class ValidateHeatTemplateValidator(validation.Validator):
|
|||||||
self.fail("No file found by the given path %s" % template_path)
|
self.fail("No file found by the given path %s" % template_path)
|
||||||
with open(template_path, "r") as f:
|
with open(template_path, "r") as f:
|
||||||
try:
|
try:
|
||||||
for user in credentials["openstack"]["users"]:
|
for user in context["users"]:
|
||||||
clients = user["credential"].clients()
|
clients = user["credential"].clients()
|
||||||
clients.heat().stacks.validate(template=f.read())
|
clients.heat().stacks.validate(template=f.read())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -464,10 +462,10 @@ class RequiredCinderServicesValidator(validation.Validator):
|
|||||||
super(RequiredCinderServicesValidator, self).__init__()
|
super(RequiredCinderServicesValidator, self).__init__()
|
||||||
self.services = services
|
self.services = services
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
|
|
||||||
clients = credentials["openstack"]["admin"].clients().cinder()
|
clients = context["admin"]["credential"].clients()
|
||||||
for service in clients.services.list():
|
for service in clients.cinder().services.list():
|
||||||
if (service.binary == six.text_type(self.services)
|
if (service.binary == six.text_type(self.services)
|
||||||
and service.state == six.text_type("up")):
|
and service.state == six.text_type("up")):
|
||||||
return
|
return
|
||||||
@ -489,13 +487,13 @@ class RequiredAPIVersionsValidator(validation.Validator):
|
|||||||
self.component = component
|
self.component = component
|
||||||
self.versions = versions
|
self.versions = versions
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
versions = [str(v) for v in self.versions]
|
versions = [str(v) for v in self.versions]
|
||||||
versions_str = ", ".join(versions)
|
versions_str = ", ".join(versions)
|
||||||
msg = ("Task was designed to be used with %(component)s "
|
msg = ("Task was designed to be used with %(component)s "
|
||||||
"V%(version)s, but V%(found_version)s is "
|
"V%(version)s, but V%(found_version)s is "
|
||||||
"selected.")
|
"selected.")
|
||||||
for user in credentials["openstack"]["users"]:
|
for user in context["users"]:
|
||||||
clients = user["credential"].clients()
|
clients = user["credential"].clients()
|
||||||
if self.component == "keystone":
|
if self.component == "keystone":
|
||||||
if "2.0" not in versions and hasattr(
|
if "2.0" not in versions and hasattr(
|
||||||
@ -539,14 +537,17 @@ class VolumeTypeExistsValidator(validation.Validator):
|
|||||||
self.param = param_name
|
self.param = param_name
|
||||||
self.nullable = nullable
|
self.nullable = nullable
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
volume_type = config.get("args", {}).get(self.param, False)
|
volume_type = config.get("args", {}).get(self.param, False)
|
||||||
|
|
||||||
if not volume_type and self.nullable:
|
if not volume_type and self.nullable:
|
||||||
return
|
return
|
||||||
|
|
||||||
if volume_type:
|
if not volume_type:
|
||||||
for user in credentials["openstack"]["users"]:
|
self.fail("The parameter '%s' is required and should not be empty."
|
||||||
|
% self.param)
|
||||||
|
|
||||||
|
for user in context["users"]:
|
||||||
clients = user["credential"].clients()
|
clients = user["credential"].clients()
|
||||||
vt_names = [vt.name for vt in
|
vt_names = [vt.name for vt in
|
||||||
clients.cinder().volume_types.list()]
|
clients.cinder().volume_types.list()]
|
||||||
@ -556,9 +557,6 @@ class VolumeTypeExistsValidator(validation.Validator):
|
|||||||
self.fail("Specified volume type %s not found for user %s."
|
self.fail("Specified volume type %s not found for user %s."
|
||||||
" List of available types: %s" %
|
" List of available types: %s" %
|
||||||
(volume_type, user, vt_names))
|
(volume_type, user, vt_names))
|
||||||
else:
|
|
||||||
self.fail("The parameter '%s' is required and should not be empty."
|
|
||||||
% self.param)
|
|
||||||
|
|
||||||
|
|
||||||
@validation.configure(name="workbook_contains_workflow", platform="openstack")
|
@validation.configure(name="workbook_contains_workflow", platform="openstack")
|
||||||
@ -574,7 +572,7 @@ class WorkbookContainsWorkflowValidator(validators.FileExistsValidator):
|
|||||||
self.workbook = workbook_param
|
self.workbook = workbook_param
|
||||||
self.workflow = workflow_param
|
self.workflow = workflow_param
|
||||||
|
|
||||||
def validate(self, credentials, config, plugin_cls, plugin_cfg):
|
def validate(self, context, config, plugin_cls, plugin_cfg):
|
||||||
wf_name = config.get("args", {}).get(self.workflow)
|
wf_name = config.get("args", {}).get(self.workflow)
|
||||||
if wf_name:
|
if wf_name:
|
||||||
wb_path = config.get("args", {}).get(self.workbook)
|
wb_path = config.get("args", {}).get(self.workbook)
|
||||||
|
@ -294,8 +294,8 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ValidCommandValidatorTestCase, self).setUp()
|
super(ValidCommandValidatorTestCase, self).setUp()
|
||||||
self.credentials = dict(openstack={"admin": mock.MagicMock(),
|
self.context = {"admin": {"credential": mock.MagicMock()},
|
||||||
"users": [mock.MagicMock()], })
|
"users": [{"credential": mock.MagicMock()}]}
|
||||||
|
|
||||||
@ddt.data({"command": {"script_inline": "foobar",
|
@ddt.data({"command": {"script_inline": "foobar",
|
||||||
"interpreter": ["ENV=bar", "/bin/foo"],
|
"interpreter": ["ENV=bar", "/bin/foo"],
|
||||||
@ -341,8 +341,8 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
required=True)
|
required=True)
|
||||||
mock__file_access_ok.return_value = None
|
mock__file_access_ok.return_value = None
|
||||||
command = {"script_file": "foobar", "interpreter": "foo"}
|
command = {"script_file": "foobar", "interpreter": "foo"}
|
||||||
result = validator.validate({"args": {"p": command}},
|
result = validator.validate(self.context, {"args": {"p": command}},
|
||||||
self.credentials, None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
mock__file_access_ok.assert_called_once_with(
|
mock__file_access_ok.assert_called_once_with(
|
||||||
filename="foobar", mode=os.R_OK, param_name="p",
|
filename="foobar", mode=os.R_OK, param_name="p",
|
||||||
@ -351,8 +351,8 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
def test_valid_command_not_required(self):
|
def test_valid_command_not_required(self):
|
||||||
validator = vmtasks.ValidCommandValidator(param_name="p",
|
validator = vmtasks.ValidCommandValidator(param_name="p",
|
||||||
required=False)
|
required=False)
|
||||||
result = validator.validate({"args": {"p": None}},
|
result = validator.validate(self.context, {"args": {"p": None}},
|
||||||
self.credentials, None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_valid_command_required(self):
|
def test_valid_command_required(self):
|
||||||
@ -362,7 +362,7 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validation.ValidationError,
|
validation.ValidationError,
|
||||||
validator.validate, {"args": {"p": None}},
|
validator.validate, {"args": {"p": None}},
|
||||||
self.credentials, None, None)
|
self.context, None, None)
|
||||||
self.assertEqual("Command must be a dictionary", e.message)
|
self.assertEqual("Command must be a dictionary", e.message)
|
||||||
|
|
||||||
@mock.patch("rally.plugins.common.validators.FileExistsValidator"
|
@mock.patch("rally.plugins.common.validators.FileExistsValidator"
|
||||||
@ -376,8 +376,8 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
command = {"script_file": "foobar", "interpreter": "foo"}
|
command = {"script_file": "foobar", "interpreter": "foo"}
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validation.ValidationError,
|
validation.ValidationError,
|
||||||
validator.validate, {"args": {"p": command}},
|
validator.validate, self.context, {"args": {"p": command}},
|
||||||
self.credentials, None, None)
|
None, None)
|
||||||
self.assertEqual("O_o", e.message)
|
self.assertEqual("O_o", e.message)
|
||||||
|
|
||||||
@mock.patch("%s.ValidCommandValidator.check_command_dict" % BASE)
|
@mock.patch("%s.ValidCommandValidator.check_command_dict" % BASE)
|
||||||
@ -391,7 +391,7 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validation.ValidationError,
|
validation.ValidationError,
|
||||||
validator.validate, {"args": {"p": {"foo": "bar"}}},
|
validator.validate, {"args": {"p": {"foo": "bar"}}},
|
||||||
self.credentials, None, None)
|
self.context, None, None)
|
||||||
self.assertEqual("foobar", e.message)
|
self.assertEqual("foobar", e.message)
|
||||||
|
|
||||||
def test_valid_command_script_inline(self):
|
def test_valid_command_script_inline(self):
|
||||||
@ -399,7 +399,7 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
command = {"script_inline": "bar", "interpreter": "/bin/sh"}
|
command = {"script_inline": "bar", "interpreter": "/bin/sh"}
|
||||||
result = validator.validate({"args": {"p": command}}, self.credentials,
|
result = validator.validate(self.context, {"args": {"p": command}},
|
||||||
None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ class ValidCommandValidatorTestCase(test.TestCase):
|
|||||||
command = {"remote_path": "bar", "local_path": "foobar"}
|
command = {"remote_path": "bar", "local_path": "foobar"}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
validation.ValidationError,
|
validation.ValidationError,
|
||||||
validator.validate, {"args": {"p": command}}, self.credentials,
|
validator.validate, self.context, {"args": {"p": command}},
|
||||||
None, None)
|
None, None)
|
||||||
mock__file_access_ok.assert_called_once_with(
|
mock__file_access_ok.assert_called_once_with(
|
||||||
filename="foobar", mode=os.R_OK, param_name="p",
|
filename="foobar", mode=os.R_OK, param_name="p",
|
||||||
|
@ -29,11 +29,9 @@ from tests.unit import test
|
|||||||
PATH = "rally.plugins.openstack.validators"
|
PATH = "rally.plugins.openstack.validators"
|
||||||
|
|
||||||
|
|
||||||
credentials = {
|
context = {
|
||||||
"openstack": {
|
|
||||||
"admin": mock.MagicMock(),
|
"admin": mock.MagicMock(),
|
||||||
"users": [mock.MagicMock()],
|
"users": [mock.MagicMock()],
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config = dict(args={"image": {"id": "fake_id",
|
config = dict(args={"image": {"id": "fake_id",
|
||||||
@ -57,7 +55,7 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
super(ImageExistsValidatorTestCase, self).setUp()
|
super(ImageExistsValidatorTestCase, self).setUp()
|
||||||
self.validator = validators.ImageExistsValidator("image", True)
|
self.validator = validators.ImageExistsValidator("image", True)
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
@ -70,8 +68,7 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.ImageExistsValidator(param_name,
|
validator = validators.ImageExistsValidator(param_name,
|
||||||
nullable)
|
nullable)
|
||||||
|
|
||||||
clients = self.credentials[
|
clients = self.context["users"][0].clients.return_value
|
||||||
"openstack"]["users"][0].clients.return_value
|
|
||||||
|
|
||||||
clients.glance().images.get = mock.Mock()
|
clients.glance().images.get = mock.Mock()
|
||||||
if ex:
|
if ex:
|
||||||
@ -80,10 +77,10 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
if err_msg:
|
if err_msg:
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual(err_msg, e.message)
|
self.assertEqual(err_msg, e.message)
|
||||||
else:
|
else:
|
||||||
result = validator.validate(self.config, self.credentials, None,
|
result = validator.validate(self.config, self.context, None,
|
||||||
None)
|
None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -93,7 +90,7 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
"images": {
|
"images": {
|
||||||
"image_name": "foo"}}}
|
"image_name": "foo"}}}
|
||||||
|
|
||||||
self.validator.validate(self.credentials, config, None, None)
|
self.validator.validate(self.context, config, None, None)
|
||||||
|
|
||||||
@mock.patch("%s.openstack_types.GlanceImage.transform" % PATH,
|
@mock.patch("%s.openstack_types.GlanceImage.transform" % PATH,
|
||||||
return_value="image_id")
|
return_value="image_id")
|
||||||
@ -103,11 +100,11 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
"images": {
|
"images": {
|
||||||
"fake_image_name": "foo"}}}
|
"fake_image_name": "foo"}}}
|
||||||
|
|
||||||
clients = self.credentials[
|
clients = self.context[
|
||||||
"openstack"]["users"][0].get.return_value.clients.return_value
|
"users"][0]["credential"].clients.return_value
|
||||||
clients.glance().images.get = mock.Mock()
|
clients.glance().images.get = mock.Mock()
|
||||||
|
|
||||||
result = self.validator.validate(self.credentials, config, None, None)
|
result = self.validator.validate(self.context, config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
mock_glance_image_transform.assert_called_once_with(
|
mock_glance_image_transform.assert_called_once_with(
|
||||||
@ -121,7 +118,7 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, self.credentials, config, None, None)
|
self.validator.validate, self.context, config, None, None)
|
||||||
|
|
||||||
self.assertEqual("Image 'fake_image' not found", e.message)
|
self.assertEqual("Image 'fake_image' not found", e.message)
|
||||||
|
|
||||||
@ -133,7 +130,7 @@ class ExternalNetworkExistsValidatorTestCase(test.TestCase):
|
|||||||
super(ExternalNetworkExistsValidatorTestCase, self).setUp()
|
super(ExternalNetworkExistsValidatorTestCase, self).setUp()
|
||||||
self.validator = validators.ExternalNetworkExistsValidator("net")
|
self.validator = validators.ExternalNetworkExistsValidator("net")
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
@ -153,7 +150,7 @@ class ExternalNetworkExistsValidatorTestCase(test.TestCase):
|
|||||||
def test_validator(self, foo_conf, net1_name="public", net2_name="custom",
|
def test_validator(self, foo_conf, net1_name="public", net2_name="custom",
|
||||||
err_msg=""):
|
err_msg=""):
|
||||||
|
|
||||||
user = self.credentials["openstack"]["users"][0]
|
user = self.context["users"][0]
|
||||||
|
|
||||||
net1 = {"name": net1_name, "router:external": True}
|
net1 = {"name": net1_name, "router:external": True}
|
||||||
net2 = {"name": net2_name, "router:external": True}
|
net2 = {"name": net2_name, "router:external": True}
|
||||||
@ -163,13 +160,13 @@ class ExternalNetworkExistsValidatorTestCase(test.TestCase):
|
|||||||
if err_msg:
|
if err_msg:
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, self.credentials, foo_conf,
|
self.validator.validate, self.context, foo_conf,
|
||||||
None, None)
|
None, None)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
err_msg.format(user["credential"].username, net1, net2),
|
err_msg.format(user["credential"].username, net1, net2),
|
||||||
e.message)
|
e.message)
|
||||||
else:
|
else:
|
||||||
result = self.validator.validate(self.credentials, foo_conf,
|
result = self.validator.validate(self.context, foo_conf,
|
||||||
None, None)
|
None, None)
|
||||||
self.assertIsNone(result, "Unexpected result '%s'" % result)
|
self.assertIsNone(result, "Unexpected result '%s'" % result)
|
||||||
|
|
||||||
@ -180,32 +177,30 @@ class RequiredNeutronExtensionsValidatorTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RequiredNeutronExtensionsValidatorTestCase, self).setUp()
|
super(RequiredNeutronExtensionsValidatorTestCase, self).setUp()
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
def test_validator(self):
|
def test_validator(self):
|
||||||
validator = validators.RequiredNeutronExtensionsValidator(
|
validator = validators.RequiredNeutronExtensionsValidator(
|
||||||
"existing_extension")
|
"existing_extension")
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.neutron().list_extensions.return_value = {
|
clients.neutron().list_extensions.return_value = {
|
||||||
"extensions": [{"alias": "existing_extension"}]}
|
"extensions": [{"alias": "existing_extension"}]}
|
||||||
|
|
||||||
validator.validate(self.credentials, {}, None, None)
|
validator.validate(self.context, {}, None, None)
|
||||||
|
|
||||||
def test_validator_failed(self):
|
def test_validator_failed(self):
|
||||||
err_msg = "Neutron extension absent_extension is not configured"
|
err_msg = "Neutron extension absent_extension is not configured"
|
||||||
validator = validators.RequiredNeutronExtensionsValidator(
|
validator = validators.RequiredNeutronExtensionsValidator(
|
||||||
"absent_extension")
|
"absent_extension")
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.neutron().list_extensions.return_value = {
|
clients.neutron().list_extensions.return_value = {
|
||||||
"extensions": [{"alias": "existing_extension"}]}
|
"extensions": [{"alias": "existing_extension"}]}
|
||||||
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None)
|
validator.validate, self.context, {}, None, None)
|
||||||
self.assertEqual(err_msg, e.message)
|
self.assertEqual(err_msg, e.message)
|
||||||
|
|
||||||
|
|
||||||
@ -216,13 +211,13 @@ class FlavorExistsValidatorTestCase(test.TestCase):
|
|||||||
self.validator = validators.FlavorExistsValidator(
|
self.validator = validators.FlavorExistsValidator(
|
||||||
param_name="foo_flavor")
|
param_name="foo_flavor")
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
def test__get_validated_flavor_wrong_value_in_config(self):
|
def test__get_validated_flavor_wrong_value_in_config(self):
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator._get_validated_flavor, self.config,
|
self.validator._get_validated_flavor, self.config,
|
||||||
self.credentials, "foo_flavor")
|
mock.MagicMock(), "foo_flavor")
|
||||||
self.assertEqual("Parameter foo_flavor is not specified.",
|
self.assertEqual("Parameter foo_flavor is not specified.",
|
||||||
e.message)
|
e.message)
|
||||||
|
|
||||||
@ -290,14 +285,14 @@ class FlavorExistsValidatorTestCase(test.TestCase):
|
|||||||
side_effect=expected_e)
|
side_effect=expected_e)
|
||||||
|
|
||||||
config = mock.Mock()
|
config = mock.Mock()
|
||||||
creds = mock.MagicMock()
|
ctx = mock.MagicMock()
|
||||||
actual_e = self.assertRaises(
|
actual_e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, creds, config, None, None)
|
self.validator.validate, ctx, config, None, None)
|
||||||
self.assertEqual(expected_e, actual_e)
|
self.assertEqual(expected_e, actual_e)
|
||||||
self.validator._get_validated_flavor.assert_called_once_with(
|
self.validator._get_validated_flavor.assert_called_once_with(
|
||||||
config=config,
|
config=config,
|
||||||
clients=creds["openstack"]["users"][0]["credential"].clients(),
|
clients=ctx["users"][0]["credential"].clients(),
|
||||||
param_name=self.validator.param_name)
|
param_name=self.validator.param_name)
|
||||||
|
|
||||||
|
|
||||||
@ -309,7 +304,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
self.validator = validators.ImageValidOnFlavorValidator("foo_flavor",
|
self.validator = validators.ImageValidOnFlavorValidator("foo_flavor",
|
||||||
"image")
|
"image")
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
{"validate_disk": True, "flavor_disk": True},
|
{"validate_disk": True, "flavor_disk": True},
|
||||||
@ -339,20 +334,19 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
# case 1: no image, but it is ok, since fail_on_404_image is False
|
# case 1: no image, but it is ok, since fail_on_404_image is False
|
||||||
validator._get_validated_image = mock.Mock(
|
validator._get_validated_image = mock.Mock(
|
||||||
side_effect=validators.validation.ValidationError("!!!"))
|
side_effect=validators.validation.ValidationError("!!!"))
|
||||||
validator.validate(self.credentials, {}, None, None)
|
validator.validate(self.context, {}, None, None)
|
||||||
|
|
||||||
# case 2: there is an image
|
# case 2: there is an image
|
||||||
validator._get_validated_image = mock.Mock(
|
validator._get_validated_image = mock.Mock(
|
||||||
return_value=fake_image)
|
return_value=fake_image)
|
||||||
validator.validate(self.credentials, {}, None, None)
|
validator.validate(self.context, {}, None, None)
|
||||||
|
|
||||||
# case 3: check caching of the flavor
|
# case 3: check caching of the flavor
|
||||||
user = self.credentials["openstack"]["users"][0]
|
self.context["users"].append(self.context["users"][0])
|
||||||
self.credentials["openstack"]["users"].append(user)
|
|
||||||
validator._get_validated_image.reset_mock()
|
validator._get_validated_image.reset_mock()
|
||||||
validator._get_validated_flavor.reset_mock()
|
validator._get_validated_flavor.reset_mock()
|
||||||
|
|
||||||
validator.validate(self.credentials, {}, None, None)
|
validator.validate(self.context, {}, None, None)
|
||||||
|
|
||||||
self.assertEqual(1, validator._get_validated_flavor.call_count)
|
self.assertEqual(1, validator._get_validated_flavor.call_count)
|
||||||
self.assertEqual(2, validator._get_validated_image.call_count)
|
self.assertEqual(2, validator._get_validated_image.call_count)
|
||||||
@ -378,7 +372,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
side_effect=expected_e)
|
side_effect=expected_e)
|
||||||
actual_e = self.assertRaises(
|
actual_e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
self.assertEqual(expected_e, actual_e)
|
self.assertEqual(expected_e, actual_e)
|
||||||
|
|
||||||
@ -387,7 +381,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
validator._get_validated_flavor.side_effect = expected_e
|
validator._get_validated_flavor.side_effect = expected_e
|
||||||
actual_e = self.assertRaises(
|
actual_e = self.assertRaises(
|
||||||
KeyError,
|
KeyError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
self.assertEqual(expected_e, actual_e)
|
self.assertEqual(expected_e, actual_e)
|
||||||
|
|
||||||
@ -400,7 +394,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
return_value=fake_image)
|
return_value=fake_image)
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"The memory size for flavor 'flavor_id' is too small for "
|
"The memory size for flavor 'flavor_id' is too small for "
|
||||||
@ -414,7 +408,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
return_value=fake_image)
|
return_value=fake_image)
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"The disk size for flavor 'flavor_id' is too small for "
|
"The disk size for flavor 'flavor_id' is too small for "
|
||||||
@ -429,7 +423,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
return_value=fake_image)
|
return_value=fake_image)
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"The minimal disk size for flavor 'flavor_id' is too small for "
|
"The minimal disk size for flavor 'flavor_id' is too small for "
|
||||||
@ -449,7 +443,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
actual_e = self.assertRaises(
|
actual_e = self.assertRaises(
|
||||||
KeyError,
|
KeyError,
|
||||||
validator.validate, self.credentials, {}, None, None
|
validator.validate, self.context, {}, None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(expected_e, actual_e)
|
self.assertEqual(expected_e, actual_e)
|
||||||
@ -467,7 +461,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
"image": {"regex": r"^foo$"}}, "context": {
|
"image": {"regex": r"^foo$"}}, "context": {
|
||||||
"images": {
|
"images": {
|
||||||
"image_name": "foo"}
|
"image_name": "foo"}
|
||||||
}}, self.credentials, "image")
|
}}, mock.Mock(), "image")
|
||||||
self.assertEqual(image, result)
|
self.assertEqual(image, result)
|
||||||
|
|
||||||
clients = mock.Mock()
|
clients = mock.Mock()
|
||||||
@ -491,7 +485,7 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
|
|||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator._get_validated_image, self.config,
|
self.validator._get_validated_image, self.config,
|
||||||
self.credentials, "fake_param")
|
mock.Mock(), "fake_param")
|
||||||
self.assertEqual("Parameter fake_param is not specified.",
|
self.assertEqual("Parameter fake_param is not specified.",
|
||||||
e.message)
|
e.message)
|
||||||
|
|
||||||
@ -546,21 +540,20 @@ class RequiredClientsValidatorTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RequiredClientsValidatorTestCase, self).setUp()
|
super(RequiredClientsValidatorTestCase, self).setUp()
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
def test_validate(self):
|
def test_validate(self):
|
||||||
validator = validators.RequiredClientsValidator(components=["keystone",
|
validator = validators.RequiredClientsValidator(components=["keystone",
|
||||||
"nova"])
|
"nova"])
|
||||||
clients = self.credentials[
|
clients = self.context["users"][0]["credential"].clients.return_value
|
||||||
"openstack"]["users"][0]["credential"].clients.return_value
|
|
||||||
|
|
||||||
result = validator.validate(self.credentials, self.config, None, None)
|
result = validator.validate(self.context, self.config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
clients.nova.side_effect = ImportError
|
clients.nova.side_effect = ImportError
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual("Client for nova is not installed. To install it "
|
self.assertEqual("Client for nova is not installed. To install it "
|
||||||
"run `pip install python-novaclient`", e.message)
|
"run `pip install python-novaclient`", e.message)
|
||||||
|
|
||||||
@ -568,15 +561,14 @@ class RequiredClientsValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.RequiredClientsValidator(components=["keystone",
|
validator = validators.RequiredClientsValidator(components=["keystone",
|
||||||
"nova"],
|
"nova"],
|
||||||
admin=True)
|
admin=True)
|
||||||
clients = self.credentials[
|
clients = self.context["admin"]["credential"].clients.return_value
|
||||||
"openstack"]["admin"].clients.return_value
|
result = validator.validate(self.context, self.config, None, None)
|
||||||
result = validator.validate(self.credentials, self.config, None, None)
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
clients.keystone.side_effect = ImportError
|
clients.keystone.side_effect = ImportError
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual("Client for keystone is not installed. To install it "
|
self.assertEqual("Client for keystone is not installed. To install it "
|
||||||
"run `pip install python-keystoneclient`", e.message)
|
"run `pip install python-keystoneclient`", e.message)
|
||||||
|
|
||||||
@ -590,33 +582,33 @@ class RequiredServicesValidatorTestCase(test.TestCase):
|
|||||||
consts.Service.NOVA,
|
consts.Service.NOVA,
|
||||||
consts.Service.NOVA_NET])
|
consts.Service.NOVA_NET])
|
||||||
self.config = config
|
self.config = config
|
||||||
self.credentials = credentials
|
self.context = context
|
||||||
|
|
||||||
def test_validator(self):
|
def test_validator(self):
|
||||||
|
|
||||||
self.config["context"]["api_versions@openstack"].get = mock.Mock(
|
self.config["context"]["api_versions@openstack"].get = mock.Mock(
|
||||||
return_value={consts.Service.KEYSTONE: "service_type"})
|
return_value={consts.Service.KEYSTONE: "service_type"})
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["admin"].clients()
|
clients = self.context["admin"].get("credential").clients()
|
||||||
|
|
||||||
clients.services().values.return_value = [
|
clients.services().values.return_value = [
|
||||||
consts.Service.KEYSTONE, consts.Service.NOVA,
|
consts.Service.KEYSTONE, consts.Service.NOVA,
|
||||||
consts.Service.NOVA_NET]
|
consts.Service.NOVA_NET]
|
||||||
fake_service = mock.Mock(binary="nova-network", status="enabled")
|
fake_service = mock.Mock(binary="nova-network", status="enabled")
|
||||||
clients.nova.services.list.return_value = [fake_service]
|
clients.nova.services.list.return_value = [fake_service]
|
||||||
result = self.validator.validate(self.credentials, self.config,
|
result = self.validator.validate(self.context, self.config,
|
||||||
None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
fake_service = mock.Mock(binary="keystone", status="enabled")
|
fake_service = mock.Mock(binary="keystone", status="enabled")
|
||||||
clients.nova.services.list.return_value = [fake_service]
|
clients.nova.services.list.return_value = [fake_service]
|
||||||
result = self.validator.validate(self.credentials, self.config,
|
result = self.validator.validate(self.context, self.config,
|
||||||
None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
fake_service = mock.Mock(binary="nova-network", status="disabled")
|
fake_service = mock.Mock(binary="nova-network", status="disabled")
|
||||||
clients.nova.services.list.return_value = [fake_service]
|
clients.nova.services.list.return_value = [fake_service]
|
||||||
result = self.validator.validate(self.credentials, self.config,
|
result = self.validator.validate(self.context, self.config,
|
||||||
None, None)
|
None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -626,7 +618,7 @@ class RequiredServicesValidatorTestCase(test.TestCase):
|
|||||||
return_value={consts.Service.KEYSTONE: "service_type",
|
return_value={consts.Service.KEYSTONE: "service_type",
|
||||||
consts.Service.NOVA: "service_name"})
|
consts.Service.NOVA: "service_name"})
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["admin"].clients()
|
clients = self.context["admin"].get("credential").clients()
|
||||||
clients.services().values.return_value = [
|
clients.services().values.return_value = [
|
||||||
consts.Service.KEYSTONE, consts.Service.NOVA]
|
consts.Service.KEYSTONE, consts.Service.NOVA]
|
||||||
|
|
||||||
@ -636,7 +628,7 @@ class RequiredServicesValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, {}, None, None)
|
validator.validate, self.context, {}, None, None)
|
||||||
expected_msg = ("'{0}' service is not available. Hint: If '{0}'"
|
expected_msg = ("'{0}' service is not available. Hint: If '{0}'"
|
||||||
" service has non-default service_type, try to setup"
|
" service has non-default service_type, try to setup"
|
||||||
" it via 'api_versions' context.").format("lol")
|
" it via 'api_versions' context.").format("lol")
|
||||||
@ -651,7 +643,7 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
self.validator = validators.ValidateHeatTemplateValidator(
|
self.validator = validators.ValidateHeatTemplateValidator(
|
||||||
"template_path1", "template_path2")
|
"template_path1", "template_path2")
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
{"exception_msg": "Heat template validation failed on fake_path1. "
|
{"exception_msg": "Heat template validation failed on fake_path1. "
|
||||||
@ -664,8 +656,7 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
@mock.patch("rally.plugins.openstack.validators.open",
|
@mock.patch("rally.plugins.openstack.validators.open",
|
||||||
side_effect=mock.mock_open(), create=True)
|
side_effect=mock.mock_open(), create=True)
|
||||||
def test_validate(self, mock_open, mock_exists, exception_msg):
|
def test_validate(self, mock_open, mock_exists, exception_msg):
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
mock_open().__enter__().read.side_effect = ["fake_template1",
|
mock_open().__enter__().read.side_effect = ["fake_template1",
|
||||||
"fake_template2"]
|
"fake_template2"]
|
||||||
heat_validator = mock.MagicMock()
|
heat_validator = mock.MagicMock()
|
||||||
@ -675,8 +666,7 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
context = {"args": {"template_path1": "fake_path1",
|
context = {"args": {"template_path1": "fake_path1",
|
||||||
"template_path2": "fake_path2"}}
|
"template_path2": "fake_path2"}}
|
||||||
if not exception_msg:
|
if not exception_msg:
|
||||||
result = self.validator.validate(self.credentials, context, None,
|
result = self.validator.validate(self.context, context, None, None)
|
||||||
None)
|
|
||||||
|
|
||||||
heat_validator.assert_has_calls([
|
heat_validator.assert_has_calls([
|
||||||
mock.call(template="fake_template1"),
|
mock.call(template="fake_template1"),
|
||||||
@ -690,7 +680,7 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
else:
|
else:
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, self.credentials, context, None, None)
|
self.validator.validate, self.context, context, None, None)
|
||||||
heat_validator.assert_called_once_with(
|
heat_validator.assert_called_once_with(
|
||||||
template="fake_template1")
|
template="fake_template1")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -703,7 +693,7 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
|
|
||||||
expected_msg = ("Path to heat template is not specified. Its needed "
|
expected_msg = ("Path to heat template is not specified. Its needed "
|
||||||
"for heat template validation. Please check the "
|
"for heat template validation. Please check the "
|
||||||
@ -713,11 +703,11 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||||||
@mock.patch("%s.os.path.exists" % PATH,
|
@mock.patch("%s.os.path.exists" % PATH,
|
||||||
return_value=False)
|
return_value=False)
|
||||||
def test_validate_file_not_found(self, mock_exists):
|
def test_validate_file_not_found(self, mock_exists):
|
||||||
context = {"args": {"template_path1": "fake_path1",
|
config = {"args": {"template_path1": "fake_path1",
|
||||||
"template_path2": "fake_path2"}}
|
"template_path2": "fake_path2"}}
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, self.credentials, context, None, None)
|
self.validator.validate, self.context, config, None, None)
|
||||||
expected_msg = "No file found by the given path fake_path1"
|
expected_msg = "No file found by the given path fake_path1"
|
||||||
self.assertEqual(expected_msg, e.message)
|
self.assertEqual(expected_msg, e.message)
|
||||||
|
|
||||||
@ -726,7 +716,7 @@ class RequiredCinderServicesValidatorTestCase(test.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RequiredCinderServicesValidatorTestCase, self).setUp()
|
super(RequiredCinderServicesValidatorTestCase, self).setUp()
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
|
|
||||||
def test_validate(self):
|
def test_validate(self):
|
||||||
@ -734,15 +724,15 @@ class RequiredCinderServicesValidatorTestCase(test.TestCase):
|
|||||||
"cinder_service")
|
"cinder_service")
|
||||||
|
|
||||||
fake_service = mock.Mock(binary="cinder_service", state="up")
|
fake_service = mock.Mock(binary="cinder_service", state="up")
|
||||||
clients = self.credentials["openstack"]["admin"].clients()
|
clients = self.context["admin"]["credential"].clients()
|
||||||
clients.cinder().services.list.return_value = [fake_service]
|
clients.cinder().services.list.return_value = [fake_service]
|
||||||
result = validator.validate(self.credentials, self.config, None, None)
|
result = validator.validate(self.context, self.config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
fake_service.state = "down"
|
fake_service.state = "down"
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual("cinder_service service is not available",
|
self.assertEqual("cinder_service service is not available",
|
||||||
e.message)
|
e.message)
|
||||||
|
|
||||||
@ -753,7 +743,7 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RequiredAPIVersionsValidatorTestCase, self).setUp()
|
super(RequiredAPIVersionsValidatorTestCase, self).setUp()
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
def _get_keystone_v2_mock_client(self):
|
def _get_keystone_v2_mock_client(self):
|
||||||
keystone = mock.Mock()
|
keystone = mock.Mock()
|
||||||
@ -771,28 +761,26 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.RequiredAPIVersionsValidator("keystone",
|
validator = validators.RequiredAPIVersionsValidator("keystone",
|
||||||
[2.0, 3])
|
[2.0, 3])
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
||||||
validator.validate(self.credentials, self.config, None, None)
|
validator.validate(self.context, self.config, None, None)
|
||||||
|
|
||||||
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
||||||
validator.validate(self.credentials, self.config, None, None)
|
validator.validate(self.context, self.config, None, None)
|
||||||
|
|
||||||
def test_validate_with_keystone_v2(self):
|
def test_validate_with_keystone_v2(self):
|
||||||
validator = validators.RequiredAPIVersionsValidator("keystone",
|
validator = validators.RequiredAPIVersionsValidator("keystone",
|
||||||
[2.0])
|
[2.0])
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
||||||
validator.validate(self.credentials, self.config, None, None)
|
validator.validate(self.context, self.config, None, None)
|
||||||
|
|
||||||
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual("Task was designed to be used with keystone V2.0, "
|
self.assertEqual("Task was designed to be used with keystone V2.0, "
|
||||||
"but V3 is selected.", e.message)
|
"but V3 is selected.", e.message)
|
||||||
|
|
||||||
@ -800,15 +788,14 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.RequiredAPIVersionsValidator("keystone",
|
validator = validators.RequiredAPIVersionsValidator("keystone",
|
||||||
[3])
|
[3])
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
clients.keystone.return_value = self._get_keystone_v3_mock_client()
|
||||||
validator.validate(self.credentials, self.config, None, None)
|
validator.validate(self.context, self.config, None, None)
|
||||||
|
|
||||||
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
clients.keystone.return_value = self._get_keystone_v2_mock_client()
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual("Task was designed to be used with keystone V3, "
|
self.assertEqual("Task was designed to be used with keystone V3, "
|
||||||
"but V2.0 is selected.", e.message)
|
"but V2.0 is selected.", e.message)
|
||||||
|
|
||||||
@ -829,8 +816,7 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.RequiredAPIVersionsValidator("nova",
|
validator = validators.RequiredAPIVersionsValidator("nova",
|
||||||
versions)
|
versions)
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.nova.choose_version.return_value = nova
|
clients.nova.choose_version.return_value = nova
|
||||||
config = {"context": {"api_versions@openstack": {}}}
|
config = {"context": {"api_versions@openstack": {}}}
|
||||||
@ -838,10 +824,10 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
if err_msg:
|
if err_msg:
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, config, None, None)
|
validator.validate, self.context, config, None, None)
|
||||||
self.assertEqual(err_msg, e.message)
|
self.assertEqual(err_msg, e.message)
|
||||||
else:
|
else:
|
||||||
result = validator.validate(self.credentials, config, None, None)
|
result = validator.validate(self.context, config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
@ -858,10 +844,10 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
|
|||||||
if err_msg:
|
if err_msg:
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, config, None, None)
|
validator.validate, self.context, config, None, None)
|
||||||
self.assertEqual(err_msg, e.message)
|
self.assertEqual(err_msg, e.message)
|
||||||
else:
|
else:
|
||||||
result = validator.validate(self.credentials, config, None, None)
|
result = validator.validate(self.context, config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
@ -872,70 +858,61 @@ class VolumeTypeExistsValidatorTestCase(test.TestCase):
|
|||||||
self.validator = validators.VolumeTypeExistsValidator("volume_type",
|
self.validator = validators.VolumeTypeExistsValidator("volume_type",
|
||||||
True)
|
True)
|
||||||
self.config = copy.deepcopy(config)
|
self.config = copy.deepcopy(config)
|
||||||
self.credentials = copy.deepcopy(credentials)
|
self.context = copy.deepcopy(context)
|
||||||
|
|
||||||
def test_validator_without_ctx(self):
|
def test_validator_without_ctx(self):
|
||||||
validator = validators.VolumeTypeExistsValidator("fake_param",
|
validator = validators.VolumeTypeExistsValidator("fake_param",
|
||||||
nullable=True)
|
nullable=True)
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.cinder().volume_types.list.return_value = [mock.MagicMock()]
|
clients.cinder().volume_types.list.return_value = [mock.MagicMock()]
|
||||||
|
|
||||||
result = validator.validate(self.credentials, self.config, None, None)
|
result = validator.validate(self.context, self.config, None, None)
|
||||||
self.assertIsNone(result, "Unexpected result")
|
self.assertIsNone(result, "Unexpected result")
|
||||||
|
|
||||||
def test_validator_without_ctx_failed(self):
|
def test_validator_without_ctx_failed(self):
|
||||||
validator = validators.VolumeTypeExistsValidator("fake_param",
|
validator = validators.VolumeTypeExistsValidator("fake_param",
|
||||||
nullable=False)
|
nullable=False)
|
||||||
|
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
|
|
||||||
clients.cinder().volume_types.list.return_value = [mock.MagicMock()]
|
clients.cinder().volume_types.list.return_value = [mock.MagicMock()]
|
||||||
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
validator.validate, self.credentials, self.config, None, None)
|
validator.validate, self.context, self.config, None, None)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"The parameter 'fake_param' is required and should not be empty.",
|
"The parameter 'fake_param' is required and should not be empty.",
|
||||||
e.message)
|
e.message)
|
||||||
|
|
||||||
def test_validate_with_ctx(self):
|
def test_validate_with_ctx(self):
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
clients.cinder().volume_types.list.return_value = []
|
clients.cinder().volume_types.list.return_value = []
|
||||||
ctx = {"args": {"volume_type": "fake_type"},
|
ctx = {"args": {"volume_type": "fake_type"},
|
||||||
"context": {"volume_types": ["fake_type"]}}
|
"context": {"volume_types": ["fake_type"]}}
|
||||||
result = self.validator.validate(self.credentials, ctx, None, None)
|
result = self.validator.validate(self.context, ctx, None, None)
|
||||||
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_validate_with_ctx_failed(self):
|
def test_validate_with_ctx_failed(self):
|
||||||
clients = self.credentials["openstack"]["users"][0][
|
clients = self.context["users"][0]["credential"].clients()
|
||||||
"credential"].clients()
|
|
||||||
clients.cinder().volume_types.list.return_value = []
|
clients.cinder().volume_types.list.return_value = []
|
||||||
ctx = {"args": {"volume_type": "fake_type"},
|
config = {"args": {"volume_type": "fake_type"},
|
||||||
"context": {"volume_types": ["fake_type_2"]}}
|
"context": {"volume_types": ["fake_type_2"]}}
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
validators.validation.ValidationError,
|
validators.validation.ValidationError,
|
||||||
self.validator.validate, self.credentials, ctx, None, None)
|
self.validator.validate, self.context, config, None, None)
|
||||||
|
|
||||||
err_msg = ("Specified volume type fake_type not found for user {}. "
|
err_msg = ("Specified volume type fake_type not found for user {}. "
|
||||||
"List of available types: ['fake_type_2']")
|
"List of available types: ['fake_type_2']")
|
||||||
fake_user = self.credentials["openstack"]["users"][0]
|
fake_user = self.context["users"][0]
|
||||||
self.assertEqual(err_msg.format(fake_user), e.message)
|
self.assertEqual(err_msg.format(fake_user), e.message)
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
class WorkbookContainsWorkflowValidatorTestCase(test.TestCase):
|
class WorkbookContainsWorkflowValidatorTestCase(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(WorkbookContainsWorkflowValidatorTestCase, self).setUp()
|
|
||||||
self.config = copy.deepcopy(config)
|
|
||||||
self.credentials = copy.deepcopy(credentials)
|
|
||||||
|
|
||||||
@mock.patch("rally.common.yamlutils.safe_load")
|
@mock.patch("rally.common.yamlutils.safe_load")
|
||||||
@mock.patch("%s.os.access" % PATH)
|
@mock.patch("%s.os.access" % PATH)
|
||||||
@mock.patch("%s.open" % PATH)
|
@mock.patch("%s.open" % PATH)
|
||||||
@ -957,14 +934,14 @@ class WorkbookContainsWorkflowValidatorTestCase(test.TestCase):
|
|||||||
validator = validators.WorkbookContainsWorkflowValidator(
|
validator = validators.WorkbookContainsWorkflowValidator(
|
||||||
workbook_param="definition", workflow_param="workflow_name")
|
workbook_param="definition", workflow_param="workflow_name")
|
||||||
|
|
||||||
context = {
|
config = {
|
||||||
"args": {
|
"args": {
|
||||||
"definition": "fake_path1",
|
"definition": "fake_path1",
|
||||||
"workflow_name": "wf1"
|
"workflow_name": "wf1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = validator.validate(None, context, None, None)
|
result = validator.validate(None, config, None, None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
self.assertEqual(1, mock_open.called)
|
self.assertEqual(1, mock_open.called)
|
||||||
|
Loading…
Reference in New Issue
Block a user