Add "capabilities:" to multiple_backends extra-spec key

cinder-scheduler uses all the "capabilities:" to scope the
cinder-volume. With no "capabilities:" prefix set in extra_spec,
it will be no effect from cinder-scheduler to schedule the
cinder-volume, which is not the purpose of the testcase.
To address the review comment, This change will not remove but
adds 2 cases for the "capabilities:" prefix to volume type key:
extra-spec "capabilities:volume_backend_name".

Change-Id: Ie870091f2a5657b3ab6a0171de2cffe6945a0f7c
Closes-Bug: #1295050
diff --git a/tempest/api/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py
index e79d23c..d451517 100644
--- a/tempest/api/volume/admin/test_multi_backend.py
+++ b/tempest/api/volume/admin/test_multi_backend.py
@@ -36,42 +36,55 @@
 
         cls.volume_client = cls.os_adm.volumes_client
         cls.volume_type_id_list = []
-        cls.volume_id_list = []
+        cls.volume_id_list_with_prefix = []
+        cls.volume_id_list_without_prefix = []
 
-        # Volume/Type creation (uses backend1_name)
-        type1_name = data_utils.rand_name('Type-')
-        vol1_name = data_utils.rand_name('Volume-')
-        extra_specs1 = {"volume_backend_name": cls.backend1_name}
-        resp, cls.type1 = cls.client.create_volume_type(
-            type1_name, extra_specs=extra_specs1)
-        cls.volume_type_id_list.append(cls.type1['id'])
-
-        resp, cls.volume1 = cls.volume_client.create_volume(
-            size=1, display_name=vol1_name, volume_type=type1_name)
-        cls.volume_id_list.append(cls.volume1['id'])
-        cls.volume_client.wait_for_volume_status(cls.volume1['id'],
-                                                 'available')
+        # Volume/Type creation (uses volume_backend_name)
+        cls._create_type_and_volume(cls.backend1_name, False)
+        # Volume/Type creation (uses capabilities:volume_backend_name)
+        cls._create_type_and_volume(cls.backend1_name, True)
 
         if cls.backend1_name != cls.backend2_name:
             # Volume/Type creation (uses backend2_name)
-            type2_name = data_utils.rand_name('Type-')
-            vol2_name = data_utils.rand_name('Volume-')
-            extra_specs2 = {"volume_backend_name": cls.backend2_name}
-            resp, cls.type2 = cls.client.create_volume_type(
-                type2_name, extra_specs=extra_specs2)
-            cls.volume_type_id_list.append(cls.type2['id'])
+            cls._create_type_and_volume(cls.backend2_name, False)
+            # Volume/Type creation (uses capabilities:volume_backend_name)
+            cls._create_type_and_volume(cls.backend2_name, True)
 
-            resp, cls.volume2 = cls.volume_client.create_volume(
-                size=1, display_name=vol2_name, volume_type=type2_name)
-            cls.volume_id_list.append(cls.volume2['id'])
-            cls.volume_client.wait_for_volume_status(cls.volume2['id'],
-                                                     'available')
+    @classmethod
+    def _create_type_and_volume(self, backend_name_key, with_prefix):
+        # Volume/Type creation
+        type_name = data_utils.rand_name('Type')
+        vol_name = data_utils.rand_name('Volume')
+        spec_key_with_prefix = "capabilities:volume_backend_name"
+        spec_key_without_prefix = "volume_backend_name"
+        if with_prefix:
+            extra_specs = {spec_key_with_prefix: backend_name_key}
+        else:
+            extra_specs = {spec_key_without_prefix: backend_name_key}
+        resp, self.type = self.client.create_volume_type(
+            type_name, extra_specs=extra_specs)
+        self.volume_type_id_list.append(self.type['id'])
+
+        resp, self.volume = self.volume_client.create_volume(
+            size=1, display_name=vol_name, volume_type=type_name)
+        self.volume_client.wait_for_volume_status(
+            self.volume['id'], 'available')
+        if with_prefix:
+            self.volume_id_list_with_prefix.append(self.volume['id'])
+        else:
+            self.volume_id_list_without_prefix.append(
+                self.volume['id'])
 
     @classmethod
     def tearDownClass(cls):
         # volumes deletion
