def test_heal_ns_heal_non_existing_ns(self, mock_start): mock_start.side_effect = NSLCMException("NS Not Found") ns_inst_id = "2" data = HEAL_NS_DICT.copy() data["healNsData"]["vnfInstanceId"] = self.nf_inst_id response = self.client.post(self.url % ns_inst_id, data=data) self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_heal_ns_url(self, mock_run): data = HEAL_NS_DICT.copy() data["healNsData"]["vnfInstanceId"] = self.nf_inst_id response = self.client.post(self.url % self.ns_inst_id, data=data) self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data) self.assertIsNotNone(response['Location']) response = self.client.get(response['Location'], format='json') self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_heal_ns_thread(self, mock_get, mock_sleep, mock_run): mock_run.return_value = None mock_sleep.return_value = None mock_get.return_value = JobModel(progress=JOB_PROGRESS.FINISHED) heal_ns_json = HEAL_NS_DICT.copy() heal_ns_json['healNsData']['vnfInstanceId'] = self.nf_inst_id NSHealService(self.ns_inst_id, heal_ns_json, self.job_id).run() self.assertEqual( NSInstModel.objects.get(id=self.ns_inst_id).status, NS_INST_STATUS.ACTIVE)
def test_heal_ns_heal_non_existing_ns(self, mock_start): mock_start.side_effect = NSLCMException('NS Not Found') ns_inst_id = '2' heal_ns_json = HEAL_NS_DICT.copy() heal_ns_json['healNsData']['vnfInstanceId'] = self.nf_inst_id response = self.client.post('/api/nslcm/v1/ns/%s/heal' % ns_inst_id, data=heal_ns_json, format='json') self.assertEqual(response.data['error'], 'NS Not Found') self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) self.assertIn('error', response.data)
def test_heal_ns_url(self, mock_run): heal_ns_json = HEAL_NS_DICT.copy() heal_ns_json['healNsData']['vnfInstanceId'] = self.nf_inst_id response = self.client.post('/api/nslcm/v1/ns/%s/heal' % self.ns_inst_id, data=heal_ns_json, format='json') self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data) self.assertIsNotNone(response.data) self.assertIn('jobId', response.data) self.assertNotIn('error', response.data) response = self.client.delete('/api/nslcm/v1/ns/%s' % self.ns_inst_id) self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
def test_heal_ns_thread_when_nf_heal_failed(self, mock_get, mock_sleep, mock_run): mock_run.return_value = None mock_sleep.return_value = None mock_get.return_value = JobModel(progress=JOB_PROGRESS.ERROR) heal_ns_json = HEAL_NS_DICT.copy() heal_ns_json['healNsData']['vnfInstanceId'] = self.nf_inst_id ns_heal_service = NSHealService(self.ns_inst_id, heal_ns_json, self.job_id) ns_heal_service.run() self.assertEqual( JobModel.objects.filter(jobid=self.job_id).first().progress, JOB_PROGRESS.ERROR) self.assertEqual( NSLcmOpOccModel.objects.filter( id=ns_heal_service.occ_id).first().operation_state, 'FAILED')
def test_heal_ns_thread_when_nsinsts_does_not_exist(self): NSInstModel(id='text_nsinsts_does_not_exist', name='ns_name', status='null').save() heal_ns_json = HEAL_NS_DICT.copy() heal_ns_json['healNsData'][ 'vnfInstanceId'] = 'text_nsinsts_does_not_exist' job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.HEAL, 'text_nsinsts_does_not_exist') ns_heal_service = NSHealService('text_nsinsts_does_not_exist', heal_ns_json, job_id) ns_heal_service.run() self.assertEqual( JobModel.objects.filter(jobid=job_id).first().progress, JOB_PROGRESS.ERROR) self.assertEqual( NSLcmOpOccModel.objects.filter( id=ns_heal_service.occ_id).first().operation_state, 'FAILED')