Merge "Adding gnocchi client and keystoneauth to rally"

This commit is contained in:
Jenkins 2016-05-12 20:09:35 +00:00 committed by Gerrit Code Review
commit f697c4b1bb
8 changed files with 91 additions and 12 deletions

View File

@ -22,8 +22,8 @@ class Credential(object):
permission=consts.EndpointPermission.USER, permission=consts.EndpointPermission.USER,
region_name=None, endpoint_type=consts.EndpointType.PUBLIC, region_name=None, endpoint_type=consts.EndpointType.PUBLIC,
domain_name=None, endpoint=None, domain_name=None, endpoint=None,
user_domain_name="Default", admin_domain_name="Default", user_domain_name=None, admin_domain_name="Default",
project_domain_name="Default", project_domain_name=None,
https_insecure=False, https_cacert=None): https_insecure=False, https_cacert=None):
self.auth_url = auth_url self.auth_url = auth_url
self.username = username self.username = username

View File

@ -111,6 +111,7 @@ class _Service(utils.ImmutableMixin, utils.EnumMixin):
MISTRAL = "mistral" MISTRAL = "mistral"
MURANO = "murano" MURANO = "murano"
IRONIC = "ironic" IRONIC = "ironic"
GNOCCHI = "gnocchi"
class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): class _ServiceType(utils.ImmutableMixin, utils.EnumMixin):
@ -137,6 +138,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin):
WORKFLOW_EXECUTION = "workflowv2" WORKFLOW_EXECUTION = "workflowv2"
APPLICATION_CATALOG = "application-catalog" APPLICATION_CATALOG = "application-catalog"
BARE_METAL = "baremetal" BARE_METAL = "baremetal"
METRIC = "metric"
def __init__(self): def __init__(self):
self.__names = { self.__names = {
@ -161,6 +163,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin):
self.WORKFLOW_EXECUTION: _Service.MISTRAL, self.WORKFLOW_EXECUTION: _Service.MISTRAL,
self.APPLICATION_CATALOG: _Service.MURANO, self.APPLICATION_CATALOG: _Service.MURANO,
self.BARE_METAL: _Service.IRONIC, self.BARE_METAL: _Service.IRONIC,
self.METRIC: _Service.GNOCCHI,
} }
def __getitem__(self, service_type): def __getitem__(self, service_type):

View File

@ -130,9 +130,9 @@ class ExistingCloud(engine.Engine):
consts.EndpointType.PUBLIC), consts.EndpointType.PUBLIC),
endpoint=common.get("endpoint"), endpoint=common.get("endpoint"),
domain_name=user.get("domain_name"), domain_name=user.get("domain_name"),
user_domain_name=user.get("user_domain_name", "Default"), user_domain_name=user.get("user_domain_name", None),
admin_domain_name=user.get("admin_domain_name", "Default"), admin_domain_name=user.get("admin_domain_name", "Default"),
project_domain_name=user.get("project_domain_name", "Default"), project_domain_name=user.get("project_domain_name", None),
https_insecure=common.get("https_insecure", False), https_insecure=common.get("https_insecure", False),
https_cacert=common.get("https_cacert") https_cacert=common.get("https_cacert")
) )

View File

