1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from oslo_utils import uuidutils
13 from yardstick.common import openstack_utils
14 from yardstick.common import exceptions
15 from yardstick.benchmark.scenarios.lib import create_volume
18 class CreateVolumeTestCase(unittest.TestCase):
22 self._mock_create_volume = mock.patch.object(
23 openstack_utils, 'create_volume')
24 self.mock_create_volume = (
25 self._mock_create_volume.start())
26 self._mock_get_shade_client = mock.patch.object(
27 openstack_utils, 'get_shade_client')
28 self.mock_get_shade_client = self._mock_get_shade_client.start()
29 self._mock_log = mock.patch.object(create_volume, 'LOG')
30 self.mock_log = self._mock_log.start()
31 self.args = {'options': {'size_gb': 1}}
34 self.cvolume_obj = create_volume.CreateVolume(self.args, mock.ANY)
35 self.addCleanup(self._stop_mock)
38 self._mock_create_volume.stop()
39 self._mock_get_shade_client.stop()
43 _uuid = uuidutils.generate_uuid()
44 self.cvolume_obj.scenario_cfg = {'output': 'id'}
45 self.mock_create_volume.return_value = {'name': 'yardstick_volume',
47 'status': 'available'}
48 output = self.cvolume_obj.run(self.result)
49 self.assertDictEqual({'volume_create': 1}, self.result)
50 self.assertDictEqual({'id': _uuid}, output)
51 self.mock_log.info.asset_called_once_with('Create volume successful!')
53 def test_run_fail(self):
54 self.mock_create_volume.return_value = None
55 with self.assertRaises(exceptions.ScenarioCreateVolumeError):
56 self.cvolume_obj.run(self.result)
57 self.assertDictEqual({'volume_create': 0}, self.result)
58 self.mock_log.error.assert_called_once_with('Create volume failed!')