diff options
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/pub/msapi/extsys.py | 7 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/tests/test_extsys.py | 20 |
2 files changed, 24 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 index 46636eb..c13779c 100644 --- a/multivimbroker/multivimbroker/tests/test_extsys.py +++ b/multivimbroker/multivimbroker/tests/test_extsys.py @@ -8,9 +8,11 @@ # 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): @@ -20,3 +22,21 @@ class TestExtsys(unittest.TestCase): 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) |