aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuoyu Ying <ruoyu.ying@intel.com>2018-09-14 19:46:43 +0800
committerRuoyu Ying <ruoyu.ying@intel.com>2018-09-17 18:30:14 +0800
commit018b4aeebdb803e3e7cd1868fa915f7a9ed8bbff (patch)
treea6d6ada4e5420267070367084340fece25b32913
parenta544f7db29abce453fc550bf0b810b5fc4d428a6 (diff)
Send homing request to OOF
Add code to send homing request to OOF and unit test Change-Id: I4ab56611aa43a36118ab2b4653ffdfe58e7e921b Issue-ID: VFC-941 Signed-off-by: Ruoyu Ying <ruoyu.ying@intel.com>
-rw-r--r--lcm/ns_vnfs/biz/create_vnfs.py87
-rw-r--r--lcm/ns_vnfs/tests/tests.py53
-rw-r--r--lcm/pub/config/config.py5
3 files changed, 144 insertions, 1 deletions
diff --git a/lcm/ns_vnfs/biz/create_vnfs.py b/lcm/ns_vnfs/biz/create_vnfs.py
index ac1847ec..9952fd6e 100644
--- a/lcm/ns_vnfs/biz/create_vnfs.py
+++ b/lcm/ns_vnfs/biz/create_vnfs.py
@@ -19,7 +19,7 @@ from threading import Thread
from lcm.ns.const import OWNER_TYPE
from lcm.pub.config.config import REPORT_TO_AAI
-from lcm.pub.database.models import NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel
+from lcm.pub.database.models import NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel, OOFDataModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.aai import create_vnf_aai
from lcm.pub.msapi.extsys import get_vnfm_by_id
@@ -30,8 +30,10 @@ from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil, JOB_TYPE
from lcm.pub.utils.share_lock import do_biz_with_share_lock
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
+from lcm.pub.utils import restcall
from lcm.ns_vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND, INST_TYPE, INST_TYPE_NAME
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
+from lcm.pub.config.config import REG_TO_MSB_REG_PARAM, OOF_BASE_URL, OOF_PASSWD, OOF_USER
logger = logging.getLogger(__name__)
@@ -75,6 +77,7 @@ class CreateVnfs(Thread):
self.create_vnf_in_aai()
self.check_nf_package_valid()
self.send_nf_init_request_to_vnfm()
+ self.send_homing_request_to_OOF()
self.send_get_vnfm_request_to_extsys()
self.send_create_vnf_request_to_resmgr()
self.wait_vnfm_job_finish()
@@ -208,6 +211,88 @@ class CreateVnfs(Thread):
input_params=json.JSONEncoder().encode(self.inputs),
lastuptime=now_time())
+ def build_homing_request(self):
+ id = str(uuid.uuid4())
+ callback_uri = " {vfcBaseUrl}/api/nslcm/v1/ns/placevnf"
+ IP = REG_TO_MSB_REG_PARAM["nodes"][0]["ip"]
+ PORT = REG_TO_MSB_REG_PARAM["nodes"][0]["port"]
+ vfcBaseUrl = IP + ':' + PORT
+ callback_uri = callback_uri.format(vfcBaseUrl=vfcBaseUrl)
+ modelInvariantId = "no-resourceModelInvariantId"
+ modelVersionId = "no-resourceModelVersionId"
+ nsInfo = NSInstModel.objects.filter(id=self.ns_inst_id)
+ placementDemand = {
+ "resourceModuleName": self.vnf_inst_name,
+ "serviceResourceId": self.vnfm_nf_inst_id,
+ "resourceModelInfo": {
+ "modelInvariantId": modelInvariantId,
+ "modelVersionId": modelVersionId
+ }
+ }
+ req_body = {
+ "requestInfo": {
+ "transactionId": id,
+ "requestId": id,
+ "callbackUrl": callback_uri,
+ "sourceId": "vfc",
+ "requestType": "create",
+ "numSolutions": 1,
+ "optimizers": ["placement"],
+ "timeout": 600
+ },
+ "placementInfo": {
+ "placementDemands": []
+ },
+ "serviceInfo": {
+ "serviceInstanceId": self.ns_inst_id,
+ "serviceName": self.ns_inst_name,
+ "modelInfo": {
+ "modelInvariantId": nsInfo[0].nsd_invariant_id,
+ "modelVersionId": nsInfo[0].nsd_id
+ }
+ }
+ }
+ req_body["placementInfo"]["placementDemands"].append(placementDemand)
+ # Stored the init request info inside DB
+ OOFDataModel.objects.create(
+ request_id=id,
+ transaction_id=id,
+ request_status="init",
+ request_module_name=self.vnfm_nf_inst_id,
+ service_resource_id=self.vnf_inst_name,
+ vim_id="",
+ cloud_owner="",
+ cloud_region_id="",
+ vdu_info="",
+ )
+ return req_body
+
+ def send_homing_request_to_OOF(self):
+ req_body = self.build_homing_request()
+ base_url = OOF_BASE_URL
+ resources = "/api/oof/v1/placement"
+ resp = restcall.call_req(base_url=base_url, user=OOF_USER, passwd=OOF_PASSWD,
+ auth_type=restcall.rest_oneway_auth, resource=resources,
+ method="POST", content=req_body, additional_headers="")
+ resp_body = resp[-2]
+ resp_status = resp[-1]
+ if resp_body:
+ logger.debug("Got OOF sync response")
+ else:
+ logger.warn("Missing OOF sync response")
+ logger.debug(("OOF sync response code is %s") % resp_status)
+ if str(resp_status) != '202' or resp[0] != 0:
+ OOFDataModel.objects.filter(request_id=req_body["requestInfo"]["requestId"],
+ transaction_id=req_body["requestInfo"]["transactionId"]).update(
+ request_status="failed",
+ vim_id="none",
+ cloud_owner="none",
+ cloud_region_id="none",
+ vdu_info="none"
+ )
+ raise Exception("Received a Bad Sync from OOF with response code %s" % resp_status)
+ logger.info("Completed Homing request to OOF")
+
def send_get_vnfm_request_to_extsys(self):
resp_body = get_vnfm_by_id(self.vnfm_inst_id)
self.vnfm_inst_name = ignore_case_get(resp_body, 'name')
diff --git a/lcm/ns_vnfs/tests/tests.py b/lcm/ns_vnfs/tests/tests.py
index 2490b92e..ba92e194 100644
--- a/lcm/ns_vnfs/tests/tests.py
+++ b/lcm/ns_vnfs/tests/tests.py
@@ -139,6 +139,59 @@ class TestCreateVnfViews(TestCase):
CreateVnfs(data, nf_inst_id, job_id).run()
self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE)
+ @mock.patch.object(restcall, 'call_req')
+ @mock.patch.object(CreateVnfs, 'build_homing_request')
+ def test_send_homing_request(self, mock_build_req, mock_call_req):
+ nf_inst_id, job_id = create_vnfs.prepare_create_params()
+ OOFDataModel.objects.all().delete()
+ resp = {
+ "requestId": "1234",
+ "transactionId": "1234",
+ "requestStatus": "accepted"
+ }
+ mock_build_req.return_value = {
+ "requestInfo": {
+ "transactionId": "1234",
+ "requestId": "1234",
+ "callbackUrl": "xx",
+ "sourceId": "vfc",
+ "requestType": "create",
+ "numSolutions": 1,
+ "optimizers": ["placement"],
+ "timeout": 600
+ },
+ "placementInfo": {
+ "placementDemands": [
+ {
+ "resourceModuleName": "vG",
+ "serviceResourceId": "1234",
+ "resourceModelInfo": {
+ "modelInvariantId": "1234",
+ "modelVersionId": "1234"
+ }
+ }
+ ]
+ },
+ "serviceInfo": {
+ "serviceInstanceId": "1234",
+ "serviceName": "1234",
+ "modelInfo": {
+ "modelInvariantId": "5678",
+ "modelVersionId": "7890"
+ }
+ }
+ }
+ mock_call_req.return_value = [0, json.JSONEncoder().encode(resp), '202']
+ data = {
+ 'ns_instance_id': ignore_case_get(self.data, 'nsInstanceId'),
+ 'additional_param_for_ns': ignore_case_get(self.data, 'additionalParamForNs'),
+ 'additional_param_for_vnf': ignore_case_get(self.data, 'additionalParamForVnf'),
+ 'vnf_index': ignore_case_get(self.data, 'vnfIndex')
+ }
+ CreateVnfs(data, nf_inst_id, job_id).send_homing_request_to_OOF()
+ ret = OOFDataModel.objects.filter(request_id="1234", transaction_id="1234")
+ self.assertIsNotNone(ret)
+
class TestTerminateVnfViews(TestCase):
def setUp(self):
diff --git a/lcm/pub/config/config.py b/lcm/pub/config/config.py
index ebffddca..9d63b254 100644
--- a/lcm/pub/config/config.py
+++ b/lcm/pub/config/config.py
@@ -68,3 +68,8 @@ MR_PORT = '3904'
DEPLOY_WORKFLOW_WHEN_START = False
# Support option: activiti/wso2/buildin
WORKFLOW_OPTION = "buildin"
+
+# [OOF config]
+OOF_BASE_URL = "http://oof.api.simpledemo.onap.org:8698"
+OOF_USER = "vfc_test"
+OOF_PASSWD = "vfc_testpwd"