From eb12f68421bac1c0dd410ea2f0bbb828797dfcd3 Mon Sep 17 00:00:00 2001 From: Sean Mooney <work@seanmooney.info> Date: Wed, 19 Feb 2020 15:43:04 +0000 Subject: [PATCH] add support for multi node deployments to fake driver This change alters the fake driver to include the hostname in the deployable list so that each host in a multi node deployment will have a unique placment RP name. Change-Id: Ib0e202cac8af5ef7c5028c22dc0654911eb730f5 --- cyborg/accelerator/drivers/fake.py | 13 ++++++++++++- .../unit/accelerator/drivers/test_fake_driver.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cyborg/accelerator/drivers/fake.py b/cyborg/accelerator/drivers/fake.py index 2b513e13..396f53eb 100644 --- a/cyborg/accelerator/drivers/fake.py +++ b/cyborg/accelerator/drivers/fake.py @@ -11,11 +11,14 @@ # License for the specific language governing permissions and limitations # under the License. +import re + import os_resource_classes as orc from oslo_serialization import jsonutils from cyborg.accelerator.drivers.driver import GenericDriver from cyborg.common import constants +from cyborg.conf import CONF from cyborg.objects.driver_objects import driver_attach_handle from cyborg.objects.driver_objects import driver_attribute from cyborg.objects.driver_objects import driver_controlpath_id @@ -74,7 +77,15 @@ class FakeDriver(GenericDriver): driver_dep = driver_deployable.DriverDeployable() driver_dep.attach_handle_list = self._generate_attach_handles( pci, self.NUM_ACCELERATORS) - driver_dep.name = pci.get('device') + # NOTE(sean-k-mooney): we need to prepend the host name to the + # device name as this is used to generate the RP name and uuid in + # the cyborg conductor when updating placement. As such this needs + # to be unique per host to allow multi node testing with the fake + # driver. + name = "%s_%s" % (CONF.host, pci.get('device')) + # Replace any non alphanumeric, hyphen or underscore character with + # underscore to comply with placement RP name requirements + driver_dep.name = re.sub("(?![a-zA-Z0-9_\-]).", "_", name) driver_dep.driver_name = 'fake' driver_dep.num_accelerators = self.NUM_ACCELERATORS driver_dep.attribute_list = self._generate_attribute_list() diff --git a/cyborg/tests/unit/accelerator/drivers/test_fake_driver.py b/cyborg/tests/unit/accelerator/drivers/test_fake_driver.py index 957df9ec..beb3e374 100644 --- a/cyborg/tests/unit/accelerator/drivers/test_fake_driver.py +++ b/cyborg/tests/unit/accelerator/drivers/test_fake_driver.py @@ -123,7 +123,7 @@ class TestFakeDriver(base.TestCase): deployables = devices[0].deployable_list self.assertEqual(1, len(deployables)) - self.assertEqual('FakeDevice', deployables[0]['name']) + self.assertEqual('fake-mini_FakeDevice', deployables[0]['name']) self.assertGreater(deployables[0]['num_accelerators'], 1) # Since num_accelerators can change, we don't test for its value.