summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-11 14:40:00 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-11 14:40:00 +0800
commitfd8aa2a4eec4a6d8e7775b5bd63454694c3ff0a4 (patch)
tree7fc9cfe877ab32e2692a7772d5d26dee2563d308
parenta759abc3e8fe796f2e2137862583fdd6aa0e3e8b (diff)
Add ut cases for heal vnf
Change-Id: I8cded9c137443c80a9f224262a1d3635561cc3a1 Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/lcm/nf/tests/test_heal_vnf.py10
-rw-r--r--lcm/lcm/nf/views/heal_vnf_view.py7
2 files changed, 16 insertions, 1 deletions
diff --git a/lcm/lcm/nf/tests/test_heal_vnf.py b/lcm/lcm/nf/tests/test_heal_vnf.py
index 17f3e5e8..14743b2e 100644
--- a/lcm/lcm/nf/tests/test_heal_vnf.py
+++ b/lcm/lcm/nf/tests/test_heal_vnf.py
@@ -54,6 +54,16 @@ class TestNFInstantiate(TestCase):
response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)
+ def test_heal_vnf_conflict(self):
+ req_data = {}
+ NfInstModel(
+ nfinstid='1267',
+ nf_name='VNF1',
+ status='NOT_INSTANTIATED').save()
+ response = self.client.post("/api/vnflcm/v1/vnf_instances/1267/heal", data=req_data, format='json')
+ self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)
+ NfInstModel.objects.filter(nfinstid='1267').delete()
+
@mock.patch.object(HealVnf, 'run')
def test_heal_vnf_success(self, mock_run):
req_data = {}
diff --git a/lcm/lcm/nf/views/heal_vnf_view.py b/lcm/lcm/nf/views/heal_vnf_view.py
index 4fe3f847..24b33e34 100644
--- a/lcm/lcm/nf/views/heal_vnf_view.py
+++ b/lcm/lcm/nf/views/heal_vnf_view.py
@@ -22,7 +22,9 @@ from rest_framework.views import APIView
from lcm.nf.biz.heal_vnf import HealVnf
from lcm.nf.serializers.heal_vnf_req import HealVnfRequestSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMExceptionConflict
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.database.models import NfInstModel
from lcm.nf.const import VNF_STATUS
@@ -63,6 +65,9 @@ class HealVnfView(APIView):
if not vnf_insts.exists():
raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
+ if vnf_insts[0].status != 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
NfInstModel.objects.filter(nfinstid=nf_inst_id).update(status=VNF_STATUS.HEALING)
JobUtil.add_job_status(job_id, 15, 'Nf healing pre-check finish')
logger.info("Nf healing pre-check finish")