summaryrefslogtreecommitdiffstats
path: root/ocata
diff options
context:
space:
mode:
authorHuang Haibin <haibin.huang@intel.com>2018-09-12 09:50:50 +0800
committerHuang Haibin <haibin.huang@intel.com>2018-09-12 09:50:50 +0800
commit9ac5aad96afbe2d40319239ce93ad05d71c0e40f (patch)
tree93fa7f8fd642f2e0fc86249245636e7b6f10da11 /ocata
parent7c1f75989e8cc63fd3542acf546fc77c90aa6327 (diff)
Test case for buildBacklog_fault_vm in ocata
Change-Id: I2e7476633e748fdce57709e3d8c444cee20e80fc Issue-ID: MULTICLOUD-230 Signed-off-by: Huang Haibin <haibin.huang@intel.com>
Diffstat (limited to 'ocata')
-rw-r--r--ocata/ocata/vesagent/event_domain/fault_vm.py10
-rw-r--r--ocata/ocata/vesagent/event_domain/tests_fault_vm.py25
2 files changed, 27 insertions, 8 deletions
diff --git a/ocata/ocata/vesagent/event_domain/fault_vm.py b/ocata/ocata/vesagent/event_domain/fault_vm.py
index df1ca60d..faddd25c 100644
--- a/ocata/ocata/vesagent/event_domain/fault_vm.py
+++ b/ocata/ocata/vesagent/event_domain/fault_vm.py
@@ -21,7 +21,7 @@ import time
from django.conf import settings
from ocata.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/ocata/ocata/vesagent/event_domain/tests_fault_vm.py b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
index 376f1fee..f2828a93 100644
--- a/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
+++ b/ocata/ocata/vesagent/event_domain/tests_fault_vm.py
@@ -18,11 +18,17 @@ import unittest
import json
from ocata.vesagent.vespublish import publishAnyEventToVES
-from common.utils.restcall import _call_req
+from common.utils import restcall
from ocata.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