diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-23 13:24:21 +0800 |
---|---|---|
committer | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-23 13:25:12 +0800 |
commit | 50e8ac124985365f74250a023c2adc1625476346 (patch) | |
tree | 3311b5f46f45d1d2b914c1fbace45fd8dcf5712c /multivimbroker | |
parent | 9b8db0c739cb74483c3e7319bec4fa78cf421dfe (diff) |
Add test_get_vim_by_id_success
Add unit test test_get_vim_by_id_success for extsys.py
Change-Id: I9d487ad9860fdd67f651d21b4833d3a5076babe1
Issue-ID: MULTICLOUD-198
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
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) |