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
This commit is contained in:
Artom Lifshitz 2019-01-26 11:14:25 -05:00
parent d3c648e1e4
commit 2738ae0bb0
8 changed files with 27 additions and 53 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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'])

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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')