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 ##############################################################################
13 from yardstick.benchmark.scenarios.lib import create_floating_ip
14 import yardstick.common.openstack_utils as op_utils
17 class CreateFloatingIpTestCase(unittest.TestCase):
20 self._mock_get_network_id = mock.patch.object(
21 op_utils, 'get_network_id')
22 self.mock_get_network_id = self._mock_get_network_id.start()
23 self._mock_create_floating_ip = mock.patch.object(
24 op_utils, 'create_floating_ip')
25 self.mock_create_floating_ip = self._mock_create_floating_ip.start()
26 self._mock_get_neutron_client = mock.patch.object(
27 op_utils, 'get_neutron_client')
28 self.mock_get_neutron_client = self._mock_get_neutron_client.start()
29 self._mock_get_shade_client = mock.patch.object(
30 op_utils, 'get_shade_client')
31 self.mock_get_shade_client = self._mock_get_shade_client.start()
32 self._mock_log = mock.patch.object(create_floating_ip, 'LOG')
33 self.mock_log = self._mock_log.start()
35 self._fip_obj = create_floating_ip.CreateFloatingIp(mock.ANY, mock.ANY)
36 self._fip_obj.scenario_cfg = {'output': 'key1\nkey2'}
38 self.addCleanup(self._stop_mock)
41 self._mock_get_network_id.stop()
42 self._mock_create_floating_ip.stop()
43 self._mock_get_neutron_client.stop()
44 self._mock_get_shade_client.stop()
48 self.mock_create_floating_ip.return_value = {'fip_id': 'value1',
50 output = self._fip_obj.run(mock.ANY)
51 self.assertDictEqual({'key1': 'value1', 'key2': 'value2'}, output)
53 def test_run_no_fip(self):
54 self.mock_create_floating_ip.return_value = None
55 output = self._fip_obj.run(mock.ANY)
56 self.assertIsNone(output)
57 self.mock_log.error.assert_called_once_with(
58 'Creating floating ip failed!')