summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
Diffstat (limited to 'lcm')
-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")