Merge "Get flavor from instance"

This commit is contained in:
Jenkins
2017-05-04 19:42:59 +00:00
committed by Gerrit Code Review
20 changed files with 175 additions and 251 deletions

View File

@@ -88,13 +88,14 @@ class TestLocalDisk(test.TestCase):
mock_copy.return_value = 'vdisk'
inst = mock.Mock()
inst.configure_mock(name='Inst Name',
uuid='d5065c2c-ac43-3fa6-af32-ea84a3960291')
uuid='d5065c2c-ac43-3fa6-af32-ea84a3960291',
flavor=mock.Mock(root_gb=20))
mock_image = mock.MagicMock()
mock_image.name = 'cached_image'
mock_get_image.return_value = mock_image
vdisk = self.get_ls(self.apt).create_disk_from_image(
None, inst, powervm.TEST_IMAGE1, 20)
None, inst, powervm.TEST_IMAGE1)
self.assertEqual('vdisk', vdisk)
mock_get_image.reset_mock()
@@ -102,7 +103,7 @@ class TestLocalDisk(test.TestCase):
mock_get_image.side_effect = exception
self.assertRaises(exception,
self.get_ls(self.apt).create_disk_from_image,
None, inst, powervm.TEST_IMAGE1, 20)
None, inst, powervm.TEST_IMAGE1)
self.assertEqual(mock_get_image.call_count, 4)
@mock.patch('pypowervm.tasks.storage.upload_new_vdisk', autospec=True)

View File

@@ -287,7 +287,7 @@ class TestSSPDiskAdapter(test.TestCase):
# Default image_type
self.assertEqual('lu', ssp.create_disk_from_image(
'ctx', instance, img_meta, 'disk_gb'))
'ctx', instance, img_meta))
mock_goru.assert_called_once_with(
self.mock_get_tier.return_value, mock_gin.return_value,
mock_vuuid.return_value, mock_it2f.return_value, img_meta.size,
@@ -297,7 +297,7 @@ class TestSSPDiskAdapter(test.TestCase):
mock_gdn.assert_called_once_with(disk_dvr.DiskType.BOOT, instance)
mock_crt_lu.assert_called_once_with(
self.mock_get_tier.return_value, mock_gdn.return_value,
'disk_gb', typ=pvm_stg.LUType.DISK,
instance.flavor.root_gb, typ=pvm_stg.LUType.DISK,
clone=mock_goru.return_value)
# Reset
@@ -309,7 +309,7 @@ class TestSSPDiskAdapter(test.TestCase):
# Specified image_type
self.assertEqual('lu', ssp.create_disk_from_image(
'ctx', instance, img_meta, 'disk_gb', image_type='imgtyp'))
'ctx', instance, img_meta, image_type='imgtyp'))
mock_goru.assert_called_once_with(
self.mock_get_tier.return_value, mock_gin.return_value,
mock_vuuid.return_value, mock_it2f.return_value, img_meta.size,
@@ -319,7 +319,8 @@ class TestSSPDiskAdapter(test.TestCase):
mock_gdn.assert_called_once_with('imgtyp', instance)
mock_crt_lu.assert_called_once_with(
self.mock_get_tier.return_value, mock_gdn.return_value,
'disk_gb', typ=pvm_stg.LUType.DISK, clone=mock_goru.return_value)
instance.flavor.root_gb, typ=pvm_stg.LUType.DISK,
clone=mock_goru.return_value)
def test_get_image_name(self):
"""Generate image name from ImageMeta."""

View File

@@ -1,4 +1,4 @@
# Copyright 2015, 2016 IBM Corp.
# Copyright 2015, 2017 IBM Corp.
#
# All Rights Reserved.
#
@@ -183,9 +183,7 @@ class TaskFlow(fixtures.Fixture):
testcase.assertEqual(expected, observed.name)
# Compare the list of expected against added.
for func in map(compare_tasks, expected_tasks, self.tasks_added):
# Call the function to do the compare
func
map(compare_tasks, expected_tasks, self.tasks_added)
class DriverTaskFlow(TaskFlow):

View File

@@ -130,16 +130,14 @@ class TestStorage(test.TestCase):
def test_create_disk_for_img(self):
image_meta = mock.Mock()
disk_size = 10
image_type = mock.Mock()
task = tf_stg.CreateDiskForImg(
self.disk_dvr, self.context, self.instance, image_meta,
disk_size=disk_size, image_type=image_type)
image_type=image_type)
task.execute()
self.disk_dvr.create_disk_from_image.assert_called_once_with(
self.context, self.instance, image_meta, disk_size,
image_type=image_type)
self.context, self.instance, image_meta, image_type=image_type)
task.revert('result', 'flow failures')
self.disk_dvr.delete_disks.assert_called_once_with(['result'])

View File

@@ -45,15 +45,15 @@ class TestVMTasks(test.TestCase):
# Test create with normal (non-recreate) ftsk
crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance,
'flavor', mock_ftsk, nvram_mgr=nvram_mgr,
stg_ftsk=mock_ftsk, nvram_mgr=nvram_mgr,
slot_mgr='slot_mgr')
mock_vm_crt.return_value = lpar_entry
crt_entry = crt.execute()
mock_ftsk.execute.assert_not_called()
mock_vm_crt.assert_called_once_with(self.apt, 'host_wrapper',
self.instance, 'flavor',
nvram='data', slot_mgr='slot_mgr')
mock_vm_crt.assert_called_once_with(
self.apt, 'host_wrapper', self.instance, nvram='data',
slot_mgr='slot_mgr')
self.assertEqual(lpar_entry, crt_entry)
nvram_mgr.fetch.assert_called_once_with(self.instance)
@@ -61,7 +61,7 @@ class TestVMTasks(test.TestCase):
mock_bld.return_value = mock_ftsk
# Test create with recreate ftsk
rcrt = tf_vm.Create(self.apt, 'host_wrapper', self.instance,
'flavor', None, nvram_mgr=nvram_mgr,
stg_ftsk=None, nvram_mgr=nvram_mgr,
slot_mgr='slot_mgr')
mock_bld.assert_called_once_with(
self.apt, name='create_scrubber',
@@ -76,8 +76,8 @@ class TestVMTasks(test.TestCase):
mock_get_pvm_uuid):
mock_crt_exc.side_effect = exception.NovaException()
crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance,
'flavor', 'stg_ftsk', None)
crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance, 'stg_ftsk',
None)
# Assert that a failure while building does not revert
crt.instance.task_state = task_states.SPAWNING
@@ -154,12 +154,12 @@ class TestVMTasks(test.TestCase):
def test_resize(self, mock_vm_update):
resize = tf_vm.Resize(self.apt, 'host_wrapper', self.instance,
'flavor', name='new_name')
name='new_name')
mock_vm_update.return_value = 'resized_entry'
resized_entry = resize.execute()
mock_vm_update.assert_called_once_with(self.apt, 'host_wrapper',
self.instance, 'flavor',
entry=None, name='new_name')
mock_vm_update.assert_called_once_with(
self.apt, 'host_wrapper', self.instance, entry=None,
name='new_name')
self.assertEqual('resized_entry', resized_entry)
@mock.patch('nova_powervm.virt.powervm.vm.rename')

