Set volume ID as dev tag when mapping VSCSI vols

To facilitate subsequent discovery and correlation between the cinder
volume and the physical device, tag the device with the volume_id from
the BDM connection info when it is attached.  This sprung out of [1].

[1] https://github.ibm.com/powercloud/icp-ppc64le/issues/151#issuecomment-4075391

Change-Id: Ifa345764df119d0a8f2ff985b74f8ecc21aa2b74
This commit is contained in:
Eric Fried 2018-03-12 18:02:48 -05:00
parent 6249706488
commit 1f84164ae5
9 changed files with 41 additions and 21 deletions

View File

@ -49,8 +49,10 @@ class TestFileIOVolumeAdapter(test_vol.TestVolumeAdapter):
self.adpt = self.useFixture(pvm_fx.AdapterFx()).adpt
mock_inst = mock.MagicMock(uuid='2BC123')
self.vol_drv = FakeFileIOVolAdapter(self.adpt, 'host_uuid', mock_inst,
dict(serial='volid1'))
self.vol_drv = FakeFileIOVolAdapter(
self.adpt, 'host_uuid', mock_inst,
{'data': {'volume_id': 'a_vol_id'},
'serial': 'volid1'})
self.fake_vios = pvm_vios.VIOS.bld(
self.adpt, 'vios1',
@ -96,7 +98,7 @@ class TestFileIOVolumeAdapter(test_vol.TestVolumeAdapter):
# Validate
mock_file_bld.assert_called_once_with(
self.adpt, 'fake_path',
backstore_type=pvm_stg.BackStoreType.FILE_IO)
backstore_type=pvm_stg.BackStoreType.FILE_IO, tag='a_vol_id')
self.assertEqual(1, mock_build_map.call_count)
self.assertEqual(1, mock_udid_to_map.call_count)
@ -128,7 +130,7 @@ class TestFileIOVolumeAdapter(test_vol.TestVolumeAdapter):
# Validate
mock_file_bld.assert_called_once_with(
self.adpt, 'fake_path',
backstore_type=pvm_stg.BackStoreType.FILE_IO)
backstore_type=pvm_stg.BackStoreType.FILE_IO, tag='a_vol_id')
self.assertEqual(0, mock_build_map.call_count)
@mock.patch('pypowervm.tasks.partition.get_mgmt_partition', autospec=True)

View File

@ -74,7 +74,8 @@ class TestISCSIAdapter(test_vol.TestVolumeAdapter):
'target_lun': self.lun,
'target_portal': self.host_ip,
'auth_username': self.user,
'auth_password': self.password
'auth_password': self.password,
'volume_id': 'a_volume_id',
},
}
self.auth_method = 'CHAP'
@ -94,7 +95,8 @@ class TestISCSIAdapter(test_vol.TestVolumeAdapter):
'discovery_auth_password': self.password,
'target_iqns': [self.iqn],
'target_luns': [self.lun],
'target_portals': [self.host_ip]
'target_portals': [self.host_ip],
'volume_id': 'b_volume_id',
},
}
mock_inst = mock.MagicMock()
@ -135,6 +137,7 @@ class TestISCSIAdapter(test_vol.TestVolumeAdapter):
self.assertIsInstance(vios_w, pvm_vios.VIOS)
self.assertEqual('1234', lpar_uuid)
self.assertIsInstance(pv, pvm_stor.PV)
self.assertEqual('_volume_id', pv.tag[1:])
self.assertEqual(62, lpar_slot_num)
self.assertEqual('the_lua', lua)
self.assertEqual('ISCSI-bar_%s' % self.lun, target_name)

View File

@ -45,9 +45,10 @@ class TestRBDVolumeAdapter(test_vol.TestVolumeAdapter):
self.adpt = self.useFixture(pvm_fx.AdapterFx()).adpt
mock_inst = mock.MagicMock(uuid='2BC123')
self.vol_drv = FakeRBDVolAdapter(self.adpt, 'host_uuid', mock_inst,
{'data': {'name': 'pool/image'},
'serial': 'volid1'})
self.vol_drv = FakeRBDVolAdapter(
self.adpt, 'host_uuid', mock_inst,
{'data': {'name': 'pool/image', 'volume_id': 'a_vol_id'},
'serial': 'volid1'})
self.fake_vios = pvm_vios.VIOS.bld(
self.adpt, 'vios1',
@ -95,7 +96,7 @@ class TestRBDVolumeAdapter(test_vol.TestVolumeAdapter):
# Validate
mock_rbd_bld_ref.assert_called_once_with(
self.adpt, 'pool/image')
self.adpt, 'pool/image', tag='a_vol_id')
self.assertEqual(1, mock_build_map.call_count)
self.assertEqual(1, mock_udid_to_map.call_count)
@ -128,7 +129,7 @@ class TestRBDVolumeAdapter(test_vol.TestVolumeAdapter):
# Validate
mock_rbd_bld_ref.assert_called_once_with(
self.adpt, 'pool/image')
self.adpt, 'pool/image', tag='a_vol_id')
self.assertEqual(0, mock_build_map.call_count)
@mock.patch('pypowervm.entities.Entry.uuid',

View File

@ -69,7 +69,8 @@ class BaseVSCSITest(test_vol.TestVolumeAdapter):
p_wwpn1: ['t1'],
p_wwpn2: ['t2', 't3']
},
'target_lun': '1'
'target_lun': '1',
'volume_id': 'a_volume_identifier',
},
}
mock_inst = mock.MagicMock()
@ -210,6 +211,7 @@ class TestVSCSIAdapter(BaseVSCSITest):
self.assertIsInstance(vios_w, pvm_vios.VIOS)
self.assertEqual('1234', lpar_uuid)
self.assertIsInstance(pv, pvm_stor.PV)
self.assertEqual('a_volume_identifier', pv.tag)
self.assertEqual(62, lpar_slot_num)
self.assertEqual('the_lua', lua)
return 'fake_map'

