Replace cinder get_volume_id with shade client. 35/59135/1
authorShobhi Jain <shobhi.jain@intel.com>
Fri, 6 Apr 2018 10:41:54 +0000 (11:41 +0100)
committerEmma Foley <emma.l.foley@intel.com>
Wed, 27 Jun 2018 16:17:51 +0000 (17:17 +0100)
Function get_volume_id now uses shade client.

JIRA: YARDSTICK-891

Change-Id: I45ae40982a64f677dbbdeb6c9510a0ec9ac973f1
Signed-off-by: Shobhi Jain <shobhi.jain@intel.com>
(cherry picked from commit be197a6197e803b6334f2ccf72f561245ef7aac7)

yardstick/common/openstack_utils.py
yardstick/tests/unit/common/test_openstack_utils.py

index 68cf0a5..14c34e2 100644 (file)
@@ -769,9 +769,8 @@ def list_images(shade_client=None):
 # *********************************************
 #   CINDER
 # *********************************************
-def get_volume_id(volume_name):    # pragma: no cover
-    volumes = get_cinder_client().volumes.list()
-    return next((v.id for v in volumes if v.name == volume_name), None)
+def get_volume_id(shade_client, volume_name):
+    return shade_client.get_volume_id(volume_name)
 
 
 def create_volume(cinder_client, volume_name, volume_size,
index 81bcd8c..bfd73de 100644 (file)
@@ -511,3 +511,25 @@ class GetFlavorTestCase(unittest.TestCase):
                                             'flavor_name_or_id')
         mock_logger.error.assert_called_once()
         self.assertIsNone(output)
+
+# *********************************************
+#   CINDER
+# *********************************************
+
+
+class GetVolumeIDTestCase(unittest.TestCase):
+
+    def test_get_volume_id(self):
+        self.mock_shade_client = mock.Mock()
+        _uuid = uuidutils.generate_uuid()
+        self.mock_shade_client.get_volume_id.return_value = _uuid
+        output = openstack_utils.get_volume_id(self.mock_shade_client,
+                                               'volume_name')
+        self.assertEqual(_uuid, output)
+
+    def test_get_volume_id_None(self):
+        self.mock_shade_client = mock.Mock()
+        self.mock_shade_client.get_volume_id.return_value = None
+        output = openstack_utils.get_volume_id(self.mock_shade_client,
+                                               'volume_name')
+        self.assertIsNone(output)