Merge "ansible: disable Extra cloud image kernel stub"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / lib / test_create_floating_ip.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
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
10 import unittest
11 import mock
12
13 from yardstick.benchmark.scenarios.lib import create_floating_ip
14 import yardstick.common.openstack_utils as op_utils
15
16
17 class CreateFloatingIpTestCase(unittest.TestCase):
18
19     def setUp(self):
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()
34
35         self._fip_obj = create_floating_ip.CreateFloatingIp(mock.ANY, mock.ANY)
36         self._fip_obj.scenario_cfg = {'output': 'key1\nkey2'}
37
38         self.addCleanup(self._stop_mock)
39
40     def _stop_mock(self):
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()
45         self._mock_log.stop()
46
47     def test_run(self):
48         self.mock_create_floating_ip.return_value = {'fip_id': 'value1',
49                                                      'fip_addr': 'value2'}
50         output = self._fip_obj.run(mock.ANY)
51         self.assertDictEqual({'key1': 'value1', 'key2': 'value2'}, output)
52
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!')