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 from yardstick.benchmark.scenarios.lib import 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'
35 self.scenario = create_volume.CreateVolume(
36 scenario_cfg=self.scenario_cfg,
40 self._mock_cinder_client.stop()
41 self._mock_glance_client.stop()
44 self.mock_cinder_client.return_value = "All volumes are equal"
45 self.mock_glance_client.return_value = "Images are more equal"
47 expected_vol_name = self.scenario_cfg["options"]["volume_name"]
48 expected_vol_size = self.scenario_cfg["options"]["size"]
49 expected_im_name = self.scenario_cfg["options"]["image"]
52 scenario = create_volume.CreateVolume(
53 scenario_cfg=self.scenario_cfg,
56 self.assertEqual(expected_vol_name, scenario.volume_name)
57 self.assertEqual(expected_vol_size, scenario.volume_size)
58 self.assertEqual(expected_im_name, scenario.image_name)
59 self.assertEqual(expected_im_id, scenario.image_id)
60 self.assertEqual("All volumes are equal", scenario.cinder_client)
61 self.assertEqual("Images are more equal", scenario.glance_client)
64 self.assertFalse(self.scenario.setup_done)
66 self.assertTrue(self.scenario.setup_done)
68 @mock.patch('yardstick.common.openstack_utils.create_volume')
69 @mock.patch('yardstick.common.openstack_utils.get_image_id')
70 def test_run(self, mock_image_id, mock_create_volume):
73 mock_image_id.assert_called_once()
74 mock_create_volume.assert_called_once()
76 @mock.patch.object(create_volume.CreateVolume, 'setup')
77 def test_run_no_setup(self, scenario_setup):
78 self.scenario.setup_done = False
80 scenario_setup.assert_called_once()
82 @mock.patch('yardstick.common.openstack_utils.create_volume')
83 @mock.patch('yardstick.common.openstack_utils.get_image_id')
84 @mock.patch('yardstick.common.openstack_utils.get_cinder_client')
85 @mock.patch('yardstick.common.openstack_utils.get_glance_client')
86 def test_create_volume(self, mock_get_glance_client,
87 mock_get_cinder_client, mock_image_id,
90 'volume_name': 'yardstick_test_volume_01',
92 'image': 'cirros-0.3.5'
94 args = {"options": options}
95 scenario = create_volume.CreateVolume(args, {})
97 mock_create_volume.assert_called_once()
98 mock_image_id.assert_called_once()
99 mock_get_glance_client.assert_called_once()
100 mock_get_cinder_client.assert_called_once()