Merge "Moving of 'required_cinder_services' validator to '../validators.py'"
This commit is contained in:
commit
569925d650
|
@ -26,8 +26,8 @@ from rally.task import validation
|
|||
subdict="create_volume_kwargs")
|
||||
@validation.add("restricted_parameters", param_names="name",
|
||||
subdict="create_backup_kwargs")
|
||||
@validation.required_cinder_services("cinder-backup")
|
||||
@validation.add("required_services", services=[consts.Service.CINDER])
|
||||
@validation.add("required_cinder_services", services="cinder-backup")
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup": ["cinder"]},
|
||||
name="CinderVolumeBackups."
|
||||
|
|
|
@ -611,8 +611,8 @@ class CreateAndUploadVolumeToImage(cinder_utils.CinderBasic,
|
|||
subdict="create_volume_kwargs")
|
||||
@validation.add("restricted_parameters", param_names="name",
|
||||
subdict="create_backup_kwargs")
|
||||
@validation.required_cinder_services("cinder-backup")
|
||||
@validation.add("required_services", services=[consts.Service.CINDER])
|
||||
@validation.add("required_cinder_services", services="cinder-backup")
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup": ["cinder"]},
|
||||
name="CinderVolumes.create_volume_backup")
|
||||
|
@ -643,8 +643,8 @@ class CreateVolumeBackup(cinder_utils.CinderBasic):
|
|||
subdict="create_volume_kwargs")
|
||||
@validation.add("restricted_parameters", param_names="name",
|
||||
subdict="create_backup_kwargs")
|
||||
@validation.required_cinder_services("cinder-backup")
|
||||
@validation.add("required_services", services=[consts.Service.CINDER])
|
||||
@validation.add("required_cinder_services", services="cinder-backup")
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup": ["cinder"]},
|
||||
name="CinderVolumes.create_and_restore_volume_backup")
|
||||
|
@ -676,8 +676,8 @@ class CreateAndRestoreVolumeBackup(cinder_utils.CinderBasic):
|
|||
subdict="create_volume_kwargs")
|
||||
@validation.add("restricted_parameters", param_names="name",
|
||||
subdict="create_backup_kwargs")
|
||||
@validation.required_cinder_services("cinder-backup")
|
||||
@validation.add("required_services", services=[consts.Service.CINDER])
|
||||
@validation.add("required_cinder_services", services="cinder-backup")
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@scenario.configure(context={"cleanup": ["cinder"]},
|
||||
name="CinderVolumes.create_and_list_volume_backups")
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
|
||||
from glanceclient import exc as glance_exc
|
||||
from novaclient import exceptions as nova_exc
|
||||
|
@ -46,8 +47,7 @@ class ImageExistsValidator(validation.Validator):
|
|||
self.param_name = param_name
|
||||
self.nullable = nullable
|
||||
|
||||
def validate(self, config, credentials, plugin_cls,
|
||||
plugin_cfg):
|
||||
def validate(self, config, credentials, plugin_cls, plugin_cfg):
|
||||
|
||||
image_args = config.get("args", {}).get(self.param_name)
|
||||
|
||||
|
@ -442,3 +442,30 @@ class ValidateHeatTemplateValidator(validation.Validator):
|
|||
msg = ("Heat template validation failed on %(path)s. "
|
||||
"Original error message: %(msg)s.") % dct
|
||||
return self.fail(msg)
|
||||
|
||||
|
||||
@validation.add("required_platform", platform="openstack", admin=True)
|
||||
@validation.configure(name="required_cinder_services", namespace="openstack")
|
||||
class RequiredCinderServicesValidator(validation.Validator):
|
||||
|
||||
def __init__(self, services):
|
||||
"""Validator checks that specified Cinder service is available.
|
||||
|
||||
It uses Cinder client with admin permissions to call
|
||||
'cinder service-list' call
|
||||
|
||||
:param services: Cinder service name
|
||||
"""
|
||||
super(RequiredCinderServicesValidator, self).__init__()
|
||||
self.services = services
|
||||
|
||||
def validate(self, config, credentials, plugin_cls, plugin_cfg):
|
||||
|
||||
clients = credentials["openstack"]["admin"].clients().cinder()
|
||||
for service in clients.services.list():
|
||||
if (service.binary == six.text_type(self.services)
|
||||
and service.state == six.text_type("up")):
|
||||
return
|
||||
|
||||
msg = ("%s service is not available") % self.services
|
||||
return self.fail(msg)
|
||||
|
|
|
@ -310,27 +310,6 @@ def flavor_exists(config, clients, deployment, param_name):
|
|||
return _get_validated_flavor(config, clients, param_name)[0]
|
||||
|
||||
|
||||
@validator
|
||||
def required_cinder_services(config, clients, deployment, service_name):
|
||||
"""Validator checks that specified Cinder service is available.
|
||||
|
||||
It uses Cinder client with admin permissions to call 'cinder service-list'
|
||||
call
|
||||
|
||||
:param service_name: Cinder service name
|
||||
"""
|
||||
creds = deployment.get_credentials_for("openstack")
|
||||
admin_client = creds["admin"].clients().cinder()
|
||||
|
||||
for service in admin_client.services.list():
|
||||
if (service.binary == six.text_type(service_name) and
|
||||
service.state == six.text_type("up")):
|
||||
return ValidationResult(True)
|
||||
|
||||
msg = _("%s service is not available") % service_name
|
||||
return ValidationResult(False, msg)
|
||||
|
||||
|
||||
@validator
|
||||
def required_contexts(config, clients, deployment, *context_names):
|
||||
"""Validator checks if required benchmark contexts are specified.
|
||||
|
@ -502,3 +481,7 @@ validate_heat_template = deprecated_validator("validate_heat_template",
|
|||
restricted_parameters = deprecated_validator("restricted_parameters",
|
||||
"restricted_parameters",
|
||||
"0.10.0")
|
||||
|
||||
required_cinder_services = deprecated_validator("required_cinder_services",
|
||||
"required_cinder_services",
|
||||
"0.10.0")
|
||||
|
|
|
@ -77,7 +77,6 @@ class ImageExistsValidatorTestCase(test.TestCase):
|
|||
result = validator.validate(self.config, self.credentials, None, None)
|
||||
|
||||
if err_msg:
|
||||
print(result)
|
||||
self.assertEqual(err_msg, result.msg)
|
||||
elif result:
|
||||
self.assertIsNone(result, "Unexpected result '%s'" % result.msg)
|
||||
|
@ -660,3 +659,27 @@ class ValidateHeatTemplateValidatorTestCase(test.TestCase):
|
|||
expected_msg = "No file found by the given path fake_path1"
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(expected_msg, result.msg)
|
||||
|
||||
|
||||
class RequiredCinderServicesValidatorTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(RequiredCinderServicesValidatorTestCase, self).setUp()
|
||||
self.credentials = copy.deepcopy(credentials)
|
||||
self.config = copy.deepcopy(config)
|
||||
|
||||
def test_validate(self):
|
||||
validator = validators.RequiredCinderServicesValidator(
|
||||
"cinder_service")
|
||||
|
||||
fake_service = mock.Mock(binary="cinder_service", state="up")
|
||||
clients = self.credentials["openstack"]["admin"].clients()
|
||||
clients.cinder().services.list.return_value = [fake_service]
|
||||
result = validator.validate(self.config, self.credentials, None, None)
|
||||
self.assertIsNone(result)
|
||||
|
||||
fake_service.state = "down"
|
||||
result = validator.validate(self.config, self.credentials, None, None)
|
||||
self.assertTrue(result)
|
||||
self.assertEqual("cinder_service service is not available",
|
||||
result.msg)
|
||||
|
|
|
@ -19,7 +19,6 @@ import ddt
|
|||
from glanceclient import exc as glance_exc
|
||||
import mock
|
||||
from novaclient import exceptions as nova_exc
|
||||
import six
|
||||
|
||||
from rally.common.plugin import plugin
|
||||
from rally.common import validation as common_validation
|
||||
|
@ -572,23 +571,6 @@ class ValidatorsTestCase(test.TestCase):
|
|||
result = validator(context, clients, mock.MagicMock())
|
||||
self.assertFalse(result.is_valid, result.msg)
|
||||
|
||||
def test_required_cinder_services(self):
|
||||
validator = self._unwrap_validator(
|
||||
validation.required_cinder_services,
|
||||
service_name=six.text_type("cinder-service"))
|
||||
|
||||
fake_service = mock.Mock(binary="cinder-service", state="up")
|
||||
admin = fakes.fake_credential(foo="bar")
|
||||
cinder = admin.clients.return_value.cinder.return_value
|
||||
cinder.services.list.return_value = [fake_service]
|
||||
deployment = fakes.FakeDeployment(admin=admin)
|
||||
result = validator({}, None, deployment)
|
||||
self.assertTrue(result.is_valid, result.msg)
|
||||
|
||||
fake_service.state = "down"
|
||||
result = validator({}, None, deployment)
|
||||
self.assertFalse(result.is_valid, result.msg)
|
||||
|
||||
def _get_keystone_v2_mock_client(self):
|
||||
keystone = mock.Mock()
|
||||
del keystone.projects
|
||||
|
|
Loading…
Reference in New Issue