Merge "Create host VMs configuration"
[yardstick.git] / yardstick / tests / unit / common / test_openstack_utils.py
1 ##############################################################################
2 # Copyright (c) 2016 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 from oslo_utils import uuidutils
11 import unittest
12 import mock
13
14 from yardstick.common import openstack_utils
15
16
17 class GetCredentialsTestCase(unittest.TestCase):
18
19     @mock.patch('yardstick.common.openstack_utils.os')
20     def test_get_credentials(self, _):
21         with mock.patch.dict('os.environ', {'OS_IDENTITY_API_VERSION': '2'},
22                              clear=True):
23             openstack_utils.get_credentials()
24
25
26 class GetHeatApiVersionTestCase(unittest.TestCase):
27
28     def test_get_heat_api_version_check_result(self):
29         API = 'HEAT_API_VERSION'
30         expected_result = '2'
31
32         with mock.patch.dict('os.environ', {API: '2'}, clear=True):
33             api_version = openstack_utils.get_heat_api_version()
34             self.assertEqual(api_version, expected_result)
35
36
37 class GetNetworkIdTestCase(unittest.TestCase):
38
39     def test_get_network_id(self):
40         _uuid = uuidutils.generate_uuid()
41         mock_shade_client = mock.Mock()
42         mock_shade_client.list_networks = mock.Mock()
43         mock_shade_client.list_networks.return_value = [{'id': _uuid}]
44
45         output = openstack_utils.get_network_id(mock_shade_client,
46                                                 'network_name')
47         self.assertEqual(_uuid, output)
48
49     def test_get_network_id_no_network(self):
50         mock_shade_client = mock.Mock()
51         mock_shade_client.list_networks = mock.Mock()
52         mock_shade_client.list_networks.return_value = None
53
54         output = openstack_utils.get_network_id(mock_shade_client,
55                                                 'network_name')
56         self.assertEqual(None, output)