Retrieve boot_hba uri from hba object

In some cases we need the hba object to retrieve the wwpn of
the hba used for boot, in some the element-uri. We had 2 different
ways of gathering this information.

This patch transforms the get_boot_hba_uri method into a more generic
get_boot_hba method. From this object it's easy to retrieve the
required properties 'element-uri' and 'wwpn'.

Change-Id: If518a915408caf5c59d4425b8aa2e0673acbcc19
This commit is contained in:
Andreas Scheuring 2018-01-12 11:32:09 +01:00
parent a0c7b2bf6e
commit a9c2c15fdd
4 changed files with 15 additions and 21 deletions

View File

@ -154,6 +154,7 @@ class DPMdriverInitHostTestCase(TestCase):
mock_get_partition.return_value = self.partition
mock_block_device.return_value = BLOCK_DEVICE
inst = vm.PartitionInstance(mock.Mock(), mock.Mock())
target_wwpn, lun = self.dpmdriver.get_fc_boot_props(
mock.Mock(), inst)
self.assertEqual(target_wwpn, '500507680B214AC1')
@ -322,7 +323,7 @@ class DPMDriverInstanceTestCase(TestCase):
@mock.patch.object(driver.DPMDriver, 'get_fc_boot_props',
return_value=(None, None))
@mock.patch.object(vm.PartitionInstance, 'get_boot_hba_uri')
@mock.patch.object(vm.PartitionInstance, 'get_boot_hba')
@mock.patch.object(vm.PartitionInstance, 'launch')
@mock.patch.object(vm.PartitionInstance, 'attach_hbas')
@mock.patch.object(vm.PartitionInstance, 'properties')

View File

@ -284,12 +284,11 @@ class VmPartitionInstanceTestCase(TestCase):
'object-uri') + '/hbas/1',
self.partition_inst.get_hba_uris()[0])
def test_get_boot_hba_uri(self):
def test_get_boot_hba(self):
partition = self.cpc.partitions.find(**{"name": self.part_name})
self.assertEqual(
partition.get_property(
'object-uri') + '/hbas/1',
self.partition_inst.get_boot_hba_uri())
hba = self.partition_inst.get_boot_hba()
self.assertEqual(partition.get_property('object-uri') + '/hbas/1',
hba.get_property('element-uri'))
def test_power_on_vm_when_paused(self):
instance = instance_obj.Instance()

View File

@ -353,7 +353,7 @@ class DPMDriver(driver.ComputeDriver):
nic_boot_string += self._get_nic_string_for_guest_os(nic, vif)
inst.set_boot_os_specific_parameters(nic_boot_string)
hba_uri = inst.get_boot_hba_uri()
hba_uri = inst.get_boot_hba().get_property("element-uri")
LOG.debug("HBA boot uri %s for the instance %s", hba_uri,
instance.hostname)
@ -378,9 +378,7 @@ class DPMDriver(driver.ComputeDriver):
LOG.debug("Block device mapping %s", str(block_device_mapping))
partition_hba_uri = inst.get_boot_hba_uri()
partition_hba = inst.get_partition().hbas.find(**{
"element-uri": partition_hba_uri})
partition_hba = inst.get_boot_hba()
partition_wwpn = partition_hba.get_property('wwpn')
mapped_block_device = block_device_mapping[0]

View File

@ -251,20 +251,16 @@ class PartitionInstance(object):
LOG.debug('Get Hba properties')
return self.partition.get_property('hba-uris')
def get_boot_hba_uri(self):
hbas = self.get_hba_uris()
def get_boot_hba(self):
# Using the first adapter in the config option for boot
adapter_uuid, port = CONF.dpm.physical_storage_adapter_mappings[0]
hba_uri = None
for hba in hbas:
if hba.find(adapter_uuid):
hba_uri = str(hba)
break
if not hba_uri:
raise Exception('No HBA found')
return hba_uri
adapter_port_uri = "/api/adapters/%s/storage-ports/%s" % (adapter_uuid,
port)
# will raise zhmcclient NoUniqueMatch exception when multiple found
hba = self.partition.hbas.find(
**{"adapter-port-uri": adapter_port_uri})
return hba
def get_partition_wwpns(self):
LOG.debug('Get Partition wwpns')