summaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/common/test_openstack_utils.py
diff options
context:
space:
mode:
authorShobhi Jain <shobhi.jain@intel.com>2018-04-11 09:34:22 +0100
committerEmma Foley <emma.l.foley@intel.com>2018-06-27 17:27:36 +0100
commit3976fdc1cdfb6e0e749a6886a732040cb7dc6ece (patch)
treea647d75f21233eb810edef56f0ee9174897e18d8 /yardstick/tests/unit/common/test_openstack_utils.py
parent9d3a72f7dd9b2dbb0e4aeafc43adee419aabd242 (diff)
Replace glance create image with shade client.
Function create_image now uses shade client. JIRA: YARDSTICK-892 Change-Id: Ia41d9ce702a1f24031080f8a365c1b2bd9ac9faa Signed-off-by: Shobhi Jain <shobhi.jain@intel.com> (cherry picked from commit c31edc5ab9013d93ffd32ed72adb14740e43b24a)
Diffstat (limited to 'yardstick/tests/unit/common/test_openstack_utils.py')
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index d1d91e2d5..9b23c65b8 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -631,3 +631,39 @@ class DetachVolumeTestCase(unittest.TestCase):
'volume_name_or_id')
mock_logger.error.assert_called_once()
self.assertFalse(output)
+
+
+# *********************************************
+# GLANCE
+# *********************************************
+
+class CreateImageTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self._uuid = uuidutils.generate_uuid()
+ self.name = 'image_name'
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_image_already_exit(self, mock_logger):
+ self.mock_shade_client.get_image_id.return_value = self._uuid
+ output = openstack_utils.create_image(self.mock_shade_client, self.name)
+ mock_logger.info.assert_called_once()
+ self.assertEqual(self._uuid, output)
+
+ def test_create_image(self):
+ self.mock_shade_client.get_image_id.return_value = None
+ self.mock_shade_client.create_image.return_value = {'id': self._uuid}
+ output = openstack_utils.create_image(self.mock_shade_client, self.name)
+ self.assertEqual(self._uuid, output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_image_exception(self, mock_logger):
+ self.mock_shade_client.get_image_id.return_value = None
+ self.mock_shade_client.create_image.side_effect = (
+ exc.OpenStackCloudException('error message'))
+
+ output = openstack_utils.create_image(self.mock_shade_client,
+ self.name)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)