diff --git a/nova/block_device.py b/nova/block_device.py index 31dd9bda73bf..b40aa5c7a0dc 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -510,7 +510,7 @@ def instance_block_mapping(instance, bdms): root_device_name = instance['root_device_name'] # NOTE(clayg): remove this when xenapi is setting default_root_device if root_device_name is None: - if driver.compute_driver_matches('xenapi.XenAPIDriver'): + if driver.is_xenapi(): root_device_name = '/dev/xvda' else: return _DEFAULT_MAPPINGS diff --git a/nova/compute/utils.py b/nova/compute/utils.py index ee801f5e87f7..e98eca281497 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -136,7 +136,6 @@ def get_next_device_name(instance, device_name_list, /dev/vdc is specified but the backend uses /dev/xvdc), the device name will be converted to the appropriate format. """ - is_xen = driver.compute_driver_matches('xenapi.XenAPIDriver') req_prefix = None req_letter = None @@ -157,7 +156,7 @@ def get_next_device_name(instance, device_name_list, raise exception.InvalidDevicePath(path=root_device_name) # NOTE(vish): remove this when xenapi is setting default_root_device - if is_xen: + if driver.is_xenapi(): prefix = '/dev/xvd' if req_prefix != prefix: @@ -171,7 +170,7 @@ def get_next_device_name(instance, device_name_list, # NOTE(vish): remove this when xenapi is properly setting # default_ephemeral_device and default_swap_device - if is_xen: + if driver.is_xenapi(): flavor = instance.get_flavor() if flavor.ephemeral_gb: used_letters.add('b') diff --git a/nova/tests/unit/compute/test_compute_utils.py b/nova/tests/unit/compute/test_compute_utils.py index 429b831227c4..402be955d6a1 100644 --- a/nova/tests/unit/compute/test_compute_utils.py +++ b/nova/tests/unit/compute/test_compute_utils.py @@ -48,7 +48,7 @@ import nova.tests.unit.image.fake from nova.tests.unit.objects import test_flavor from nova.tests.unit.objects import test_migration from nova.tests import uuidsentinel as uuids -from nova.virt import driver + CONF = nova.conf.CONF CONF.import_opt('compute_manager', 'nova.service') @@ -288,19 +288,9 @@ class DefaultDeviceNamesForInstanceTestCase(test.NoDBTestCase): self.root_device_name = '/dev/vda' self.update_called = False - def fake_driver_matches(driver_string): - if driver_string == 'libvirt.LibvirtDriver': - return self.is_libvirt - return False - self.patchers = [] self.patchers.append( mock.patch.object(objects.BlockDeviceMapping, 'save')) - self.patchers.append( - mock.patch.object(driver, - 'compute_driver_matches', - new=mock.Mock( - side_effect=fake_driver_matches))) for patcher in self.patchers: patcher.start() diff --git a/nova/tests/unit/virt/test_driver.py b/nova/tests/unit/virt/test_driver.py index 572afdedeca7..aa7478ca0b96 100644 --- a/nova/tests/unit/virt/test_driver.py +++ b/nova/tests/unit/virt/test_driver.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import fixture as fixture_config + from nova import test from nova.virt import driver @@ -56,3 +58,24 @@ class ToDriverRegistryTestCase(test.NoDBTestCase): drvs['key2'], FakeDriver2, 'arg1', 'arg2', param1='value1', param2='value2') + + +class DriverMethodTestCase(test.NoDBTestCase): + + def setUp(self): + super(DriverMethodTestCase, self).setUp() + self.CONF = self.useFixture(fixture_config.Config()).conf + + def test_is_xenapi_true(self): + self.CONF.set_override('compute_driver', 'xenapi.XenAPIDriver', + enforce_type=True) + self.assertTrue(driver.is_xenapi()) + + def test_is_xenapi_false(self): + driver_names = ('libvirt.LibvirtDriver', 'fake.FakeDriver', + 'ironic.IronicDriver', 'vmwareapi.VMwareVCDriver', + 'hyperv.HyperVDriver', None) + for driver_name in driver_names: + self.CONF.set_override('compute_driver', driver_name, + enforce_type=True) + self.assertFalse(driver.is_xenapi()) diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 0412ec1fdc16..ef8272712476 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -1626,5 +1626,5 @@ def load_compute_driver(virtapi, compute_driver=None): sys.exit(1) -def compute_driver_matches(match): - return CONF.compute_driver and CONF.compute_driver.endswith(match) +def is_xenapi(): + return CONF.compute_driver == 'xenapi.XenAPIDriver'