View File

@@ -298,10 +298,9 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
@mock.patch('nova_powervm.virt.powervm.driver.PowerVMDriver._vol_drv_iter')
def test_spawn_ops(self, mock_vdi, mock_pwron, mock_get_flv, mock_cfg_drv,
def test_spawn_ops(self, mock_vdi, mock_pwron, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif, mock_boot_from_vol,
mock_crt_disk_img, mock_conn_vol, mock_crt_cfg_drv,
mock_sanitize, mock_pwron_opts):
@@ -310,7 +309,6 @@ class TestPowerVMDriver(test.TestCase):
Uses a basic disk image, attaching networks and powering on.
"""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = False
mock_pwron_opts.return_value = 'fake-opts'
@@ -328,8 +326,8 @@ class TestPowerVMDriver(test.TestCase):
self.assertTrue(mock_plug_mgmt_vif.called)
self.assertTrue(mock_crt_disk_img.called)
self.crt_lpar.assert_called_with(
self.apt, self.drv.host_wrapper, self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.apt, self.drv.host_wrapper, self.inst, nvram=None,
slot_mgr=self.slot_mgr)
mock_pwron.assert_called_once_with(self.apt, self.inst,
opts='fake-opts')
mock_sanitize.assert_not_called()
@@ -346,14 +344,12 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
'create_cfg_drv_vopt')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_with_cfg(self, mock_pwron, mock_get_flv, mock_cfg_drv,
mock_cfg_vopt, mock_plug_vifs, mock_plug_mgmt_vif,
mock_sanitize, mock_pwron_opts):
def test_spawn_with_cfg(self, mock_pwron, mock_cfg_drv, mock_cfg_vopt,
mock_plug_vifs, mock_plug_mgmt_vif, mock_sanitize,
mock_pwron_opts):
"""Validates the PowerVM spawn w/ config drive operations."""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = True
mock_sanitize.return_value = 'fake-name'
self.flags(remove_vopt_media_on_boot=True, group='powervm')
@@ -366,8 +362,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
# Config drive was called
self.assertTrue(mock_cfg_vopt.called)
self.assertTrue(self.validate_vopt.called)
@@ -388,11 +384,10 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_with_bdms(self, mock_pwron, mock_get_flv, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif,
mock_boot_from_vol, mock_crt_img, mock_save):
def test_spawn_with_bdms(self, mock_pwron, mock_cfg_drv, mock_plug_vifs,
mock_plug_mgmt_vif, mock_boot_from_vol,
mock_crt_img, mock_save):
"""Validates the PowerVM spawn.
Specific Test: spawn of an image that has a disk image and block device
@@ -401,7 +396,6 @@ class TestPowerVMDriver(test.TestCase):
the BDMs passed in do not have the root device for the instance.
"""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = False
@@ -420,8 +414,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
# Power on was called
mock_pwron.assert_called_once_with(self.apt, self.inst, opts=mock.ANY)
@@ -442,11 +436,9 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_with_image_meta_root_bdm(self, mock_pwron, mock_get_flv,
mock_cfg_drv, mock_plug_vifs,
mock_plug_mgmt_vif,
def test_spawn_with_image_meta_root_bdm(self, mock_pwron, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif,
mock_boot_from_vol,
mock_crt_img, mock_save):
@@ -465,7 +457,6 @@ class TestPowerVMDriver(test.TestCase):
nova.compute.api.API.snapshot_volume_backed flow produces such images.
"""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = True
@@ -483,8 +474,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
# Power on was called
mock_pwron.assert_called_once_with(self.apt, self.inst, opts=mock.ANY)
@@ -502,9 +493,8 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_with_root_bdm(self, mock_pwron, mock_get_flv, mock_cfg_drv,
def test_spawn_with_root_bdm(self, mock_pwron, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif,
mock_boot_from_vol, mock_crt_img, mock_save):
"""Validates the PowerVM spawn.
@@ -513,7 +503,6 @@ class TestPowerVMDriver(test.TestCase):
are given on the create server request.
"""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = True
@@ -531,8 +520,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
# Power on was called
mock_pwron.assert_called_once_with(self.apt, self.inst, opts=mock.ANY)
@@ -555,15 +544,14 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.tasks.vm.PowerOn')
@mock.patch('nova_powervm.virt.powervm.driver.PowerVMDriver._vol_drv_iter')
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
@mock.patch('taskflow.patterns.linear_flow.Flow')
@mock.patch('taskflow.engines.run')
def test_spawn_recreate(self, mock_tf_run, mock_flow, mock_build_slot_mgr,
mock_vol_drv_iter, mock_pwron, mock_get_flv,
mock_cfg_drv, mock_plug_vifs, mock_plug_mgmt_vif,
mock_vol_drv_iter, mock_pwron, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif,
mock_boot_from_vol, mock_find_disk, mock_conn_disk,
mock_conn_vol, mock_crt_cfg_drv):
"""Validates the 'recreate' spawn flow.
@@ -573,7 +561,6 @@ class TestPowerVMDriver(test.TestCase):
# Set up the mocks to the tasks.
self.drv.nvram_mgr = mock.Mock()
self.drv.nvram_mgr.fetch.return_value = 'nvram data'
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = False
# Some tasks are mocked; some are not. Have Flow.add "execute" them so
@@ -610,8 +597,8 @@ class TestPowerVMDriver(test.TestCase):
self.assertTrue(mock_plug_mgmt_vif.called)
self.assertTrue(mock_find_disk.called)
self.crt_lpar.assert_called_with(
self.apt, self.drv.host_wrapper, self.inst, self.inst.get_flavor(),
nvram='nvram data', slot_mgr=mock_build_slot_mgr.return_value)
self.apt, self.drv.host_wrapper, self.inst, nvram='nvram data',
slot_mgr=mock_build_slot_mgr.return_value)
# SaveSlotStore.execute
mock_build_slot_mgr.return_value.save.assert_called_once_with()
self.assertTrue(mock_pwron.called)
@@ -626,15 +613,13 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova_powervm.virt.powervm.vm.dlt_lpar')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
def test_spawn_ops_rollback(self, mock_pwroff, mock_pwron, mock_get_flv,
mock_cfg_drv, mock_dlt, mock_plug_vifs,
mock_plug_mgmt_vifs, mock_save):
def test_spawn_ops_rollback(self, mock_pwroff, mock_pwron, mock_cfg_drv,
mock_dlt, mock_plug_vifs, mock_plug_mgmt_vifs,
mock_save):
"""Validates the PowerVM driver operations. Will do a rollback."""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
block_device_info = self._fake_bdms()
@@ -648,8 +633,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
self.assertEqual(2, self.vol_drv.connect_volume.call_count)
# Power on was called
@@ -666,19 +651,17 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.tasks.vm.UpdateIBMiSettings.'
'execute')
@mock.patch('nova.virt.powervm_ext.driver.PowerVMDriver.'
'_get_boot_connectivity_type')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_ibmi(self, mock_pwron, mock_boot_conn_type,
mock_update_lod_src, mock_get_flv, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif, mock_boot_from_vol,
mock_crt_img, mock_save):
mock_update_lod_src, mock_cfg_drv, mock_plug_vifs,
mock_plug_mgmt_vif, mock_boot_from_vol, mock_crt_img,
mock_save):
"""Validates the PowerVM spawn to create an IBMi server."""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst_ibmi.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = True
mock_boot_conn_type.return_value = 'vscsi'
@@ -696,9 +679,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst_ibmi,
self.inst_ibmi.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst_ibmi, nvram=None,
slot_mgr=self.slot_mgr)
self.assertTrue(mock_boot_conn_type.called)
self.assertTrue(mock_update_lod_src.called)
@@ -724,25 +706,22 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugMgmtVif.execute')
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.tasks.vm.UpdateIBMiSettings'
'.execute')
@mock.patch('nova.virt.powervm_ext.driver.PowerVMDriver.'
'_get_boot_connectivity_type')
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
def test_spawn_ibmi_without_bdms(self, mock_pwron, mock_boot_conn_type,
mock_update_lod_src, mock_get_flv,
mock_cfg_drv, mock_plug_vifs,
mock_plug_mgmt_vif, mock_boot_from_vol,
mock_crt_disk_img, mock_conn_vol,
mock_crt_cfg_drv):
mock_update_lod_src, mock_cfg_drv,
mock_plug_vifs, mock_plug_mgmt_vif,
mock_boot_from_vol, mock_crt_disk_img,
mock_conn_vol, mock_crt_cfg_drv):
"""Validates the 'typical' spawn flow for IBMi
Perform an UT using an image with local disk, attaching networks
and powering on.
"""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst_ibmi.get_flavor()
mock_cfg_drv.return_value = False
mock_boot_from_vol.return_value = False
mock_boot_conn_type.return_value = 'vscsi'
@@ -755,8 +734,8 @@ class TestPowerVMDriver(test.TestCase):
self.assertTrue(mock_plug_mgmt_vif.called)
self.assertTrue(mock_crt_disk_img.called)
self.crt_lpar.assert_called_with(
self.apt, self.drv.host_wrapper, self.inst_ibmi,
self.inst_ibmi.get_flavor(), nvram=None, slot_mgr=self.slot_mgr)
self.apt, self.drv.host_wrapper, self.inst_ibmi, nvram=None,
slot_mgr=self.slot_mgr)
self.assertTrue(mock_update_lod_src.called)
mock_pwron.assert_called_once_with(self.apt, self.inst_ibmi,
opts=mock.ANY)
@@ -772,14 +751,11 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova_powervm.virt.powervm.vm.dlt_lpar')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
def test_spawn_ops_rollback_disk(self, mock_get_flv, mock_cfg_drv,
mock_dlt, mock_plug_vifs,
mock_plug_mgmt_vifs, mock_crt_disk,
mock_delete_disks):
def test_spawn_ops_rollback_disk(self, mock_cfg_drv, mock_dlt,
mock_plug_vifs, mock_plug_mgmt_vifs,
mock_crt_disk, mock_delete_disks):
"""Validates the rollback if failure occurs on disk create."""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
# Make sure power on fails.
@@ -792,8 +768,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
# Since the create disks method failed, the delete disks should not
# have been called
@@ -804,16 +780,14 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.tasks.network.PlugVifs.execute')
@mock.patch('nova_powervm.virt.powervm.vm.dlt_lpar')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('pypowervm.tasks.power.power_on')
@mock.patch('pypowervm.tasks.power.power_off')
def test_spawn_ops_rollback_on_vol_connect(self, mock_pwroff, mock_pwron,
mock_get_flv, mock_cfg_drv,
mock_dlt, mock_plug_vifs,
mock_cfg_drv, mock_dlt,
mock_plug_vifs,
mock_plug_mgmt_vifs, mock_save):
"""Validates the rollbacks on a volume connect failure."""
# Set up the mocks to the tasks.
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg_drv.return_value = False
block_device_info = self._fake_bdms()
@@ -830,8 +804,8 @@ class TestPowerVMDriver(test.TestCase):
# Create LPAR was called
self.crt_lpar.assert_called_with(self.apt, self.drv.host_wrapper,
self.inst, self.inst.get_flavor(),
nvram=None, slot_mgr=self.slot_mgr)
self.inst, nvram=None,
slot_mgr=self.slot_mgr)
self.assertEqual(1, self.vol_drv.connect_volume.call_count)
# Power on should not be called. Shouldn't get that far in flow.
@@ -950,10 +924,9 @@ class TestPowerVMDriver(test.TestCase):
'dlt_vopt')
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
def test_destroy_internal(
self, mock_bld_slot_mgr, mock_get_flv, mock_cfg, mock_pvmuuid,
self, mock_bld_slot_mgr, mock_cfg, mock_pvmuuid,
mock_dlt_vopt, mock_pwroff, mock_dlt, mock_boot_from_vol,
mock_unplug_vifs, mock_rm_maps):
"""Validates the basic PowerVM destroy."""
@@ -1089,12 +1062,11 @@ class TestPowerVMDriver(test.TestCase):
'dlt_vopt')
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
def test_destroy_internal_no_nvram_cleanup(
self, mock_bld_slot_mgr, mock_get_flv, mock_cfg, mock_pvmuuid,
mock_dlt_vopt, mock_pwroff, mock_dlt, mock_boot_from_vol,
mock_unplug_vifs, mock_rm_maps):
self, mock_bld_slot_mgr, mock_cfg, mock_pvmuuid, mock_dlt_vopt,
mock_pwroff, mock_dlt, mock_boot_from_vol, mock_unplug_vifs,
mock_rm_maps):
"""Validates the basic PowerVM destroy, without NVRAM cleanup.
Used to validate the behavior when destroying evacuated instances.
@@ -1248,14 +1220,11 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
'dlt_vopt')
@mock.patch('nova.virt.configdrive.required_by')
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
def test_destroy_rollback(self, mock_get_flv, mock_cfg, mock_dlt_vopt,
mock_pwroff, mock_dlt, mock_unplug_vifs,
mock_rm_maps):
def test_destroy_rollback(self, mock_cfg, mock_dlt_vopt, mock_pwroff,
mock_dlt, mock_unplug_vifs, mock_rm_maps):
"""Validates the basic PowerVM destroy rollback mechanism works."""
# Set up the mocks to the tasks.
mock_rm_maps.return_value = []
mock_get_flv.return_value = self.inst.get_flavor()
mock_cfg.return_value = True
# BDMs
@@ -1338,9 +1307,8 @@ class TestPowerVMDriver(test.TestCase):
taskflow_fix.tasks_added[4].slot_mgr)
self.san_lpar_name.assert_called_with('migrate_' + self.inst.name)
@mock.patch('nova.objects.flavor.Flavor.get_by_id')
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
def test_finish_migration(self, mock_bld_slot_mgr, mock_get_flv):
def test_finish_migration(self, mock_bld_slot_mgr):
mock_bdms = self._fake_bdms()
mig = objects.Migration(**powervm.TEST_MIGRATION)
mig_same_host = objects.Migration(**powervm.TEST_MIGRATION_SAME_HOST)
@@ -1432,8 +1400,7 @@ class TestPowerVMDriver(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
def test_finish_revert_migration(self, mock_off, mock_update, mock_on):
"""Validates that the finish revert migration works."""
mock_flavor = mock.Mock()
mock_instance = mock.Mock(flavor=mock_flavor)
mock_instance = mock.Mock()
# Validate with a default power on
self.drv.finish_revert_migration('context', mock_instance, None)
@@ -1441,7 +1408,7 @@ class TestPowerVMDriver(test.TestCase):
# Asserts
mock_off.assert_called_once_with(self.apt, mock_instance)
mock_update.assert_called_once_with(
self.apt, self.drv.host_wrapper, mock_instance, mock_flavor)
self.apt, self.drv.host_wrapper, mock_instance)
mock_on.assert_called_once_with(self.apt, mock_instance)
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
@@ -1450,8 +1417,7 @@ class TestPowerVMDriver(test.TestCase):
def test_finish_revert_migration_no_power_on(self, mock_off, mock_update,
mock_on):
"""Validates that the finish revert migration works, no power_on."""
mock_flavor = mock.Mock()
mock_instance = mock.Mock(flavor=mock_flavor)
mock_instance = mock.Mock()
# Validate with power_on set to false
self.drv.finish_revert_migration(
@@ -1460,7 +1426,7 @@ class TestPowerVMDriver(test.TestCase):
# Asserts
mock_off.assert_called_once_with(self.apt, mock_instance)
mock_update.assert_called_once_with(
self.apt, self.drv.host_wrapper, mock_instance, mock_flavor)
self.apt, self.drv.host_wrapper, mock_instance)
mock_on.assert_not_called()
@mock.patch('nova_powervm.virt.powervm.vm.power_off')

