summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py9
-rw-r--r--lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py69
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py7
-rw-r--r--lcm/lcm/nf/vnfs/vnf_query/query_vnf.py2
-rw-r--r--lcm/lcm/pub/database/models.py4
5 files changed, 48 insertions, 43 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
index 2f139e56..748a39c5 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
@@ -11,6 +11,7 @@
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# # See the License for the specific language governing permissions and
# # limitations under the License.
+import json
import uuid
import mock
@@ -20,6 +21,7 @@ from rest_framework import status
from lcm.nf.vnfs.vnf_cancel.term_vnf import TermVnf
from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \
PortInstModel, NfvoRegInfoModel
+from lcm.pub.utils import restcall
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
@@ -90,12 +92,15 @@ class TestNFTerminate(TestCase):
self.assert_job_result(self.job_id, 255, "VnfInst(%s) does not exist" % self.nf_inst_id)
-
- def test_terminate_vnf_success(self):
+ @mock.patch.object(restcall, 'call_req')
+ def test_terminate_vnf_success(self, mock_call_req):
NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='',
netype='', vnfd_model='', status='VNF_INSTANTIATED', nf_desc='', vnfdid='',
vnfSoftwareVersion='', vnfConfigurableProperties='todo',
localizationLanguage='EN_US', create_time=now_time())
+ t1_apply_grant_result = [0, json.JSONEncoder().encode(
+ {"vim": {"vimid": 'vimid_1', "accessinfo": {"tenant": 'tenantname_1'}}}), '200']
+ mock_call_req.side_effect = [t1_apply_grant_result]
data = {"terminationType": "FORCEFUL",
"gracefulTerminationTimeout": 120}
self.nf_inst_id = '1111'
diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
index 4b83fa02..5172abc4 100644
--- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
@@ -17,10 +17,11 @@ from threading import Thread
from lcm.nf.vnfs.const import VNF_STATUS
from lcm.pub.database.models import JobStatusModel, NfInstModel, VmInstModel, NetworkInstModel, StorageInstModel, \
- FlavourInstModel, PortInstModel, SubNetworkInstModel, NfvoRegInfoModel
+ FlavourInstModel, PortInstModel, SubNetworkInstModel, NfvoRegInfoModel, VNFCInstModel
from lcm.pub.exceptions import NFLCMException
from lcm.pub.msapi.nfvolcm import apply_grant_to_nfvo
from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
@@ -45,19 +46,21 @@ class TermVnf(Thread):
def run(self):
try:
self.term_pre()
- # self.query_inst_resource(self.nf_inst_id)
- # self.grant_resource()
+ self.grant_resource()
+ # self.query_inst_resource()
JobUtil.add_job_status(self.job_id, 100, "Terminate Vnf success.")
is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists()
logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist)
except NFLCMException as e:
- logger.error('VNF instantiation failed, detail message: %s' % e.message)
- # NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time())
- JobUtil.add_job_status(self.job_id, 255, e.message)
- # self.vnf_term_failed_handle(e.message)
+ self.vnf_inst_failed_handle(e.message)
except:
- # self.vnf_term_failed_handle('unexpected exception')
logger.error(traceback.format_exc())
+ self.vnf_inst_failed_handle(traceback.format_exc())
+
+ def vnf_inst_failed_handle(self, error_msg):
+ logger.error('VNF termination failed, detail message: %s' % error_msg)
+ NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time())
+ JobUtil.add_job_status(self.job_id, 255, error_msg)
def term_pre(self):
vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
@@ -73,11 +76,10 @@ class TermVnf(Thread):
JobUtil.add_job_status(self.job_id, 10, 'Nf terminating pre-check finish')
logger.info("Nf terminating pre-check finish")
- def query_inst_resource(self, inst_id):
- logger.info('[query_resource begin]:inst_id=%s' % inst_id)
+ def query_inst_resource(self):
+ logger.info('[query_resource begin]:inst_id=%s' % self.nf_inst_id)
# query_volumn_resource
- vol_list = StorageInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ vol_list = StorageInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for vol in vol_list:
vol_info = {}
if not vol.resouceid:
@@ -88,8 +90,7 @@ class TermVnf(Thread):
logger.info('[query_volumn_resource]:ret_volumns=%s' % self.inst_resource['volumn'])
# query_network_resource
- network_list = NetworkInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ network_list = NetworkInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for network in network_list:
network_info = {}
if not network.resouceid:
@@ -100,8 +101,7 @@ class TermVnf(Thread):
logger.info('[query_network_resource]:ret_networks=%s' % self.inst_resource['network'])
# query_subnetwork_resource
- subnetwork_list = SubNetworkInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ subnetwork_list = SubNetworkInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for subnetwork in subnetwork_list:
subnetwork_info = {}
if not subnetwork.resouceid:
@@ -112,8 +112,7 @@ class TermVnf(Thread):
logger.info('[query_subnetwork_resource]:ret_networks=%s' % self.inst_resource['subnet'])
# query_port_resource
- port_list = PortInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ port_list = PortInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for port in port_list:
port_info = {}
if not port.resouceid:
@@ -124,8 +123,7 @@ class TermVnf(Thread):
logger.info('[query_port_resource]:ret_networks=%s' % self.inst_resource['port'])
# query_flavor_resource
- flavor_list = FlavourInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ flavor_list = FlavourInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for flavor in flavor_list:
flavor_info = {}
if not flavor.resouceid:
@@ -136,8 +134,7 @@ class TermVnf(Thread):
logger.info('[query_flavor_resource]:ret_networks=%s' % self.inst_resource['flavor'])
# query_vm_resource
- vm_list = VmInstModel.objects.filter(instid=inst_id,
- is_predefined=1)
+ vm_list = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
for vm in vm_list:
vm_info = {}
if not vm.resouceid:
@@ -149,21 +146,23 @@ class TermVnf(Thread):
def grant_resource(self):
logger.info("nf_cancel_task grant_resource begin")
- JobUtil.add_job_status(self.job_id, 30, 'nf_cancel_task grant_resource')
- reg_info = NfvoRegInfoModel.objects.filter(vnfminstid=self.vnfm_inst_id).first()
- nf_info = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id).first()
- content_args = {'nfvoInstanceId': reg_info.nfvoid, 'vnfmInstanceId': self.vnfm_inst_id,
- 'nfInstanceId': self.vnf_inst_id, 'nfDescriptorId': nf_info.vnf_id,
- 'lifecycleOperation': 'Terminal', 'jobId': '', 'addResource': [],
- 'removeResource': [], 'placementConstraint': [], 'exVimIdList': [], 'additionalParam': {}}
-
- content_args['removeResource'] = self.get_grant_data()
+ content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '',
+ 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id,
+ 'addResource': [], 'removeResource': [],
+ 'placementConstraint': [], 'additionalParam': {}}
+
+ vdus = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
+ res_index = 1
+ for vdu in vdus:
+ res_def = {'type': 'VDU',
+ 'resDefId': str(res_index),
+ 'resDesId': vdu.resouceid}
+ content_args['removeResource'].append(res_def)
+ res_index += 1
logger.info('content_args=%s' % content_args)
- rsp = apply_grant_to_nfvo(content_args)
- logger.info("nf_cancel_task grant_resource rsp: %s" % rsp)
- if rsp[0] != 0:
- logger.error("nf_cancel_task grant_resource failed.[%s]" % str(rsp[1]))
+ self.apply_result = apply_grant_to_nfvo(content_args)
+ vim_info = ignore_case_get(self.apply_result, "vim")
logger.info("nf_cancel_task grant_resource end")
# def load_nfvo_config(self):
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index b04cf04e..9760381c 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -62,7 +62,6 @@ class InstVnf(Thread):
# self.rollback(e.message)
except:
self.vnf_inst_failed_handle('unexpected exception')
- tt= traceback.format_exc()
logger.error(traceback.format_exc())
# self.rollback('unexpected exception')
@@ -150,7 +149,7 @@ class InstVnf(Thread):
def lcm_notify(self):
logger.info('[NF instantiation] send notify request to nfvo start')
affected_vnfc = []
- vnfcs = VNFCInstModel.objects.filter(nfinstid=self.nf_inst_id)
+ vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id)
for vnfc in vnfcs:
vmResource = {}
if vnfc.vmid:
@@ -374,8 +373,8 @@ class InstVnf(Thread):
VNFCInstModel.objects.create(
vnfcinstanceid=str(uuid.uuid4()),
vduid=ignore_case_get(ret, "id"),
- # vdutype='AAA',
- nfinstid=self.nf_inst_id,
+ is_predefined=ignore_case_get(ret, "returnCode"),
+ instid=self.nf_inst_id,
vmid=vm_id)
# def do_rollback(self, args_=None):
diff --git a/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py b/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py
index 7f4dc8da..3ef1a8d7 100644
--- a/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_query/query_vnf.py
@@ -72,7 +72,7 @@ class QueryVnf:
}
vl_arr.append(v_dic)
logger.info('Get VNFCInstModel of list.')
- vnfc_insts = VNFCInstModel.objects.filter(nfinstid=vnf.nfinstid)
+ vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
vnfc_arr = []
for vnfc in vnfc_insts:
vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index ec0c25da..e01e11f0 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -136,6 +136,7 @@ class VmInstModel(models.Model):
is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
instid = models.CharField(db_column='INSTID', max_length=255)
+ nodeId = models.CharField(db_column='NODEID', max_length=255, null=True)
class VNFCInstModel(models.Model):
class Meta:
@@ -144,8 +145,9 @@ class VNFCInstModel(models.Model):
vnfcinstanceid = models.CharField(db_column='VNFCINSTANCEID', max_length=255, primary_key=True)
vduid = models.CharField(db_column='VDUID', max_length=255)
vdutype = models.CharField(db_column='VDUTYPE', max_length=255)
- nfinstid = models.CharField(db_column='NFINSTID', max_length=255)
+ instid = models.CharField(db_column='NFINSTID', max_length=255)
vmid = models.CharField(db_column='VMID', max_length=255)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
class FlavourInstModel(models.Model):
class Meta: