1 ##############################################################################
2 # Copyright (c) 2016 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 ##############################################################################
10 from oslo_utils import uuidutils
14 from yardstick.common import openstack_utils
17 class GetCredentialsTestCase(unittest.TestCase):
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'},
23 openstack_utils.get_credentials()
26 class GetHeatApiVersionTestCase(unittest.TestCase):
28 def test_get_heat_api_version_check_result(self):
29 API = 'HEAT_API_VERSION'
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)
37 class GetNetworkIdTestCase(unittest.TestCase):
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}]
45 output = openstack_utils.get_network_id(mock_shade_client,
47 self.assertEqual(_uuid, output)
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
54 output = openstack_utils.get_network_id(mock_shade_client,
56 self.assertEqual(None, output)