FUP for test_reshape

Fix a couple of minor issues found while working the reshaper series:

- Move mdev name/uuid conversions to helpers [0], [1]
- Typo: PR=>RP [2]
- Typo: temporally=>temporarily [3]

[0] https://review.openstack.org/#/c/599208/18/nova/virt/libvirt/driver.py@6835
[1] https://review.openstack.org/#/c/639854/4/nova/tests/functional/libvirt/test_reshape.py@117
[2] https://review.openstack.org/#/c/639854/4/nova/tests/functional/libvirt/test_reshape.py@189
[3] https://review.openstack.org/#/c/639854/4/nova/tests/functional/libvirt/test_reshape.py@98

Change-Id: I8d9b2b2f49a72e656a7ab263025f59000813f5b4
This commit is contained in:
Eric Fried 2019-03-06 14:57:52 -06:00
parent a5d174c29f
commit e3376eaa42
4 changed files with 30 additions and 5 deletions

View File

@ -20,6 +20,8 @@ from nova import context
from nova import objects
from nova.tests.functional.libvirt import base
from nova.tests.unit.virt.libvirt import fakelibvirt
from nova.virt.libvirt import utils
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
@ -95,7 +97,7 @@ class VGPUReshapeTests(base.ServersTestBase):
# NOTE(gibi): during instance_claim() there is a
# driver.update_provider_tree() call that would detect the old tree and
# would fail as this is not a good time to reshape. To avoid that we
# temporally mock update_provider_tree here.
# temporarily mock update_provider_tree here.
with mock.patch('nova.virt.libvirt.driver.LibvirtDriver.'
'update_provider_tree'):
created_server1 = self.api.post_server({'server': server_req})
@ -114,7 +116,7 @@ class VGPUReshapeTests(base.ServersTestBase):
self.assertEqual(1, len(mdevs))
mdev_uuid = mdevs[0]
mdev_info = self.compute.driver._get_mediated_device_information(
"mdev_" + mdev_uuid.replace('-', '_'))
utils.mdev_uuid2name(mdev_uuid))
inst_to_pgpu[inst.uuid] = mdev_info['parent']
# The VGPUs should have come from different pGPUs
self.assertNotEqual(*list(inst_to_pgpu.values()))
@ -186,7 +188,7 @@ class VGPUReshapeTests(base.ServersTestBase):
{'DISK_GB': 20, 'MEMORY_MB': 2048, 'VCPU': 2},
allocations[compute_rp_uuid]['resources'])
rp_uuids = list(allocations.keys())
# We only have two RPs, the compute PR (the root) and the child
# We only have two RPs, the compute RP (the root) and the child
# pGPU RP
gpu_rp_uuid = (rp_uuids[1] if rp_uuids[0] == compute_rp_uuid
else rp_uuids[0])

View File

@ -177,3 +177,11 @@ def version_to_string(version):
def cpu_features_to_traits(features):
return libvirt_utils.cpu_features_to_traits(features)
def mdev_name2uuid(mdev_name):
return libvirt_utils.mdev_name2uuid(mdev_name)
def mdev_uuid2name(mdev_uuid):
return libvirt_utils.mdev_uuid2name(mdev_uuid)

View File

@ -6137,7 +6137,7 @@ class LibvirtDriver(driver.ComputeDriver):
device = {
"dev_id": cfgdev.name,
# name is like mdev_00ead764_fdc0_46b6_8db9_2963f5c815b4
"uuid": str(uuid.UUID(cfgdev.name[5:].replace('_', '-'))),
"uuid": libvirt_utils.mdev_name2uuid(cfgdev.name),
# the physical GPU PCI device
"parent": cfgdev.parent,
"type": cfgdev.mdev_information.type,
@ -6833,7 +6833,7 @@ class LibvirtDriver(driver.ComputeDriver):
vgpu_count_per_pgpu = collections.defaultdict(int)
for mdev_uuid in mdev_uuids:
# libvirt name is like mdev_00ead764_fdc0_46b6_8db9_2963f5c815b4
dev_name = "mdev_" + mdev_uuid.replace('-', '_')
dev_name = libvirt_utils.mdev_uuid2name(mdev_uuid)
# Count how many vGPUs are in use for this instance
dev_info = self._get_mediated_device_information(dev_name)
pgpu_dev_id = dev_info['parent']

View File

@ -21,6 +21,7 @@
import errno
import os
import re
import uuid
import os_traits
from oslo_concurrency import processutils
@ -546,3 +547,17 @@ def get_cpu_model_from_arch(arch):
elif arch == obj_fields.Architecture.PPC64LE:
mode = 'POWER8'
return mode
def mdev_name2uuid(mdev_name):
"""Convert an mdev name (of the form mdev_<uuid_with_underscores>) to a
uuid (of the form 8-4-4-4-12).
"""
return str(uuid.UUID(mdev_name[5:].replace('_', '-')))
def mdev_uuid2name(mdev_uuid):
"""Convert an mdev uuid (of the form 8-4-4-4-12) to a name (of the form
mdev_<uuid_with_underscores>).
"""
return "mdev_" + mdev_uuid.replace('-', '_')