1 # Copyright (c) 2017-2018 VMware, Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 from multivimbroker.pub import exceptions
15 from multivimbroker.pub.msapi import extsys
16 from multivimbroker.pub.utils import syscomm
19 class TestSyscomm(unittest.TestCase):
21 def test_getVIMTypes(self):
23 "openstack": ["titanium_cloud", "ocata", "pike", "starlingx"],
27 ret = syscomm.getVIMTypes()
29 for v in item['versions']:
30 self.assertIn(v, expected_body[item['vim_type']])
32 @mock.patch.object(extsys, "get_vim_by_id")
33 def test_getMultivimDriver(self, mock_get_vim):
34 mock_get_vim.return_value = {
38 full_path = "multicloud/v0/openstack_regionone/identity"
39 expect_path = "multicloud-ocata/v0/openstack_regionone/identity"
40 ret_path = syscomm.getMultivimDriver("openstack_regionone", full_path)
41 self.assertEqual(expect_path, ret_path)
43 def test_findMultivimDriver_no_type(self):
44 vim = {"type": "wrong type"}
45 self.assertRaises(exceptions.NotFound, syscomm.findMultivimDriver, vim)
47 def test_findMultivimDriver_no_version(self):
48 vim = {"type": "openstack"}
49 ret = syscomm.findMultivimDriver(vim)
50 self.assertEqual("multicloud-ocata", ret)
52 def test_findMultivimDriver_with_version(self):
53 vim = {"type": "openstack", "version": "titanium_cloud"}
54 ret = syscomm.findMultivimDriver(vim)
55 self.assertEqual("multicloud-titaniumcloud", ret)
57 def test_originHeaders(self):
60 "HTTP_X_AUTH_TOKEN": "token_1",
61 "NOT_STARTSWITH_HTTP": "value_1",
62 "CONTENT_TYPE": "application/json"
65 "X-AUTH-TOKEN": "token_1",
66 "CONTENT-TYPE": "application/json"
68 ret_headers = syscomm.originHeaders(req)
69 self.assertDictEqual(expect_headers, ret_headers)
71 def test_getHeadersKeys_no_connection(self):
73 self.assertEqual([], syscomm.getHeadersKeys(resp))
75 def test_getHeadersKeys_with_connection(self):
77 "connection": "aa,bb",
83 self.assertEqual(["cc"], syscomm.getHeadersKeys(resp))