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
This commit is contained in:
Biser Milanov 2024-08-13 17:54:50 +03:00
parent 41a07d63bf
commit d9e31ee702

View File

@ -32,15 +32,16 @@ sys.modules['storpool'] = fakeStorPool
from cinder import exception from cinder import exception
from cinder.tests.unit import fake_constants
from cinder.tests.unit import test from cinder.tests.unit import test
from cinder.volume import configuration as conf from cinder.volume import configuration as conf
from cinder.volume.drivers import storpool as driver from cinder.volume.drivers import storpool as driver
volume_types = { volume_types = {
1: {}, fake_constants.VOLUME_TYPE_ID: {},
2: {'storpool_template': 'ssd'}, fake_constants.VOLUME_TYPE2_ID: {'storpool_template': 'ssd'},
3: {'storpool_template': 'hdd'} fake_constants.VOLUME_TYPE3_ID: {'storpool_template': 'hdd'}
} }
volumes = {} volumes = {}
snapshots = {} snapshots = {}
@ -329,7 +330,8 @@ class StorPoolTestCase(test.TestCase):
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, 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.assertCountEqual([volumeName('1')], volumes.keys())
self.assertVolumeNames(('1',)) self.assertVolumeNames(('1',))
v = volumes[volumeName('1')] v = volumes[volumeName('1')]
@ -339,8 +341,9 @@ class StorPoolTestCase(test.TestCase):
caught = False caught = False
try: try:
self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 0, self.driver.create_volume(
'volume_type': None}) {'id': '1', 'name': 'v1', 'size': 0,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
except exception.VolumeBackendAPIException: except exception.VolumeBackendAPIException:
caught = True caught = True
self.assertTrue(caught) self.assertTrue(caught)
@ -349,8 +352,9 @@ class StorPoolTestCase(test.TestCase):
self.assertVolumeNames([]) self.assertVolumeNames([])
self.assertDictEqual({}, volumes) self.assertDictEqual({}, volumes)
self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 2, self.driver.create_volume(
'volume_type': None}) {'id': '1', 'name': 'v1', 'size': 2,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('1',)) self.assertVolumeNames(('1',))
v = volumes[volumeName('1')] v = volumes[volumeName('1')]
self.assertEqual(2 * units.Gi, v['size']) self.assertEqual(2 * units.Gi, v['size'])
@ -358,23 +362,26 @@ class StorPoolTestCase(test.TestCase):
self.assertEqual(3, v['replication']) self.assertEqual(3, v['replication'])
self.driver.create_volume({'id': '2', 'name': 'v2', 'size': 3, 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')) self.assertVolumeNames(('1', '2'))
v = volumes[volumeName('2')] v = volumes[volumeName('2')]
self.assertEqual(3 * units.Gi, v['size']) self.assertEqual(3 * units.Gi, v['size'])
self.assertIsNone(v['template']) self.assertIsNone(v['template'])
self.assertEqual(3, v['replication']) self.assertEqual(3, v['replication'])
self.driver.create_volume({'id': '3', 'name': 'v2', 'size': 4, self.driver.create_volume(
'volume_type': {'id': 2}}) {'id': '3', 'name': 'v2', 'size': 4,
'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}})
self.assertVolumeNames(('1', '2', '3')) self.assertVolumeNames(('1', '2', '3'))
v = volumes[volumeName('3')] v = volumes[volumeName('3')]
self.assertEqual(4 * units.Gi, v['size']) self.assertEqual(4 * units.Gi, v['size'])
self.assertEqual('ssd', v['template']) self.assertEqual('ssd', v['template'])
self.assertNotIn('replication', v.keys()) self.assertNotIn('replication', v.keys())
self.driver.create_volume({'id': '4', 'name': 'v2', 'size': 5, self.driver.create_volume(
'volume_type': {'id': 3}}) {'id': '4', 'name': 'v2', 'size': 5,
'volume_type': {'id': fake_constants.VOLUME_TYPE3_ID}})
self.assertVolumeNames(('1', '2', '3', '4')) self.assertVolumeNames(('1', '2', '3', '4'))
v = volumes[volumeName('4')] v = volumes[volumeName('4')]
self.assertEqual(5 * units.Gi, v['size']) self.assertEqual(5 * units.Gi, v['size'])
@ -400,10 +407,12 @@ class StorPoolTestCase(test.TestCase):
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
# Create two volumes # Create two volumes
self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': '1', 'name': 'v1', 'size': 1,
self.driver.create_volume({'id': '2', 'name': 'v2', 'size': 1, 'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
'volume_type': None}) self.driver.create_volume(
{'id': '2', 'name': 'v2', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertCountEqual([volumeName('1'), volumeName('2')], self.assertCountEqual([volumeName('1'), volumeName('2')],
volumes.keys()) volumes.keys())
self.assertVolumeNames(('1', '2',)) self.assertVolumeNames(('1', '2',))
@ -438,20 +447,27 @@ class StorPoolTestCase(test.TestCase):
self.assertDictEqual({}, volumes) self.assertDictEqual({}, volumes)
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
@mock_volume_types
def test_clone_extend_volume(self): def test_clone_extend_volume(self):
self.assertVolumeNames([]) self.assertVolumeNames([])
self.assertDictEqual({}, volumes) self.assertDictEqual({}, volumes)
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
self.driver.create_volume({'id': '1', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': '1', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('1',)) self.assertVolumeNames(('1',))
self.driver.extend_volume({'id': '1'}, 2) self.driver.extend_volume({'id': '1'}, 2)
self.assertEqual(2 * units.Gi, volumes[volumeName('1')]['size']) self.assertEqual(2 * units.Gi, volumes[volumeName('1')]['size'])
with mock.patch.object(self.driver, 'db', new=MockVolumeDB()): with mock.patch.object(self.driver, 'db', new=MockVolumeDB()):
self.driver.create_cloned_volume( 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}) {'id': 1})
self.assertVolumeNames(('1', '2')) self.assertVolumeNames(('1', '2'))
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
@ -468,24 +484,16 @@ class StorPoolTestCase(test.TestCase):
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
@ddt.data(*itertools.product( @ddt.data(*itertools.product(
[None] + [{'id': key} for key in sorted(volume_types.keys())], [{'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())]))
@ddt.unpack @ddt.unpack
@mock_volume_types @mock_volume_types
def test_create_cloned_volume(self, src_type, dst_type): def test_create_cloned_volume(self, src_type, dst_type):
self.assertDictEqual({}, volumes) self.assertDictEqual({}, volumes)
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
src_template = ( src_template = volume_types[src_type['id']].get('storpool_template')
None dst_template = volume_types[dst_type['id']].get('storpool_template')
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_name = 's-none' if src_template is None else 's-' + src_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 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(21, pool['total_capacity_gb'])
self.assertEqual(5, int(pool['free_capacity_gb'])) self.assertEqual(5, int(pool['free_capacity_gb']))
self.driver.create_volume({'id': 'cfgrepl1', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': 'cfgrepl1', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('cfgrepl1',)) self.assertVolumeNames(('cfgrepl1',))
v = volumes[volumeName('cfgrepl1')] v = volumes[volumeName('cfgrepl1')]
self.assertEqual(3, v['replication']) self.assertEqual(3, v['replication'])
@ -567,16 +576,18 @@ class StorPoolTestCase(test.TestCase):
self.assertEqual(21, pool['total_capacity_gb']) self.assertEqual(21, pool['total_capacity_gb'])
self.assertEqual(8, int(pool['free_capacity_gb'])) self.assertEqual(8, int(pool['free_capacity_gb']))
self.driver.create_volume({'id': 'cfgrepl2', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': 'cfgrepl2', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('cfgrepl2',)) self.assertVolumeNames(('cfgrepl2',))
v = volumes[volumeName('cfgrepl2')] v = volumes[volumeName('cfgrepl2')]
self.assertEqual(2, v['replication']) self.assertEqual(2, v['replication'])
self.assertIsNone(v['template']) self.assertIsNone(v['template'])
self.driver.delete_volume({'id': 'cfgrepl2'}) self.driver.delete_volume({'id': 'cfgrepl2'})
self.driver.create_volume({'id': 'cfgrepl3', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': {'id': 2}}) {'id': 'cfgrepl3', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}})
self.assertVolumeNames(('cfgrepl3',)) self.assertVolumeNames(('cfgrepl3',))
v = volumes[volumeName('cfgrepl3')] v = volumes[volumeName('cfgrepl3')]
self.assertNotIn('replication', v) self.assertNotIn('replication', v)
@ -599,16 +610,18 @@ class StorPoolTestCase(test.TestCase):
self.driver.configuration.storpool_template = None self.driver.configuration.storpool_template = None
self.driver.create_volume({'id': 'cfgtempl1', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': 'cfgtempl1', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('cfgtempl1',)) self.assertVolumeNames(('cfgtempl1',))
v = volumes[volumeName('cfgtempl1')] v = volumes[volumeName('cfgtempl1')]
self.assertEqual(3, v['replication']) self.assertEqual(3, v['replication'])
self.assertIsNone(v['template']) self.assertIsNone(v['template'])
self.driver.delete_volume({'id': 'cfgtempl1'}) self.driver.delete_volume({'id': 'cfgtempl1'})
self.driver.create_volume({'id': 'cfgtempl2', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': {'id': 2}}) {'id': 'cfgtempl2', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}})
self.assertVolumeNames(('cfgtempl2',)) self.assertVolumeNames(('cfgtempl2',))
v = volumes[volumeName('cfgtempl2')] v = volumes[volumeName('cfgtempl2')]
self.assertNotIn('replication', v) self.assertNotIn('replication', v)
@ -617,16 +630,18 @@ class StorPoolTestCase(test.TestCase):
self.driver.configuration.storpool_template = 'hdd' self.driver.configuration.storpool_template = 'hdd'
self.driver.create_volume({'id': 'cfgtempl3', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': 'cfgtempl3', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames(('cfgtempl3',)) self.assertVolumeNames(('cfgtempl3',))
v = volumes[volumeName('cfgtempl3')] v = volumes[volumeName('cfgtempl3')]
self.assertNotIn('replication', v) self.assertNotIn('replication', v)
self.assertEqual('hdd', v['template']) self.assertEqual('hdd', v['template'])
self.driver.delete_volume({'id': 'cfgtempl3'}) self.driver.delete_volume({'id': 'cfgtempl3'})
self.driver.create_volume({'id': 'cfgtempl4', 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': {'id': 2}}) {'id': 'cfgtempl4', 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE2_ID}})
self.assertVolumeNames(('cfgtempl4',)) self.assertVolumeNames(('cfgtempl4',))
v = volumes[volumeName('cfgtempl4')] v = volumes[volumeName('cfgtempl4')]
self.assertNotIn('replication', v) self.assertNotIn('replication', v)
@ -643,10 +658,10 @@ class StorPoolTestCase(test.TestCase):
# No volume type at all: 'default' # No volume type at all: 'default'
('default', None), ('default', None),
# No storpool_template in the type extra specs: 'default' # No storpool_template in the type extra specs: 'default'
('default', {'id': 1}), ('default', {'id': fake_constants.VOLUME_TYPE_ID}),
# An actual template specified: 'template_*' # An actual template specified: 'template_*'
('template_ssd', {'id': 2}), ('template_ssd', {'id': fake_constants.VOLUME_TYPE2_ID}),
('template_hdd', {'id': 3}), ('template_hdd', {'id': fake_constants.VOLUME_TYPE3_ID}),
) )
@ddt.unpack @ddt.unpack
@mock_volume_types @mock_volume_types
@ -656,6 +671,7 @@ class StorPoolTestCase(test.TestCase):
'volume_type': volume_type 'volume_type': volume_type
})) }))
@mock_volume_types
def test_volume_revert(self): def test_volume_revert(self):
vol_id = 'rev1' vol_id = 'rev1'
vol_name = volumeName(vol_id) vol_name = volumeName(vol_id)
@ -666,8 +682,9 @@ class StorPoolTestCase(test.TestCase):
self.assertDictEqual({}, volumes) self.assertDictEqual({}, volumes)
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)
self.driver.create_volume({'id': vol_id, 'name': 'v1', 'size': 1, self.driver.create_volume(
'volume_type': None}) {'id': vol_id, 'name': 'v1', 'size': 1,
'volume_type': {'id': fake_constants.VOLUME_TYPE_ID}})
self.assertVolumeNames((vol_id,)) self.assertVolumeNames((vol_id,))
self.assertDictEqual({}, snapshots) self.assertDictEqual({}, snapshots)