View File

@ -94,10 +94,10 @@ class FileIOVolumeAdapter(v_driver.PowerVMVolumeAdapter):
def _connect_volume(self, slot_mgr):
path = self._get_path()
# Get the File Path
volid = self.connection_info['data']['volume_id']
fio = pvm_stg.FileIO.bld(
self.adapter, path,
backstore_type=pvm_stg.BackStoreType.FILE_IO)
backstore_type=pvm_stg.BackStoreType.FILE_IO, tag=volid)
def add_func(vios_w):
# If the vios doesn't match, just return

View File

@ -163,12 +163,13 @@ class IscsiVolumeAdapter(volume.VscsiVolumeAdapter,
iqn = self.connection_info["data"]["target_iqn"]
lun = self.connection_info["data"]["target_lun"]
target_name = "ISCSI-%s_%s" % (iqn.split(":")[1], str(lun))
volume_id = self.connection_info["data"]["volume_id"]
# Found a hdisk on this Virtual I/O Server. Add the action to
# map it to the VM when the stg_ftsk is executed.
with lockutils.lock(hash(self)):
self._add_append_mapping(
vios_w.uuid, device_name, lpar_slot_num=slot, lua=lua,
target_name=target_name, udid=udid)
target_name=target_name, udid=udid, tag=volume_id)
# Save the devname for the disk in the connection info. It is
# used for the detach.

View File

@ -87,8 +87,8 @@ class RBDVolumeAdapter(v_driver.PowerVMVolumeAdapter):
def _connect_volume(self, slot_mgr):
name = self.connection_info["data"]["name"]
# Get the File Path
rbd = pvm_stg.RBD.bld_ref(self.adapter, name)
volid = self.connection_info["data"]["volume_id"]
rbd = pvm_stg.RBD.bld_ref(self.adapter, name, tag=volid)
def add_func(vios_w):
# If the vios doesn't match, just return

View File

@ -129,11 +129,12 @@ class VscsiVolumeAdapter(object):
raise p_exc.VolumeAttachFailed(**ex_args)
def _add_append_mapping(self, vios_uuid, device_name, lpar_slot_num=None,
lua=None, target_name=None, udid=None):
lua=None, target_name=None, udid=None,
tag=None):
"""Update the stg_ftsk to append the mapping to the VIOS.
:param vios_uuid: The UUID of the vios for the pypowervm adapter.
:param device_name: The The hdisk device name.
:param device_name: The hdisk device name.
:param lpar_slot_num: (Optional, Default:None) If specified, the client
lpar slot number to use on the mapping. If left
as None, it will use the next available slot
@ -142,11 +143,19 @@ class VscsiVolumeAdapter(object):
the TargetDevice. If None, the LUA will be assigned by the
server. Should be specified for all of the VSCSIMappings
for a particular bus, or none of them.
:param target_name: (Optional. Default: None) Name to set on the
TargetDevice. If None, it will be assigned by the
server.
:param udid: (Optional. Default: None) Universal Disk IDentifier of
the physical volume to attach. Used to resolve name
conflicts.
:param tag: String tag to set on the physical volume.
"""
def add_func(vios_w):
LOG.info("Adding vSCSI mapping to Physical Volume %(dev)s",
{'dev': device_name}, instance=self.instance)
pv = pvm_stor.PV.bld(self.adapter, device_name, udid)
pv = pvm_stor.PV.bld(self.adapter, device_name, udid=udid,
tag=tag)
v_map = tsk_map.build_vscsi_mapping(
self.host_uuid, vios_w, self.vm_uuid, pv,
lpar_slot_num=lpar_slot_num, lua=lua, target_name=target_name)

View File

@ -232,11 +232,13 @@ class PVVscsiFCVolumeAdapter(volume.VscsiVolumeAdapter,
return False
if hdisk.good_discovery(status, device_name):
volume_id = self.connection_info["data"]["volume_id"]
# Found a hdisk on this Virtual I/O Server. Add the action to
# map it to the VM when the stg_ftsk is executed.
with lockutils.lock(hash(self)):
self._add_append_mapping(vios_w.uuid, device_name,
lpar_slot_num=slot, lua=lua)
lpar_slot_num=slot, lua=lua,
tag=volume_id)
# Save the UDID for the disk in the connection info. It is
# used for the detach.