diff options
-rw-r--r-- | lcm/ns/ns_create.py | 4 | ||||
-rw-r--r-- | lcm/ns/ns_delete.py | 4 | ||||
-rw-r--r-- | lcm/ns/tests/test_ns_instant.py | 6 | ||||
-rw-r--r-- | lcm/ns/tests/vls/tests.py | 71 | ||||
-rw-r--r-- | lcm/ns/tests/vnfs/tests.py | 155 | ||||
-rw-r--r-- | lcm/ns/vnfs/create_vnfs.py | 39 | ||||
-rw-r--r-- | lcm/ns/vnfs/terminate_nfs.py | 4 | ||||
-rw-r--r-- | lcm/pub/config/config.py | 1 |
8 files changed, 171 insertions, 113 deletions
diff --git a/lcm/ns/ns_create.py b/lcm/ns/ns_create.py index a80bf8d5..620427f3 100644 --- a/lcm/ns/ns_create.py +++ b/lcm/ns/ns_create.py @@ -14,6 +14,7 @@ import logging import uuid +from lcm.pub.config.config import REPORT_TO_AAI from lcm.pub.database.models import NSDModel, NSInstModel from lcm.pub.exceptions import NSLCMException from lcm.pub.msapi.aai import create_customer_aai @@ -34,7 +35,8 @@ class CreateNSService(object): self.check_nsd_valid() self.check_ns_inst_name_exist() self.create_ns_inst() - self.create_ns_in_aai() + if REPORT_TO_AAI: + self.create_ns_in_aai() logger.debug("CreateNSService::do_biz::ns_inst_id=%s" % self.ns_inst_id) return self.ns_inst_id diff --git a/lcm/ns/ns_delete.py b/lcm/ns/ns_delete.py index 7d51df46..0883cf2a 100644 --- a/lcm/ns/ns_delete.py +++ b/lcm/ns/ns_delete.py @@ -16,6 +16,7 @@ import logging import traceback +from lcm.pub.config.config import REPORT_TO_AAI from lcm.pub.database.models import DefPkgMappingModel, InputParamMappingModel, ServiceBaseInfoModel from lcm.pub.database.models import NSInstModel from lcm.pub.msapi.aai import get_customer_aai, delete_customer_aai @@ -31,7 +32,8 @@ class DeleteNsService(object): def do_biz(self): try: self.delete_ns() - self.delete_ns_in_aai() + if REPORT_TO_AAI: + self.delete_ns_in_aai() except: logger.error(traceback.format_exc()) diff --git a/lcm/ns/tests/test_ns_instant.py b/lcm/ns/tests/test_ns_instant.py index 77fb7f38..955284ce 100644 --- a/lcm/ns/tests/test_ns_instant.py +++ b/lcm/ns/tests/test_ns_instant.py @@ -60,6 +60,6 @@ class TestNsInstant(TestCase): self.assertEqual(resp.status_code, status.HTTP_200_OK) """ - # def test_swagger_ok(self): - # resp = self.client.get("/api/nslcm/v1/swagger.json", format='json') - # self.assertEqual(resp.status_code, status.HTTP_200_OK) + def test_swagger_ok(self): + resp = self.client.get("/api/nslcm/v1/swagger.json", format='json') + self.assertEqual(resp.status_code, status.HTTP_200_OK) diff --git a/lcm/ns/tests/vls/tests.py b/lcm/ns/tests/vls/tests.py index 3c99bfbc..366fcef7 100644 --- a/lcm/ns/tests/vls/tests.py +++ b/lcm/ns/tests/vls/tests.py @@ -23,42 +23,43 @@ from lcm.pub.database.models import VLInstModel, NSInstModel, VNFFGInstModel from lcm.pub.nfvi.vim import vimadaptor from lcm.pub.utils import restcall -vim_info = {"cloud-owner": "example-cloud-owner-val-97336", - "cloud-region-id": "example-cloud-region-id-val-35532", - "cloud-type": "example-cloud-type-val-18046", - "owner-defined-type": "example-owner-defined-type-val-9413", - "cloud-region-version": "example-cloud-region-version-val-85706", - "identity-url": "example-identity-url-val-71252", - "cloud-zone": "example-cloud-zone-val-27112", - "complex-name": "example-complex-name-val-85283", - "sriov-automation": True, - "cloud-extra-info": "example-cloud-extra-info-val-90854", - "cloud-epa-caps": "example-cloud-epa-caps-val-2409", - "resource-version": "example-resource-version-val-42094", - "esr-system-info-list": { - "esr-system-info": [ - { - "esr-system-info-id": "example-esr-system-info-id-val-7713", - "system-name": "example-system-name-val-19801", - "type": "example-type-val-24477", - "vendor": "example-vendor-val-50079", - "version": "example-version-val-93146", - "service-url": "example-service-url-val-68090", - "user-name": "example-user-name-val-14470", - "password": "example-password-val-84190", - "system-type": "example-system-type-val-42773", - "protocal": "example-protocal-val-85736", - "ssl-cacert": "example-ssl-cacert-val-33989", - "ssl-insecure": True, - "ip-address": "example-ip-address-val-99038", - "port": "example-port-val-27323", - "cloud-domain": "example-cloud-domain-val-55163", - "default-tenant": "example-default-tenant-val-99383", - "resource-version": "example-resource-version-val-15424" - } - ] - } +vim_info = { + "cloud-owner": "example-cloud-owner-val-97336", + "cloud-region-id": "example-cloud-region-id-val-35532", + "cloud-type": "example-cloud-type-val-18046", + "owner-defined-type": "example-owner-defined-type-val-9413", + "cloud-region-version": "example-cloud-region-version-val-85706", + "identity-url": "example-identity-url-val-71252", + "cloud-zone": "example-cloud-zone-val-27112", + "complex-name": "example-complex-name-val-85283", + "sriov-automation": True, + "cloud-extra-info": "example-cloud-extra-info-val-90854", + "cloud-epa-caps": "example-cloud-epa-caps-val-2409", + "resource-version": "example-resource-version-val-42094", + "esr-system-info-list": { + "esr-system-info": [ + { + "esr-system-info-id": "example-esr-system-info-id-val-7713", + "system-name": "example-system-name-val-19801", + "type": "example-type-val-24477", + "vendor": "example-vendor-val-50079", + "version": "example-version-val-93146", + "service-url": "example-service-url-val-68090", + "user-name": "example-user-name-val-14470", + "password": "example-password-val-84190", + "system-type": "example-system-type-val-42773", + "protocal": "example-protocal-val-85736", + "ssl-cacert": "example-ssl-cacert-val-33989", + "ssl-insecure": True, + "ip-address": "example-ip-address-val-99038", + "port": "example-port-val-27323", + "cloud-domain": "example-cloud-domain-val-55163", + "default-tenant": "admin", + "resource-version": "example-resource-version-val-15424" } + ] + } +} class TestVlViews(TestCase): def setUp(self): diff --git a/lcm/ns/tests/vnfs/tests.py b/lcm/ns/tests/vnfs/tests.py index f9cf3393..d5b02eab 100644 --- a/lcm/ns/tests/vnfs/tests.py +++ b/lcm/ns/tests/vnfs/tests.py @@ -18,6 +18,7 @@ import mock from django.test import TestCase, Client from rest_framework import status +from lcm.ns.tests.vls.tests import vim_info from lcm.ns.vnfs import create_vnfs from lcm.ns.vnfs.const import VNF_STATUS from lcm.ns.vnfs.create_vnfs import CreateVnfs @@ -84,14 +85,27 @@ class TestCreateVnfViews(TestCase): self.ns_inst_id = str(uuid.uuid4()) self.job_id = str(uuid.uuid4()) self.data = { - 'nsInstanceId': self.ns_inst_id, - 'additionalParamForNs': {"inputs": json.dumps({})}, - 'additionalParamForVnf': [{ - 'vnfprofileid': 'VBras', - 'additionalparam': { - 'inputs': json.dumps({'vnf_param1': '11', 'vnf_param2': '22'}), - 'vnfminstanceid': "1"}}], - 'vnfIndex': '1'} + "nsInstanceId": self.ns_inst_id, + "additionalParamForNs": { + "inputs": json.dumps({ + + }) + }, + "additionalParamForVnf": [ + { + "vnfprofileid": "VBras", + "additionalparam": { + "inputs": json.dumps({ + "vnf_param1": "11", + "vnf_param2": "22" + }), + "vnfminstanceid": "1", + "vimId": "zte_test" + } + } + ], + "vnfIndex": "1" + } self.client = Client() NfPackageModel(uuid=str(uuid.uuid4()), nfpackageid='package_id1', vnfdid='zte_vbras', vendor='zte', vnfdversion='1.0.0', vnfversion='1.0.0', vnfdmodel=json.dumps(vnfd_model_dict)).save() @@ -112,16 +126,23 @@ class TestCreateVnfViews(TestCase): @mock.patch.object(restcall, 'call_req') def test_create_vnf_thread(self, mock_call_req): + nf_inst_id, job_id = create_vnfs.prepare_create_params() mock_vals = { "/api/ztevmanagerdriver/v1/1/vnfs": [0, json.JSONEncoder().encode({"jobId": self.job_id, "vnfInstanceId": 3}), '200'], - "/external-system/esr-vnfm-list/esr-vnfm/1": + "/external-system/esr-vnfm-list/esr-vnfm/1?depth=all": [0, json.JSONEncoder().encode(vnfm_info), '200'], "/api/resmgr/v1/vnf": [0, json.JSONEncoder().encode({}), '200'], "/api/resmgr/v1/vnfinfo": [0, json.JSONEncoder().encode({}), '200'], - "/api/ztevmanagerdriver/v1/jobs/" + self.job_id + "&responseId=0": + "/network/generic-vnfs/generic-vnf/%s" % nf_inst_id: + [0, json.JSONEncoder().encode({}), '201'], + "/cloud-infrastructure/cloud-regions/cloud-region/zte/test?depth=all": + [0, json.JSONEncoder().encode(vim_info), '201'], + "/cloud-infrastructure/cloud-regions/cloud-region/zte/test/tenants/tenant/admin/vservers/vserver/1": + [0, json.JSONEncoder().encode({}), '201'], + "/api/ztevmanagerdriver/v1/1/jobs/" + self.job_id + "?responseId=0": [0, json.JSONEncoder().encode({"jobid": self.job_id, "responsedescriptor": {"progress": "100", "status": JOB_MODEL_STATUS.FINISHED, @@ -142,7 +163,6 @@ class TestCreateVnfViews(TestCase): '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')} - nf_inst_id, job_id = create_vnfs.prepare_create_params() CreateVnfs(data, nf_inst_id, job_id).run() self.assertTrue(NfInstModel.objects.get(nfinstid=nf_inst_id).status, VNF_STATUS.ACTIVE) @@ -453,52 +473,50 @@ class TestGetVnfmInfoViews(TestCase): @mock.patch.object(restcall, "call_req") def test_get_vnfm_info(self, mock_call_req): - vnfm_info_aai = \ - { - "vnfm-id": "example-vnfm-id-val-62576", - "vim-id": "example-vim-id-val-35114", - "certificate-url": "example-certificate-url-val-90242", - "esr-system-info-list": { - "esr-system-info": [ - { - "esr-system-info-id": "example-esr-system-info-id-val-78484", - "system-name": "example-system-name-val-23790", - "type": "example-type-val-52596", - "vendor": "example-vendor-val-47399", - "version": "example-version-val-42051", - "service-url": "example-service-url-val-10731", - "user-name": "example-user-name-val-65946", - "password": "example-password-val-22505", - "system-type": "example-system-type-val-27221", - "protocal": "example-protocal-val-54632", - "ssl-cacert": "example-ssl-cacert-val-45965", - "ssl-insecure": True, - "ip-address": "example-ip-address-val-19212", - "port": "example-port-val-57641", - "cloud-domain": "example-cloud-domain-val-26296", - "default-tenant": "example-default-tenant-val-87724" - } - ] - } + vnfm_info_aai = { + "vnfm-id": "example-vnfm-id-val-62576", + "vim-id": "example-vim-id-val-35114", + "certificate-url": "example-certificate-url-val-90242", + "esr-system-info-list": { + "esr-system-info": [ + { + "esr-system-info-id": "example-esr-system-info-id-val-78484", + "system-name": "example-system-name-val-23790", + "type": "example-type-val-52596", + "vendor": "example-vendor-val-47399", + "version": "example-version-val-42051", + "service-url": "example-service-url-val-10731", + "user-name": "example-user-name-val-65946", + "password": "example-password-val-22505", + "system-type": "example-system-type-val-27221", + "protocal": "example-protocal-val-54632", + "ssl-cacert": "example-ssl-cacert-val-45965", + "ssl-insecure": True, + "ip-address": "example-ip-address-val-19212", + "port": "example-port-val-57641", + "cloud-domain": "example-cloud-domain-val-26296", + "default-tenant": "example-default-tenant-val-87724" + } + ] } + } r1 = [0, json.JSONEncoder().encode(vnfm_info_aai), '200'] mock_call_req.side_effect = [r1] esr_system_info = ignore_case_get(ignore_case_get(vnfm_info_aai, "esr-system-info-list"), "esr-system-info") - expect_data = \ - { - "vnfmId": vnfm_info_aai["vnfm-id"], - "name": vnfm_info_aai["vnfm-id"], - "type": ignore_case_get(esr_system_info[0], "type"), - "vimId": vnfm_info_aai["vim-id"], - "vendor": ignore_case_get(esr_system_info[0], "vendor"), - "version": ignore_case_get(esr_system_info[0], "version"), - "description": "vnfm", - "certificateUrl": vnfm_info_aai["certificate-url"], - "url": ignore_case_get(esr_system_info[0], "service-url"), - "userName": ignore_case_get(esr_system_info[0], "user-name"), - "password": ignore_case_get(esr_system_info[0], "password"), - "createTime": "2016-07-06 15:33:18" - } + expect_data = { + "vnfmId": vnfm_info_aai["vnfm-id"], + "name": vnfm_info_aai["vnfm-id"], + "type": ignore_case_get(esr_system_info[0], "type"), + "vimId": vnfm_info_aai["vim-id"], + "vendor": ignore_case_get(esr_system_info[0], "vendor"), + "version": ignore_case_get(esr_system_info[0], "version"), + "description": "vnfm", + "certificateUrl": vnfm_info_aai["certificate-url"], + "url": ignore_case_get(esr_system_info[0], "service-url"), + "userName": ignore_case_get(esr_system_info[0], "user-name"), + "password": ignore_case_get(esr_system_info[0], "password"), + "createTime": "2016-07-06 15:33:18" + } response = self.client.get("/api/nslcm/v1/vnfms/%s" % self.vnfm_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) @@ -518,22 +536,21 @@ class TestGetVimInfoViews(TestCase): r1 = [0, json.JSONEncoder().encode(vim_info_aai), '200'] mock_call_req.side_effect = [r1] esr_system_info = ignore_case_get(ignore_case_get(vim_info_aai, "esr-system-info-list"), "esr-system-info") - expect_data = \ - { - "vimId": self.vim_id, - "name": self.vim_id, - "url": ignore_case_get(esr_system_info[0], "service-url"), - "userName": ignore_case_get(esr_system_info[0], "user-name"), - "password": ignore_case_get(esr_system_info[0], "password"), - # "tenant": ignore_case_get(tenants[0], "tenant-id"), - "tenant": ignore_case_get(esr_system_info[0], "default-tenant"), - "vendor": ignore_case_get(esr_system_info[0], "vendor"), - "version": ignore_case_get(esr_system_info[0], "version"), - "description": "vim", - "domain": "", - "type": ignore_case_get(esr_system_info[0], "type"), - "createTime": "2016-07-18 12:22:53" - } + expect_data = { + "vimId": self.vim_id, + "name": self.vim_id, + "url": ignore_case_get(esr_system_info[0], "service-url"), + "userName": ignore_case_get(esr_system_info[0], "user-name"), + "password": ignore_case_get(esr_system_info[0], "password"), + # "tenant": ignore_case_get(tenants[0], "tenant-id"), + "tenant": ignore_case_get(esr_system_info[0], "default-tenant"), + "vendor": ignore_case_get(esr_system_info[0], "vendor"), + "version": ignore_case_get(esr_system_info[0], "version"), + "description": "vim", + "domain": "", + "type": ignore_case_get(esr_system_info[0], "type"), + "createTime": "2016-07-18 12:22:53" + } response = self.client.get("/api/nslcm/v1/vims/%s" % self.vim_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) diff --git a/lcm/ns/vnfs/create_vnfs.py b/lcm/ns/vnfs/create_vnfs.py index dc633f02..6850ba07 100644 --- a/lcm/ns/vnfs/create_vnfs.py +++ b/lcm/ns/vnfs/create_vnfs.py @@ -20,10 +20,11 @@ from lcm.ns.const import OWNER_TYPE from lcm.ns.vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND, INST_TYPE, INST_TYPE_NAME from lcm.ns.vnfs.wait_job import wait_job_finish +from lcm.pub.config.config import REPORT_TO_AAI from lcm.pub.database.models import NfPackageModel, NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel 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 +from lcm.pub.msapi.aai import create_vnf_aai, create_vserver_aai +from lcm.pub.msapi.extsys import get_vnfm_by_id, split_vim_to_owner_region, get_vim_by_id from lcm.pub.msapi.resmgr import create_vnf, create_vnf_creation_info from lcm.pub.msapi.vnfmdriver import send_nf_init_request from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil, JOB_TYPE @@ -76,7 +77,9 @@ class CreateVnfs(Thread): self.wait_vnfm_job_finish() self.write_vnf_creation_info() self.save_info_to_db() - self.create_vnf_in_aai() + if REPORT_TO_AAI: + self.create_vnf_in_aai() + self.create_vserver_in_aai() except NSLCMException as e: self.vnf_inst_failed_handle(e.message) except Exception: @@ -284,3 +287,33 @@ class CreateVnfs(Thread): logger.debug("Fail to create vnf instance[%s] to aai, resp_status: [%s]." % (self.nf_inst_id, resp_status)) else: logger.debug("Success to create vnf instance[%s] to aai, resp_status: [%s]." % (self.nf_inst_id, resp_status)) + + def create_vserver_in_aai(self): + logger.debug("create_vserver_in_aai start!") + cloud_owner, cloud_region_id = split_vim_to_owner_region(self.vim_id) + + # query vim_info from aai + vim_info = get_vim_by_id(self.vim_id) + tenant_id = vim_info["tenant"] + vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.nf_inst_id) + for vm_inst_info in vm_inst_infos: + vserver_id = vm_inst_info.resouceid + data = { + "vserver-id": vm_inst_info.resouceid, + "vserver-name": vm_inst_info.vmname, + "prov-status": "ACTIVE", + "vserver-selflink": "", + "in-maint": True, + "is-closed-loop-disabled": False + } + + # create vserver instance in aai + resp_data, resp_status = create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data) + if resp_data: + logger.debug( + "Fail to create vserver instance[%s] to aai, resp_status: [%s]." % (vserver_id, resp_status)) + else: + logger.debug( + "Success to create vserver instance[%s] to aai, resp_status: [%s]." % (vserver_id, resp_status)) + + logger.debug("create_vserver_in_aai end!") diff --git a/lcm/ns/vnfs/terminate_nfs.py b/lcm/ns/vnfs/terminate_nfs.py index 9bc0cbbd..fe4ebdf0 100644 --- a/lcm/ns/vnfs/terminate_nfs.py +++ b/lcm/ns/vnfs/terminate_nfs.py @@ -18,6 +18,7 @@ import json import threading from lcm.ns.vnfs.wait_job import wait_job_finish +from lcm.pub.config.config import REPORT_TO_AAI from lcm.pub.database.models import NfInstModel from lcm.ns.vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai @@ -49,7 +50,8 @@ class TerminateVnfs(threading.Thread): self.wait_vnfm_job_finish() self.send_terminate_vnf_to_resMgr() self.delete_data_from_db() - self.delete_vnf_in_aai() + if REPORT_TO_AAI: + self.delete_vnf_in_aai() except NSLCMException as e: self.exception(e.message) except Exception: diff --git a/lcm/pub/config/config.py b/lcm/pub/config/config.py index 278e8a09..fdde894a 100644 --- a/lcm/pub/config/config.py +++ b/lcm/pub/config/config.py @@ -60,6 +60,7 @@ CATALOG_URL_PATH = None AAI_BASE_URL = "https://127.0.0.1:8443/aai/v11" AAI_USER = "AAI" AAI_PASSWD = "AAI" +REPORT_TO_AAI = False # [sdc config] SDC_BASE_URL = "https://127.0.0.1:8443/api/sdc/v1" |