Modify SetupClass to pick up AZ of the created volume type
Pick up AZ from volume type and use it upon volume creation
Related-prod: PRODX-39384
Change-Id: I5869d8168106e49b3e9cb86722531f5da86d2f83
(cherry picked from commit 4b21b1e679e2ae260fec14aeb619219982147fc5)
diff --git a/tempest/api/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py
index 028bf1a..b45824e 100644
--- a/tempest/api/volume/admin/test_multi_backend.py
+++ b/tempest/api/volume/admin/test_multi_backend.py
@@ -30,8 +30,9 @@
raise cls.skipException("Cinder multi-backend feature disabled")
if len(set(CONF.volume.backend_names)) < 2:
- raise cls.skipException("Requires at least two different "
- "backend names")
+ raise cls.skipException(
+ "Requires at least two different "
+ "backend names")
@classmethod
def resource_setup(cls):
@@ -66,21 +67,34 @@
extra_specs = {spec_key_with_prefix: backend_name_key}
else:
extra_specs = {spec_key_without_prefix: backend_name_key}
- cls.create_volume_type(name=type_name,
- extra_specs=extra_specs)
+ cls.create_volume_type(
+ name=type_name, extra_specs=extra_specs)
+ # Pick up AZ from volume_type
+ services = cls.admin_volume_services_client.list_services()
+ vol_svrs = [
+ srv
+ for srv in services.get("services")
+ if srv["binary"] == "cinder-volume" and backend_name_key
+ in srv["host"]
+ ]
+ vol_type_zone = vol_svrs[0]["zone"]
- params = {'name': vol_name, 'volume_type': type_name,
- 'size': CONF.volume.volume_size}
+ params = {
+ "name": vol_name,
+ "volume_type": type_name,
+ "size": CONF.volume.volume_size,
+ "availability_zone": vol_type_zone,
+ }
cls.volume = cls.create_volume(**params)
if with_prefix:
- cls.volume_id_list_with_prefix.append(cls.volume['id'])
+ cls.volume_id_list_with_prefix.append(cls.volume["id"])
else:
- cls.volume_id_list_without_prefix.append(
- cls.volume['id'])
- waiters.wait_for_volume_resource_status(cls.admin_volume_client,
- cls.volume['id'], 'available')
+ cls.volume_id_list_without_prefix.append(cls.volume["id"])
+ waiters.wait_for_volume_resource_status(
+ cls.admin_volume_client, cls.volume["id"], "available"
+ )
- @decorators.idempotent_id('c1a41f3f-9dad-493e-9f09-3ff197d477cc')
+ @decorators.idempotent_id("c1a41f3f-9dad-493e-9f09-3ff197d477cc")
def test_backend_name_reporting(self):
"""Test backend name reporting for volume when type is without prefix
@@ -92,7 +106,7 @@
for volume_id in self.volume_id_list_without_prefix:
self._test_backend_name_reporting_by_volume_id(volume_id)
- @decorators.idempotent_id('f38e647f-ab42-4a31-a2e7-ca86a6485215')
+ @decorators.idempotent_id("f38e647f-ab42-4a31-a2e7-ca86a6485215")
def test_backend_name_reporting_with_prefix(self):
"""Test backend name reporting for volume when type is with prefix
@@ -105,7 +119,7 @@
for volume_id in self.volume_id_list_with_prefix:
self._test_backend_name_reporting_by_volume_id(volume_id)
- @decorators.idempotent_id('46435ab1-a0af-4401-8373-f14e66b0dd58')
+ @decorators.idempotent_id("46435ab1-a0af-4401-8373-f14e66b0dd58")
def test_backend_name_distinction(self):
"""Test volume backend distinction when type is without prefix
@@ -116,7 +130,7 @@
"""
self._test_backend_name_distinction(self.volume_id_list_without_prefix)
- @decorators.idempotent_id('4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed')
+ @decorators.idempotent_id("4236305b-b65a-4bfc-a9d2-69cb5b2bf2ed")
def test_backend_name_distinction_with_prefix(self):
"""Test volume backend distinction when type is with prefix
@@ -128,28 +142,29 @@
self._test_backend_name_distinction(self.volume_id_list_with_prefix)
def _get_volume_host(self, volume_id):
- return self.admin_volume_client.show_volume(
- volume_id)['volume']['os-vol-host-attr:host']
+ return self.admin_volume_client.show_volume(volume_id)["volume"][
+ "os-vol-host-attr:host"
+ ]
def _test_backend_name_reporting_by_volume_id(self, volume_id):
# this test checks if os-vol-attr:host is populated correctly after
# the multi backend feature has been enabled
# if multi-backend is enabled: os-vol-attr:host should be like:
# host@backend_name
- volume = self.admin_volume_client.show_volume(volume_id)['volume']
+ volume = self.admin_volume_client.show_volume(volume_id)["volume"]
- volume1_host = volume['os-vol-host-attr:host']
- msg = ("multi-backend reporting incorrect values for volume %s" %
- volume_id)
+ volume1_host = volume["os-vol-host-attr:host"]
+ msg = ("multi-backend reporting incorrect values for volume %s"
+ % volume_id)
self.assertGreater(len(volume1_host.split("@")), 1, msg)
def _test_backend_name_distinction(self, volume_id_list):
# this test checks that the volumes created at setUp don't
# belong to the same backend (if they are, than the
# volume backend distinction is not working properly)
- volume_hosts = [self._get_volume_host(volume) for volume in
- volume_id_list]
+ volume_hosts = [self._get_volume_host(volume)
+ for volume in volume_id_list]
# assert that volumes are each created on separate hosts:
- msg = ("volumes %s were created in the same backend" % ", "
- .join(volume_hosts))
+ msg = "volumes %s were created in the same backend" % ", ".join(
+ volume_hosts)
self.assertCountEqual(volume_hosts, set(volume_hosts), msg)