virt: refactor method compute_driver_matches
We only use method compute_driver_matches for checking if compute_driver equals 'xenapi.XenAPIDriver'. To be explicit, just rename it to is_xenapi. Change-Id: I2fb61491c4a321ab430f39476127412d8ee17c0d
This commit is contained in:
parent
848de1f712
commit
f89fe67ae7
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue