Merge "Add required_cinder_services validator"
This commit is contained in:
commit
8fad3a4a69
@ -20,12 +20,15 @@ import re
|
|||||||
|
|
||||||
from glanceclient import exc as glance_exc
|
from glanceclient import exc as glance_exc
|
||||||
from novaclient import exceptions as nova_exc
|
from novaclient import exceptions as nova_exc
|
||||||
|
import six
|
||||||
|
|
||||||
from rally.benchmark.context import flavors as flavors_ctx
|
from rally.benchmark.context import flavors as flavors_ctx
|
||||||
from rally.benchmark import types as types
|
from rally.benchmark import types as types
|
||||||
from rally.common.i18n import _
|
from rally.common.i18n import _
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
|
from rally import objects
|
||||||
|
from rally import osclients
|
||||||
from rally.verification.tempest import tempest
|
from rally.verification.tempest import tempest
|
||||||
|
|
||||||
|
|
||||||
@ -393,6 +396,28 @@ def required_services(config, clients, deployment, *required_services):
|
|||||||
False, _("Service is not available: %s") % service)
|
False, _("Service is not available: %s") % service)
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
"""
|
||||||
|
|
||||||
|
admin_client = osclients.Clients(
|
||||||
|
objects.Endpoint(**deployment["admin"])).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
|
@validator
|
||||||
def required_clients(config, clients, task, *components):
|
def required_clients(config, clients, task, *components):
|
||||||
"""Validator checks if specified OpenStack clients are available.
|
"""Validator checks if specified OpenStack clients are available.
|
||||||
|
@ -16,10 +16,12 @@
|
|||||||
from glanceclient import exc as glance_exc
|
from glanceclient import exc as glance_exc
|
||||||
import mock
|
import mock
|
||||||
from novaclient import exceptions as nova_exc
|
from novaclient import exceptions as nova_exc
|
||||||
|
import six
|
||||||
|
|
||||||
from rally.benchmark import validation
|
from rally.benchmark import validation
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
|
import rally.osclients
|
||||||
from rally.verification.tempest import tempest
|
from rally.verification.tempest import tempest
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
@ -614,3 +616,26 @@ class ValidatorsTestCase(test.TestCase):
|
|||||||
clients.nova.side_effect = ImportError
|
clients.nova.side_effect = ImportError
|
||||||
result = validator({}, clients, None)
|
result = validator({}, clients, None)
|
||||||
self.assertFalse(result.is_valid, result.msg)
|
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"))
|
||||||
|
|
||||||
|
with mock.patch.object(rally.osclients.Clients, "cinder") as client:
|
||||||
|
fake_service = mock.Mock(binary="cinder-service", state="up")
|
||||||
|
cinder_client = mock.Mock()
|
||||||
|
services = mock.Mock()
|
||||||
|
services.list.return_value = [fake_service]
|
||||||
|
cinder_client.services = services
|
||||||
|
client.return_value = cinder_client
|
||||||
|
|
||||||
|
deployment = {"admin": {"auth_url": "fake_endpoint",
|
||||||
|
"username": "username",
|
||||||
|
"password": "password"}}
|
||||||
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user