View File

@@ -1,4 +1,4 @@
# Copyright 2014, 2015 IBM Corp.
# Copyright 2014, 2017 IBM Corp.
#
# All Rights Reserved.
#
@@ -21,6 +21,9 @@ import logging
from nova import test
from oslo_serialization import jsonutils
import pypowervm.tests.test_fixtures as pvm_fx
from pypowervm.wrappers import iocard as pvm_card
from pypowervm.wrappers import managed_system as pvm_ms
from pypowervm.wrappers import mtms as pvm_mtms
from nova_powervm.virt.powervm import host as pvm_host
@@ -28,23 +31,37 @@ LOG = logging.getLogger(__name__)
logging.basicConfig()
class TestPowerVMHost(test.TestCase):
def mock_sriov(adap_id, pports):
sriov = mock.create_autospec(pvm_card.SRIOVAdapter, spec_set=True)
sriov.configure_mock(sriov_adap_id=adap_id, phys_ports=pports)
return sriov
def mock_pport(port_id, label, maxlps):
port = mock.create_autospec(pvm_card.SRIOVEthPPort, spec_set=True)
port.configure_mock(port_id=port_id, label=label, supp_max_lps=maxlps)
return port
class TestPowerVMHost(test.NoDBTestCase):
def test_host_resources(self):
# Create objects to test with
sriov_adaps = [
mock.Mock(sriov_adap_id=1, phys_ports=[
mock.Mock(port_id=2, label='foo', supp_max_lps=1),
mock.Mock(port_id=3, label='', supp_max_lps=2)]),
mock.Mock(sriov_adap_id=4, phys_ports=[
mock.Mock(port_id=5, label='bar', supp_max_lps=3)])]
ms_wrapper = mock.MagicMock(
mock_sriov(1, [mock_pport(2, 'foo', 1), mock_pport(3, '', 2)]),
mock_sriov(4, [mock_pport(5, 'bar', 3)])]
ms_wrapper = mock.create_autospec(pvm_ms.System, spec_set=True)
mtms = mock.create_autospec(pvm_mtms.MTMS, spec_set=True)
mtms.configure_mock(mtms_str='8484923A123456')
asio = mock.create_autospec(pvm_ms.ASIOConfig, spec_set=True)
asio.configure_mock(sriov_adapters=sriov_adaps)
ms_wrapper.configure_mock(
proc_units_configurable=500,
proc_units_avail=500,
memory_configurable=5242880,
memory_free=5242752,
mtms=mock.MagicMock(mtms_str='8484923A123456'),
mtms=mtms,
memory_region_size='big',
asio_config=mock.Mock(sriov_adapters=sriov_adaps))
asio_config=asio)
# Run the actual test
stats = pvm_host.build_host_resource_from_ms(ms_wrapper)

