diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-06-15 16:43:54 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-06-15 16:45:42 +0800 |
commit | b2924e2392890911619baa756450ff1ed4de2ed5 (patch) | |
tree | 14521de23310aaadf772b56084c24d7e2512f101 /windriver | |
parent | 4cbbd70061e3690e53c3d468bc223303eef19c00 (diff) |
Test case for buildBacklog_fault_vm
Change-Id: I69b7e40bb7dd9a87f56df1c7619e35b9dbf07de4
Issue-ID: MULTICLOUD-230
Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'windriver')
-rw-r--r-- | windriver/titanium_cloud/vesagent/event_domain/fault_vm.py | 10 | ||||
-rw-r--r-- | windriver/titanium_cloud/vesagent/event_domain/tests_fault_vm.py | 25 |
2 files changed, 27 insertions, 8 deletions
diff --git a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py b/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py index b7a0646d..48ff05fc 100644 --- a/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py +++ b/windriver/titanium_cloud/vesagent/event_domain/fault_vm.py @@ -21,7 +21,7 @@ import time from django.conf import settings from titanium_cloud.vesagent.vespublish import publishAnyEventToVES -from common.utils.restcall import _call_req +from common.utils import restcall import datetime import time @@ -61,7 +61,7 @@ def buildBacklog_fault_vm(vimid, backlog_input): auth_api_data = { "auth":{"tenantName": tenant_name} } base_url = settings.MULTICLOUD_PREFIX extra_headers = '' - ret = _call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data)) + ret = restcall._call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data)) if ret[0] > 0 or ret[1] is None: logger.critical("call url %s failed with status %s" % (auth_api_url, ret[0])) return None @@ -79,7 +79,7 @@ def buildBacklog_fault_vm(vimid, backlog_input): f_server_name=server_name) base_url = settings.MULTICLOUD_PREFIX extra_headers = {'X-Auth-Token': token} - ret = _call_req(base_url, "", "", 0, vserver_api_url, "GET", extra_headers, "") + ret = restcall._call_req(base_url, "", "", 0, vserver_api_url, "GET", extra_headers, "") if ret[0] > 0 or ret[1] is None: logger.critical("call url %s failed with status %s" % (vserver_api_url, ret[0])) return None @@ -143,7 +143,7 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog): base_url = settings.MULTICLOUD_PREFIX extra_headers = '' logger.debug("authenticate with url:%s" % auth_api_url) - ret = _call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data)) + ret = restcall._call_req(base_url, "", "", 0, auth_api_url, "POST", extra_headers, json.dumps(auth_api_data)) if ret[0] > 0 or ret[1] is None: logger.critical("call url %s failed with status %s" % (auth_api_url, ret[0])) @@ -159,7 +159,7 @@ def processBacklog_fault_vm(vesAgentConfig, vesAgentState, oneBacklog): extra_headers = {'X-Auth-Token': token} #which one is correct? extra_headers = {'HTTP_X_AUTH_TOKEN': token} logger.debug("authenticate with url:%s, header:%s" % (auth_api_url,extra_headers)) - ret = _call_req(base_url, "", "", 0, api_link, method, extra_headers, data) + ret = restcall._call_req(base_url, "", "", 0, api_link, method, extra_headers, data) if ret[0] > 0 or ret[1] is None: logger.critical("call url %s failed with status %s" % (api_link, ret[0])) diff --git a/windriver/titanium_cloud/vesagent/event_domain/tests_fault_vm.py b/windriver/titanium_cloud/vesagent/event_domain/tests_fault_vm.py index 2e9057aa..aeec977c 100644 --- a/windriver/titanium_cloud/vesagent/event_domain/tests_fault_vm.py +++ b/windriver/titanium_cloud/vesagent/event_domain/tests_fault_vm.py @@ -18,11 +18,17 @@ import unittest import json from titanium_cloud.vesagent.vespublish import publishAnyEventToVES -from common.utils.restcall import _call_req +from common.utils import restcall from titanium_cloud.vesagent.event_domain import fault_vm - - +MOCK_TOKEN_RESPONSE = {"access":{"token":{"issued_at":"2018-05-10T16:56:56.000000Z","expires":"2018-05-10T17:56:56.000000Z","id":"4a832860dd744306b3f66452933f939e","tenant":{"domain":{"id":"default","name":"Default"},"enabled":"true","id":"0e148b76ee8c42f78d37013bf6b7b1ae","name":"VIM"}},"serviceCatalog":[],"user":{"domain":{"id":"default","name":"Default"},"id":"ba76c94eb5e94bb7bec6980e5507aae2","name":"demo"}}} +MOCK_SERVERS_GET_RESPONSE = {"servers": [{"id": "c4b575fa-ed85-4642-ab4b-335cb5744721", "links": [{"href": "http://10.12.25.2:8774/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", "rel": "self"}, {"href": "http://10.12.25.2:8774/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", "rel": "bookmark"}], "name": "onap-aaf"}]} +MOCK_BACKLOG_INPUT = {"backlog_uuid": "ce2d7597-22e1-4239-890f-bc303bd67076", + "server_id": "c4b575fa-ed85-4642-ab4b-335cb5744721", + "tenant_id": "0e148b76ee8c42f78d37013bf6b7b1ae", "api_method": "GET", + "source": "onap-aaf", + "api_link": "/onaplab_RegionOne/compute/v2.1/0e148b76ee8c42f78d37013bf6b7b1ae/servers/c4b575fa-ed85-4642-ab4b-335cb5744721", + "domain": "fault", "type": "vm", "tenant": "VIM"} class FaultVMTest(unittest.TestCase): def setUp(self): pass @@ -34,3 +40,16 @@ class FaultVMTest(unittest.TestCase): epoch = fault_vm.get_epoch_now_usecond() self.assertGreater(epoch, 1) pass + + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_fault_vm(self, mock_call_req): + + mock_call_req.side_effect= [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = fault_vm.buildBacklog_fault_vm(vimid="windriver-hudson-dc_RegionOne", + backlog_input = MOCK_BACKLOG_INPUT) + self.assertIsNotNone(backlog) + pass |