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 ##############################################################################
12 import yardstick.benchmark.scenarios.lib.create_volume
15 class CreateVolumeTestCase(unittest.TestCase):
18 self._mock_cinder_client = mock.patch(
19 'yardstick.common.openstack_utils.get_cinder_client')
20 self.mock_cinder_client = self._mock_cinder_client.start()
21 self._mock_glance_client = mock.patch(
22 'yardstick.common.openstack_utils.get_glance_client')
23 self.mock_glance_client = self._mock_glance_client.start()
24 self.addCleanup(self._stop_mock)
29 'volume_name': 'yardstick_test_volume_01',
31 'image': 'cirros-0.3.5'
36 yardstick.benchmark.scenarios.lib.create_volume.CreateVolume(
37 scenario_cfg=self.scenario_cfg,
41 self._mock_cinder_client.stop()
42 self._mock_glance_client.stop()
45 self.mock_cinder_client.return_value = "All volumes are equal"
46 self.mock_glance_client.return_value = "Images are more equal"
48 expected_vol_name = self.scenario_cfg["options"]["volume_name"]
49 expected_vol_size = self.scenario_cfg["options"]["size"]
50 expected_im_name = self.scenario_cfg["options"]["image"]
54 yardstick.benchmark.scenarios.lib.create_volume.CreateVolume(
55 scenario_cfg=self.scenario_cfg,
58 self.assertEqual(expected_vol_name, scenario.volume_name)
59 self.assertEqual(expected_vol_size, scenario.volume_size)
60 self.assertEqual(expected_im_name, scenario.image_name)
61 self.assertEqual(expected_im_id, scenario.image_id)
62 self.assertEqual("All volumes are equal", scenario.cinder_client)
63 self.assertEqual("Images are more equal", scenario.glance_client)
66 self.assertFalse(self.scenario.setup_done)
68 self.assertTrue(self.scenario.setup_done)
70 @mock.patch('yardstick.common.openstack_utils.create_volume')
71 @mock.patch('yardstick.common.openstack_utils.get_image_id')
72 def test_run(self, mock_image_id, mock_create_volume):
75 mock_image_id.assert_called_once()
76 mock_create_volume.assert_called_once()
79 yardstick.benchmark.scenarios.lib.create_volume.CreateVolume, 'setup')
80 def test_run_no_setup(self, scenario_setup):
81 self.scenario.setup_done = False
83 scenario_setup.assert_called_once()
90 if __name__ == '__main__':