diff options
Diffstat (limited to 'yardstick/tests/unit/common/test_openstack_utils.py')
-rw-r--r-- | yardstick/tests/unit/common/test_openstack_utils.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index a1a4af2e9..9361a97f2 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -656,3 +656,66 @@ 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) + + +class DeleteImageTestCase(unittest.TestCase): + + def test_delete_image(self): + self.mock_shade_client = mock.Mock() + self.mock_shade_client.delete_image.return_value = True + output = openstack_utils.delete_image(self.mock_shade_client, + 'image_name_or_id') + self.assertTrue(output) + + def test_delete_image_fail(self): + self.mock_shade_client = mock.Mock() + self.mock_shade_client.delete_image.return_value = False + output = openstack_utils.delete_image(self.mock_shade_client, + 'image_name_or_id') + self.assertFalse(output) + + @mock.patch.object(openstack_utils, 'log') + def test_delete_image_exception(self, mock_logger): + self.mock_shade_client = mock.Mock() + self.mock_shade_client.delete_image.side_effect = ( + exc.OpenStackCloudException('error message')) + output = openstack_utils.delete_image(self.mock_shade_client, + 'image_name_or_id') + mock_logger.error.assert_called_once() + self.assertFalse(output) |