1 # Copyright (c) 2018 Amdocs
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 from multicloud_azure.pub.utils.restcall import AAIClient
19 from multicloud_azure.pub.msapi import extsys
20 from multicloud_azure.pub.utils.timeutil import now_time
21 from multicloud_azure.pub.utils.fileutil import make_dirs, delete_dirs
22 from multicloud_azure.pub.utils.fileutil import download_file_from_http
23 from multicloud_azure.pub.vim.vimsdk.azure_credentials import ClientObj
24 from multicloud_azure.pub.exceptions import VimDriverAzureException
31 'username': TENANT_ID,
37 class TestPub(unittest.TestCase):
39 def test_client_obj(self):
40 self.assertRaises(VimDriverAzureException,
41 ClientObj().get_client_obj, params)
44 fmt = "%Y-%m-%d %H:%M:%S"
45 self.assertIsNotNone(now_time(fmt))
47 def test_make_dirs(self):
48 path = "/tmp/azure/azure/bin"
49 self.assertEqual(os.makedirs(path, 0o777), make_dirs(path))
51 def test_delete_dirs(self):
52 path = "/tmp/azure/azure/bin"
53 self.assertIsNone(delete_dirs(path))
55 def test_download_file(self):
56 url = "https://raw.githubusercontent.com/onapdemo/" \
57 "onap-scripts/master/entrypoint/azure-rancher-server.sh"
58 local_dir = "usr/local/bin"
60 self.assertNotEquals(False, "usr/local/bin/azure",
61 download_file_from_http(url, local_dir,
64 def test_split_vim_to_owner_region(self):
65 vim_id = 'ATT_eastus2'
66 self.assertEquals(('ATT', 'eastus2'),
67 extsys.split_vim_to_owner_region(vim_id))
69 @mock.patch.object(AAIClient, 'get_vim')
70 def test_get_vim_id(self, mock_vim_info):
71 vim_id = 'ATT_eastus2'
72 json_file = os.path.join(os.path.dirname(
73 __file__), 'aai_response.json')
74 f = open(json_file).read()
76 mock_vim_info.return_value = ret
77 self.assertEqual(ret, extsys.get_vim_by_id(vim_id))