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 get_flavor
18 class GetFlavorTestCase(unittest.TestCase):
22 self._mock_get_flavor = mock.patch.object(
23 openstack_utils, 'get_flavor')
24 self.mock_get_flavor = self._mock_get_flavor.start()
25 self._mock_get_shade_client = mock.patch.object(
26 openstack_utils, 'get_shade_client')
27 self.mock_get_shade_client = self._mock_get_shade_client.start()
28 self._mock_log = mock.patch.object(get_flavor, 'LOG')
29 self.mock_log = self._mock_log.start()
30 self.args = {'options': {'name_or_id': 'yardstick_flavor'}}
33 self.getflavor_obj = get_flavor.GetFlavor(self.args, mock.ANY)
34 self.addCleanup(self._stop_mock)
37 self._mock_get_flavor.stop()
38 self._mock_get_shade_client.stop()
42 _uuid = uuidutils.generate_uuid()
43 self.getflavor_obj.scenario_cfg = {'output': 'flavor'}
44 self.mock_get_flavor.return_value = (
45 {'name': 'flavor-name', 'id': _uuid})
46 output = self.getflavor_obj.run(self.result)
47 self.assertDictEqual({'get_flavor': 1}, self.result)
48 self.assertDictEqual({'flavor': {'name': 'flavor-name', 'id': _uuid}},
50 self.mock_log.info.asset_called_once_with('Get flavor successful!')
52 def test_run_fail(self):
53 self.mock_get_flavor.return_value = None
54 with self.assertRaises(exceptions.ScenarioGetFlavorError):
55 self.getflavor_obj.run(self.result)
56 self.assertDictEqual({'get_flavor': 0}, self.result)
57 self.mock_log.error.assert_called_once_with('Get flavor failed!')