Merge "Create snapshot of VM"

This commit is contained in:
Jenkins 2016-10-19 20:57:54 +00:00 committed by Gerrit Code Review
commit aa51468c85
4 changed files with 66 additions and 0 deletions

View File

@ -311,6 +311,17 @@ class TestLocalDisk(test.TestCase):
vios1.scsi_mappings[0].backing_storage.name = 'b_Name_Of__d506'
return inst, lpar_wrap, vios1, vios2
def test_boot_disk_path_for_instance(self):
local = self.get_ls(self.apt)
inst = mock.Mock()
inst.name = 'Name Of Instance'
inst.uuid = 'f921620A-EE30-440E-8C2D-9F7BA123F298'
vios1 = pvm_vios.VIOS.wrap(self.vio_to_vg)
vios1.scsi_mappings[0].backing_storage.name = 'b_Name_Of__f921'
self.apt.read.return_value = vios1.entry
dev_name = local.boot_disk_path_for_instance(inst, vios1.uuid)
self.assertEqual('boot_7f81628b', dev_name)
@mock.patch('pypowervm.wrappers.storage.VG')
def test_instance_disk_iter(self, mock_vg):
def assert_read_calls(num):

View File

@ -79,6 +79,23 @@ class TestStorage(test.TestCase):
'stg_name')
mock_rm.assert_called_with('/dev/disk')
# Management Partition is VIOS and Novalink hosted storage
reset_mocks()
disk_dvr.vios_uuids = ['mp_uuid']
dev_name = '/dev/vg/fake_name'
disk_dvr.boot_disk_path_for_instance.return_value = dev_name
tf = tf_stg.InstanceDiskToMgmt(disk_dvr, mock_instance)
self.assertEqual((None, None, dev_name), tf.execute())
# Management Partition is VIOS and not Novalink hosted storage
reset_mocks()
disk_dvr.vios_uuids = ['mp_uuid']
disk_dvr.boot_disk_path_for_instance.return_value = None
tf = tf_stg.InstanceDiskToMgmt(disk_dvr, mock_instance)
tf.execute()
disk_dvr.connect_instance_disk_to_mgmt.assert_called_with(
mock_instance)
# Bad path - find_maps returns no results
reset_mocks()
mock_find.return_value = []

View File

@ -133,6 +133,33 @@ class DiskAdapter(object):
"""
raise NotImplementedError()
def boot_disk_path_for_instance(self, instance, vios_uuid):
"""Find scsi mappings on given vios for the instance.
This method finds all scsi mappings on a given vios that are associated
with the instance and disk_type.
:param instance: nova.objects.instance.Instance object owning the
requested disk.
:param disk_type: The type of disk to find, one of the DiskType enum
values.
:param lpar_wrap: pypowervm.wrappers.logical_partition.LPAR
corresponding to the instance. If not specified, it
will be retrieved; i.e. specify this parameter to
save on REST calls.
:return: Iterator of scsi mappings that are associated with the
instance and disk_type.
"""
vm_uuid = vm.get_pvm_uuid(instance)
match_func = self.disk_match_func(DiskType.BOOT, instance)
vios_wrap = pvm_vios.VIOS.get(self.adapter, uuid=vios_uuid,
xag=[pvm_const.XAG.VIO_SMAP])
maps = tsk_map.find_maps(vios_wrap.scsi_mappings,
client_lpar_id=vm_uuid, match_func=match_func)
if maps:
return maps[0].server_adapter.backing_dev_name
return None
def instance_disk_iter(self, instance, disk_type=DiskType.BOOT,
lpar_wrap=None):
"""Return the instance's storage element wrapper of the specified type.

View File

@ -242,6 +242,14 @@ class InstanceDiskToMgmt(pvm_task.PowerVMTask):
def execute_impl(self):
"""Map the instance's boot disk and discover it."""
# Search for boot disk on the Novalink partition
if self.disk_dvr.mp_uuid in self.disk_dvr.vios_uuids:
dev_name = self.disk_dvr.boot_disk_path_for_instance(
self.instance, self.disk_dvr.mp_uuid)
if dev_name is not None:
return None, None, dev_name
self.stg_elem, self.vios_wrap = (
self.disk_dvr.connect_instance_disk_to_mgmt(self.instance))
new_maps = pvm_smap.find_maps(
@ -324,6 +332,9 @@ class RemoveInstanceDiskFromMgmt(pvm_task.PowerVMTask):
:param disk_path: The local path to the disk device to be removed, e.g.
'/dev/sde'
"""
# stg_elem is None if boot disk was not mapped to management partition
if stg_elem is None:
return
LOG.info(_LI("Unmapping boot disk %(disk_name)s of instance "
"%(instance_name)s from management partition via Virtual "
"I/O Server %(vios_name)s."),