View File

@@ -89,8 +89,7 @@ class TestVMBuilder(test.TestCase):
flavor.extra_specs = {'powervm:dedicated_proc': 'true'}
test_attrs = dict(lpar_attrs, dedicated_proc='true')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
@@ -104,32 +103,28 @@ class TestVMBuilder(test.TestCase):
dedicated_proc='true',
sharing_mode='sre idle procs active',
min_vcpu='1', max_vcpu='3')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
# Test shared proc sharing mode
flavor.extra_specs = {'powervm:uncapped': 'true'}
test_attrs = dict(lpar_attrs, sharing_mode='uncapped')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
# Test availability priority
flavor.extra_specs = {'powervm:availability_priority': '150'}
test_attrs = dict(lpar_attrs, avail_priority='150')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
# Test processor compatibility
flavor.extra_specs = {'powervm:processor_compatibility': 'POWER8'}
test_attrs = dict(lpar_attrs, processor_compatibility='POWER8')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
@@ -137,8 +132,7 @@ class TestVMBuilder(test.TestCase):
test_attrs = dict(
lpar_attrs,
processor_compatibility=pvm_bp.LPARCompat.POWER6_PLUS)
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
@@ -147,8 +141,7 @@ class TestVMBuilder(test.TestCase):
test_attrs = dict(
lpar_attrs,
processor_compatibility=pvm_bp.LPARCompat.POWER6_PLUS_ENHANCED)
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
@@ -157,8 +150,7 @@ class TestVMBuilder(test.TestCase):
'powervm:max_proc_units': '2.0'}
test_attrs = dict(lpar_attrs, min_proc_units='0.5',
max_proc_units='2.0')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
@@ -166,16 +158,14 @@ class TestVMBuilder(test.TestCase):
flavor.extra_specs = {'powervm:min_mem': '1024',
'powervm:max_mem': '4096'}
test_attrs = dict(lpar_attrs, min_mem='1024', max_mem='4096')
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.san_lpar_name.assert_called_with(instance.name)
self.san_lpar_name.reset_mock()
# Test remote restart set to false
flavor.extra_specs = {'powervm:srr_capability': 'false'}
test_attrs = dict(lpar_attrs, srr_capability=False)
self.assertEqual(self.lpar_b._format_flavor(instance, flavor),
test_attrs)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
@mock.patch('pypowervm.wrappers.shared_proc_pool.SharedProcPool.search')
def test_spp_pool_id(self, mock_search):
@@ -422,7 +412,7 @@ class TestVM(test.TestCase):
lparw = pvm_lpar.LPAR.wrap(self.resp.feed.entries[0])
mock_bld.return_value = lparw
self.apt.create.return_value = lparw.entry
vm.crt_lpar(self.apt, host_wrapper, instance, flavor, nvram='data')
vm.crt_lpar(self.apt, host_wrapper, instance, nvram='data')
self.apt.create.assert_called_once_with(
lparw, host_wrapper.schema_type, child_type='LogicalPartition',
root_id=host_wrapper.uuid, service='uom', timeout=-1)
@@ -439,8 +429,7 @@ class TestVM(test.TestCase):
self.apt.create.return_value = lparw.entry
mock_slot_mgr = mock.Mock(build_map=mock.Mock(
get_max_vslots=mock.Mock(return_value=123)))
vm.crt_lpar(self.apt, host_wrapper, instance, flavor,
slot_mgr=mock_slot_mgr)
vm.crt_lpar(self.apt, host_wrapper, instance, slot_mgr=mock_slot_mgr)
self.assertTrue(self.apt.create.called)
self.assertTrue(mock_vld_all.called)
self.assertTrue(lparw.srr_enabled)
@@ -455,20 +444,20 @@ class TestVM(test.TestCase):
mock_bld.side_effect = lpar_bld.LPARBuilderException("Invalid Name")
host_wrapper = mock.Mock()
self.assertRaises(exception.BuildAbortException, vm.crt_lpar,
self.apt, host_wrapper, instance, flavor)
self.apt, host_wrapper, instance)
resp = mock.Mock(status=202, method='fake', path='/dev/',
reason='Failure')
mock_bld.side_effect = pvm_exc.HttpError(resp)
try:
vm.crt_lpar(self.apt, host_wrapper, instance, flavor)
vm.crt_lpar(self.apt, host_wrapper, instance)
except nvex.PowerVMAPIFailed as e:
self.assertEqual(e.kwargs['inst_name'], instance.name)
self.assertEqual(e.kwargs['reason'], mock_bld.side_effect)
flavor.extra_specs = {'powervm:BADATTR': 'true'}
host_wrapper = mock.Mock()
self.assertRaises(exception.InvalidAttribute, vm.crt_lpar,
self.apt, host_wrapper, instance, flavor)
self.apt, host_wrapper, instance)
@mock.patch('pypowervm.wrappers.logical_partition.LPAR.get')
def test_get_instance_wrapper(self, mock_get):
@@ -483,12 +472,12 @@ class TestVM(test.TestCase):
@mock.patch('nova_powervm.virt.powervm.vm.VMBuilder')
def test_update(self, mock_vmb, mock_get_inst):
instance = objects.Instance(**powervm.TEST_INSTANCE)
flavor, entry = mock.Mock(), mock.Mock()
entry = mock.Mock()
name = "new_name"
entry.update.return_value = 'NewEntry'
bldr = mock_vmb.return_value
lpar_bldr = bldr.lpar_builder.return_value
new_entry = vm.update(self.apt, 'mock_host_wrap', instance, flavor,
new_entry = vm.update(self.apt, 'mock_host_wrap', instance,
entry=entry, name=name)
# Ensure the lpar was rebuilt
lpar_bldr.rebuild.assert_called_once_with(entry)

View File

@@ -629,8 +629,7 @@ class TestNPIVAdapter(test_vol.TestVolumeAdapter):
# Verify that on migration, the WWPNs are reversed.
self.assertEqual(2, self.vol_drv.stg_ftsk.feed.reverse.call_count)
@mock.patch('pypowervm.tasks.vfc_mapper.'
'build_migration_mappings')
@mock.patch('pypowervm.tasks.vfc_mapper.build_migration_mappings')
@mock.patch('nova_powervm.virt.powervm.volume.npiv.NPIVVolumeAdapter.'
'_fabric_names')
def test_pre_live_migration_on_destination(
@@ -649,8 +648,7 @@ class TestNPIVAdapter(test_vol.TestVolumeAdapter):
# Order of the mappings is not important.
self.assertEqual(
set({'b', 'a'}),
set(jsonutils.loads(mig_data.get('vfc_lpm_mappings'))))
{'b', 'a'}, set(jsonutils.loads(mig_data.get('vfc_lpm_mappings'))))
def test_set_fabric_meta(self):
port_map = [('1', 'aa AA'), ('2', 'bb BB'),

View File

@@ -349,7 +349,7 @@ class DiskAdapter(object):
"""
pass
def create_disk_from_image(self, context, instance, image_meta, disk_size,
def create_disk_from_image(self, context, instance, image_meta,
image_type=DiskType.BOOT):
"""Creates a disk and copies the specified image to it.
@@ -357,10 +357,6 @@ class DiskAdapter(object):
:param instance: instance to create the disk for.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param disk_size: The size of the disk to create in GB. If smaller
than the image, it will be ignored (as the disk
must be at least as big as the image). Must be an
int.
:param image_type: the image type. See disk constants above.
:return: The backing pypowervm storage object that was created.
"""
@@ -369,8 +365,7 @@ class DiskAdapter(object):
for attempt in range(1, 5):
try:
return self._create_disk_from_image(
context, instance, image_meta,
disk_size, image_type=image_type)
context, instance, image_meta, image_type=image_type)
except Exception as error:
if attempt < 4:
LOG.exception(error)
@@ -383,7 +378,7 @@ class DiskAdapter(object):
else:
raise
def _create_disk_from_image(self, context, instance, image_meta, disk_size,
def _create_disk_from_image(self, context, instance, image_meta,
image_type=DiskType.BOOT):
"""Creates a disk and copies the specified image to it.
@@ -393,10 +388,6 @@ class DiskAdapter(object):
:param instance: instance to create the disk for.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param disk_size: The size of the disk to create in GB. If smaller
than the image, it will be ignored (as the disk
must be at least as big as the image). Must be an
int.
:param image_type: the image type. See disk constants above.
:return: The backing pypowervm storage object that was created.
"""

View File

@@ -190,7 +190,7 @@ class LocalStorage(disk_dvr.DiskAdapter):
'disk_name': disk_name, 'mp_uuid': self.mp_uuid,
'vios_name': vios_uuid})
def _create_disk_from_image(self, context, instance, image_meta, disk_size,
def _create_disk_from_image(self, context, instance, image_meta,
image_type=disk_dvr.DiskType.BOOT):
"""Creates a disk and copies the specified image to it.
@@ -200,17 +200,14 @@ class LocalStorage(disk_dvr.DiskAdapter):
:param instance: instance to create the disk for.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param disk_size: The size of the disk to create in GB. If smaller
than the image, it will be ignored (as the disk
must be at least as big as the image). Must be an
int.
:param image_type: the image type. See disk constants above.
:return: The backing pypowervm storage object that was created.
"""
LOG.info(_LI('Create disk.'), instance=instance)
# Disk size to API is in bytes. Input from method is in Gb
disk_bytes = self._disk_gb_to_bytes(disk_size, floor=image_meta.size)
# Disk size to API is in bytes. Input from flavor is in Gb
disk_bytes = self._disk_gb_to_bytes(instance.flavor.root_gb,
floor=image_meta.size)
vol_name = self._get_disk_name(image_type, instance, short=True)
with self.cache_lock.read_lock():

View File

@@ -201,7 +201,6 @@ class SSPDiskAdapter(disk_drv.DiskAdapter):
tsk_stg.rm_tier_storage(storage_elems, tier=self._tier)
def _create_disk_from_image(self, context, instance, image_meta,
disk_size_gb,
image_type=disk_drv.DiskType.BOOT):
"""Creates a boot disk and links the specified image to it.
@@ -213,10 +212,6 @@ class SSPDiskAdapter(disk_drv.DiskAdapter):
:param instance: instance to create the disk for.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param disk_size_gb: The size of the disk to create in GB. If smaller
than the image, it will be ignored (as the disk
must be at least as big as the image). Must be an
int.
:param image_type: The image type. See disk_drv.DiskType.
:return: The backing pypowervm LU storage object that was created.
"""
@@ -234,8 +229,9 @@ class SSPDiskAdapter(disk_drv.DiskAdapter):
boot_lu_name = self._get_disk_name(image_type, instance)
LOG.info(_LI('SSP: Disk name is %s'), boot_lu_name)
return tsk_stg.crt_lu(self._tier, boot_lu_name, disk_size_gb,
typ=pvm_stg.LUType.DISK, clone=image_lu)[1]
return tsk_stg.crt_lu(
self._tier, boot_lu_name, instance.flavor.root_gb,
typ=pvm_stg.LUType.DISK, clone=image_lu)[1]
def get_disk_ref(self, instance, disk_type):
"""Returns a reference to the disk for the instance."""

View File

@@ -23,7 +23,6 @@ from nova import context as ctx
from nova import exception
from nova import image
from nova import objects
from nova.objects import flavor as flavor_obj
from nova import utils as n_utils
from nova.virt import configdrive
from nova.virt import driver
@@ -339,8 +338,7 @@ class PowerVMDriver(driver.ComputeDriver):
return False
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None,
flavor=None):
admin_password, network_info=None, block_device_info=None):
"""Create a new instance/VM/domain on the virtualization platform.
Once this successfully completes, the instance should be
@@ -350,31 +348,19 @@ class PowerVMDriver(driver.ComputeDriver):
cleaned up, and the virtualization platform should be in the state
that it was before this call began.
Spawn can be called while deploying an instance for the first time or
it can be called to recreate an instance that was shelved or during
evacuation. We have to be careful to handle all these cases. During
evacuation, when on shared storage, the image_meta will be empty.
:param context: security context
:param instance: Instance object as returned by DB layer.
:param instance: nova.objects.instance.Instance
This function should use the data there to guide
the creation of the new instance.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param injected_files: User files to inject into instance.
:param admin_password: Administrator password to set in instance.
:param network_info:
:py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
:param network_info: instance network information
:param block_device_info: Information about block devices to be
attached to the instance.
:param flavor: The flavor for the instance to be spawned.
"""
self._log_operation('spawn', instance)
if not flavor:
admin_ctx = ctx.get_admin_context(read_deleted='yes')
flavor = (
flavor_obj.Flavor.get_by_id(admin_ctx,
instance.instance_type_id))
# Extract the block devices.
bdms = self._extract_bdm(block_device_info)
@@ -409,7 +395,7 @@ class PowerVMDriver(driver.ComputeDriver):
# Create task produce a FeedTask that will be used to scrub stale
# adapters immediately after the LPAR is created.
flow_spawn.add(tf_vm.Create(
self.adapter, self.host_wrapper, instance, flavor,
self.adapter, self.host_wrapper, instance,
stg_ftsk=(None if recreate else stg_ftsk), nvram_mgr=nvram_mgr,
slot_mgr=slot_mgr))
@@ -430,8 +416,7 @@ class PowerVMDriver(driver.ComputeDriver):
else:
# Creates the boot image.
flow_spawn.add(tf_stg.CreateDiskForImg(
self.disk_dvr, context, instance, image_meta,
disk_size=flavor.root_gb))
self.disk_dvr, context, instance, image_meta))
# Connects up the disk to the LPAR
flow_spawn.add(tf_stg.ConnectDisk(
self.disk_dvr, instance, stg_ftsk=stg_ftsk))
@@ -1267,13 +1252,13 @@ class PowerVMDriver(driver.ComputeDriver):
# This is just a resize.
new_name = self._gen_resize_name(instance, same_host=True)
flow.add(tf_vm.Resize(self.adapter, self.host_wrapper, instance,
instance.flavor, name=new_name))
name=new_name))
else:
# This is a migration over to another host. We have a lot of work.
# Create the LPAR
flow.add(tf_vm.Create(self.adapter, self.host_wrapper, instance,
instance.flavor, stg_ftsk,
nvram_mgr=self.nvram_mgr, slot_mgr=slot_mgr))
stg_ftsk=stg_ftsk, nvram_mgr=self.nvram_mgr,
slot_mgr=slot_mgr))
# Create a flow for the network IO
flow.add(tf_net.PlugVifs(self.virtapi, self.adapter, instance,
@@ -1356,8 +1341,7 @@ class PowerVMDriver(driver.ComputeDriver):
#
# The flavor should be the 'old' flavor now.
vm.power_off(self.adapter, instance)
vm.update(self.adapter, self.host_wrapper, instance,
instance.flavor)
vm.update(self.adapter, self.host_wrapper, instance)
if power_on:
vm.power_on(self.adapter, instance)

View File

@@ -112,7 +112,7 @@ class VolumePreMigrationFailed(nex.NovaException):
class PowerVMAPIFailed(nex.NovaException):
msg_fmt = _("PowerVM API Failed to complete for instance=%(inst_name)s."
msg_fmt = _("PowerVM API failed to complete for instance=%(inst_name)s."
"%(reason)s")

View File

@@ -237,7 +237,7 @@ class LiveMigrationDest(LiveMigration):
"""
LOG.info(_LI('Performing detach for volume %(volume)s'),
dict(volume=vol_drv.volume_id), instance=self.instance)
# Ensure the voulme data is present before trying cleanup
# Ensure the volume data is present before trying cleanup
if self.pre_live_vol_data:
try:
vol_drv.cleanup_volume_at_destination(self.pre_live_vol_data)

View File

@@ -60,10 +60,12 @@ class ConfigDrivePowerVM(object):
# Validate that the virtual optical exists
self.vios_uuid, self.vg_uuid = tsk_vopt.validate_vopt_repo_exists(
self.adapter, CONF.powervm.vopt_media_volume_group,
CONF.powervm.vopt_media_rep_size)
self.adapter,
vopt_media_volume_group=CONF.powervm.vopt_media_volume_group,
vopt_media_rep_size=CONF.powervm.vopt_media_rep_size)
def _sanitize_network_info(self, network_info):
@staticmethod
def _sanitize_network_info(network_info):
"""Will sanitize the network info for the config drive.
Newer versions of cloud-init look at the vif type information in

View File

@@ -134,7 +134,7 @@ class CreateDiskForImg(pvm_task.PowerVMTask):
"""The Task to create the disk from an image in the storage."""
def __init__(self, disk_dvr, context, instance, image_meta, disk_size=0,
def __init__(self, disk_dvr, context, instance, image_meta,
image_type=disk_driver.DiskType.BOOT):
"""Create the Task.
@@ -146,8 +146,6 @@ class CreateDiskForImg(pvm_task.PowerVMTask):
:param instance: The nova instance.
:param nova.objects.ImageMeta image_meta:
The metadata of the image of the instance.
:param disk_size: The size of disk to create. If the size is smaller
than the image, the image size will be used.
:param image_type: The image type. See disk/driver.py
"""
super(CreateDiskForImg, self).__init__(
@@ -155,12 +153,11 @@ class CreateDiskForImg(pvm_task.PowerVMTask):
self.disk_dvr = disk_dvr
self.context = context
self.image_meta = image_meta
self.disk_size = disk_size
self.image_type = image_type
def execute_impl(self):
return self.disk_dvr.create_disk_from_image(
self.context, self.instance, self.image_meta, self.disk_size,
self.context, self.instance, self.image_meta,
image_type=self.image_type)
def revert_impl(self, result, flow_failures):

View File

@@ -57,7 +57,7 @@ class Create(pvm_task.PowerVMTask):
"""The task for creating a VM."""
def __init__(self, adapter, host_wrapper, instance, flavor, stg_ftsk=None,
def __init__(self, adapter, host_wrapper, instance, stg_ftsk=None,
nvram_mgr=None, slot_mgr=None):
"""Creates the Task for creating a VM.
@@ -79,7 +79,6 @@ class Create(pvm_task.PowerVMTask):
:param adapter: The adapter for the pypowervm API
:param host_wrapper: The managed system wrapper
:param instance: The nova instance.
:param flavor: The nova flavor.
:param stg_ftsk: (Optional, Default: None) A FeedTask managing storage
I/O operations. If None, one will be built locally
and executed immediately. Otherwise it is the caller's
@@ -93,7 +92,6 @@ class Create(pvm_task.PowerVMTask):
instance, 'crt_vm', provides='lpar_wrap')
self.adapter = adapter
self.host_wrapper = host_wrapper
self.flavor = flavor
self.stg_ftsk = stg_ftsk or pvm_tpar.build_active_vio_feed_task(
adapter, name='create_scrubber',
xag={pvm_const.XAG.VIO_SMAP, pvm_const.XAG.VIO_FMAP})
@@ -109,7 +107,7 @@ class Create(pvm_task.PowerVMTask):
LOG.debug('NVRAM data is: %s', data, instance=self.instance)
wrap = vm.crt_lpar(self.adapter, self.host_wrapper, self.instance,
self.flavor, nvram=data, slot_mgr=self.slot_mgr)
nvram=data, slot_mgr=self.slot_mgr)
pvm_stg.add_lpar_storage_scrub_tasks([wrap.id], self.stg_ftsk,
lpars_exist=True)
# If the stg_ftsk passed in was None and we initialized a
@@ -141,7 +139,7 @@ class Resize(pvm_task.PowerVMTask):
"""The task for resizing an existing VM."""
def __init__(self, adapter, host_wrapper, instance, flavor, name=None):
def __init__(self, adapter, host_wrapper, instance, name=None):
"""Creates the Task to resize a VM.
Provides the 'lpar_wrap' for other tasks.
@@ -149,7 +147,6 @@ class Resize(pvm_task.PowerVMTask):
:param adapter: The adapter for the pypowervm API
:param host_wrapper: The managed system wrapper
:param instance: The nova instance.
:param flavor: The nova flavor.
:param name: VM name to use for the update. Used on resize when we
want to rename it but not use the instance name.
"""
@@ -157,13 +154,11 @@ class Resize(pvm_task.PowerVMTask):
instance, 'resize_vm', provides='lpar_wrap')
self.adapter = adapter
self.host_wrapper = host_wrapper
self.flavor = flavor
self.vm_name = name
def execute_impl(self):
return vm.update(self.adapter, self.host_wrapper,
self.instance, self.flavor, entry=None,
name=self.vm_name)
self.instance, entry=None, name=self.vm_name)
class Rename(pvm_task.PowerVMTask):

