aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark/scenarios/lib
diff options
context:
space:
mode:
authorShobhi Jain <shobhi.jain@intel.com>2018-04-11 09:34:22 +0100
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-05-29 11:19:38 +0000
commitc31edc5ab9013d93ffd32ed72adb14740e43b24a (patch)
treec27bc95a259be9e7580cc37804d95ac15689d2d1 /yardstick/tests/unit/benchmark/scenarios/lib
parent180b0b4c7b7288bc2fd8e2905858d17d0fefc93a (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>
Diffstat (limited to 'yardstick/tests/unit/benchmark/scenarios/lib')
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py62
1 files changed, 41 insertions, 21 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
index 639cf2906..aebd1dfe8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
@@ -6,30 +6,50 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import unittest
+
import mock
+from oslo_utils import uuidutils
+import unittest
-from yardstick.benchmark.scenarios.lib import create_image
from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import create_image
+
-# NOTE(elfoley): There should be more tests here.
class CreateImageTestCase(unittest.TestCase):
- @mock.patch.object(openstack_utils, 'create_image')
- @mock.patch.object(openstack_utils, 'get_glance_client')
- def test_create_image(self, mock_get_glance_client, mock_create_image):
- options = {
- 'image_name': 'yardstick_test_image_01',
- 'disk_format': 'qcow2',
- 'container_format': 'bare',
- 'min_disk': '1',
- 'min_ram': '512',
- 'protected': 'False',
- 'tags': '["yardstick automatic test image"]',
- 'file_path': '/home/opnfv/images/cirros-0.3.5-x86_64-disk.img'
- }
- args = {"options": options}
- obj = create_image.CreateImage(args, {})
- obj.run({})
- mock_create_image.assert_called_once()
- mock_get_glance_client.assert_called_once()
+ def setUp(self):
+ self._mock_create_image = mock.patch.object(
+ openstack_utils, 'create_image')
+ self.mock_create_image = (
+ self._mock_create_image.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(create_image, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'image_name': 'yardstick_image'}}
+ self.result = {}
+ self.cimage_obj = create_image.CreateImage(self.args, mock.ANY)
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_create_image.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ _uuid = uuidutils.generate_uuid()
+ self.cimage_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_image.return_value = _uuid
+ output = self.cimage_obj.run(self.result)
+ self.assertEqual({'image_create': 1}, self.result)
+ self.assertEqual({'id': _uuid}, output)
+ self.mock_log.info.asset_called_once_with('Create image successful!')
+
+ def test_run_fail(self):
+ self.mock_create_image.return_value = None
+ with self.assertRaises(exceptions.ScenarioCreateImageError):
+ self.cimage_obj.run(self.result)
+ self.assertEqual({'image_create': 0}, self.result)
+ self.mock_log.error.assert_called_once_with('Create image failed!')