From c898a2892966c656134d955ed0dc2da564d3276d Mon Sep 17 00:00:00 2001 From: ghanshyam Date: Wed, 14 Oct 2015 14:44:06 +0900 Subject: [PATCH] Use Tempest-lib's compute hosts_client Compute hosts_client has been migrated to tempest-lib- I59c82bc896d5036d936e6f9cddb3c7b004648dde Now Tempest-lib provides this client as stable interface so Tempest should start using this from lib and remove its own copy. Also remove its unit tests. This commits makes Tempest to use compute hosts_client from Tempest-lib. Change-Id: I5f0846c3fbe2100223f01f9aa9b22c10d75a2468 --- .../api_schema/response/compute/v2_1/hosts.py | 116 -------------- tempest/clients.py | 2 +- tempest/services/compute/json/hosts_client.py | 81 ---------- .../services/compute/test_hosts_client.py | 147 ------------------ 4 files changed, 1 insertion(+), 345 deletions(-) delete mode 100644 tempest/api_schema/response/compute/v2_1/hosts.py delete mode 100644 tempest/services/compute/json/hosts_client.py delete mode 100644 tempest/tests/services/compute/test_hosts_client.py diff --git a/tempest/api_schema/response/compute/v2_1/hosts.py b/tempest/api_schema/response/compute/v2_1/hosts.py deleted file mode 100644 index ae70ff1fdb..0000000000 --- a/tempest/api_schema/response/compute/v2_1/hosts.py +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright 2014 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - - -list_hosts = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'hosts': { - 'type': 'array', - 'items': { - 'type': 'object', - 'properties': { - 'host_name': {'type': 'string'}, - 'service': {'type': 'string'}, - 'zone': {'type': 'string'} - }, - 'additionalProperties': False, - 'required': ['host_name', 'service', 'zone'] - } - } - }, - 'additionalProperties': False, - 'required': ['hosts'] - } -} - -get_host_detail = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'host': { - 'type': 'array', - 'item': { - 'type': 'object', - 'properties': { - 'resource': { - 'type': 'object', - 'properties': { - 'cpu': {'type': 'integer'}, - 'disk_gb': {'type': 'integer'}, - 'host': {'type': 'string'}, - 'memory_mb': {'type': 'integer'}, - 'project': {'type': 'string'} - }, - 'additionalProperties': False, - 'required': ['cpu', 'disk_gb', 'host', - 'memory_mb', 'project'] - } - }, - 'additionalProperties': False, - 'required': ['resource'] - } - } - }, - 'additionalProperties': False, - 'required': ['host'] - } -} - -startup_host = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'host': {'type': 'string'}, - 'power_action': {'enum': ['startup']} - }, - 'additionalProperties': False, - 'required': ['host', 'power_action'] - } -} - -# The 'power_action' attribute of 'shutdown_host' API is 'shutdown' -shutdown_host = copy.deepcopy(startup_host) - -shutdown_host['response_body']['properties']['power_action'] = { - 'enum': ['shutdown'] -} - -# The 'power_action' attribute of 'reboot_host' API is 'reboot' -reboot_host = copy.deepcopy(startup_host) - -reboot_host['response_body']['properties']['power_action'] = { - 'enum': ['reboot'] -} - -update_host = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'host': {'type': 'string'}, - 'maintenance_mode': {'enum': ['on_maintenance', - 'off_maintenance']}, - 'status': {'enum': ['enabled', 'disabled']} - }, - 'additionalProperties': False, - 'required': ['host', 'maintenance_mode', 'status'] - } -} diff --git a/tempest/clients.py b/tempest/clients.py index f161ea2849..6c33e376a0 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -32,6 +32,7 @@ from tempest_lib.services.compute.floating_ip_pools_client import \ FloatingIPPoolsClient from tempest_lib.services.compute.floating_ips_bulk_client import \ FloatingIPsBulkClient +from tempest_lib.services.compute.hosts_client import HostsClient from tempest_lib.services.identity.v2.token_client import TokenClient from tempest_lib.services.identity.v3.token_client import V3TokenClient @@ -45,7 +46,6 @@ from tempest.services.baremetal.v1.json.baremetal_client import \ from tempest.services import botoclients from tempest.services.compute.json.floating_ips_client import \ FloatingIPsClient -from tempest.services.compute.json.hosts_client import HostsClient from tempest.services.compute.json.hypervisor_client import \ HypervisorClient from tempest.services.compute.json.images_client import ImagesClient diff --git a/tempest/services/compute/json/hosts_client.py b/tempest/services/compute/json/hosts_client.py deleted file mode 100644 index 3d3cb18859..0000000000 --- a/tempest/services/compute/json/hosts_client.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2013 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_serialization import jsonutils as json -from six.moves.urllib import parse as urllib - -from tempest.api_schema.response.compute.v2_1 import hosts as schema -from tempest.common import service_client - - -class HostsClient(service_client.ServiceClient): - - def list_hosts(self, **params): - """Lists all hosts.""" - - url = 'os-hosts' - if params: - url += '?%s' % urllib.urlencode(params) - - resp, body = self.get(url) - body = json.loads(body) - self.validate_response(schema.list_hosts, resp, body) - return service_client.ResponseBody(resp, body) - - def show_host(self, hostname): - """Show detail information for the host.""" - - resp, body = self.get("os-hosts/%s" % hostname) - body = json.loads(body) - self.validate_response(schema.get_host_detail, resp, body) - return service_client.ResponseBody(resp, body) - - def update_host(self, hostname, **kwargs): - """Update a host.""" - - request_body = { - 'status': None, - 'maintenance_mode': None, - } - request_body.update(**kwargs) - request_body = json.dumps(request_body) - - resp, body = self.put("os-hosts/%s" % hostname, request_body) - body = json.loads(body) - self.validate_response(schema.update_host, resp, body) - return service_client.ResponseBody(resp, body) - - def startup_host(self, hostname): - """Startup a host.""" - - resp, body = self.get("os-hosts/%s/startup" % hostname) - body = json.loads(body) - self.validate_response(schema.startup_host, resp, body) - return service_client.ResponseBody(resp, body) - - def shutdown_host(self, hostname): - """Shutdown a host.""" - - resp, body = self.get("os-hosts/%s/shutdown" % hostname) - body = json.loads(body) - self.validate_response(schema.shutdown_host, resp, body) - return service_client.ResponseBody(resp, body) - - def reboot_host(self, hostname): - """reboot a host.""" - - resp, body = self.get("os-hosts/%s/reboot" % hostname) - body = json.loads(body) - self.validate_response(schema.reboot_host, resp, body) - return service_client.ResponseBody(resp, body) diff --git a/tempest/tests/services/compute/test_hosts_client.py b/tempest/tests/services/compute/test_hosts_client.py deleted file mode 100644 index 2b7fdb5310..0000000000 --- a/tempest/tests/services/compute/test_hosts_client.py +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest.services.compute.json import hosts_client -from tempest.tests import fake_auth_provider -from tempest.tests.services.compute import base - - -class TestHostsClient(base.BaseComputeServiceTest): - FAKE_HOST_DATA = { - "host": { - "resource": { - "cpu": 1, - "disk_gb": 1028, - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "memory_mb": 8192, - "project": "(total)" - } - }, - "hosts": { - "host_name": "c1a7de0ac9d94e4baceae031d05caae3", - "service": "conductor", - "zone": "internal" - }, - "enable_hosts": { - "host": "65c5d5b7e3bd44308e67fc50f362aee6", - "maintenance_mode": "off_maintenance", - "status": "enabled" - } - } - - FAKE_CONTROL_DATA = { - "shutdown": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "shutdown" - }, - "startup": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "startup" - }, - "reboot": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "reboot" - }} - - HOST_DATA = {'host': [FAKE_HOST_DATA['host']]} - HOSTS_DATA = {'hosts': [FAKE_HOST_DATA['hosts']]} - ENABLE_HOST_DATA = FAKE_HOST_DATA['enable_hosts'] - HOST_ID = "c1a7de0ac9d94e4baceae031d05caae3" - TEST_HOST_DATA = { - "status": "enable", - "maintenance_mode": "disable" - } - - def setUp(self): - super(TestHostsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = hosts_client.HostsClient(fake_auth, 'compute', - 'regionOne') - self.params = {'hostname': self.HOST_ID} - self.func2mock = { - 'get': 'tempest.common.service_client.ServiceClient.get', - 'put': 'tempest.common.service_client.ServiceClient.put'} - - def _test_host_data(self, test_type='list', bytes_body=False): - expected_resp = self.HOST_DATA - if test_type != 'list': - function_call = self.client.show_host - else: - expected_resp = self.HOSTS_DATA - function_call = self.client.list_hosts - self.params = {'host_name': self.HOST_ID} - - self.check_service_client_function( - function_call, self.func2mock['get'], - expected_resp, bytes_body, - 200, **self.params) - - def _test_update_hosts(self, bytes_body=False): - expected_resp = self.ENABLE_HOST_DATA - self.check_service_client_function( - self.client.update_host, self.func2mock['put'], - expected_resp, bytes_body, - 200, **self.params) - - def _test_control_host(self, control_op='reboot', bytes_body=False): - if control_op == 'start': - expected_resp = self.FAKE_CONTROL_DATA['startup'] - function_call = self.client.startup_host - elif control_op == 'stop': - expected_resp = self.FAKE_CONTROL_DATA['shutdown'] - function_call = self.client.shutdown_host - else: - expected_resp = self.FAKE_CONTROL_DATA['reboot'] - function_call = self.client.reboot_host - - self.check_service_client_function( - function_call, self.func2mock['get'], - expected_resp, bytes_body, - 200, **self.params) - - def test_show_host_with_str_body(self): - self._test_host_data('show') - - def test_show_host_with_bytes_body(self): - self._test_host_data('show', True) - - def test_list_host_with_str_body(self): - self._test_host_data() - - def test_list_host_with_bytes_body(self): - self._test_host_data(bytes_body=True) - - def test_start_host_with_str_body(self): - self._test_control_host('start') - - def test_start_host_with_bytes_body(self): - self._test_control_host('start', True) - - def test_stop_host_with_str_body(self): - self._test_control_host('stop') - - def test_stop_host_with_bytes_body(self): - self._test_control_host('stop', True) - - def test_reboot_host_with_str_body(self): - self._test_control_host('reboot') - - def test_reboot_host_with_bytes_body(self): - self._test_control_host('reboot', True) - - def test_update_host_with_str_body(self): - self._test_update_hosts() - - def test_update_host_with_bytes_body(self): - self._test_update_hosts(True)