aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/common/test_openstack_utils.py
diff options
context:
space:
mode:
authorShobhi Jain <shobhi.jain@intel.com>2018-04-06 14:44:33 +0100
committerShobhi Jain <shobhi.jain@intel.com>2018-05-08 08:21:16 +0000
commit2d33d0f289f3dd3864fe57289e953b876f362c06 (patch)
treedb91b3ec639b8bee32f7f70a587446b58e470319 /yardstick/tests/unit/common/test_openstack_utils.py
parentbe197a6197e803b6334f2ccf72f561245ef7aac7 (diff)
Replace cinder create volume with shade client.
Adds get_volume function. Function create volume now uses shade client. JIRA: YARDSTICK-891 Change-Id: I0b2fae5f2cf52eaf2e4a0062c858d49bc4ce9ccd Signed-off-by: Shobhi Jain <shobhi.jain@intel.com>
Diffstat (limited to 'yardstick/tests/unit/common/test_openstack_utils.py')
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index cc19d98b4..bc3c995b7 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -558,3 +558,47 @@ class GetVolumeIDTestCase(unittest.TestCase):
output = openstack_utils.get_volume_id(self.mock_shade_client,
'volume_name')
self.assertIsNone(output)
+
+
+class GetVolumeTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.mock_shade_client.get_volume = mock.Mock()
+
+ def test_get_volume(self):
+ self.mock_shade_client.get_volume.return_value = {'volume'}
+ output = openstack_utils.get_volume(self.mock_shade_client,
+ 'volume_name_or_id')
+ self.assertEqual({'volume'}, output)
+
+ def test_get_volume_None(self):
+ self.mock_shade_client.get_volume.return_value = None
+ output = openstack_utils.get_volume(self.mock_shade_client,
+ 'volume_name_or_id')
+ self.assertIsNone(output)
+
+
+class CreateVolumeTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.size = 1
+
+ def test_create_volume(self):
+ self.mock_shade_client.create_volume.return_value = (
+ {'name': 'volume-name', 'size': self.size})
+ output = openstack_utils.create_volume(
+ self.mock_shade_client, self.size)
+ self.assertEqual(
+ {'name': 'volume-name', 'size': self.size},
+ output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_volume_fail(self, mock_logger):
+ self.mock_shade_client.create_volume.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.create_volume(self.mock_shade_client,
+ self.size)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)