summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/pub/msapi/extsys.py7
-rw-r--r--multivimbroker/multivimbroker/tests/test_extsys.py42
-rw-r--r--multivimbroker/multivimbroker/tests/test_restcall.py31
3 files changed, 77 insertions, 3 deletions
diff --git a/multivimbroker/multivimbroker/pub/msapi/extsys.py b/multivimbroker/multivimbroker/pub/msapi/extsys.py
index f5e26aa..e04c5f5 100644
--- a/multivimbroker/multivimbroker/pub/msapi/extsys.py
+++ b/multivimbroker/multivimbroker/pub/msapi/extsys.py
@@ -14,7 +14,7 @@ import json
import logging
from multivimbroker.pub.exceptions import VimBrokerException
-from multivimbroker.pub.utils.restcall import get_res_from_aai
+from multivimbroker.pub.utils import restcall
logger = logging.getLogger(__name__)
@@ -28,8 +28,9 @@ def split_vim_to_owner_region(vim_id):
def get_vim_by_id(vim_id):
cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
- ret = get_res_from_aai("/cloud-infrastructure/cloud-regions/cloud-region"
- "/%s/%s" % (cloud_owner, cloud_region))
+ ret = restcall.get_res_from_aai("/cloud-infrastructure/cloud-regions/"
+ "cloud-region/%s/%s" % (
+ cloud_owner, cloud_region))
if ret[0] != 0:
logger.error("Status code is %s, detail is %s." % (ret[2], ret[1]))
raise VimBrokerException(
diff --git a/multivimbroker/multivimbroker/tests/test_extsys.py b/multivimbroker/multivimbroker/tests/test_extsys.py
new file mode 100644
index 0000000..c13779c
--- /dev/null
+++ b/multivimbroker/multivimbroker/tests/test_extsys.py
@@ -0,0 +1,42 @@
+# Copyright (c) 2017-2018 VMware, Inc.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+import mock
+import unittest
+
+from multivimbroker.pub.msapi import extsys
+from multivimbroker.pub.utils import restcall
+
+
+class TestExtsys(unittest.TestCase):
+
+ def test_split_vim_to_owner_region(self):
+ vim_id = "openstack_regionone"
+ cloud_owner, cloud_region = extsys.split_vim_to_owner_region(vim_id)
+ self.assertEqual("openstack", cloud_owner)
+ self.assertEqual("regionone", cloud_region)
+
+ @mock.patch.object(restcall, "get_res_from_aai")
+ def test_get_vim_by_id_success(self, mock_get_res):
+ resp_body = """{
+ "cloud-type": "openstack",
+ "cloud-region-version": "regionone"
+ }"""
+ mock_get_res.return_value = (0, resp_body, 200, mock.Mock())
+ vim_id = "openstack_regionone"
+ ret = extsys.get_vim_by_id(vim_id)
+ expect_ret = {
+ "cloud-type": "openstack",
+ "cloud-region-version": "regionone",
+ "type": "openstack",
+ "version": "regionone",
+ "vimId": vim_id
+ }
+ self.assertDictEqual(expect_ret, ret)
diff --git a/multivimbroker/multivimbroker/tests/test_restcall.py b/multivimbroker/multivimbroker/tests/test_restcall.py
index b76b0a6..235d58a 100644
--- a/multivimbroker/multivimbroker/tests/test_restcall.py
+++ b/multivimbroker/multivimbroker/tests/test_restcall.py
@@ -8,6 +8,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+import mock
import unittest
from multivimbroker.pub.utils import restcall
@@ -22,3 +23,33 @@ class TestRestCall(unittest.TestCase):
expected = "http://a.com/test/resource"
for i in range(len(url)):
self.assertEqual(expected, restcall.combine_url(url[i], res[i]))
+
+ @mock.patch.object(restcall, "call_req")
+ def test_get_res_from_aai(self, mock_call):
+ res = "cloud-regions"
+ content = ""
+ expect_url = "https://aai.api.simpledemo.openecomp.org:8443/aai/v13"
+ expect_user = "AAI"
+ expect_pass = "AAI"
+ expect_headers = {
+ 'X-FromAppId': 'MultiCloud',
+ 'X-TransactionId': '9001',
+ 'content-type': 'application/json',
+ 'accept': 'application/json'
+ }
+ restcall.get_res_from_aai(res, content=content)
+ mock_call.assert_called_once_with(
+ expect_url, expect_user, expect_pass, restcall.rest_no_auth,
+ res, "GET", content, expect_headers)
+
+ @mock.patch.object(restcall, "call_req")
+ def test_req_by_msb(self, mock_call):
+ res = "multicloud"
+ method = "GET"
+ content = "no content"
+ headers = None
+ restcall.req_by_msb(res, method, content=content, headers=headers)
+ expect_url = "http://127.0.0.1:10080/"
+ mock_call.assert_called_once_with(
+ expect_url, "", "", restcall.rest_no_auth, res, method,
+ content, headers)