diff options
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py | 5 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 5 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py | 27 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py | 11 | ||||
-rw-r--r-- | lcm/lcm/pub/aaiapi/aai.py | 2 |
5 files changed, 38 insertions, 12 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py index 53936b0f..8cdfb7f2 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py @@ -56,11 +56,14 @@ class TestNFTerminate(TestCase): descp=job_detail) self.assertEqual(1, len(jobs)) - def test_delete_vnf_identifier(self): + @mock.patch.object(restcall, 'call_req_aai') + def test_delete_vnf_identifier(self, mock_call_req_aai): NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='', vnfdid='', vnfSoftwareVersion='', vnfConfigurableProperties='todo', localizationLanguage='EN_US', create_time=now_time()) + r1_create_vnf_to_aai = [0, json.JSONEncoder().encode({}), '200'] + mock_call_req_aai.side_effect = [r1_create_vnf_to_aai] response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111") self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertEqual(None, response.data) diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index ad94fb60..d4d5d77c 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -48,12 +48,15 @@ class TestNFInstantiate(TestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) @mock.patch.object(restcall, 'call_req') - def test_create_vnf_identifier(self, mock_call_req): + @mock.patch.object(restcall, 'call_req_aai') + def test_create_vnf_identifier(self, mock_call_req_aai, mock_call_req): r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode({'csars':[{'package_id': '222', 'csarId': '2222', 'vnfdId': '111'}]}), '200'] r2_get_rawdata_from_catalog = [0, json.JSONEncoder().encode(vnfd_rawdata), '200'] + r3_create_vnf_to_aai = [0, json.JSONEncoder().encode({}), '200'] mock_call_req.side_effect = [r1_get_csarid_by_vnfdid, r2_get_rawdata_from_catalog] + mock_call_req_aai.side_effect = [r3_create_vnf_to_aai] data = { "vnfdId": "111", "vnfInstanceName": "vFW_01", diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py index 1eedb543..91d92089 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py @@ -13,7 +13,9 @@ # limitations under the License. import logging +from lcm.pub.aaiapi.aai import delete_vnf from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel +from lcm.pub.exceptions import NFLCMException logger = logging.getLogger(__name__) @@ -24,12 +26,19 @@ class DeleteVnf: self.nf_inst_id = instanceid def do_biz(self): - vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) - if not vnf_insts.exists(): - logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id) - return - #sel_vnf = vnf_insts[0] - #if sel_vnf.status != 'NOT_INSTANTIATED': - # raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) - NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete() - NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete() + try: + vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) + if not vnf_insts.exists(): + logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id) + return + #sel_vnf = vnf_insts[0] + #if sel_vnf.status != 'NOT_INSTANTIATED': + # raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) + NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete() + NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete() + + delete_vnf(self.nf_inst_id) + except NFLCMException as e: + logger.debug('Delete VNF instance[%s] from AAI failed' % self.nf_inst_id) + except: + logger.debug('Delete VNF instance[%s] failed' % self.nf_inst_id) diff --git a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py index 09170d5a..a91c8d02 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py @@ -15,6 +15,7 @@ import json import logging import uuid +from lcm.pub.aaiapi.aai import create_vnf from lcm.pub.database.models import NfInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.msapi.catalog import query_rawdata_from_catalog @@ -66,6 +67,16 @@ class CreateVnf: version=version, vendor=vendor, netype=netype, vnfd_model=vnfd_model, status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, vnfSoftwareVersion=vnfsoftwareversion, create_time=now_time()) + data = { + "vnf-id": nf_inst_id, + "vnf-name": self.vnf_instance_mame, + "vnf-type": "INFRA", + "in-maint": "true", + "is-closed-loop-disabled": "false" + } + create_vnf(nf_inst_id, data) + except NFLCMException as e: + logger.debug('Create VNF instance[%s] to AAI failed' % nf_inst_id) except: NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id='', version='', vendor='', netype='', vnfd_model='', diff --git a/lcm/lcm/pub/aaiapi/aai.py b/lcm/lcm/pub/aaiapi/aai.py index e8b42fa2..f45b099c 100644 --- a/lcm/lcm/pub/aaiapi/aai.py +++ b/lcm/lcm/pub/aaiapi/aai.py @@ -66,7 +66,7 @@ def create_vnf(vnf_id, data): raise NFLCMException("Vnf instance creation exception in AAI")
return json.JSONDecoder().decode(ret[1])
-def delete_vnf(vnf_id, data):
+def delete_vnf(vnf_id, data=[]):
resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
ret = call_aai(resource, "DELETE", data)
# ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)
|