Retrieve PartitionInstance via getter method

In some methods we directly created an instance of the PartitionInstnace object.
The instantiation of this object is now moved into a separate method. This is
even more usefull when we introduce ssc support in the future. In that case
we could simply introduce a SSCPartitionInstance class. The newly created method
would be the only place where the decission between ssc and pure dpm is done.

Change-Id: I06e6d8ee84b7f308f2cdbf120c08e46afd4dd8be
This commit is contained in:
Andreas Scheuring 2018-01-12 10:05:27 +01:00
parent 0e24d6b6cd
commit a0c7b2bf6e
2 changed files with 21 additions and 10 deletions

View File

@ -238,7 +238,9 @@ class DPMdriverInitHostTestCase(TestCase):
@mock.patch.object(vm.PartitionInstance, 'get_partition')
def test_get_volume_connector(self, mock_get_partition):
self.dpmdriver.get_volume_connector(mock.Mock())
instance = mock.Mock()
instance.image_ref = ""
self.dpmdriver.get_volume_connector(instance)
def test_get_available_nodes(self):
self.flags(host="fake-mini")
@ -312,9 +314,11 @@ class DPMDriverInstanceTestCase(TestCase):
def test_spawn_max_nics(self, mock_prop, mock_create, mock_get_part):
dpmdriver = driver.DPMDriver(None)
network_info = [x for x in range(0, 13)]
mock_instance = mock.Mock()
mock_instance.image_ref = ""
self.assertRaises(exceptions.MaxAmountOfInstancePortsExceededError,
dpmdriver.spawn, None, None, None, None, None,
None, network_info)
dpmdriver.spawn, None, mock_instance, None, None,
None, None, network_info)
@mock.patch.object(driver.DPMDriver, 'get_fc_boot_props',
return_value=(None, None))
@ -332,6 +336,7 @@ class DPMDriverInstanceTestCase(TestCase):
mock_instance = mock.Mock()
mock_instance.uuid = "1"
mock_instance.image_ref = ""
vif = {"address": "aa:bb:cc:dd:ee:ff",
"id": "foo-id",

View File

@ -69,6 +69,12 @@ class DPMDriver(driver.ComputeDriver):
self.volume_drivers = self._get_volume_drivers()
def _get_partition_instance(self, instance):
if instance.image_ref != '':
raise exceptions.BootFromImageNotSupported()
else:
return vm.PartitionInstance(instance, self._cpc)
def init_host(self, host):
"""Driver initialization of the hypervisor node"""
LOG.debug("init_host")
@ -201,7 +207,7 @@ class DPMDriver(driver.ComputeDriver):
props['wwpns'] = self.deleted_instance_wwpns_mapping.pop(
instance.uuid)
else:
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
props['wwpns'] = inst.get_partition_wwpns()
props['host'] = instance.uuid
@ -316,7 +322,7 @@ class DPMDriver(driver.ComputeDriver):
if instance.image_ref != '':
raise exceptions.BootFromImageNotSupported()
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
inst.create(inst.properties())
inst.attach_hbas()
@ -325,7 +331,7 @@ class DPMDriver(driver.ComputeDriver):
admin_password, allocations, network_info=None,
block_device_info=None):
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
# The creation of NICs is limited in DPM by the partitions
# boot-os-specific-parameters property. It is used to pass additional
@ -422,7 +428,7 @@ class DPMDriver(driver.ComputeDriver):
def destroy(self, context, instance, network_info, block_device_info=None,
destroy_disks=True, migrate_data=None):
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
# Need to save wwpns before deletion of the partition
# Because after driver.destroy function driver.get_volume_connector
# will be called which required hbas wwpns of partition.
@ -431,15 +437,15 @@ class DPMDriver(driver.ComputeDriver):
inst.destroy()
def power_off(self, instance, timeout=0, retry_interval=0):
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
inst.power_off_vm()
def power_on(self, context, instance, network_info,
block_device_info=None):
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
inst.power_on_vm()
def reboot(self, context, instance, network_info, reboot_type,
block_device_info=None, bad_volumes_callback=None):
inst = vm.PartitionInstance(instance, self._cpc)
inst = self._get_partition_instance(instance)
inst.reboot_vm()