From: fujinhua Date: Thu, 11 Apr 2019 04:03:13 +0000 (+0800) Subject: Add ut cases for update vnf X-Git-Tag: 1.3.0~52 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vfc%2Fgvnfm%2Fvnflcm.git;a=commitdiff_plain;h=b92d2628810369f70705737e12100ac246b7278a Add ut cases for update vnf Change-Id: I830453076392fe5dc33b3c61d2709ffea2283b0c Issue-ID: VFC-1306 Signed-off-by: fujinhua --- diff --git a/lcm/lcm/nf/biz/update_vnf.py b/lcm/lcm/nf/biz/update_vnf.py index 0721c5d9..311c24aa 100644 --- a/lcm/lcm/nf/biz/update_vnf.py +++ b/lcm/lcm/nf/biz/update_vnf.py @@ -12,13 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import traceback from threading import Thread from lcm.pub.database.models import NfInstModel +from lcm.pub.exceptions import NFLCMException from lcm.nf.const import OPERATION_STATE_TYPE from lcm.nf.const import OPERATION_TYPE from lcm.pub.utils.notificationsutil import NotificationsUtil from lcm.pub.utils.notificationsutil import prepare_notification +from lcm.pub.utils.jobutil import JobUtil from lcm.pub.utils.timeutil import now_time logger = logging.getLogger(__name__) @@ -34,19 +37,34 @@ class UpdateVnf(Thread): def run(self): logger.debug("start update for vnf %s", self.nf_inst_id) key = "vnfInstanceName" - if key in self.data and self.data[key] is not None: - self.vnf_insts.update(nf_name=self.data[key], - lastuptime=now_time()) - - key = "vnfInstanceDescription" - if key in self.data and self.data[key] is not None: - self.vnf_insts.update(nf_desc=self.data[key], - lastuptime=now_time()) - - key = "vnfPkgId" - if key in self.data: - self.vnf_insts.update(vnfdid=self.data[key], - lastuptime=now_time()) + try: + JobUtil.add_job_status(self.job_id, 50, "Start updating VNF.") + + if key in self.data and self.data[key] is not None: + self.vnf_insts.update(nf_name=self.data[key], + lastuptime=now_time()) + + key = "vnfInstanceDescription" + if key in self.data and self.data[key] is not None: + self.vnf_insts.update(nf_desc=self.data[key], + lastuptime=now_time()) + + key = "vnfPkgId" + if key in self.data: + self.vnf_insts.update(vnfdid=self.data[key], + lastuptime=now_time()) + + JobUtil.add_job_status(self.job_id, 75, "Start sending notification.") + self.send_notification() + + JobUtil.add_job_status(self.job_id, 100, "Update VNF success.") + except NFLCMException as e: + logger.error(e.message) + JobUtil.add_job_status(self.job_id, 255, e.message) + except Exception as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + JobUtil.add_job_status(self.job_id, 255, e.message) def send_notification(self): notify_data = prepare_notification(nfinstid=self.nf_inst_id, diff --git a/lcm/lcm/nf/tests/test_update_vnf.py b/lcm/lcm/nf/tests/test_update_vnf.py index 865dfafd..484885a1 100644 --- a/lcm/lcm/nf/tests/test_update_vnf.py +++ b/lcm/lcm/nf/tests/test_update_vnf.py @@ -12,10 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import mock from django.test import TestCase from rest_framework.test import APIClient from rest_framework import status +from lcm.pub.utils import restcall +from lcm.pub.database.models import NfInstModel +from lcm.pub.utils.jobutil import JobUtil +from lcm.nf.biz.update_vnf import UpdateVnf + class TestNFUpdate(TestCase): def setUp(self): @@ -33,3 +39,22 @@ class TestNFUpdate(TestCase): data=self.upd_data, format='json') self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code) + + @mock.patch.object(restcall, 'call_req') + def test_update_vnf_success(self, mock_call_req): + instanceid = "12" + NfInstModel(nfinstid=instanceid, + nf_name='VNF1', + nf_desc="VNF DESC", + vnfdid="1", + netype="XGW", + vendor="ZTE", + vnfSoftwareVersion="V1", + version="V1", + package_id="2", + status='INSTANTIATED').save() + mock_call_req.return_value = [0, {}, status.HTTP_202_ACCEPTED] + job_id = JobUtil.create_job('NF', 'UPDATETEST', instanceid) + UpdateVnf(self.upd_data, instanceid, job_id).run() + name = NfInstModel.objects.filter(nfinstid=instanceid).get().nf_name + self.failUnlessEqual("vnf new name", name)