diff --git a/rally/plugins/openstack/scenarios/cinder/utils.py b/rally/plugins/openstack/scenarios/cinder/utils.py index 1e8b7bd5..2101dfb3 100644 --- a/rally/plugins/openstack/scenarios/cinder/utils.py +++ b/rally/plugins/openstack/scenarios/cinder/utils.py @@ -17,7 +17,8 @@ import random from oslo_config import cfg -from rally.common.i18n import _ +from rally.common.i18n import _, _LW +from rally.common import logging from rally import exceptions from rally.plugins.openstack import scenario from rally.plugins.openstack.services.storage import block @@ -27,6 +28,7 @@ from rally.task import atomic from rally.task import utils as bench_utils CONF = cfg.CONF +LOG = logging.getLogger(__name__) class CinderBasic(scenario.OpenStackScenario): @@ -49,6 +51,14 @@ class CinderBasic(scenario.OpenStackScenario): class CinderScenario(scenario.OpenStackScenario): """Base class for Cinder scenarios with basic atomic actions.""" + def __init__(self, context=None, admin_clients=None, clients=None): + super(CinderScenario, self).__init__(context, admin_clients, clients) + LOG.warning(_LW( + "Class %s is deprecated since Rally 0.10.0 and will be removed " + "soon. Use " + "rally.plugins.openstack.services.storage.block.BlockStorage " + "instead.") % self.__class__) + @atomic.action_timer("cinder.list_volumes") def _list_volumes(self, detailed=True): """Returns user volumes list.""" diff --git a/rally/plugins/openstack/scenarios/nova/servers.py b/rally/plugins/openstack/scenarios/nova/servers.py index c51357b3..e9bd30c4 100755 --- a/rally/plugins/openstack/scenarios/nova/servers.py +++ b/rally/plugins/openstack/scenarios/nova/servers.py @@ -41,7 +41,7 @@ LOG = logging.getLogger(__name__) @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_list_server") -class BootAndListServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndListServer(utils.NovaScenario): def run(self, image, flavor, detailed=True, **kwargs): """Boot a server from an image and then list all servers. @@ -75,7 +75,7 @@ class BootAndListServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.list_servers") -class ListServers(utils.NovaScenario, cinder_utils.CinderScenario): +class ListServers(utils.NovaScenario): def run(self, detailed=True): """List all servers. @@ -97,7 +97,7 @@ class ListServers(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_delete_server") -class BootAndDeleteServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndDeleteServer(utils.NovaScenario): def run(self, image, flavor, min_sleep=0, max_sleep=0, force_delete=False, **kwargs): @@ -128,8 +128,7 @@ class BootAndDeleteServer(utils.NovaScenario, cinder_utils.CinderScenario): admin=True, users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_delete_multiple_servers") -class BootAndDeleteMultipleServers(utils.NovaScenario, - cinder_utils.CinderScenario): +class BootAndDeleteMultipleServers(utils.NovaScenario): def run(self, image, flavor, count=2, min_sleep=0, max_sleep=0, force_delete=False, **kwargs): @@ -162,7 +161,7 @@ class BootAndDeleteMultipleServers(utils.NovaScenario, @scenario.configure(context={"cleanup": ["nova", "cinder"]}, name="NovaServers.boot_server_from_volume_and_delete") class BootServerFromVolumeAndDelete(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, volume_size, volume_type=None, min_sleep=0, max_sleep=0, force_delete=False, **kwargs): @@ -183,8 +182,8 @@ class BootServerFromVolumeAndDelete(utils.NovaScenario, :param force_delete: True if force_delete should be used :param kwargs: Optional additional arguments for server creation """ - volume = self._create_volume(volume_size, imageRef=image, - volume_type=volume_type) + volume = self.cinder.create_volume(volume_size, imageRef=image, + volume_type=volume_type) block_device_mapping = {"vda": "%s:::1" % volume.id} server = self._boot_server(None, flavor, block_device_mapping=block_device_mapping, @@ -201,7 +200,7 @@ class BootServerFromVolumeAndDelete(utils.NovaScenario, @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_bounce_server") -class BootAndBounceServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndBounceServer(utils.NovaScenario): def run(self, image, flavor, force_delete=False, actions=None, **kwargs): """Boot a server and run specified actions against it. @@ -242,7 +241,7 @@ class BootAndBounceServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_lock_unlock_and_delete") -class BootLockUnlockAndDelete(utils.NovaScenario, cinder_utils.CinderScenario): +class BootLockUnlockAndDelete(utils.NovaScenario): def run(self, image, flavor, min_sleep=0, max_sleep=0, force_delete=False, **kwargs): @@ -277,7 +276,7 @@ class BootLockUnlockAndDelete(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova", "glance"]}, name="NovaServers.snapshot_server") -class SnapshotServer(utils.NovaScenario, cinder_utils.CinderScenario): +class SnapshotServer(utils.NovaScenario): def run(self, image, flavor, force_delete=False, **kwargs): """Boot a server, make its snapshot and delete both. @@ -305,7 +304,7 @@ class SnapshotServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_server") -class BootServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootServer(utils.NovaScenario): def run(self, image, flavor, auto_assign_nic=False, **kwargs): """Boot a server. @@ -330,7 +329,7 @@ class BootServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova", "cinder"]}, name="NovaServers.boot_server_from_volume") -class BootServerFromVolume(utils.NovaScenario, cinder_utils.CinderScenario): +class BootServerFromVolume(utils.NovaScenario, cinder_utils.CinderBasic): def run(self, image, flavor, volume_size, volume_type=None, auto_assign_nic=False, **kwargs): @@ -347,8 +346,8 @@ class BootServerFromVolume(utils.NovaScenario, cinder_utils.CinderScenario): :param auto_assign_nic: True if NICs should be assigned :param kwargs: Optional additional arguments for server creation """ - volume = self._create_volume(volume_size, imageRef=image, - volume_type=volume_type) + volume = self.cinder.create_volume(volume_size, imageRef=image, + volume_type=volume_type) block_device_mapping = {"vda": "%s:::1" % volume.id} self._boot_server(None, flavor, auto_assign_nic=auto_assign_nic, block_device_mapping=block_device_mapping, @@ -364,7 +363,7 @@ class BootServerFromVolume(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.resize_server") -class ResizeServer(utils.NovaScenario, cinder_utils.CinderScenario): +class ResizeServer(utils.NovaScenario): def run(self, image, flavor, to_flavor, force_delete=False, **kwargs): """Boot a server, then resize and delete it. @@ -434,10 +433,10 @@ class ResizeShutoffServer(utils.NovaScenario): consts.Service.CINDER]) @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["cinder", "nova"]}, - name=("NovaServers.boot_server" - "_attach_created_volume_and_resize")) + name=("NovaServers." + "boot_server_attach_created_volume_and_resize")) class BootServerAttachCreatedVolumeAndResize(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, to_flavor, volume_size, min_sleep=0, max_sleep=0, force_delete=False, confirm=True, do_delete=True, @@ -466,7 +465,7 @@ class BootServerAttachCreatedVolumeAndResize(utils.NovaScenario, create_volume_kwargs = create_volume_kwargs or {} server = self._boot_server(image, flavor, **boot_server_kwargs) - volume = self._create_volume(volume_size, **create_volume_kwargs) + volume = self.cinder.create_volume(volume_size, **create_volume_kwargs) attachment = self._attach_volume(server, volume) self.sleep_between(min_sleep, max_sleep) @@ -479,7 +478,7 @@ class BootServerAttachCreatedVolumeAndResize(utils.NovaScenario, if do_delete: self._detach_volume(server, volume, attachment) - self._delete_volume(volume) + self.cinder.delete_volume(volume) self._delete_server(server, force=force_delete) @@ -494,7 +493,7 @@ class BootServerAttachCreatedVolumeAndResize(utils.NovaScenario, @scenario.configure(context={"cleanup": ["nova", "cinder"]}, name="NovaServers.boot_server_from_volume_and_resize") class BootServerFromVolumeAndResize(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, to_flavor, volume_size, min_sleep=0, max_sleep=0, force_delete=False, confirm=True, do_delete=True, @@ -528,8 +527,8 @@ class BootServerFromVolumeAndResize(utils.NovaScenario, if boot_server_kwargs.get("block_device_mapping"): LOG.warning("Using already existing volume is not permitted.") - volume = self._create_volume(volume_size, imageRef=image, - **create_volume_kwargs) + volume = self.cinder.create_volume(volume_size, imageRef=image, + **create_volume_kwargs) boot_server_kwargs["block_device_mapping"] = { "vda": "%s:::1" % volume.id} @@ -554,7 +553,7 @@ class BootServerFromVolumeAndResize(utils.NovaScenario, @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.suspend_and_resume_server") -class SuspendAndResumeServer(utils.NovaScenario, cinder_utils.CinderScenario): +class SuspendAndResumeServer(utils.NovaScenario): def run(self, image, flavor, force_delete=False, **kwargs): """Create a server, suspend, resume and then delete it @@ -578,8 +577,7 @@ class SuspendAndResumeServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.pause_and_unpause_server") -class PauseAndUnpauseServer(utils.NovaScenario, - cinder_utils.CinderScenario): +class PauseAndUnpauseServer(utils.NovaScenario): def run(self, image, flavor, force_delete=False, **kwargs): """Create a server, pause, unpause and then delete it @@ -603,8 +601,7 @@ class PauseAndUnpauseServer(utils.NovaScenario, @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.shelve_and_unshelve_server") -class ShelveAndUnshelveServer(utils.NovaScenario, - cinder_utils.CinderScenario): +class ShelveAndUnshelveServer(utils.NovaScenario): def run(self, image, flavor, force_delete=False, **kwargs): """Create a server, shelve, unshelve and then delete it @@ -629,8 +626,7 @@ class ShelveAndUnshelveServer(utils.NovaScenario, admin=True, users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_live_migrate_server") -class BootAndLiveMigrateServer(utils.NovaScenario, - cinder_utils.CinderScenario): +class BootAndLiveMigrateServer(utils.NovaScenario): def run(self, image, flavor, block_migration=False, disk_over_commit=False, min_sleep=0, max_sleep=0, **kwargs): @@ -675,7 +671,7 @@ class BootAndLiveMigrateServer(utils.NovaScenario, name=("NovaServers.boot_server_from_volume" "_and_live_migrate")) class BootServerFromVolumeAndLiveMigrate(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, volume_size, volume_type=None, block_migration=False, disk_over_commit=False, force_delete=False, @@ -704,8 +700,8 @@ class BootServerFromVolumeAndLiveMigrate(utils.NovaScenario, :param max_sleep: Maximum sleep time in seconds (non-negative) :param kwargs: Optional additional arguments for server creation """ - volume = self._create_volume(volume_size, imageRef=image, - volume_type=volume_type) + volume = self.cinder.create_volume(volume_size, imageRef=image, + volume_type=volume_type) block_device_mapping = {"vda": "%s:::1" % volume.id} server = self._boot_server(None, flavor, block_device_mapping=block_device_mapping, @@ -731,7 +727,7 @@ class BootServerFromVolumeAndLiveMigrate(utils.NovaScenario, name=("NovaServers.boot_server_attach_created_volume" "_and_live_migrate")) class BootServerAttachCreatedVolumeAndLiveMigrate(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, size, block_migration=False, disk_over_commit=False, boot_server_kwargs=None, @@ -763,7 +759,7 @@ class BootServerAttachCreatedVolumeAndLiveMigrate(utils.NovaScenario, create_volume_kwargs = {} server = self._boot_server(image, flavor, **boot_server_kwargs) - volume = self._create_volume(size, **create_volume_kwargs) + volume = self.cinder.create_volume(size, **create_volume_kwargs) attachment = self._attach_volume(server, volume) @@ -775,7 +771,7 @@ class BootServerAttachCreatedVolumeAndLiveMigrate(utils.NovaScenario, self._detach_volume(server, volume, attachment) - self._delete_volume(volume) + self.cinder.delete_volume(volume) self._delete_server(server) @@ -788,7 +784,7 @@ class BootServerAttachCreatedVolumeAndLiveMigrate(utils.NovaScenario, admin=True, users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_migrate_server") -class BootAndMigrateServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndMigrateServer(utils.NovaScenario): def run(self, image, flavor, **kwargs): """Migrate a server. @@ -825,7 +821,7 @@ class BootAndMigrateServer(utils.NovaScenario, cinder_utils.CinderScenario): admin=True, users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_rebuild_server") -class BootAndRebuildServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndRebuildServer(utils.NovaScenario): def run(self, from_image, to_image, flavor, **kwargs): """Rebuild a server. @@ -852,8 +848,7 @@ class BootAndRebuildServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_contexts", contexts=("network")) @scenario.configure(context={"cleanup": ["nova", "neutron.floatingip"]}, name="NovaServers.boot_and_associate_floating_ip") -class BootAndAssociateFloatingIp(utils.NovaScenario, - cinder_utils.CinderScenario): +class BootAndAssociateFloatingIp(utils.NovaScenario): def run(self, image, flavor, **kwargs): """Boot a server and associate a floating IP to it. @@ -910,7 +905,7 @@ class BootServerAndAttachInterface(utils.NovaScenario, @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_show_server") -class BootAndShowServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndShowServer(utils.NovaScenario): def run(self, image, flavor, **kwargs): """Show server details. @@ -935,7 +930,7 @@ class BootAndShowServer(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_get_console_output") -class BootAndGetConsoleOutput(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndGetConsoleOutput(utils.NovaScenario): def run(self, image, flavor, length=None, **kwargs): """Get text console output from server. @@ -962,7 +957,7 @@ class BootAndGetConsoleOutput(utils.NovaScenario, cinder_utils.CinderScenario): @validation.add("required_platform", platform="openstack", users=True) @scenario.configure(context={"cleanup": ["nova"]}, name="NovaServers.boot_and_update_server") -class BootAndUpdateServer(utils.NovaScenario, cinder_utils.CinderScenario): +class BootAndUpdateServer(utils.NovaScenario): def run(self, image, flavor, description=None, **kwargs): """Boot a server, then update its name and description. @@ -989,7 +984,7 @@ class BootAndUpdateServer(utils.NovaScenario, cinder_utils.CinderScenario): @scenario.configure(context={"cleanup": ["nova", "cinder"]}, name="NovaServers.boot_server_from_volume_snapshot") class BootServerFromVolumeSnapshot(utils.NovaScenario, - cinder_utils.CinderScenario): + cinder_utils.CinderBasic): def run(self, image, flavor, volume_size, volume_type=None, auto_assign_nic=False, **kwargs): @@ -1008,9 +1003,9 @@ class BootServerFromVolumeSnapshot(utils.NovaScenario, :param auto_assign_nic: True if NICs should be assigned :param kwargs: Optional additional arguments for server creation """ - volume = self._create_volume(volume_size, imageRef=image, - volume_type=volume_type) - snapshot = self._create_snapshot(volume.id, False) + volume = self.cinder.create_volume(volume_size, imageRef=image, + volume_type=volume_type) + snapshot = self.cinder.create_snapshot(volume.id, force=False) block_device_mapping = {"vda": "%s:snap::1" % snapshot.id} self._boot_server(None, flavor, auto_assign_nic=auto_assign_nic, block_device_mapping=block_device_mapping, diff --git a/rally/plugins/openstack/scenarios/nova/utils.py b/rally/plugins/openstack/scenarios/nova/utils.py index aa054004..d69896cb 100644 --- a/rally/plugins/openstack/scenarios/nova/utils.py +++ b/rally/plugins/openstack/scenarios/nova/utils.py @@ -680,7 +680,7 @@ class NovaScenario(scenario.OpenStackScenario): def _detach_volume(self, server, volume, attachment=None): server_id = server.id # NOTE(chenhb): Recommend the use of attachment.The use of - # volume.id is retained mainly for backwoard compatible. + # volume.id is retained mainly for backward compatibility. attachment_id = attachment.id if attachment else volume.id self.clients("nova").volumes.delete_server_volume(server_id, diff --git a/rally/plugins/openstack/scenarios/vm/utils.py b/rally/plugins/openstack/scenarios/vm/utils.py index b194760b..ad41409f 100644 --- a/rally/plugins/openstack/scenarios/vm/utils.py +++ b/rally/plugins/openstack/scenarios/vm/utils.py @@ -24,7 +24,6 @@ import six from rally.common.i18n import _ from rally.common import logging from rally.common import sshutils -from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils from rally.plugins.openstack.scenarios.nova import utils as nova_utils from rally.plugins.openstack.wrappers import network as network_wrapper from rally.task import atomic @@ -82,7 +81,7 @@ class Host(object): return not self.__eq__(other) -class VMScenario(nova_utils.NovaScenario, cinder_utils.CinderScenario): +class VMScenario(nova_utils.NovaScenario): """Base class for VM scenarios with basic atomic actions. VM scenarios are scenarios executed inside some launched VM instance. diff --git a/rally/plugins/openstack/scenarios/vm/vmtasks.py b/rally/plugins/openstack/scenarios/vm/vmtasks.py index 327fcc78..ce00de1b 100644 --- a/rally/plugins/openstack/scenarios/vm/vmtasks.py +++ b/rally/plugins/openstack/scenarios/vm/vmtasks.py @@ -21,6 +21,7 @@ from rally.common import sshutils from rally import consts from rally import exceptions from rally.plugins.openstack import scenario +from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils from rally.plugins.openstack.scenarios.vm import utils as vm_utils from rally.plugins.openstack.services import heat from rally.task import atomic @@ -50,7 +51,7 @@ LOG = logging.getLogger(__name__) @scenario.configure(context={"cleanup": ["nova", "cinder"], "keypair": {}, "allow_ssh": None}, name="VMTasks.boot_runcommand_delete") -class BootRuncommandDelete(vm_utils.VMScenario): +class BootRuncommandDelete(vm_utils.VMScenario, cinder_utils.CinderBasic): def run(self, flavor, username, password=None, image=None, @@ -146,7 +147,8 @@ class BootRuncommandDelete(vm_utils.VMScenario): errors: str, raw data from the script's stderr stream """ if volume_args: - volume = self._create_volume(volume_args["size"], imageRef=None) + volume = self.cinder.create_volume(volume_args["size"], + imageRef=None) kwargs["block_device_mapping"] = {"vdrally": "%s:::1" % volume.id} if not image: diff --git a/rally/plugins/openstack/services/storage/cinder_v1.py b/rally/plugins/openstack/services/storage/cinder_v1.py index 023b445a..f2fb2a52 100644 --- a/rally/plugins/openstack/services/storage/cinder_v1.py +++ b/rally/plugins/openstack/services/storage/cinder_v1.py @@ -47,21 +47,22 @@ class CinderV1Service(service.Service, cinder_common.CinderMixin): :returns: Return a new volume. """ - kwargs = {"display_name": display_name or self.generate_random_name(), - "display_description": display_description, - "snapshot_id": snapshot_id, - "source_volid": source_volid, - "volume_type": volume_type, - "user_id": user_id, - "project_id": project_id, - "availability_zone": availability_zone, - "metadata": metadata, - "imageRef": imageRef} if isinstance(size, dict): size = random.randint(size["min"], size["max"]) - volume = (self._get_client() - .volumes.create(size, **kwargs)) + volume = self._get_client().volumes.create( + size, + display_name=(display_name or self.generate_random_name()), + display_description=display_description, + snapshot_id=snapshot_id, + source_volid=source_volid, + volume_type=volume_type, + user_id=user_id, + project_id=project_id, + availability_zone=availability_zone, + metadata=metadata, + imageRef=imageRef + ) # NOTE(msdubov): It is reasonable to wait 5 secs before starting to # check whether the volume is ready => less API calls. diff --git a/rally/plugins/openstack/wrappers/cinder.py b/rally/plugins/openstack/wrappers/cinder.py index 5579d09a..483885f9 100644 --- a/rally/plugins/openstack/wrappers/cinder.py +++ b/rally/plugins/openstack/wrappers/cinder.py @@ -80,6 +80,10 @@ class CinderV2Wrapper(CinderWrapper): def wrap(client, owner): """Returns cinderclient wrapper based on cinder client version.""" + LOG.warning("Method wrap from %s and whole Cinder wrappers are " + "deprecated since Rally 0.10.0 and will be removed soon. Use " + "rally.plugins.openstack.services.storage.block.BlockStorage " + "instead." % __file__) version = client.choose_version() if version == "1": return CinderV1Wrapper(client(), owner) diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_servers.py b/tests/unit/plugins/openstack/scenarios/nova/test_servers.py index 163b3713..fcb0e957 100644 --- a/tests/unit/plugins/openstack/scenarios/nova/test_servers.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_servers.py @@ -345,40 +345,46 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario.run(True) scenario._list_servers.assert_called_once_with(True) - def test_boot_server_from_volume(self): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_from_volume(self, mock_block_storage): fake_server = object() - scenario = servers.BootServerFromVolume(self.context) + scenario = servers.BootServerFromVolume( + self.context, clients=mock.Mock()) scenario._boot_server = mock.MagicMock(return_value=fake_server) fake_volume = fakes.FakeVolumeManager().create() fake_volume.id = "volume_id" - scenario._create_volume = mock.MagicMock(return_value=fake_volume) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume scenario.run("img", 0, 5, volume_type=None, auto_assign_nic=False, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img", - volume_type=None) + cinder.create_volume.assert_called_once_with(5, imageRef="img", + volume_type=None) scenario._boot_server.assert_called_once_with( None, 0, auto_assign_nic=False, block_device_mapping={"vda": "volume_id:::1"}, fakearg="f") - def test_boot_server_from_volume_and_delete(self): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_from_volume_and_delete(self, mock_block_storage): fake_server = object() - scenario = servers.BootServerFromVolumeAndDelete(self.context) + scenario = servers.BootServerFromVolumeAndDelete( + self.context, clients=mock.Mock()) scenario._boot_server = mock.MagicMock(return_value=fake_server) scenario.sleep_between = mock.MagicMock() scenario._delete_server = mock.MagicMock() fake_volume = fakes.FakeVolumeManager().create() fake_volume.id = "volume_id" - scenario._create_volume = mock.MagicMock(return_value=fake_volume) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume scenario.run("img", 0, 5, None, 10, 20, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img", - volume_type=None) + cinder.create_volume.assert_called_once_with(5, imageRef="img", + volume_type=None) scenario._boot_server.assert_called_once_with( None, 0, block_device_mapping={"vda": "volume_id:::1"}, @@ -511,24 +517,27 @@ class NovaServersTestCase(test.ScenarioTestCase): @ddt.data({"confirm": True, "do_delete": True}, {"confirm": False, "do_delete": True}) @ddt.unpack - def test_boot_server_attach_created_volume_and_resize(self, confirm=False, - do_delete=False): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_attach_created_volume_and_resize( + self, mock_block_storage, confirm=False, do_delete=False): fake_volume = mock.MagicMock() fake_server = mock.MagicMock() flavor = mock.MagicMock() to_flavor = mock.MagicMock() fake_attachment = mock.MagicMock() - scenario = servers.BootServerAttachCreatedVolumeAndResize(self.context) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume + + scenario = servers.BootServerAttachCreatedVolumeAndResize( + self.context, clients=mock.Mock()) scenario.generate_random_name = mock.MagicMock(return_value="name") scenario._boot_server = mock.MagicMock(return_value=fake_server) - scenario._create_volume = mock.MagicMock(return_value=fake_volume) scenario._attach_volume = mock.MagicMock(return_value=fake_attachment) scenario._resize_confirm = mock.MagicMock() scenario._resize_revert = mock.MagicMock() scenario._resize = mock.MagicMock() scenario._detach_volume = mock.MagicMock() - scenario._delete_volume = mock.MagicMock() scenario._delete_server = mock.MagicMock() scenario.sleep_between = mock.MagicMock() @@ -537,7 +546,7 @@ class NovaServersTestCase(test.ScenarioTestCase): max_sleep=20, confirm=confirm, do_delete=do_delete) scenario._boot_server.assert_called_once_with("img", flavor) - scenario._create_volume.assert_called_once_with(volume_size) + cinder.create_volume.assert_called_once_with(volume_size) scenario._attach_volume.assert_called_once_with(fake_server, fake_volume) scenario._detach_volume.assert_called_once_with(fake_server, @@ -555,19 +564,21 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._detach_volume.assert_called_once_with(fake_server, fake_volume, fake_attachment) - scenario._delete_volume.assert_called_once_with(fake_volume) + cinder.delete_volume.assert_called_once_with(fake_volume) scenario._delete_server.assert_called_once_with(fake_server, force=False) @ddt.data({"confirm": True, "do_delete": True}, {"confirm": False, "do_delete": True}) @ddt.unpack - def test_boot_server_from_volume_and_resize(self, confirm=False, - do_delete=False): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_from_volume_and_resize( + self, mock_block_storage, confirm=False, do_delete=False): fake_server = object() flavor = mock.MagicMock() to_flavor = mock.MagicMock() - scenario = servers.BootServerFromVolumeAndResize(self.context) + scenario = servers.BootServerFromVolumeAndResize(self.context, + clients=mock.Mock()) scenario._boot_server = mock.MagicMock(return_value=fake_server) scenario.generate_random_name = mock.MagicMock(return_value="name") scenario._resize_confirm = mock.MagicMock() @@ -578,13 +589,14 @@ class NovaServersTestCase(test.ScenarioTestCase): fake_volume = fakes.FakeVolumeManager().create() fake_volume.id = "volume_id" - scenario._create_volume = mock.MagicMock(return_value=fake_volume) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume volume_size = 10 scenario.run("img", flavor, to_flavor, volume_size, min_sleep=10, max_sleep=20, confirm=confirm, do_delete=do_delete) - scenario._create_volume.assert_called_once_with(10, imageRef="img") + cinder.create_volume.assert_called_once_with(10, imageRef="img") scenario._boot_server.assert_called_once_with( None, flavor, block_device_mapping={"vda": "volume_id:::1"}) @@ -626,10 +638,13 @@ class NovaServersTestCase(test.ScenarioTestCase): False, False) scenario._delete_server.assert_called_once_with(fake_server) - def test_boot_server_from_volume_and_live_migrate(self): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_from_volume_and_live_migrate(self, + mock_block_storage): fake_server = mock.MagicMock() - scenario = servers.BootServerFromVolumeAndLiveMigrate(self.context) + scenario = servers.BootServerFromVolumeAndLiveMigrate( + self.context, clients=mock.Mock()) scenario.generate_random_name = mock.MagicMock(return_value="name") scenario._boot_server = mock.MagicMock(return_value=fake_server) scenario.sleep_between = mock.MagicMock() @@ -640,13 +655,14 @@ class NovaServersTestCase(test.ScenarioTestCase): fake_volume = fakes.FakeVolumeManager().create() fake_volume.id = "volume_id" - scenario._create_volume = mock.MagicMock(return_value=fake_volume) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume scenario.run("img", 0, 5, volume_type=None, min_sleep=10, max_sleep=20, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img", - volume_type=None) + cinder.create_volume.assert_called_once_with(5, imageRef="img", + volume_type=None) scenario._boot_server.assert_called_once_with( None, 0, @@ -663,13 +679,19 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._delete_server.assert_called_once_with(fake_server, force=False) - def test_boot_server_attach_created_volume_and_live_migrate(self): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_attach_created_volume_and_live_migrate( + self, mock_block_storage): fake_volume = mock.MagicMock() fake_server = mock.MagicMock() fake_attachment = mock.MagicMock() + clients = mock.Mock() + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume + scenario = servers.BootServerAttachCreatedVolumeAndLiveMigrate( - self.context) + self.context, clients=clients) scenario._attach_volume = mock.MagicMock(return_value=fake_attachment) scenario._detach_volume = mock.MagicMock() @@ -682,8 +704,6 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._boot_server = mock.MagicMock(return_value=fake_server) scenario._delete_server = mock.MagicMock() - scenario._create_volume = mock.MagicMock(return_value=fake_volume) - scenario._delete_volume = mock.MagicMock() image = "img" flavor = "flavor" @@ -693,7 +713,7 @@ class NovaServersTestCase(test.ScenarioTestCase): boot_server_kwargs=boot_kwargs) scenario._boot_server.assert_called_once_with(image, flavor, **boot_kwargs) - scenario._create_volume.assert_called_once_with(size) + cinder.create_volume.assert_called_once_with(size) scenario._attach_volume.assert_called_once_with(fake_server, fake_volume) scenario._detach_volume.assert_called_once_with(fake_server, @@ -704,7 +724,7 @@ class NovaServersTestCase(test.ScenarioTestCase): "host_name", False, False) - scenario._delete_volume.assert_called_once_with(fake_volume) + cinder.delete_volume.assert_called_once_with(fake_volume) scenario._delete_server.assert_called_once_with(fake_server) def _test_boot_and_migrate_server(self, confirm=False): @@ -893,21 +913,26 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._attach_interface.assert_called_once_with( server, net_id=net["network"]["id"]) - def test_boot_server_from_volume_snapshot(self): + @mock.patch("rally.plugins.openstack.services.storage.block.BlockStorage") + def test_boot_server_from_volume_snapshot(self, mock_block_storage): fake_volume = mock.MagicMock(id="volume_id") fake_snapshot = mock.MagicMock(id="snapshot_id") - scenario = servers.BootServerFromVolumeSnapshot(self.context) + cinder = mock_block_storage.return_value + cinder.create_volume.return_value = fake_volume + cinder.create_snapshot.return_value = fake_snapshot + + scenario = servers.BootServerFromVolumeSnapshot(self.context, + clients=mock.Mock()) scenario._boot_server = mock.MagicMock() - scenario._create_volume = mock.MagicMock(return_value=fake_volume) - scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot) scenario.run("img", "flavor", 1, volume_type=None, auto_assign_nic=False, fakearg="f") - scenario._create_volume.assert_called_once_with(1, imageRef="img", - volume_type=None) - scenario._create_snapshot.assert_called_once_with("volume_id", False) + cinder.create_volume.assert_called_once_with(1, imageRef="img", + volume_type=None) + cinder.create_snapshot.assert_called_once_with("volume_id", + force=False) scenario._boot_server.assert_called_once_with( None, "flavor", auto_assign_nic=False, block_device_mapping={"vda": "snapshot_id:snap::1"}, diff --git a/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py b/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py index 61b25406..269eade1 100644 --- a/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py +++ b/tests/unit/plugins/openstack/scenarios/vm/test_vmtasks.py @@ -32,14 +32,18 @@ class VMTasksTestCase(test.ScenarioTestCase): self.context.update({"user": {"keypair": {"name": "keypair_name"}, "credential": mock.MagicMock()}}) + cinder_patcher = mock.patch( + "rally.plugins.openstack.services.storage.block.BlockStorage") + self.cinder = cinder_patcher.start().return_value + self.cinder.create_volume.return_value = mock.Mock(id="foo_volume") + self.addCleanup(cinder_patcher.stop) + def create_env(self, scenario): self.ip = {"id": "foo_id", "ip": "foo_ip", "is_floating": True} scenario._boot_server_with_fip = mock.Mock( return_value=("foo_server", self.ip)) scenario._wait_for_ping = mock.Mock() scenario._delete_server_with_fip = mock.Mock() - scenario._create_volume = mock.Mock( - return_value=mock.Mock(id="foo_volume")) scenario._run_command = mock.MagicMock( return_value=(0, "{\"foo\": 42}", "foo_err")) scenario.add_output = mock.Mock() @@ -60,7 +64,7 @@ class VMTasksTestCase(test.ScenarioTestCase): volume_args={"size": 16}, foo_arg="foo_value") - scenario._create_volume.assert_called_once_with(16, imageRef=None) + self.cinder.create_volume.assert_called_once_with(16, imageRef=None) scenario._boot_server_with_fip.assert_called_once_with( "foo_image", "foo_flavor", key_name="keypair_name", use_floating_ip="use_fip", floating_network="ext_network", @@ -140,7 +144,8 @@ class VMTasksTestCase(test.ScenarioTestCase): calls = [mock.call(**kw) for kw in expected] scenario.add_output.assert_has_calls(calls, any_order=True) - scenario._create_volume.assert_called_once_with(16, imageRef=None) + self.cinder.create_volume.assert_called_once_with( + 16, imageRef=None) scenario._boot_server_with_fip.assert_called_once_with( "foo_image", "foo_flavor", key_name="keypair_name", use_floating_ip="use_fip", floating_network="ext_network", @@ -229,7 +234,7 @@ class VMTasksTestCase(test.ScenarioTestCase): volume_args={"size": 16}, foo_arg="foo_value") - scenario._create_volume.assert_called_once_with(16, imageRef=None) + self.cinder.create_volume.assert_called_once_with(16, imageRef=None) scenario._boot_server_with_fip.assert_called_once_with( "image_id", "foo_flavor", key_name="foo_keypair_name", use_floating_ip="use_fip", floating_network="ext_network",