-        volume_id_list = getattr(cls, 'volume_id_list', [])
-        for volume_id in volume_id_list:
+        vid_prefix = getattr(cls, 'volume_id_list_with_prefix', [])
+        for volume_id in vid_prefix:
+            cls.volume_client.delete_volume(volume_id)
+            cls.volume_client.wait_for_resource_deletion(volume_id)
+
+        vid_no_pre = getattr(cls, 'volume_id_list_without_prefix', [])
+        for volume_id in vid_no_pre:
             cls.volume_client.delete_volume(volume_id)
             cls.volume_client.wait_for_resource_deletion(volume_id)
 
@@ -84,32 +97,57 @@
 
     @test.attr(type='smoke')
     def test_backend_name_reporting(self):
+        # get volume id which created by type without prefix
+        volume_id = self.volume_id_list_without_prefix[0]
+        self._test_backend_name_reporting_by_volume_id(volume_id)
+
+    @test.attr(type='smoke')
+    def test_backend_name_reporting_with_prefix(self):
+        # get volume id which created by type with prefix
+        volume_id = self.volume_id_list_with_prefix[0]
+        self._test_backend_name_reporting_by_volume_id(volume_id)
+
+    @test.attr(type='gate')
+    def test_backend_name_distinction(self):
+        if self.backend1_name == self.backend2_name:
+            raise self.skipException("backends configured with same name")
+        # get volume id which created by type without prefix
+        volume1_id = self.volume_id_list_without_prefix[0]
+        volume2_id = self.volume_id_list_without_prefix[1]
+        self._test_backend_name_distinction(volume1_id, volume2_id)
+
+    @test.attr(type='gate')
+    def test_backend_name_distinction_with_prefix(self):
+        if self.backend1_name == self.backend2_name:
+            raise self.skipException("backends configured with same name")
+        # get volume id which created by type without prefix
+        volume1_id = self.volume_id_list_with_prefix[0]
+        volume2_id = self.volume_id_list_with_prefix[1]
+        self._test_backend_name_distinction(volume1_id, volume2_id)
+
+    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
-        resp, volume = self.volume_client.get_volume(self.volume1['id'])
+        resp, volume = self.volume_client.get_volume(volume_id)
         self.assertEqual(200, resp.status)
 
         volume1_host = volume['os-vol-host-attr:host']
         msg = ("multi-backend reporting incorrect values for volume %s" %
-               self.volume1['id'])
+               volume_id)
         self.assertTrue(len(volume1_host.split("@")) > 1, msg)
 
-    @test.attr(type='gate')
-    def test_backend_name_distinction(self):
+    def _test_backend_name_distinction(self, volume1_id, volume2_id):
         # this test checks that the two volumes created at setUp don't
         # belong to the same backend (if they are, than the
         # volume backend distinction is not working properly)
-        if self.backend1_name == self.backend2_name:
-            raise self.skipException("backends configured with same name")
-
-        resp, volume = self.volume_client.get_volume(self.volume1['id'])
+        resp, volume = self.volume_client.get_volume(volume1_id)
         volume1_host = volume['os-vol-host-attr:host']
 
-        resp, volume = self.volume_client.get_volume(self.volume2['id'])
+        resp, volume = self.volume_client.get_volume(volume2_id)
         volume2_host = volume['os-vol-host-attr:host']
 
         msg = ("volumes %s and %s were created in the same backend" %
-               (self.volume1['id'], self.volume2['id']))
+               (volume1_id, volume2_id))
         self.assertNotEqual(volume1_host, volume2_host, msg)