From d9e31ee7020e9d20fa256998645fc5a1d41ed5c0 Mon Sep 17 00:00:00 2001 From: Biser Milanov Date: Tue, 13 Aug 2024 17:54:50 +0300 Subject: [PATCH] test_storpool.py: Assume volumes have a volume type All volumes since the Train release have a volume type [1], so test cases with a non-present volume type can be removed [1]: https://docs.openstack.org/cinder/latest/admin/default-volume-types.html Change-Id: I1df86c7d1653ece74c9cde5f77cfdaac431f581c --- .../unit/volume/drivers/test_storpool.py | 119 ++++++++++-------- 1 file changed, 68 insertions(+), 51 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/test_storpool.py b/cinder/tests/unit/volume/drivers/test_storpool.py index 80b68a8af9f..44707d0b847 100644 --- a/cinder/tests/unit/volume/drivers/test_storpool.py +++ b/cinder/tests/unit/volume/drivers/test_storpool.py @@ -32,15 +32,16 @@ sys.modules['storpool'] = fakeStorPool from cinder import exception +from cinder.tests.unit import fake_constants from cinder.tests.unit import test from cinder.volume import configuration as conf from cinder.volume.drivers import storpool as driver volume_types = { - 1: {}, - 2: {'storpool_template': 'ssd'}, - 3: {'storpool_template': 'hdd'} + fake_constants.VOLUME_TYPE_ID: {}, + fake_constants.VOLUME_TYPE2_ID: {'storpool_template': 'ssd'}, + fake_constants.VOLUME_TYPE3_ID: {'storpool_template': 'hdd'} } volumes = {} snapshots = {} @@ -329,7 +330,8 @@ class StorPoolTestCase(test.TestCase): self.assertDictEqual({}, snapshots) self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, - 'volume_type': None}) + 'volume_type': + {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertCountEqual([volumeName('1')], volumes.keys()) self.assertVolumeNames(('1',)) v = volumes[volumeName('1')] @@ -339,8 +341,9 @@ class StorPoolTestCase(test.TestCase): caught = False try: - self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 0, - 'volume_type': None}) + self.driver.create_volume( + {'id': '1', 'name': 'v1', 'size': 0, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) except exception.VolumeBackendAPIException: caught = True self.assertTrue(caught) @@ -349,8 +352,9 @@ class StorPoolTestCase(test.TestCase): self.assertVolumeNames([]) self.assertDictEqual({}, volumes) - self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 2, - 'volume_type': None}) + self.driver.create_volume( + {'id': '1', 'name': 'v1', 'size': 2, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('1',)) v = volumes[volumeName('1')] self.assertEqual(2 * units.Gi, v['size']) @@ -358,23 +362,26 @@ class StorPoolTestCase(test.TestCase): self.assertEqual(3, v['replication']) self.driver.create_volume({'id': '2', 'name': 'v2', 'size': 3, - 'volume_type': {'id': 1}}) + 'volume_type': + {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('1', '2')) v = volumes[volumeName('2')] self.assertEqual(3 * units.Gi, v['size']) self.assertIsNone(v['template']) self.assertEqual(3, v['replication']) - self.driver.create_volume({'id': '3', 'name': 'v2', 'size': 4, - 'volume_type': {'id': 2}}) + self.driver.create_volume( + {'id': '3', 'name': 'v2', 'size': 4, + 'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}}) self.assertVolumeNames(('1', '2', '3')) v = volumes[volumeName('3')] self.assertEqual(4 * units.Gi, v['size']) self.assertEqual('ssd', v['template']) self.assertNotIn('replication', v.keys()) - self.driver.create_volume({'id': '4', 'name': 'v2', 'size': 5, - 'volume_type': {'id': 3}}) + self.driver.create_volume( + {'id': '4', 'name': 'v2', 'size': 5, + 'volume_type': {'id': fake_constants.VOLUME_TYPE3_ID}}) self.assertVolumeNames(('1', '2', '3', '4')) v = volumes[volumeName('4')] self.assertEqual(5 * units.Gi, v['size']) @@ -400,10 +407,12 @@ class StorPoolTestCase(test.TestCase): self.assertDictEqual({}, snapshots) # Create two volumes - self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, - 'volume_type': None}) - self.driver.create_volume({'id': '2', 'name': 'v2', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': '1', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) + self.driver.create_volume( + {'id': '2', 'name': 'v2', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertCountEqual([volumeName('1'), volumeName('2')], volumes.keys()) self.assertVolumeNames(('1', '2',)) @@ -438,20 +447,27 @@ class StorPoolTestCase(test.TestCase): self.assertDictEqual({}, volumes) self.assertDictEqual({}, snapshots) + @mock_volume_types def test_clone_extend_volume(self): self.assertVolumeNames([]) self.assertDictEqual({}, volumes) self.assertDictEqual({}, snapshots) - self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': '1', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('1',)) self.driver.extend_volume({'id': '1'}, 2) self.assertEqual(2 * units.Gi, volumes[volumeName('1')]['size']) with mock.patch.object(self.driver, 'db', new=MockVolumeDB()): self.driver.create_cloned_volume( - {'id': '2', 'name': 'clo', 'size': 3, 'volume_type': None}, + { + 'id': '2', + 'name': 'clo', + 'size': 3, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID} + }, {'id': 1}) self.assertVolumeNames(('1', '2')) self.assertDictEqual({}, snapshots) @@ -468,24 +484,16 @@ class StorPoolTestCase(test.TestCase): self.assertDictEqual({}, snapshots) @ddt.data(*itertools.product( - [None] + [{'id': key} for key in sorted(volume_types.keys())], - [None] + [{'id': key} for key in sorted(volume_types.keys())])) + [{'id': key} for key in sorted(volume_types.keys())], + [{'id': key} for key in sorted(volume_types.keys())])) @ddt.unpack @mock_volume_types def test_create_cloned_volume(self, src_type, dst_type): self.assertDictEqual({}, volumes) self.assertDictEqual({}, snapshots) - src_template = ( - None - if src_type is None - else volume_types[src_type['id']].get('storpool_template') - ) - dst_template = ( - None - if dst_type is None - else volume_types[dst_type['id']].get('storpool_template') - ) + src_template = volume_types[src_type['id']].get('storpool_template') + dst_template = volume_types[dst_type['id']].get('storpool_template') src_name = 's-none' if src_template is None else 's-' + src_template dst_name = 'd-none' if dst_template is None else 'd-' + dst_template @@ -553,8 +561,9 @@ class StorPoolTestCase(test.TestCase): self.assertEqual(21, pool['total_capacity_gb']) self.assertEqual(5, int(pool['free_capacity_gb'])) - self.driver.create_volume({'id': 'cfgrepl1', 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': 'cfgrepl1', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('cfgrepl1',)) v = volumes[volumeName('cfgrepl1')] self.assertEqual(3, v['replication']) @@ -567,16 +576,18 @@ class StorPoolTestCase(test.TestCase): self.assertEqual(21, pool['total_capacity_gb']) self.assertEqual(8, int(pool['free_capacity_gb'])) - self.driver.create_volume({'id': 'cfgrepl2', 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': 'cfgrepl2', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('cfgrepl2',)) v = volumes[volumeName('cfgrepl2')] self.assertEqual(2, v['replication']) self.assertIsNone(v['template']) self.driver.delete_volume({'id': 'cfgrepl2'}) - self.driver.create_volume({'id': 'cfgrepl3', 'name': 'v1', 'size': 1, - 'volume_type': {'id': 2}}) + self.driver.create_volume( + {'id': 'cfgrepl3', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}}) self.assertVolumeNames(('cfgrepl3',)) v = volumes[volumeName('cfgrepl3')] self.assertNotIn('replication', v) @@ -599,16 +610,18 @@ class StorPoolTestCase(test.TestCase): self.driver.configuration.storpool_template = None - self.driver.create_volume({'id': 'cfgtempl1', 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': 'cfgtempl1', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('cfgtempl1',)) v = volumes[volumeName('cfgtempl1')] self.assertEqual(3, v['replication']) self.assertIsNone(v['template']) self.driver.delete_volume({'id': 'cfgtempl1'}) - self.driver.create_volume({'id': 'cfgtempl2', 'name': 'v1', 'size': 1, - 'volume_type': {'id': 2}}) + self.driver.create_volume( + {'id': 'cfgtempl2', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}}) self.assertVolumeNames(('cfgtempl2',)) v = volumes[volumeName('cfgtempl2')] self.assertNotIn('replication', v) @@ -617,16 +630,18 @@ class StorPoolTestCase(test.TestCase): self.driver.configuration.storpool_template = 'hdd' - self.driver.create_volume({'id': 'cfgtempl3', 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': 'cfgtempl3', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames(('cfgtempl3',)) v = volumes[volumeName('cfgtempl3')] self.assertNotIn('replication', v) self.assertEqual('hdd', v['template']) self.driver.delete_volume({'id': 'cfgtempl3'}) - self.driver.create_volume({'id': 'cfgtempl4', 'name': 'v1', 'size': 1, - 'volume_type': {'id': 2}}) + self.driver.create_volume( + {'id': 'cfgtempl4', 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}}) self.assertVolumeNames(('cfgtempl4',)) v = volumes[volumeName('cfgtempl4')] self.assertNotIn('replication', v) @@ -643,10 +658,10 @@ class StorPoolTestCase(test.TestCase): # No volume type at all: 'default' ('default', None), # No storpool_template in the type extra specs: 'default' - ('default', {'id': 1}), + ('default', {'id': fake_constants.VOLUME_TYPE_ID}), # An actual template specified: 'template_*' - ('template_ssd', {'id': 2}), - ('template_hdd', {'id': 3}), + ('template_ssd', {'id': fake_constants.VOLUME_TYPE2_ID}), + ('template_hdd', {'id': fake_constants.VOLUME_TYPE3_ID}), ) @ddt.unpack @mock_volume_types @@ -656,6 +671,7 @@ class StorPoolTestCase(test.TestCase): 'volume_type': volume_type })) + @mock_volume_types def test_volume_revert(self): vol_id = 'rev1' vol_name = volumeName(vol_id) @@ -666,8 +682,9 @@ class StorPoolTestCase(test.TestCase): self.assertDictEqual({}, volumes) self.assertDictEqual({}, snapshots) - self.driver.create_volume({'id': vol_id, 'name': 'v1', 'size': 1, - 'volume_type': None}) + self.driver.create_volume( + {'id': vol_id, 'name': 'v1', 'size': 1, + 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}}) self.assertVolumeNames((vol_id,)) self.assertDictEqual({}, snapshots)