From 9f78c543498c3c419418d3161ffe8bf5ea3d4253 Mon Sep 17 00:00:00 2001 From: Samuel de Medeiros Queiroz Date: Mon, 10 Jul 2017 11:38:10 -0400 Subject: [PATCH] De-client-ify Service Create Change-Id: Ifc71043cbb40d2888cd9c8341f135e832c553d00 --- shade/_adapter.py | 2 +- shade/_tasks.py | 5 ----- shade/operatorcloud.py | 16 ++++++++-------- shade/tests/unit/test_services.py | 13 ++----------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/shade/_adapter.py b/shade/_adapter.py index 3dd4b5799..5089b6975 100644 --- a/shade/_adapter.py +++ b/shade/_adapter.py @@ -144,7 +144,7 @@ class ShadeAdapter(adapter.Adapter): 'flavor', 'flavors', 'baymodels', 'aggregate', 'aggregates', 'availabilityZoneInfo', 'flavor_access', 'output', 'server_groups', 'domain', - 'domains']: + 'domains', 'service', 'OS-KSADM:service']: if key in result_json.keys(): self._log_request_id(response) return result_json diff --git a/shade/_tasks.py b/shade/_tasks.py index 28d8f9a57..e197e8307 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -127,11 +127,6 @@ class MachineSetProvision(task_manager.Task): return client.ironic_client.node.set_provision_state(**self.args) -class ServiceCreate(task_manager.Task): - def main(self, client): - return client.keystone_client.services.create(**self.args) - - class ServiceList(task_manager.Task): def main(self, client): return client.keystone_client.services.list() diff --git a/shade/operatorcloud.py b/shade/operatorcloud.py index 4d302e1ff..a33575e8a 100644 --- a/shade/operatorcloud.py +++ b/shade/operatorcloud.py @@ -756,18 +756,18 @@ class OperatorCloud(openstackcloud.OpenStackCloud): # TODO(mordred) When this changes to REST, force interface=admin # in the adapter call if self.cloud_config.get_api_version('identity').startswith('2'): - kwargs['service_type'] = type_ or service_type + url, key = '/OS-KSADM/services', 'OS-KSADM:service' + kwargs['type'] = type_ or service_type else: + url, key = '/services', 'service' kwargs['type'] = type_ or service_type kwargs['enabled'] = enabled + kwargs['name'] = name - with _utils.shade_exceptions( - "Failed to create service {name}".format(name=name) - ): - service = self.manager.submit_task( - _tasks.ServiceCreate(name=name, **kwargs) - ) - + msg = 'Failed to create service {name}'.format(name=name) + data = self._identity_client.post( + url, json={key: kwargs}, error_message=msg) + service = meta.get_and_munchify(key, data) return _utils.normalize_keystone_services([service])[0] @_utils.valid_kwargs('name', 'enabled', 'type', 'service_type', diff --git a/shade/tests/unit/test_services.py b/shade/tests/unit/test_services.py index cbd01bf55..585184e6f 100644 --- a/shade/tests/unit/test_services.py +++ b/shade/tests/unit/test_services.py @@ -47,12 +47,7 @@ class CloudServices(base.RequestsMockTestCase): uri=self.get_mock_url(base_url_append='OS-KSADM'), status_code=200, json=service_data.json_response_v2, - validate=dict(json={'OS-KSADM:service': reference_req})), - dict(method='GET', - uri=self.get_mock_url(base_url_append='OS-KSADM', - append=[service_data.service_id]), - status_code=200, - json=service_data.json_response_v2) + validate=dict(json={'OS-KSADM:service': reference_req})) ]) service = self.op_cloud.create_service( @@ -76,11 +71,7 @@ class CloudServices(base.RequestsMockTestCase): uri=self.get_mock_url(), status_code=200, json=service_data.json_response_v3, - validate=dict(json={'service': service_data.json_request})), - dict(method='GET', - uri=self.get_mock_url(append=[service_data.service_id]), - status_code=200, - json=service_data.json_response_v3) + validate=dict(json={'service': service_data.json_request})) ]) service = self.op_cloud.create_service(