From 2738ae0bb0b1b77da8867cb05a4e66e114c08e77 Mon Sep 17 00:00:00 2001 From: Artom Lifshitz Date: Sat, 26 Jan 2019 11:14:25 -0500 Subject: [PATCH] Move get_hypervisor_ip() to base test Since we need the admin servers client, it makes more sense to include it in the base test class. Change-Id: I763ea0508b0152fea2cff5f744c56233023932f4 --- whitebox_tempest_plugin/api/compute/base.py | 11 +++++++ .../api/compute/test_cpu_model_extra_flags.py | 4 +-- .../api/compute/test_cpu_pinning.py | 4 +-- .../api/compute/test_live_migration.py | 4 +-- .../api/compute/test_pointer_device_type.py | 4 +-- .../api/compute/test_rx_tx_queue_size.py | 4 +-- whitebox_tempest_plugin/common/utils.py | 32 ------------------- .../tests/{test_utils.py => test_base.py} | 17 ++++++---- 8 files changed, 27 insertions(+), 53 deletions(-) delete mode 100644 whitebox_tempest_plugin/common/utils.py rename whitebox_tempest_plugin/tests/{test_utils.py => test_base.py} (66%) diff --git a/whitebox_tempest_plugin/api/compute/base.py b/whitebox_tempest_plugin/api/compute/base.py index e7356e03..773e4c9e 100644 --- a/whitebox_tempest_plugin/api/compute/base.py +++ b/whitebox_tempest_plugin/api/compute/base.py @@ -18,6 +18,8 @@ from tempest.api.compute import base from tempest.common import waiters from tempest import config +from whitebox_tempest_plugin import exceptions + CONF = config.CONF LOG = logging.getLogger(__name__) @@ -62,3 +64,12 @@ class BaseWhiteboxComputeTest(base.BaseV2ComputeAdminTest): 'ACTIVE') return self.servers_client.show_server(server_id)['server'] + + def get_hypervisor_ip(self, server_id): + server = self.servers_client.show_server(server_id) + host = server['server']['OS-EXT-SRV-ATTR:host'] + try: + return CONF.whitebox.hypervisors[host] + except KeyError: + raise exceptions.MissingHypervisorException(server=server_id, + host=host) diff --git a/whitebox_tempest_plugin/api/compute/test_cpu_model_extra_flags.py b/whitebox_tempest_plugin/api/compute/test_cpu_model_extra_flags.py index f1fa8c0f..0191f20a 100644 --- a/whitebox_tempest_plugin/api/compute/test_cpu_model_extra_flags.py +++ b/whitebox_tempest_plugin/api/compute/test_cpu_model_extra_flags.py @@ -18,7 +18,6 @@ from oslo_log import log as logging from tempest import config from whitebox_tempest_plugin.api.compute import base -from whitebox_tempest_plugin.common import utils as whitebox_utils from whitebox_tempest_plugin.services import clients @@ -37,8 +36,7 @@ class CpuModelExtraFlagsTest(base.BaseWhiteboxComputeTest): def test_cpu_model_extra_flags(self): server = self.create_test_server(wait_until="ACTIVE") server_id = server['id'] - compute_node_address = whitebox_utils.get_hypervisor_ip( - self.servers_client, server_id) + compute_node_address = self.get_hypervisor_ip(server_id) virshxml_client = clients.VirshXMLClient(compute_node_address) dump = virshxml_client.dumpxml(server_id) root = ET.fromstring(dump) diff --git a/whitebox_tempest_plugin/api/compute/test_cpu_pinning.py b/whitebox_tempest_plugin/api/compute/test_cpu_pinning.py index 2aac2e95..892104c1 100644 --- a/whitebox_tempest_plugin/api/compute/test_cpu_pinning.py +++ b/whitebox_tempest_plugin/api/compute/test_cpu_pinning.py @@ -31,7 +31,6 @@ from tempest.common import utils from tempest import config from whitebox_tempest_plugin.api.compute import base -from whitebox_tempest_plugin.common import utils as whitebox_utils from whitebox_tempest_plugin import exceptions from whitebox_tempest_plugin.services import clients @@ -43,8 +42,7 @@ class BasePinningTest(base.BaseWhiteboxComputeTest): vcpus = 2 def get_server_cpu_pinning(self, server): - compute_node_address = whitebox_utils.get_hypervisor_ip( - self.servers_client, server['id']) + compute_node_address = self.get_hypervisor_ip(server['id']) virshxml = clients.VirshXMLClient(compute_node_address) xml = virshxml.dumpxml(server['id']) diff --git a/whitebox_tempest_plugin/api/compute/test_live_migration.py b/whitebox_tempest_plugin/api/compute/test_live_migration.py index 97b9ba9c..c1cba0c1 100644 --- a/whitebox_tempest_plugin/api/compute/test_live_migration.py +++ b/whitebox_tempest_plugin/api/compute/test_live_migration.py @@ -24,7 +24,6 @@ from tempest import config from tempest.lib import decorators from whitebox_tempest_plugin.api.compute import base -from whitebox_tempest_plugin.common import utils as whitebox_utils from whitebox_tempest_plugin.services import clients CONF = config.CONF @@ -84,8 +83,7 @@ class LiveMigrationTest(base.BaseWhiteboxComputeTest): msg) def _get_server_libvirt_domain(self, server_id): - compute_node_address = whitebox_utils.get_hypervisor_ip( - self.servers_client, server_id) + compute_node_address = self.get_hypervisor_ip(server_id) LOG.debug("Connecting to hypervisor %s for server %s", compute_node_address, server_id) diff --git a/whitebox_tempest_plugin/api/compute/test_pointer_device_type.py b/whitebox_tempest_plugin/api/compute/test_pointer_device_type.py index 8ee80513..56aa8376 100644 --- a/whitebox_tempest_plugin/api/compute/test_pointer_device_type.py +++ b/whitebox_tempest_plugin/api/compute/test_pointer_device_type.py @@ -20,7 +20,6 @@ from oslo_log import log as logging from tempest import config from whitebox_tempest_plugin.api.compute import base -from whitebox_tempest_plugin.common import utils as whitebox_utils from whitebox_tempest_plugin.services import clients CONF = config.CONF @@ -43,8 +42,7 @@ class PointerDeviceTypeFromImages(base.BaseWhiteboxComputeTest): def _verify_pointer_device_type_from_images(self, server_id): # Retrieve the server's hypervizor hostname - compute_node_address = whitebox_utils.get_hypervisor_ip( - self.servers_client, server_id) + compute_node_address = self.get_hypervisor_ip(server_id) # Retrieve input device from virsh dumpxml virshxml_client = clients.VirshXMLClient(compute_node_address) diff --git a/whitebox_tempest_plugin/api/compute/test_rx_tx_queue_size.py b/whitebox_tempest_plugin/api/compute/test_rx_tx_queue_size.py index 43a9e601..048b8eee 100644 --- a/whitebox_tempest_plugin/api/compute/test_rx_tx_queue_size.py +++ b/whitebox_tempest_plugin/api/compute/test_rx_tx_queue_size.py @@ -21,7 +21,6 @@ from tempest import config from tempest.lib.common.utils import data_utils from whitebox_tempest_plugin.api.compute import base -from whitebox_tempest_plugin.common import utils as whitebox_utils from whitebox_tempest_plugin.services import clients CONF = config.CONF @@ -73,8 +72,7 @@ class RxTxQueueSizeTest(base.BaseWhiteboxComputeTest): # [libvirt] # rx_queue_size = 1024 def test_rx_queue_size(self): - compute_node_address = whitebox_utils.get_hypervisor_ip( - self.servers_client, self.server_id) + compute_node_address = self.get_hypervisor_ip(self.server_id) LOG.debug("Connecting to hypervisor %s for server %s", compute_node_address, self.server_id) virshxml = clients.VirshXMLClient(compute_node_address) diff --git a/whitebox_tempest_plugin/common/utils.py b/whitebox_tempest_plugin/common/utils.py deleted file mode 100644 index f9f49d72..00000000 --- a/whitebox_tempest_plugin/common/utils.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2017 Red Hat -# 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 oslo_log import log as logging -from tempest import config -from whitebox_tempest_plugin import exceptions - - -CONF = config.CONF -LOG = logging.getLogger(__name__) - - -def get_hypervisor_ip(admin_servers_client, server_id): - server = admin_servers_client.show_server(server_id) - host = server['server']['OS-EXT-SRV-ATTR:host'] - try: - return CONF.whitebox.hypervisors[host] - except KeyError: - raise exceptions.MissingHypervisorException(server=server_id, - host=host) diff --git a/whitebox_tempest_plugin/tests/test_utils.py b/whitebox_tempest_plugin/tests/test_base.py similarity index 66% rename from whitebox_tempest_plugin/tests/test_utils.py rename to whitebox_tempest_plugin/tests/test_base.py index cae03729..0235bfec 100644 --- a/whitebox_tempest_plugin/tests/test_utils.py +++ b/whitebox_tempest_plugin/tests/test_base.py @@ -14,7 +14,7 @@ import mock -from whitebox_tempest_plugin.common import utils +from whitebox_tempest_plugin.api.compute import base as compute_base from whitebox_tempest_plugin import exceptions from whitebox_tempest_plugin.tests import base @@ -30,15 +30,20 @@ class UtilsTestCase(base.WhiteboxPluginTestCase): def setUp(self): super(UtilsTestCase, self).setUp() - self.client = mock.Mock() - self.client.show_server = fake_show_server + # NOTE(artom) We need to mock __init__ for the class to instantiate + # correctly. + compute_base.BaseWhiteboxComputeTest.__init__ = mock.Mock( + return_value=None) + self.test_class = compute_base.BaseWhiteboxComputeTest() + self.test_class.servers_client = mock.Mock() + self.test_class.servers_client.show_server = fake_show_server self.flags(hypervisors={'fake-host': 'fake-ip'}, group='whitebox') def test_get_hypervisor_ip(self): self.assertEqual('fake-ip', - utils.get_hypervisor_ip(self.client, 'fake-id')) + self.test_class.get_hypervisor_ip('fake-id')) - @mock.patch.object(utils.LOG, 'error') + @mock.patch.object(compute_base.LOG, 'error') def test_get_hypervisor_ip_keyerror(self, mock_log): self.assertRaises(exceptions.MissingHypervisorException, - utils.get_hypervisor_ip, self.client, 'missing-id') + self.test_class.get_hypervisor_ip, 'missing-id')