Factor out get_server_xml()

Getting an instance's libvirt XML is a common operation in all tests.
Create a helper for it.

Change-Id: Ib1897cf683c205b1e283a69f6687c7d833fa53ff
This commit is contained in:
Artom Lifshitz 2019-01-22 15:08:23 -05:00
parent 2738ae0bb0
commit 2b3cc2d891
6 changed files with 21 additions and 46 deletions

View File

@ -13,13 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import xml.etree.ElementTree as ET
from oslo_log import log as logging
from tempest.api.compute import base
from tempest.common import waiters
from tempest import config
from whitebox_tempest_plugin import exceptions
from whitebox_tempest_plugin.services import clients
CONF = config.CONF
LOG = logging.getLogger(__name__)
@ -73,3 +75,12 @@ class BaseWhiteboxComputeTest(base.BaseV2ComputeAdminTest):
except KeyError:
raise exceptions.MissingHypervisorException(server=server_id,
host=host)
def get_server_xml(self, server_id):
hv_ip = self.get_hypervisor_ip(server_id)
server_instance_name = self.servers_client.show_server(
server_id)['server']['OS-EXT-SRV-ATTR:instance_name']
virshxml = clients.VirshXMLClient(hv_ip)
xml = virshxml.dumpxml(server_instance_name)
return ET.fromstring(xml)

View File

@ -12,13 +12,11 @@
# 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 xml.etree.ElementTree as ET
from oslo_log import log as logging
from tempest import config
from whitebox_tempest_plugin.api.compute import base
from whitebox_tempest_plugin.services import clients
CONF = config.CONF
@ -35,11 +33,7 @@ class CpuModelExtraFlagsTest(base.BaseWhiteboxComputeTest):
# virt_type = kvm
def test_cpu_model_extra_flags(self):
server = self.create_test_server(wait_until="ACTIVE")
server_id = 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)
root = self.get_server_xml(server['id'])
# Assert that the correct CPU model as well as the proper flags
# are correctly defined in the instance XML

View File

@ -42,11 +42,7 @@ class BasePinningTest(base.BaseWhiteboxComputeTest):
vcpus = 2
def get_server_cpu_pinning(self, server):
compute_node_address = self.get_hypervisor_ip(server['id'])
virshxml = clients.VirshXMLClient(compute_node_address)
xml = virshxml.dumpxml(server['id'])
root = ET.fromstring(xml)
root = self.get_server_xml(server['id'])
vcpupin_nodes = root.findall('./cputune/vcpupin')
cpu_pinnings = {int(x.get('vcpu')): int(x.get('cpuset'))

View File

@ -16,7 +16,6 @@
from oslo_log import log as logging
import testtools
import xml.etree.ElementTree as ET
from tempest.common import utils
from tempest.common import waiters
@ -24,7 +23,6 @@ from tempest import config
from tempest.lib import decorators
from whitebox_tempest_plugin.api.compute import base
from whitebox_tempest_plugin.services import clients
CONF = config.CONF
LOG = logging.getLogger(__name__)
@ -82,16 +80,6 @@ class LiveMigrationTest(base.BaseWhiteboxComputeTest):
self.assertEqual(target_host, self.get_host_for_server(server_id),
msg)
def _get_server_libvirt_domain(self, 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)
virshxml = clients.VirshXMLClient(compute_node_address)
xml = virshxml.dumpxml(server_id)
return ET.fromstring(xml)
@testtools.skipUnless(CONF.compute_feature_enabled.
volume_backed_live_migration,
'Volume-backed live migration not available')
@ -103,7 +91,7 @@ class LiveMigrationTest(base.BaseWhiteboxComputeTest):
volume_backed=True)['id']
def root_disk_cache():
domain = self._get_server_libvirt_domain(server_id)
domain = self.get_server_xml(server_id)
return domain.find(
"devices/disk/target[@dev='vda']/../driver").attrib['cache']

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.services import clients
CONF = config.CONF
LOG = logging.getLogger(__name__)
@ -41,17 +40,11 @@ class PointerDeviceTypeFromImages(base.BaseWhiteboxComputeTest):
self.assertEqual(req_metadata, resp_metadata)
def _verify_pointer_device_type_from_images(self, server_id):
# Retrieve the server's hypervizor hostname
compute_node_address = self.get_hypervisor_ip(server_id)
# Retrieve input device from virsh dumpxml
virshxml_client = clients.VirshXMLClient(compute_node_address)
output = virshxml_client.dumpxml(server_id)
# Verify that input device contains tablet and mouse
tablet = "input type='tablet' bus='usb'"
mouse = "input type='mouse' bus='ps2'"
self.assertTrue(tablet in output)
self.assertTrue(mouse in output)
domain = self.get_server_xml(server_id).text
tablet = domain.find('./input[@type="tablet"][@bus="usb"]')
mouse = domain.find('./input[@type="mouse"][@bus="ps2"]')
self.assertTrue(tablet)
self.assertTrue(mouse)
def test_pointer_device_type_from_images(self):
# TODO(stephenfin): I'm pretty sure this modifying the main image. We

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
#
import xml.etree.ElementTree as ET
from oslo_log import log as logging
from tempest.common import waiters
@ -21,7 +20,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.services import clients
CONF = config.CONF
LOG = logging.getLogger(__name__)
@ -72,12 +70,7 @@ class RxTxQueueSizeTest(base.BaseWhiteboxComputeTest):
# [libvirt]
# rx_queue_size = 1024
def test_rx_queue_size(self):
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)
xml = virshxml.dumpxml(self.server_id)
domain = ET.fromstring(xml)
domain = self.get_server_xml(self.server_id)
driver = domain.find(
"devices/interface[@type='bridge']/driver[@name='vhost']")
self.assertEqual(