From 65bb33ed97cdb624e1fb38f87c6f00c0a09783d7 Mon Sep 17 00:00:00 2001 From: Lv Fumei Date: Fri, 1 Jul 2016 17:09:21 +0800 Subject: [PATCH] Add param volume_type when creating volume in nova scenarios Volume_type can specify a certain volume type when there are multiple backends. Change-Id: Ifdc80f5bb6c0a05c64f0b0c6b28b536a2e46f714 --- rally-jobs/nova.yaml | 4 +++ .../openstack/scenarios/nova/servers.py | 26 +++++++++++++++---- .../nova/boot-from-volume-and-delete.json | 2 ++ .../nova/boot-from-volume-and-delete.yaml | 2 ++ .../nova/boot-from-volume-snapshot.json | 4 ++- .../nova/boot-from-volume-snapshot.yaml | 2 ++ .../scenarios/nova/boot-from-volume.json | 4 ++- .../scenarios/nova/boot-from-volume.yaml | 2 ++ ...t-server-from-volume-and-live-migrate.json | 2 ++ ...t-server-from-volume-and-live-migrate.yaml | 2 ++ .../openstack/scenarios/nova/test_servers.py | 19 +++++++++----- 11 files changed, 56 insertions(+), 13 deletions(-) mode change 100644 => 100755 rally-jobs/nova.yaml mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume-and-delete.json mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume-and-delete.yaml mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume-snapshot.json mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume-snapshot.yaml mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume.json mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-from-volume.yaml mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.json mode change 100644 => 100755 samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.yaml diff --git a/rally-jobs/nova.yaml b/rally-jobs/nova.yaml old mode 100644 new mode 100755 index 0149e18b..cac9d07a --- a/rally-jobs/nova.yaml +++ b/rally-jobs/nova.yaml @@ -1,6 +1,7 @@ {%- set cirros_image_url = "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img" %} {% set image_name = "^(cirros.*uec|TestVM)$" %} {% set flavor_name = "m1.tiny" %} +{% set volume_type = "" %} --- Authenticate.validate_nova: - @@ -465,6 +466,7 @@ image: name: {{image_name}} volume_size: 1 + volume_type: {{volume_type}} runner: type: "constant" times: 2 @@ -485,6 +487,7 @@ image: name: {{image_name}} volume_size: 1 + volume_type: {{volume_type}} runner: type: "constant" times: 2 @@ -1107,6 +1110,7 @@ image: name: {{image_name}} volume_size: 1 + volume_type: {{volume_type}} runner: type: "constant" times: 2 diff --git a/rally/plugins/openstack/scenarios/nova/servers.py b/rally/plugins/openstack/scenarios/nova/servers.py index 805785d2..8578d0e1 100755 --- a/rally/plugins/openstack/scenarios/nova/servers.py +++ b/rally/plugins/openstack/scenarios/nova/servers.py @@ -135,6 +135,7 @@ class NovaServers(utils.NovaScenario, @scenario.configure(context={"cleanup": ["nova", "cinder"]}) def boot_server_from_volume_and_delete(self, image, flavor, volume_size, + volume_type=None, min_sleep=0, max_sleep=0, force_delete=False, **kwargs): """Boot a server from volume and then delete it. @@ -147,12 +148,15 @@ class NovaServers(utils.NovaScenario, :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param volume_size: volume size (in GB) + :param volume_type: specifies volume type when there are + multiple backends :param min_sleep: Minimum sleep time in seconds (non-negative) :param max_sleep: Maximum sleep time in seconds (non-negative) :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 = self._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, @@ -278,7 +282,8 @@ class NovaServers(utils.NovaScenario, @validation.required_openstack(users=True) @scenario.configure(context={"cleanup": ["nova", "cinder"]}) def boot_server_from_volume(self, image, flavor, volume_size, - auto_assign_nic=False, **kwargs): + volume_type=None, auto_assign_nic=False, + **kwargs): """Boot a server from volume. The scenario first creates a volume and then a server. @@ -287,10 +292,13 @@ class NovaServers(utils.NovaScenario, :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param volume_size: volume size (in GB) + :param volume_type: specifies volume type when there are + multiple backends :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 = self._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, @@ -649,6 +657,7 @@ class NovaServers(utils.NovaScenario, @scenario.configure(context={"cleanup": ["nova", "cinder"]}) def boot_server_from_volume_and_live_migrate(self, image, flavor, volume_size, + volume_type=None, block_migration=False, disk_over_commit=False, force_delete=False, @@ -668,6 +677,8 @@ class NovaServers(utils.NovaScenario, :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param volume_size: volume size (in GB) + :param volume_type: specifies volume type when there are + multiple backends :param block_migration: Specifies the migration type :param disk_over_commit: Specifies whether to allow overcommit on migrated instance or not @@ -676,7 +687,8 @@ class NovaServers(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 = self._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, @@ -889,6 +901,7 @@ class NovaServers(utils.NovaScenario, @validation.required_openstack(users=True) @scenario.configure(context={"cleanup": ["nova", "cinder"]}) def boot_server_from_volume_snapshot(self, image, flavor, volume_size, + volume_type=None, auto_assign_nic=False, **kwargs): """Boot a server from a snapshot. @@ -900,10 +913,13 @@ class NovaServers(utils.NovaScenario, :param image: image to be used to boot an instance :param flavor: flavor to be used to boot an instance :param volume_size: volume size (in GB) + :param volume_type: specifies volume type when there are + multiple backends :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 = self._create_volume(volume_size, imageRef=image, + volume_type=volume_type) snapshot = self._create_snapshot(volume.id, False) block_device_mapping = {"vda": "%s:snap::1" % snapshot.id} self._boot_server(None, flavor, auto_assign_nic=auto_assign_nic, diff --git a/samples/tasks/scenarios/nova/boot-from-volume-and-delete.json b/samples/tasks/scenarios/nova/boot-from-volume-and-delete.json old mode 100644 new mode 100755 index 014831dd..5b6c5dc9 --- a/samples/tasks/scenarios/nova/boot-from-volume-and-delete.json +++ b/samples/tasks/scenarios/nova/boot-from-volume-and-delete.json @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} { "NovaServers.boot_server_from_volume_and_delete": [ { @@ -10,6 +11,7 @@ "name": "^cirros.*uec$" }, "volume_size": 10, + "volume_type": "{{volume_type}}", "force_delete": false }, "runner": { diff --git a/samples/tasks/scenarios/nova/boot-from-volume-and-delete.yaml b/samples/tasks/scenarios/nova/boot-from-volume-and-delete.yaml old mode 100644 new mode 100755 index fb4f09d4..93a83d78 --- a/samples/tasks/scenarios/nova/boot-from-volume-and-delete.yaml +++ b/samples/tasks/scenarios/nova/boot-from-volume-and-delete.yaml @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} --- NovaServers.boot_server_from_volume_and_delete: - @@ -8,6 +9,7 @@ image: name: "^cirros.*uec$" volume_size: 10 + volume_type: "{{volume_type}}" force_delete: false runner: type: "constant" diff --git a/samples/tasks/scenarios/nova/boot-from-volume-snapshot.json b/samples/tasks/scenarios/nova/boot-from-volume-snapshot.json old mode 100644 new mode 100755 index 8d9ffde9..da72e009 --- a/samples/tasks/scenarios/nova/boot-from-volume-snapshot.json +++ b/samples/tasks/scenarios/nova/boot-from-volume-snapshot.json @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} { "NovaServers.boot_server_from_volume_snapshot": [ { @@ -9,7 +10,8 @@ "image": { "name": "^cirros.*uec$" }, - "volume_size": 10 + "volume_size": 10, + "volume_type": "{{volume_type}}" }, "runner": { "type": "constant", diff --git a/samples/tasks/scenarios/nova/boot-from-volume-snapshot.yaml b/samples/tasks/scenarios/nova/boot-from-volume-snapshot.yaml old mode 100644 new mode 100755 index 45d61210..85cd2d5a --- a/samples/tasks/scenarios/nova/boot-from-volume-snapshot.yaml +++ b/samples/tasks/scenarios/nova/boot-from-volume-snapshot.yaml @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} --- NovaServers.boot_server_from_volume_snapshot: - @@ -8,6 +9,7 @@ image: name: "^cirros.*uec$" volume_size: 10 + volume_type: "{{volume_type}}" runner: type: "constant" times: 10 diff --git a/samples/tasks/scenarios/nova/boot-from-volume.json b/samples/tasks/scenarios/nova/boot-from-volume.json old mode 100644 new mode 100755 index caa1c011..5462eba9 --- a/samples/tasks/scenarios/nova/boot-from-volume.json +++ b/samples/tasks/scenarios/nova/boot-from-volume.json @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} { "NovaServers.boot_server_from_volume": [ { @@ -9,7 +10,8 @@ "image": { "name": "^cirros.*uec$" }, - "volume_size": 10 + "volume_size": 10, + "volume_type": "{{volume_type}}" }, "runner": { "type": "constant", diff --git a/samples/tasks/scenarios/nova/boot-from-volume.yaml b/samples/tasks/scenarios/nova/boot-from-volume.yaml old mode 100644 new mode 100755 index c8c86ca4..3d2790a2 --- a/samples/tasks/scenarios/nova/boot-from-volume.yaml +++ b/samples/tasks/scenarios/nova/boot-from-volume.yaml @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} --- NovaServers.boot_server_from_volume: - @@ -8,6 +9,7 @@ image: name: "^cirros.*uec$" volume_size: 10 + volume_type: "{{volume_type}}" runner: type: "constant" times: 10 diff --git a/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.json b/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.json old mode 100644 new mode 100755 index 33ee9c7f..4cc370bf --- a/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.json +++ b/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.json @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} { "NovaServers.boot_server_from_volume_and_live_migrate": [ { @@ -11,6 +12,7 @@ }, "block_migration": false, "volume_size": 10, + "volume_type": "{{volume_type}}", "force_delete": false }, "runner": { diff --git a/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.yaml b/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.yaml old mode 100644 new mode 100755 index 70d24f12..8fde4a45 --- a/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.yaml +++ b/samples/tasks/scenarios/nova/boot-server-from-volume-and-live-migrate.yaml @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set volume_type = volume_type or "" %} --- NovaServers.boot_server_from_volume_and_live_migrate: - args: @@ -8,6 +9,7 @@ name: "^cirros.*uec$" block_migration: false volume_size: 10 + volume_type: "{{volume_type}}" force_delete: false runner: type: "constant" diff --git a/tests/unit/plugins/openstack/scenarios/nova/test_servers.py b/tests/unit/plugins/openstack/scenarios/nova/test_servers.py index 076a6c36..76237359 100755 --- a/tests/unit/plugins/openstack/scenarios/nova/test_servers.py +++ b/tests/unit/plugins/openstack/scenarios/nova/test_servers.py @@ -329,10 +329,12 @@ class NovaServersTestCase(test.ScenarioTestCase): fake_volume.id = "volume_id" scenario._create_volume = mock.MagicMock(return_value=fake_volume) - scenario.boot_server_from_volume("img", 0, 5, auto_assign_nic=False, + scenario.boot_server_from_volume("img", 0, 5, volume_type=None, + auto_assign_nic=False, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img") + scenario._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"}, @@ -349,10 +351,11 @@ class NovaServersTestCase(test.ScenarioTestCase): fake_volume.id = "volume_id" scenario._create_volume = mock.MagicMock(return_value=fake_volume) - scenario.boot_server_from_volume_and_delete("img", 0, 5, 10, 20, + scenario.boot_server_from_volume_and_delete("img", 0, 5, None, 10, 20, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img") + scenario._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"}, @@ -584,11 +587,13 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._create_volume = mock.MagicMock(return_value=fake_volume) scenario.boot_server_from_volume_and_live_migrate("img", 0, 5, + volume_type=None, min_sleep=10, max_sleep=20, fakearg="f") - scenario._create_volume.assert_called_once_with(5, imageRef="img") + scenario._create_volume.assert_called_once_with(5, imageRef="img", + volume_type=None) scenario._boot_server.assert_called_once_with( None, 0, @@ -780,10 +785,12 @@ class NovaServersTestCase(test.ScenarioTestCase): scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot) scenario.boot_server_from_volume_snapshot("img", "flavor", 1, + volume_type=None, auto_assign_nic=False, fakearg="f") - scenario._create_volume.assert_called_once_with(1, imageRef="img") + scenario._create_volume.assert_called_once_with(1, imageRef="img", + volume_type=None) scenario._create_snapshot.assert_called_once_with("volume_id", False) scenario._boot_server.assert_called_once_with( None, "flavor", auto_assign_nic=False,