@ -160,6 +160,21 @@ class OSClient(plugin.Plugin):
auth=auth, verify=not self.credential.insecure, auth=auth, verify=not self.credential.insecure,
timeout=CONF.openstack_client_http_timeout) timeout=CONF.openstack_client_http_timeout)
def _get_keystoneauth_session(self):
from keystoneauth1 import loading
from keystoneauth1 import session
loader = loading.get_plugin_loader("password")
plugin = loader.load_from_options(
auth_url=self.credential.auth_url,
username=self.credential.username,
password=self.credential.password,
user_domain_name=self.credential.user_domain_name,
project_name=self.credential.tenant_name,
project_domain_name=self.credential.project_domain_name)
sess = session.Session(auth=plugin, verify=(
not self.credential.insecure))
return sess
def _get_endpoint(self, service_type=None): def _get_endpoint(self, service_type=None):
kc = self.keystone() kc = self.keystone()
api_url = kc.service_catalog.url_for( api_url = kc.service_catalog.url_for(
@ -188,9 +203,11 @@ class OSClient(plugin.Plugin):
kw.update({ kw.update({
domain_name_key: self.credential.domain_name}) domain_name_key: self.credential.domain_name})
kw.update({ kw.update({
user_domain_name_key: self.credential.user_domain_name}) user_domain_name_key:
self.credential.user_domain_name or "Default"})
kw.update({ kw.update({
project_domain_name_key: self.credential.project_domain_name}) project_domain_name_key:
self.credential.project_domain_name or "Default"})
return kw return kw
@ -456,6 +473,22 @@ class Ceilometer(OSClient):
return client return client
@configure("gnocchi", default_service_type="metric", default_version="1",
supported_versions=["1"])
class Gnocchi(OSClient):
def create_client(self, version=None, service_type=None):
"""Return gnocchi client."""
# NOTE(sumantmurke): gnocchiclient requires keystoneauth1 for
# authenticating and creating a session.
from gnocchiclient import client as gnocchi
service_type = self.choose_service_type(service_type)
sess = self._get_keystoneauth_session()
gclient = gnocchi.Client(version=self.choose_version(
version), session=sess, service_type=service_type)
return gclient
@configure("ironic", default_version="1", default_service_type="baremetal", @configure("ironic", default_version="1", default_service_type="baremetal",
supported_versions=["1"]) supported_versions=["1"])
class Ironic(OSClient): class Ironic(OSClient):

View File

@ -19,8 +19,10 @@ pbr>=1.6 # Apache-2.0
PrettyTable<0.8,>=0.7 # BSD PrettyTable<0.8,>=0.7 # BSD
PyYAML>=3.1.0 # MIT PyYAML>=3.1.0 # MIT
python-designateclient>=1.5.0 # Apache-2.0 python-designateclient>=1.5.0 # Apache-2.0
gnocchiclient>=2.2.0 # Apache-2.0
python-glanceclient>=2.0.0 # Apache-2.0 python-glanceclient>=2.0.0 # Apache-2.0
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0 python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0
keystoneauth1>=2.1.0 # Apache-2.0
python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0 python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0
python-neutronclient>=4.2.0 # Apache-2.0 python-neutronclient>=4.2.0 # Apache-2.0
python-cinderclient>=1.6.0 # Apache-2.0 python-cinderclient>=1.6.0 # Apache-2.0

View File

@ -36,8 +36,8 @@ class EndpointTestCase(test.TestCase):
"endpoint_type": consts.EndpointType.PUBLIC, "endpoint_type": consts.EndpointType.PUBLIC,
"https_insecure": False, "https_insecure": False,
"https_cacert": None, "https_cacert": None,
"project_domain_name": "Default", "project_domain_name": None,
"user_domain_name": "Default", "user_domain_name": None,
"admin_domain_name": "Default"}) "admin_domain_name": "Default"})
def test_to_dict_with_include_permission(self): def test_to_dict_with_include_permission(self):
@ -57,8 +57,8 @@ class EndpointTestCase(test.TestCase):
"endpoint_type": consts.EndpointType.PUBLIC, "endpoint_type": consts.EndpointType.PUBLIC,
"https_insecure": False, "https_insecure": False,
"https_cacert": None, "https_cacert": None,
"project_domain_name": "Default", "project_domain_name": None,
"user_domain_name": "Default", "user_domain_name": None,
"admin_domain_name": "Default"}) "admin_domain_name": "Default"})
def test_to_dict_with_kwarg_credential(self): def test_to_dict_with_kwarg_credential(self):
@ -78,6 +78,6 @@ class EndpointTestCase(test.TestCase):
"endpoint_type": consts.EndpointType.PUBLIC, "endpoint_type": consts.EndpointType.PUBLIC,
"https_insecure": False, "https_insecure": False,
"https_cacert": None, "https_cacert": None,
"project_domain_name": "Default", "project_domain_name": None,
"user_domain_name": "Default", "user_domain_name": None,
"admin_domain_name": "Default"}) "admin_domain_name": "Default"})

View File

@ -207,6 +207,13 @@ class FakeSecurityGroupRule(FakeResource):
setattr(self, key, value) setattr(self, key, value)
class FakeMetric(FakeResource):
def __init_(self, manager=None, **kwargs):
super(FakeMetric, self).__init__(manager)
self.metric = kwargs.get("metric_name")
self.optional_args = kwargs.get("optional_args", {})
class FakeAlarm(FakeResource): class FakeAlarm(FakeResource):
def __init__(self, manager=None, **kwargs): def __init__(self, manager=None, **kwargs):
super(FakeAlarm, self).__init__(manager) super(FakeAlarm, self).__init__(manager)
@ -714,6 +721,17 @@ class FakeRolesManager(FakeManager):
pass pass
class FakeMetricManager(FakeManager):
def create(self, **kwargs):
metric = FakeMetric(self, **kwargs)
return self._cache(metric)
def get(self, metric_id):
metric = self.find(metric_id=metric_id)
return [metric]
class FakeAlarmManager(FakeManager): class FakeAlarmManager(FakeManager):
def get(self, alarm_id): def get(self, alarm_id):
@ -1036,6 +1054,11 @@ class FakeCeilometerClient(object):
self.query_alarm_history = FakeQueryManager() self.query_alarm_history = FakeQueryManager()
class FakeGnocchiClient(object):
def __init__(self):
self.metric = FakeMetricManager()
class FakeMonascaClient(object): class FakeMonascaClient(object):
def __init__(self): def __init__(self):

View File

@ -493,6 +493,24 @@ class OSClientsTestCase(test.TestCase):
self.assertEqual(fake_ceilometer, self.assertEqual(fake_ceilometer,
self.clients.cache["ceilometer"]) self.clients.cache["ceilometer"])
def test_gnocchi(self):
fake_gnocchi = fakes.FakeGnocchiClient()
mock_gnocchi = mock.MagicMock()
mock_gnocchi.client.Client.return_value = fake_gnocchi
mock_keystoneauth1 = mock.MagicMock()
self.assertNotIn("gnocchi", self.clients.cache)
with mock.patch.dict("sys.modules",
{"gnocchiclient": mock_gnocchi,
"keystoneauth1": mock_keystoneauth1}):
client = self.clients.gnocchi()
self.assertEqual(fake_gnocchi, client)
kw = {"version": "1",
"session": mock_keystoneauth1.session.Session(),
"service_type": "metric"}
mock_gnocchi.client.Client.assert_called_once_with(**kw)
self.assertEqual(fake_gnocchi, self.clients.cache["gnocchi"])
def test_monasca(self): def test_monasca(self):
fake_monasca = fakes.FakeMonascaClient() fake_monasca = fakes.FakeMonascaClient()
mock_monasca = mock.MagicMock() mock_monasca = mock.MagicMock()