View File

@@ -281,13 +281,12 @@ class VMBuilder(object):
kwargs['max_slots'] = slot_mgr.build_map.get_max_vslots()
self.stdz = lpar_bldr.DefaultStandardize(self.host_w, **kwargs)
def lpar_builder(self, instance, flavor):
def lpar_builder(self, instance):
"""Returns the pypowervm LPARBuilder for a given Nova flavor.
:param instance: the VM instance
:param flavor: The Nova instance flavor.
"""
attrs = self._format_flavor(instance, flavor)
attrs = self._format_flavor(instance)
self._add_IBMi_attrs(instance, attrs)
return lpar_bldr.LPARBuilder(self.adapter, attrs, self.stdz)
@@ -297,11 +296,10 @@ class VMBuilder(object):
attrs[lpar_bldr.ENV] = pvm_bp.LPARType.OS400
# Add other attributes in the future
def _format_flavor(self, instance, flavor):
def _format_flavor(self, instance):
"""Returns the pypowervm format of the flavor.
:param instance: the VM instance
:param flavor: The Nova instance flavor.
:return: a dict that can be used by the LPAR builder
"""
# The attrs are what is sent to pypowervm to convert the lpar.
@@ -311,13 +309,13 @@ class VMBuilder(object):
instance.name)
# The uuid is only actually set on a create of an LPAR
attrs[lpar_bldr.UUID] = pvm_uuid.convert_uuid_to_pvm(instance.uuid)
attrs[lpar_bldr.MEM] = flavor.memory_mb
attrs[lpar_bldr.VCPU] = flavor.vcpus
attrs[lpar_bldr.MEM] = instance.flavor.memory_mb
attrs[lpar_bldr.VCPU] = instance.flavor.vcpus
# Set the srr capability to True by default
attrs[lpar_bldr.SRR_CAPABLE] = True
# Loop through the extra specs and process powervm keys
for key in flavor.extra_specs.keys():
for key in instance.flavor.extra_specs.keys():
# If it is not a valid key, then can skip.
if not self._is_pvm_valid_key(key):
continue
@@ -328,10 +326,10 @@ class VMBuilder(object):
# Check for no direct mapping, if the value is none, need to
# derive the complex type
if bldr_key is None:
self._build_complex_type(key, attrs, flavor)
self._build_complex_type(key, attrs, instance.flavor)
else:
# We found a direct mapping
attrs[bldr_key] = flavor.extra_specs[key]
attrs[bldr_key] = instance.flavor.extra_specs[key]
return attrs
@@ -542,14 +540,12 @@ def get_vm_qp(adapter, lpar_uuid, qprop=None, log_errors=True):
return jsonutils.loads(resp.body)
def crt_lpar(adapter, host_wrapper, instance, flavor, nvram=None,
slot_mgr=None):
def crt_lpar(adapter, host_wrapper, instance, nvram=None, slot_mgr=None):
"""Create an LPAR based on the host based on the instance
:param adapter: The adapter for the pypowervm API
:param host_wrapper: The host wrapper
:param instance: The nova instance.
:param flavor: The nova flavor.
:param nvram: The NVRAM to set on the LPAR.
:param slot_mgr: NovaSlotManager to restore/save the maximum number of
virtual slots. If omitted, the default is used.
@@ -557,8 +553,7 @@ def crt_lpar(adapter, host_wrapper, instance, flavor, nvram=None,
"""
try:
lpar_b = VMBuilder(
host_wrapper, adapter, slot_mgr=slot_mgr).lpar_builder(instance,
flavor)
host_wrapper, adapter, slot_mgr=slot_mgr).lpar_builder(instance)
pending_lpar_w = lpar_b.build()
vldn.LPARWrapperValidator(pending_lpar_w, host_wrapper).validate_all()
if nvram is not None:
@@ -577,13 +572,12 @@ def crt_lpar(adapter, host_wrapper, instance, flavor, nvram=None,
raise nvex.PowerVMAPIFailed(inst_name=instance.name, reason=he)
def update(adapter, host_wrapper, instance, flavor, entry=None, name=None):
def update(adapter, host_wrapper, instance, entry=None, name=None):
"""Update an LPAR based on the host based on the instance
:param adapter: The adapter for the pypowervm API
:param host_wrapper: The host wrapper
:param instance: The nova instance.
:param flavor: The nova flavor.
:param entry: The instance pvm entry, if available, otherwise it will
be fetched.
:param name: VM name to use for the update. Used on resize when we want
@@ -594,7 +588,7 @@ def update(adapter, host_wrapper, instance, flavor, entry=None, name=None):
if not entry:
entry = get_instance_wrapper(adapter, instance)
lpar_b = VMBuilder(host_wrapper, adapter).lpar_builder(instance, flavor)
lpar_b = VMBuilder(host_wrapper, adapter).lpar_builder(instance)
lpar_b.rebuild(entry)
# Set the new name if the instance name is not desired.

View File

@@ -68,7 +68,7 @@ class FileIOVolumeAdapter(v_driver.PowerVMVolumeAdapter):
information to the live_migration command, it
should be added to this dictionary.
"""
LOG.debug("Incoming mig_data=%s" % mig_data)
LOG.debug("Incoming mig_data=%s", mig_data)
# Check if volume is available in destination.
vol_path = self._get_path()
if not os.path.exists(vol_path):