Port inner stuff to the new task format

* use new format of a runner section
  the schemas of existing plugins are changed to not include "type"

* use "contexts" key instead of "context"
  note: the database model still operates the word "context". hope it
        will be fixed soon while extendind abilities of contexts

* use new format of a hook section

Change-Id: I2ef6ba7a24b542fb001bce378cadf8c83c774b01
This commit is contained in:
Andrey Kurilin 2017-09-14 15:57:44 +03:00
parent b98f047ca0
commit dc98fa69c8
2 changed files with 30 additions and 30 deletions

View File

@ -55,7 +55,7 @@ class ImageExistsValidator(validation.Validator):
if not image_args and self.nullable:
return
image_context = config.get("context", {}).get("images", {})
image_context = config.get("contexts", {}).get("images", {})
image_ctx_name = image_context.get("image_name")
if not image_args:
@ -162,11 +162,11 @@ class FlavorExistsValidator(validation.Validator):
self.param_name = param_name
def _get_flavor_from_context(self, config, flavor_value):
if "flavors" not in config.get("context", {}):
if "flavors" not in config.get("contexts", {}):
self.fail("No flavors context")
flavors = [flavors_ctx.FlavorConfig(**f)
for f in config["context"]["flavors"]]
for f in config["contexts"]["flavors"]]
resource = types.obj_from_name(resource_config=flavor_value,
resources=flavors, typename="flavor")
flavor = flavors_ctx.FlavorConfig(**resource)
@ -223,7 +223,7 @@ class ImageValidOnFlavorValidator(FlavorExistsValidator):
self.validate_disk = validate_disk
def _get_validated_image(self, config, clients, param_name):
image_context = config.get("context", {}).get("images", {})
image_context = config.get("contexts", {}).get("images", {})
image_args = config.get("args", {}).get(param_name)
image_ctx_name = image_context.get("image_name")
@ -387,7 +387,7 @@ class RequiredServicesValidator(validation.Validator):
for service in self.services:
# NOTE(andreykurilin): validator should ignore services configured
# via context(a proper validation should be in context)
service_config = config.get("context", {}).get(
service_config = config.get("contexts", {}).get(
"api_versions@openstack", {}).get(service, {})
if (service not in available_services and
@ -507,7 +507,7 @@ class RequiredAPIVersionsValidator(validation.Validator):
"version": versions_str,
"found_version": "3"})
else:
av_ctx = config.get("context", {}).get(
av_ctx = config.get("contexts", {}).get(
"api_versions@openstack", {})
default_version = getattr(clients,
self.component).choose_version()
@ -540,10 +540,10 @@ class VolumeTypeExistsValidator(validation.Validator):
def validate(self, context, config, plugin_cls, plugin_cfg):
volume_type = config.get("args", {}).get(self.param, False)
if not volume_type and self.nullable:
return
if not volume_type:
if self.nullable:
return
self.fail("The parameter '%s' is required and should not be empty."
% self.param)
@ -551,7 +551,7 @@ class VolumeTypeExistsValidator(validation.Validator):
clients = user["credential"].clients()
vt_names = [vt.name for vt in
clients.cinder().volume_types.list()]
ctx = config.get("context", {}).get("volume_types", [])
ctx = config.get("contexts", {}).get("volume_types", [])
vt_names += ctx
if volume_type not in vt_names:
self.fail("Specified volume type %s not found for user %s."

View File

@ -85,20 +85,19 @@ class ImageExistsValidatorTestCase(test.TestCase):
self.assertIsNone(result)
def test_validator_image_from_context(self):
config = {"args": {
"image": {"regex": r"^foo$"}}, "context": {
"images": {
"image_name": "foo"}}}
config = {
"args": {"image": {"regex": r"^foo$"}},
"contexts": {"images": {"image_name": "foo"}}}
self.validator.validate(self.context, config, None, None)
@mock.patch("%s.openstack_types.GlanceImage.transform" % PATH,
return_value="image_id")
def test_validator_image_not_in_context(self, mock_glance_image_transform):
config = {"args": {
"image": "fake_image"}, "context": {
"images": {
"fake_image_name": "foo"}}}
config = {
"args": {"image": "fake_image"},
"contexts": {
"images": {"fake_image_name": "foo"}}}
clients = self.context[
"users"][0]["credential"].clients.return_value
@ -266,7 +265,7 @@ class FlavorExistsValidatorTestCase(test.TestCase):
def test__get_flavor_from_context(self, mock_flavor_config,
mock_obj_from_name):
config = {
"context": {"images": {"fake_parameter_name": "foo_image"}}}
"contexts": {"images": {"fake_parameter_name": "foo_image"}}}
e = self.assertRaises(
validators.validation.ValidationError,
@ -274,8 +273,8 @@ class FlavorExistsValidatorTestCase(test.TestCase):
config, "foo_flavor")
self.assertEqual("No flavors context", e.message)
config = {"context": {"images": {"fake_parameter_name": "foo_image"},
"flavors": [{"flavor1": "fake_flavor1"}]}}
config = {"contexts": {"images": {"fake_parameter_name": "foo_image"},
"flavors": [{"flavor1": "fake_flavor1"}]}}
result = self.validator._get_flavor_from_context(config, "foo_flavor")
self.assertEqual("<context flavor: %s>" % result.name, result.id)
@ -457,11 +456,12 @@ class ImageValidOnFlavorValidatorTestCase(test.TestCase):
"min_disk": 0
}
# Get image name from context
result = self.validator._get_validated_image({"args": {
"image": {"regex": r"^foo$"}}, "context": {
"images": {
"image_name": "foo"}
}}, mock.Mock(), "image")
result = self.validator._get_validated_image({
"args": {
"image": {"regex": r"^foo$"}},
"contexts": {
"images": {"image_name": "foo"}}},
mock.Mock(), "image")
self.assertEqual(image, result)
clients = mock.Mock()
@ -819,7 +819,7 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
clients = self.context["users"][0]["credential"].clients()
clients.nova.choose_version.return_value = nova
config = {"context": {"api_versions@openstack": {}}}
config = {"contexts": {"api_versions@openstack": {}}}
if err_msg:
e = self.assertRaises(
@ -839,7 +839,7 @@ class RequiredAPIVersionsValidatorTestCase(test.TestCase):
[version])
config = {
"context": {"api_versions@openstack": {"nova": {"version": 2}}}}
"contexts": {"api_versions@openstack": {"nova": {"version": 2}}}}
if err_msg:
e = self.assertRaises(
@ -890,7 +890,7 @@ class VolumeTypeExistsValidatorTestCase(test.TestCase):
clients = self.context["users"][0]["credential"].clients()
clients.cinder().volume_types.list.return_value = []
ctx = {"args": {"volume_type": "fake_type"},
"context": {"volume_types": ["fake_type"]}}
"contexts": {"volume_types": ["fake_type"]}}
result = self.validator.validate(self.context, ctx, None, None)
self.assertIsNone(result)
@ -899,7 +899,7 @@ class VolumeTypeExistsValidatorTestCase(test.TestCase):
clients = self.context["users"][0]["credential"].clients()
clients.cinder().volume_types.list.return_value = []
config = {"args": {"volume_type": "fake_type"},
"context": {"volume_types": ["fake_type_2"]}}
"contexts": {"volume_types": ["fake_type_2"]}}
e = self.assertRaises(
validators.validation.ValidationError,
self.validator.validate, self.context, config, None, None)