VMware: replace hardcoded strings with constants
In many places hardcoded strings are used instead already existing constants. TrivialFix Change-Id: Ic584dba3660c9d02e30992432462bc09e62e81af
This commit is contained in:
@@ -618,10 +618,10 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_ephemeral_disk_attach_from_bdi(self):
|
||||
ephemerals = [{'device_type': 'disk',
|
||||
'disk_bus': 'lsiLogic',
|
||||
'disk_bus': constants.DEFAULT_ADAPTER_TYPE,
|
||||
'size': 25},
|
||||
{'device_type': 'disk',
|
||||
'disk_bus': 'lsiLogic',
|
||||
'disk_bus': constants.DEFAULT_ADAPTER_TYPE,
|
||||
'size': 25}]
|
||||
bdi = {'ephemerals': ephemerals}
|
||||
self._create_vm(bdi=bdi, ephemeral=50)
|
||||
|
||||
@@ -203,14 +203,14 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
def test_lsilogic_controller_spec(self):
|
||||
# Test controller spec returned for lsiLogic sas adapter type
|
||||
config_spec = vm_util.create_controller_spec(fake.FakeFactory(), -101,
|
||||
adapter_type="lsiLogicsas")
|
||||
adapter_type=constants.ADAPTER_TYPE_LSILOGICSAS)
|
||||
self.assertEqual("ns0:VirtualLsiLogicSASController",
|
||||
config_spec.device.obj_name)
|
||||
|
||||
def test_paravirtual_controller_spec(self):
|
||||
# Test controller spec returned for paraVirtual adapter type
|
||||
config_spec = vm_util.create_controller_spec(fake.FakeFactory(), -101,
|
||||
adapter_type="paraVirtual")
|
||||
adapter_type=constants.ADAPTER_TYPE_PARAVIRTUAL)
|
||||
self.assertEqual("ns0:ParaVirtualSCSIController",
|
||||
config_spec.device.obj_name)
|
||||
|
||||
@@ -243,7 +243,8 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
session = fake.FakeSession()
|
||||
with mock.patch.object(session, '_call_method', return_value=devices):
|
||||
vmdk = vm_util.get_vmdk_info(session, None)
|
||||
self.assertEqual('lsiLogicsas', vmdk.adapter_type)
|
||||
self.assertEqual(constants.ADAPTER_TYPE_LSILOGICSAS,
|
||||
vmdk.adapter_type)
|
||||
self.assertEqual('[test_datastore] uuid/ephemeral_0.vmdk',
|
||||
vmdk.path)
|
||||
self.assertEqual(512, vmdk.capacity_in_bytes)
|
||||
@@ -255,7 +256,8 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
session = fake.FakeSession()
|
||||
with mock.patch.object(session, '_call_method', return_value=devices):
|
||||
vmdk = vm_util.get_vmdk_info(session, None, uuid='uuid')
|
||||
self.assertEqual('lsiLogicsas', vmdk.adapter_type)
|
||||
self.assertEqual(constants.ADAPTER_TYPE_LSILOGICSAS,
|
||||
vmdk.adapter_type)
|
||||
self.assertEqual(n_filename, vmdk.path)
|
||||
self.assertEqual(1024, vmdk.capacity_in_bytes)
|
||||
self.assertEqual(devices[0], vmdk.device)
|
||||
@@ -275,12 +277,15 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
# Test for the adapter_type to be used in vmdk descriptor
|
||||
# Adapter type in vmdk descriptor is same for LSI-SAS, LSILogic
|
||||
# and ParaVirtual
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type("lsiLogic")
|
||||
self.assertEqual("lsiLogic", vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type("lsiLogicsas")
|
||||
self.assertEqual("lsiLogic", vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type("paraVirtual")
|
||||
self.assertEqual("lsiLogic", vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type(
|
||||
constants.DEFAULT_ADAPTER_TYPE)
|
||||
self.assertEqual(constants.DEFAULT_ADAPTER_TYPE, vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type(
|
||||
constants.ADAPTER_TYPE_LSILOGICSAS)
|
||||
self.assertEqual(constants.DEFAULT_ADAPTER_TYPE, vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type(
|
||||
constants.ADAPTER_TYPE_PARAVIRTUAL)
|
||||
self.assertEqual(constants.DEFAULT_ADAPTER_TYPE, vmdk_adapter_type)
|
||||
vmdk_adapter_type = vm_util.get_vmdk_adapter_type("dummyAdapter")
|
||||
self.assertEqual("dummyAdapter", vmdk_adapter_type)
|
||||
|
||||
@@ -374,9 +379,9 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
factory = fake.FakeFactory()
|
||||
(controller_key, unit_number,
|
||||
controller_spec) = vm_util.allocate_controller_key_and_unit_number(
|
||||
factory,
|
||||
devices,
|
||||
'lsiLogic')
|
||||
factory,
|
||||
devices,
|
||||
constants.DEFAULT_ADAPTER_TYPE)
|
||||
self.assertEqual(1000, controller_key)
|
||||
self.assertEqual(8, unit_number)
|
||||
self.assertIsNone(controller_spec)
|
||||
@@ -513,7 +518,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
|
||||
expected.version = None
|
||||
expected.memoryMB = 2048
|
||||
expected.guestId = 'otherGuest'
|
||||
expected.guestId = constants.DEFAULT_OS_TYPE
|
||||
expected.extraConfig = []
|
||||
|
||||
extra_config = fake_factory.create("ns0:OptionValue")
|
||||
@@ -547,7 +552,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
extra_specs)
|
||||
expected = fake_factory.create('ns0:VirtualMachineConfigSpec')
|
||||
expected.deviceChange = []
|
||||
expected.guestId = 'otherGuest'
|
||||
expected.guestId = constants.DEFAULT_OS_TYPE
|
||||
expected.instanceUuid = self._instance.uuid
|
||||
expected.memoryMB = self._instance.memory_mb
|
||||
expected.name = self._instance.uuid
|
||||
@@ -611,7 +616,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
expected.managedBy.type = 'instance'
|
||||
|
||||
expected.version = None
|
||||
expected.guestId = 'otherGuest'
|
||||
expected.guestId = constants.DEFAULT_OS_TYPE
|
||||
|
||||
expected.tools = fake_factory.create('ns0:ToolsConfigInfo')
|
||||
expected.tools.afterPowerOn = True
|
||||
@@ -661,7 +666,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
expected.managedBy.extensionKey = 'org.openstack.compute'
|
||||
|
||||
expected.version = None
|
||||
expected.guestId = 'otherGuest'
|
||||
expected.guestId = constants.DEFAULT_OS_TYPE
|
||||
|
||||
expected.tools = fake_factory.create('ns0:ToolsConfigInfo')
|
||||
expected.tools.beforeGuestStandby = True
|
||||
@@ -709,7 +714,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
expected.managedBy.type = 'instance'
|
||||
|
||||
expected.version = None
|
||||
expected.guestId = 'otherGuest'
|
||||
expected.guestId = constants.DEFAULT_OS_TYPE
|
||||
expected.tools = fake_factory.create('ns0:ToolsConfigInfo')
|
||||
expected.tools.beforeGuestStandby = True
|
||||
expected.tools.beforeGuestReboot = True
|
||||
|
||||
@@ -1313,7 +1313,7 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
|
||||
'fake_ds',
|
||||
[],
|
||||
extra_specs,
|
||||
'otherGuest',
|
||||
constants.DEFAULT_OS_TYPE,
|
||||
profile_spec=None,
|
||||
metadata='fake-metadata')
|
||||
mock_create_vm.assert_called_once_with(
|
||||
@@ -1529,7 +1529,7 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
|
||||
vi.ii.adapter_type)
|
||||
mock_caa.assert_called_once_with(
|
||||
self._instance, 'fake-vm-ref',
|
||||
vi.dc_info, 1 * units.Mi, 'lsiLogic',
|
||||
vi.dc_info, 1 * units.Mi, constants.DEFAULT_ADAPTER_TYPE,
|
||||
'[fake_ds] fake_uuid/ephemeral_0.vmdk')
|
||||
|
||||
def test_create_ephemeral_with_bdi_but_no_ephemerals(self):
|
||||
|
||||
@@ -120,7 +120,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
|
||||
'data': {'volume': 'vm-10',
|
||||
'volume_id': 'volume-fake-id'}}
|
||||
instance = mock.MagicMock(name='fake-name', vm_state=vm_states.ACTIVE)
|
||||
vmdk_info = vm_util.VmdkInfo('fake-path', 'ide', 'preallocated', 1024,
|
||||
vmdk_info = vm_util.VmdkInfo('fake-path', constants.ADAPTER_TYPE_IDE,
|
||||
constants.DISK_TYPE_PREALLOCATED, 1024,
|
||||
'fake-device')
|
||||
with contextlib.nested(
|
||||
mock.patch.object(vm_util, 'get_vm_ref'),
|
||||
@@ -144,7 +145,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
|
||||
'data': {'volume': 'vm-10',
|
||||
'volume_id': 'volume-fake-id'}}
|
||||
instance = mock.MagicMock(name='fake-name', vm_state=vm_states.ACTIVE)
|
||||
vmdk_info = vm_util.VmdkInfo('fake-path', 'ide', 'preallocated', 1024,
|
||||
vmdk_info = vm_util.VmdkInfo('fake-path', constants.ADAPTER_TYPE_IDE,
|
||||
constants.DISK_TYPE_PREALLOCATED, 1024,
|
||||
'fake-device')
|
||||
with contextlib.nested(
|
||||
mock.patch.object(vm_util, 'get_vm_ref',
|
||||
|
||||
@@ -309,7 +309,7 @@ def _build_shadow_vm_config_spec(session, name, size_kb, disk_type, ds_name):
|
||||
|
||||
create_spec = cf.create('ns0:VirtualMachineConfigSpec')
|
||||
create_spec.name = name
|
||||
create_spec.guestId = 'otherGuest'
|
||||
create_spec.guestId = constants.DEFAULT_OS_TYPE
|
||||
create_spec.numCPUs = 1
|
||||
create_spec.memoryMB = 128
|
||||
create_spec.deviceChange = [controller_spec, disk_spec]
|
||||
@@ -461,11 +461,11 @@ def upload_image_stream_optimized(context, image_id, instance, session,
|
||||
# Otherwise, the image service client will use the VM's disk capacity
|
||||
# which will not be the image size after upload, since it is converted
|
||||
# to a stream-optimized sparse disk.
|
||||
image_metadata = {'disk_format': 'vmdk',
|
||||
image_metadata = {'disk_format': constants.DISK_FORMAT_VMDK,
|
||||
'is_public': metadata['is_public'],
|
||||
'name': metadata['name'],
|
||||
'status': 'active',
|
||||
'container_format': 'bare',
|
||||
'container_format': constants.CONTAINER_FORMAT_BARE,
|
||||
'size': 0,
|
||||
'properties': {'vmware_image_version': 1,
|
||||
'vmware_disktype': 'streamOptimized',
|
||||
|
||||
@@ -766,10 +766,10 @@ def create_virtual_disk_spec(client_factory, controller_key,
|
||||
disk_file_backing = client_factory.create(
|
||||
'ns0:VirtualDiskFlatVer2BackingInfo')
|
||||
disk_file_backing.diskMode = "persistent"
|
||||
if disk_type == "thin":
|
||||
if disk_type == constants.DISK_TYPE_THIN:
|
||||
disk_file_backing.thinProvisioned = True
|
||||
else:
|
||||
if disk_type == "eagerZeroedThick":
|
||||
if disk_type == constants.DISK_TYPE_EAGER_ZEROED_THICK:
|
||||
disk_file_backing.eagerlyScrub = True
|
||||
disk_file_backing.fileName = file_path or ""
|
||||
|
||||
|
||||
@@ -734,9 +734,9 @@ class VMwareVMOps(object):
|
||||
"VirtualMachine", "config.hardware.device")
|
||||
(controller_key, unit_number,
|
||||
controller_spec) = vm_util.allocate_controller_key_and_unit_number(
|
||||
client_factory,
|
||||
devices,
|
||||
'ide')
|
||||
client_factory,
|
||||
devices,
|
||||
constants.ADAPTER_TYPE_IDE)
|
||||
cdrom_attach_config_spec = vm_util.get_cdrom_attach_config_spec(
|
||||
client_factory, datastore, file_path,
|
||||
controller_key, unit_number)
|
||||
|
||||
@@ -367,7 +367,7 @@ class VMwareVolumeOps(object):
|
||||
driver_type = connection_info['driver_volume_type']
|
||||
LOG.debug("Volume attach. Driver type: %s", driver_type,
|
||||
instance=instance)
|
||||
if driver_type == 'vmdk':
|
||||
if driver_type == constants.DISK_FORMAT_VMDK:
|
||||
self._attach_volume_vmdk(connection_info, instance, adapter_type)
|
||||
elif driver_type == 'iscsi':
|
||||
self._attach_volume_iscsi(connection_info, instance, adapter_type)
|
||||
@@ -542,7 +542,7 @@ class VMwareVolumeOps(object):
|
||||
driver_type = connection_info['driver_volume_type']
|
||||
LOG.debug("Volume detach. Driver type: %s", driver_type,
|
||||
instance=instance)
|
||||
if driver_type == 'vmdk':
|
||||
if driver_type == constants.DISK_FORMAT_VMDK:
|
||||
self._detach_volume_vmdk(connection_info, instance)
|
||||
elif driver_type == 'iscsi':
|
||||
self._detach_volume_iscsi(connection_info, instance)
|
||||
@@ -555,7 +555,7 @@ class VMwareVolumeOps(object):
|
||||
driver_type = connection_info['driver_volume_type']
|
||||
LOG.debug("Root volume attach. Driver type: %s", driver_type,
|
||||
instance=instance)
|
||||
if driver_type == 'vmdk':
|
||||
if driver_type == constants.DISK_FORMAT_VMDK:
|
||||
vm_ref = vm_util.get_vm_ref(self._session, instance)
|
||||
data = connection_info['data']
|
||||
# Get the volume ref
|
||||
|
||||
Reference in New Issue
Block a user