diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-05-09 07:43:37 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-05-09 07:43:37 +0000 |
commit | a2fffa7d4b021cdb690345689a4131300650c952 (patch) | |
tree | 49db8bfb3e19efffcef60e62fdff42aa1071b95d | |
parent | fe8aac36f1f66c29bd68c4bc0e22c9de077a1fad (diff) | |
parent | be197a6197e803b6334f2ccf72f561245ef7aac7 (diff) |
Merge "Replace cinder get_volume_id with shade client."
-rw-r--r-- | yardstick/common/openstack_utils.py | 5 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_openstack_utils.py | 22 |
2 files changed, 24 insertions, 3 deletions
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 53f0ccc34..5a83ddb24 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -784,9 +784,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, diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index 67ca826a5..cc19d98b4 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -536,3 +536,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) |