From 0d1bcfc1d3f6f939e9b2d1855cf162e456429a46 Mon Sep 17 00:00:00 2001 From: tynorth-cisco Date: Tue, 9 Aug 2016 10:14:23 -0700 Subject: [PATCH] allow passing of specific volume type for create snapshot and attach volume Change-Id: Ibaa981a46d125f36e95343e9c2aeb55906e06a72 --- .../openstack/scenarios/cinder/volumes.py | 20 +++++++++---------- .../scenarios/cinder/test_volumes.py | 6 +++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/rally/plugins/openstack/scenarios/cinder/volumes.py b/rally/plugins/openstack/scenarios/cinder/volumes.py index dc0dc4a2..fe67e968 100755 --- a/rally/plugins/openstack/scenarios/cinder/volumes.py +++ b/rally/plugins/openstack/scenarios/cinder/volumes.py @@ -26,6 +26,7 @@ from rally.task import atomic from rally.task import types from rally.task import validation +LOG = logging.getLogger(__name__) """Scenarios for Cinder Volumes.""" @@ -378,11 +379,7 @@ class CreateSnapshotAndAttachVolume(cinder_utils.CinderScenario, def run(self, volume_type=False, size=None, **kwargs): """Create volume, snapshot and attach/detach volume. - This scenario is based on the standalone qaStressTest.py - (https://github.com/WaltHP/cinder-stress). - - :param volume_type: Whether or not to specify volume type when creating - volumes. + :param volume_type: Name of volume type to use :param size: Volume size - dictionary, contains two values: min - minimum size volumes will be created as; max - maximum size volumes will be created as. @@ -392,16 +389,17 @@ class CreateSnapshotAndAttachVolume(cinder_utils.CinderScenario, """ if size is None: size = {"min": 1, "max": 5} - selected_type = None - volume_types = [None] - if volume_type: + if isinstance(volume_type, bool): + LOG.warning("Selecting a random volume type is deprecated" + "as of Rally 0.7.0") + volume_types = [None] volume_types_list = self.clients("cinder").volume_types.list() for s in volume_types_list: volume_types.append(s.name) - selected_type = random.choice(volume_types) + volume_type = random.choice(volume_types) - volume = self._create_volume(size, volume_type=selected_type) + volume = self._create_volume(size, volume_type=volume_type) snapshot = self._create_snapshot(volume.id, False, **kwargs) server = self.get_random_server() @@ -702,4 +700,4 @@ class CreateVolumeFromSnapshot(cinder_utils.CinderScenario, if do_delete: self._delete_snapshot(snapshot) - self._delete_volume(volume) \ No newline at end of file + self._delete_volume(volume) diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py index 42d6dd44..d2a32bb8 100755 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py @@ -276,7 +276,7 @@ class CinderServersTestCase(test.ScenarioTestCase): fake_attach) scenario._delete_volume.assert_called_once_with(fake_volume) - def test_create_snapshot_and_attach_volume_use_volume_type(self): + def test_create_snapshot_and_attach_volume_use_volume_type_with_name(self): fake_volume = mock.MagicMock() fake_snapshot = mock.MagicMock() fake_server = mock.MagicMock() @@ -299,13 +299,13 @@ class CinderServersTestCase(test.ScenarioTestCase): self.clients("nova").servers.get = mock.MagicMock( return_value=fake_server) - scenario.run(volume_type=True) + scenario.run(volume_type="fake_volume_type") # Make sure create volume's second arg was the correct volume type. # fake or none (randomly selected) self.assertTrue(scenario._create_volume.called) vol_type = scenario._create_volume.call_args_list[0][1]["volume_type"] - self.assertTrue(vol_type is fake.name or vol_type is None) + self.assertEqual(vol_type, "fake_volume_type") scenario._create_snapshot.assert_called_once_with(fake_volume.id, False) scenario._delete_snapshot.assert_called_once_with(fake_snapshot)