def test_ns_manual_scale_asynchronous_tasks_success(
         self, mock_get, mock_sleep, mock_run, mock_vnf_data_info_list):
     mock_run.return_value = None
     mock_sleep.return_value = None
     mock_get.return_value = JobModel(progress=JOB_PROGRESS.FINISHED)
     mock_vnf_data_info_list.return_value = [{
         "vnfd_id": "nf_001",
         "vnf_scaleAspectId": "gpu",
         "numberOfSteps": "123"
     }, {
         "vnfd_id": "nf_002",
         "vnf_scaleAspectId": "gpu",
         "numberOfSteps": "456"
     }]
     scale_ns_json = SCALE_NS_THREAD_DICT.copy()
     ns_heal_service = NSManualScaleService(self.ns_inst_id, scale_ns_json,
                                            self.job_id)
     ns_heal_service.run()
     jobs = JobModel.objects.filter(jobid=self.job_id)
     self.assertEqual(
         NSInstModel.objects.get(id=self.ns_inst_id).status,
         NS_INST_STATUS.ACTIVE)
     self.assertEqual(JOB_PROGRESS.FINISHED, jobs[0].progress)
     self.assertEqual(
         NSLcmOpOccModel.objects.filter(
             id=ns_heal_service.occ_id).first().operation_state,
         'COMPLETED')
 def test_ns_manual_scale_asynchronous_tasks_when_error_scale_type(self):
     scale_ns_json = SCALE_NS_THREAD_DICT.copy()
     scale_ns_json['scaleType'] = 'SCALE_ERR'
     ns_heal_service = NSManualScaleService(self.ns_inst_id, scale_ns_json,
                                            self.job_id)
     ns_heal_service.run()
     jobs = JobModel.objects.filter(jobid=self.job_id)
     self.assertEqual(
         NSInstModel.objects.get(id=self.ns_inst_id).status,
         NS_INST_STATUS.ACTIVE)
     self.assertEqual(JOB_PROGRESS.ERROR, jobs[0].progress)
     self.assertEqual(
         NSLcmOpOccModel.objects.filter(
             id=ns_heal_service.occ_id).first().operation_state, 'FAILED')
 def test_ns_manual_scale_asynchronous_tasks_when_failed_to_get_scale_vnf_data_parameter(
         self, mock_vnf_data_info):
     mock_vnf_data_info.return_value = []
     scale_ns_json = SCALE_NS_THREAD_DICT.copy()
     ns_heal_service = NSManualScaleService(self.ns_inst_id, scale_ns_json,
                                            self.job_id)
     ns_heal_service.run()
     jobs = JobModel.objects.filter(jobid=self.job_id)
     self.assertEqual(
         NSInstModel.objects.get(id=self.ns_inst_id).status,
         NS_INST_STATUS.ACTIVE)
     self.assertEqual(JOB_PROGRESS.ERROR, jobs[0].progress)
     self.assertEqual(
         NSLcmOpOccModel.objects.filter(
             id=ns_heal_service.occ_id).first().operation_state, 'FAILED')
 def test_ns_manual_scale_asynchronous_tasks_when_scale_ns_by_steps_data_is_none(
         self):
     scale_ns_json = copy.deepcopy(SCALE_NS_THREAD_DICT)
     scale_ns_json['scaleNsData']["scaleNsByStepsData"] = None
     ns_heal_service = NSManualScaleService(self.ns_inst_id, scale_ns_json,
                                            self.job_id)
     ns_heal_service.run()
     jobs = JobModel.objects.filter(jobid=self.job_id)
     self.assertEqual(
         NSInstModel.objects.get(id=self.ns_inst_id).status,
         NS_INST_STATUS.ACTIVE)
     self.assertEqual(JOB_PROGRESS.ERROR, jobs[0].progress)
     self.assertEqual(
         NSLcmOpOccModel.objects.filter(
             id=ns_heal_service.occ_id).first().operation_state, 'FAILED')
Exemple #5
0
    def post(self, request, ns_instance_id):
        logger.debug("Enter ScaleNSView::post %s, %s", request.data,
                     ns_instance_id)

        req_serializer = ScaleNsRequestSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.MANUAL_SCALE,
                                    ns_instance_id)

        nsManualScaleService = NSManualScaleService(ns_instance_id,
                                                    request.data, job_id)
        nsManualScaleService.start()
        response = Response(data={}, status=status.HTTP_202_ACCEPTED)
        logger.debug("Location: %s" % nsManualScaleService.occ_id)
        response["Location"] = NS_OCC_BASE_URI % nsManualScaleService.occ_id
        logger.debug("Leave ScaleNSView")
        return response
    def post(self, request, ns_instance_id):
        logger.debug("Enter NSManualScaleView::post %s, %s", request.data,
                     ns_instance_id)
        req_serializer = _ManualScaleNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        req = request.data
        scale_data = {}
        scale_data['scaleType'] = req['scaleType']
        scaleNsData = req['scaleNsData'][0]
        scale_data['scaleNsData'] = {
            "scaleNsByStepsData": scaleNsData['scaleNsByStepsData'][0]
        }
        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.MANUAL_SCALE,
                                    ns_instance_id)
        NSManualScaleService(ns_instance_id, scale_data, job_id).start()

        resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id})
        if not resp_serializer.is_valid():
            raise NSLCMException(resp_serializer.errors)

        return Response(data={'jobId': job_id},
                        status=status.HTTP_202_ACCEPTED)