aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py')
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py120
1 files changed, 39 insertions, 81 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
index 30333dda8..f91d2c3f4 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
@@ -6,95 +6,53 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import mock
+from oslo_utils import uuidutils
import unittest
+import mock
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
from yardstick.benchmark.scenarios.lib import create_volume
class CreateVolumeTestCase(unittest.TestCase):
def setUp(self):
- self._mock_cinder_client = mock.patch(
- 'yardstick.common.openstack_utils.get_cinder_client')
- self.mock_cinder_client = self._mock_cinder_client.start()
- self._mock_glance_client = mock.patch(
- 'yardstick.common.openstack_utils.get_glance_client')
- self.mock_glance_client = self._mock_glance_client.start()
- self.addCleanup(self._stop_mock)
-
- self.scenario_cfg = {
- "options" :
- {
- 'volume_name': 'yardstick_test_volume_01',
- 'size': '256',
- 'image': 'cirros-0.3.5'
- }
- }
- self.scenario = create_volume.CreateVolume(
- scenario_cfg=self.scenario_cfg,
- context_cfg={})
+ self._mock_create_volume = mock.patch.object(
+ openstack_utils, 'create_volume')
+ self.mock_create_volume = (
+ self._mock_create_volume.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_volume, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'size_gb': 1}}
+ self.result = {}
+
+ self.cvolume_obj = create_volume.CreateVolume(self.args, mock.ANY)
+ self.addCleanup(self._stop_mock)
def _stop_mock(self):
- self._mock_cinder_client.stop()
- self._mock_glance_client.stop()
-
- def test_init(self):
- self.mock_cinder_client.return_value = "All volumes are equal"
- self.mock_glance_client.return_value = "Images are more equal"
-
- expected_vol_name = self.scenario_cfg["options"]["volume_name"]
- expected_vol_size = self.scenario_cfg["options"]["size"]
- expected_im_name = self.scenario_cfg["options"]["image"]
- expected_im_id = None
-
- scenario = create_volume.CreateVolume(
- scenario_cfg=self.scenario_cfg,
- context_cfg={})
-
- self.assertEqual(expected_vol_name, scenario.volume_name)
- self.assertEqual(expected_vol_size, scenario.volume_size)
- self.assertEqual(expected_im_name, scenario.image_name)
- self.assertEqual(expected_im_id, scenario.image_id)
- self.assertEqual("All volumes are equal", scenario.cinder_client)
- self.assertEqual("Images are more equal", scenario.glance_client)
-
- def test_setup(self):
- self.assertFalse(self.scenario.setup_done)
- self.scenario.setup()
- self.assertTrue(self.scenario.setup_done)
-
- @mock.patch('yardstick.common.openstack_utils.create_volume')
- @mock.patch('yardstick.common.openstack_utils.get_image_id')
- def test_run(self, mock_image_id, mock_create_volume):
- self.scenario.run()
-
- mock_image_id.assert_called_once()
- mock_create_volume.assert_called_once()
-
- @mock.patch.object(create_volume.CreateVolume, 'setup')
- def test_run_no_setup(self, scenario_setup):
- self.scenario.setup_done = False
- self.scenario.run()
- scenario_setup.assert_called_once()
-
- @mock.patch('yardstick.common.openstack_utils.create_volume')
- @mock.patch('yardstick.common.openstack_utils.get_image_id')
- @mock.patch('yardstick.common.openstack_utils.get_cinder_client')
- @mock.patch('yardstick.common.openstack_utils.get_glance_client')
- def test_create_volume(self, mock_get_glance_client,
- mock_get_cinder_client, mock_image_id,
- mock_create_volume):
- options = {
- 'volume_name': 'yardstick_test_volume_01',
- 'size': '256',
- 'image': 'cirros-0.3.5'
- }
- args = {"options": options}
- scenario = create_volume.CreateVolume(args, {})
- scenario.run()
- mock_create_volume.assert_called_once()
- mock_image_id.assert_called_once()
- mock_get_glance_client.assert_called_once()
- mock_get_cinder_client.assert_called_once()
+ self._mock_create_volume.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ _uuid = uuidutils.generate_uuid()
+ self.cvolume_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_volume.return_value = {'name': 'yardstick_volume',
+ 'id': _uuid,
+ 'status': 'available'}
+ output = self.cvolume_obj.run(self.result)
+ self.assertDictEqual({'volume_create': 1}, self.result)
+ self.assertDictEqual({'id': _uuid}, output)
+ self.mock_log.info.asset_called_once_with('Create volume successful!')
+
+ def test_run_fail(self):
+ self.mock_create_volume.return_value = None
+ with self.assertRaises(exceptions.ScenarioCreateVolumeError):
+ self.cvolume_obj.run(self.result)
+ self.assertDictEqual({'volume_create': 0}, self.result)
+ self.mock_log.error.assert_called_once_with('Create volume failed!')