From c64087adb003925d33f1bd75c7119f4c0f83afd6 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Thu, 2 Mar 2017 13:47:36 -0600 Subject: [PATCH] Move _get_vg_uuid to pypowervm's find_vg pypowervm commit a8c22a93c1293fd9328cd4c761f0526e33311137 introduced pypowervm.tasks.storage.find_vg, which subsumes the logic found in nova_powervm's LocalStorage._get_vg_uuid. This change set removes the latter and replaces it with the former. Change-Id: If7483ce7b76ca68053748cf3d3428a0377a57f58 --- .../tests/virt/powervm/disk/test_localdisk.py | 62 +------------------ nova_powervm/virt/powervm/disk/localdisk.py | 29 +-------- 2 files changed, 2 insertions(+), 89 deletions(-) diff --git a/nova_powervm/tests/virt/powervm/disk/test_localdisk.py b/nova_powervm/tests/virt/powervm/disk/test_localdisk.py index 84d8ef2e..91501c77 100644 --- a/nova_powervm/tests/virt/powervm/disk/test_localdisk.py +++ b/nova_powervm/tests/virt/powervm/disk/test_localdisk.py @@ -55,8 +55,7 @@ class TestLocalDisk(test.TestCase): # Set up for the mocks for get_ls self.mock_vg_uuid = self.useFixture(fixtures.MockPatch( - 'nova_powervm.virt.powervm.disk.localdisk.LocalStorage.' - '_get_vg_uuid')).mock + 'pypowervm.tasks.storage.find_vg')).mock self.vg_uuid = 'd5065c2c-ac43-3fa6-af32-ea84a3960291' self.mock_vg_uuid.return_value = ('vios_uuid', self.vg_uuid) @@ -410,62 +409,3 @@ class TestLocalDisk(test.TestCase): local.disconnect_disk_from_mgmt('vios_uuid', 'disk_name') mock_rm_vdisk_map.assert_called_with( local.adapter, 'vios_uuid', 'mp_uuid', disk_names=['disk_name']) - - -class TestLocalDiskFindVG(test.TestCase): - """Test in separate class for the static loading of the VG. - - This is abstracted in all other tests. To keep the other test cases terse - we put this one in a separate class that doesn't make use of the patchers. - """ - - def setUp(self): - super(TestLocalDiskFindVG, self).setUp() - - self.apt = self.useFixture(pvm_fx.AdapterFx()).adpt - - self.vg_to_vio = mock.Mock() - self.vg_to_vio.configure_mock(name='rootvg') - self.vio_to_vg = mock.Mock() - - self.mock_vios_feed = [self.vio_to_vg] - self.mock_vg_feed = [self.vg_to_vio] - - # Return the mgmt uuid - self.mgmt_uuid = self.useFixture(fixtures.MockPatch( - 'nova_powervm.virt.powervm.mgmt.mgmt_uuid')).mock - self.mgmt_uuid.return_value = 'mp_uuid' - - @mock.patch('pypowervm.wrappers.storage.VG.get') - @mock.patch('pypowervm.wrappers.virtual_io_server.VIOS.get') - def test_get_vg_uuid(self, mock_vio_get, mock_vg_get): - mock_vio_get.return_value = self.mock_vios_feed - mock_vg_get.return_value = self.mock_vg_feed - self.flags(volume_group_name='rootvg', group='powervm') - - storage = ld.LocalStorage(self.apt, 'host_uuid') - - # Make sure the uuids match - self.assertEqual(self.vg_to_vio.uuid, storage.vg_uuid) - - @mock.patch('pypowervm.wrappers.storage.VG.get') - @mock.patch('pypowervm.wrappers.virtual_io_server.VIOS.search') - def test_get_vg_uuid_on_vios(self, mock_vio_search, mock_vg_get): - # Return no VIOSes. - mock_vio_search.return_value = [] - - # Similar to test_get_vg_uuid, the read isn't what is useful. The - # wrap is used to simulate a feed. - self.apt.read.return_value = self.vg_to_vio - mock_vg_get.return_value = self.mock_vg_feed - - # Override that we need a specific VIOS...that won't be found. - self.flags(volume_group_name='rootvg', - volume_group_vios_name='invalid_vios', group='powervm') - - self.assertRaises(npvmex.VGNotFound, ld.LocalStorage, - self.apt, 'host_uuid') - - def test_bad_config(self): - self.assertRaises(npvmex.OptRequiredIfOtherOptValue, - ld.LocalStorage, self.apt, 'host_uuid') diff --git a/nova_powervm/virt/powervm/disk/localdisk.py b/nova_powervm/virt/powervm/disk/localdisk.py index 8cc066ef..8c14e7da 100644 --- a/nova_powervm/virt/powervm/disk/localdisk.py +++ b/nova_powervm/virt/powervm/disk/localdisk.py @@ -59,7 +59,7 @@ class LocalStorage(disk_dvr.DiskAdapter): if_opt='disk_driver', if_value='localdisk', then_opt='volume_group_name') self.vg_name = CONF.powervm.volume_group_name - self._vios_uuid, self.vg_uuid = self._get_vg_uuid(self.vg_name) + self._vios_uuid, self.vg_uuid = tsk_stg.find_vg(self.vg_name) self.image_cache_mgr = imagecache.ImageManager(self._vios_uuid, self.vg_uuid, adapter) self.cache_lock = lockutils.ReaderWriterLock() @@ -330,33 +330,6 @@ class LocalStorage(disk_dvr.DiskAdapter): LOG.exception() raise - def _get_vg_uuid(self, name): - """Returns the VIOS and VG UUIDs for the volume group. - - Will iterate over the VIOSes to find the VG with the name. - - :param name: The name of the volume group. - :return vios_uuid: The Virtual I/O Server pypowervm UUID. - :return vg_uuid: The Volume Group pypowervm UUID. - """ - if CONF.powervm.volume_group_vios_name: - # Search for the VIOS if the admin specified it. - vios_wraps = pvm_vios.VIOS.search( - self.adapter, name=CONF.powervm.volume_group_vios_name) - else: - vios_wraps = pvm_vios.VIOS.get(self.adapter) - - # Loop through each vios to find the one with the appropriate name. - for vios_wrap in vios_wraps: - # Search the feed for the volume group - vol_grps = pvm_stg.VG.get(self.adapter, parent=vios_wrap) - for vol_grp in vol_grps: - LOG.debug('Volume group: %s', vol_grp.name) - if name == vol_grp.name: - return vios_wrap.uuid, vol_grp.uuid - - raise npvmex.VGNotFound(vg_name=name) - def _get_vg_wrap(self): return pvm_stg.VG.get(self.adapter, uuid=self.vg_uuid, parent_type=pvm_vios.VIOS,