Exemplo n.º 1
0
 def setUp(self):
     self.client = APIClient()
     NfInstModel(nfinstid='12345',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='NOT_INSTANTIATED').save()
     NfInstModel(nfinstid='345',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='INSTANTIATED').save()
     self.req_data = {
         "newFlavourId": "myFlavour_new"
     }
 def setUp(self):
     self.client = Client()
     FPInstModel.objects.all().delete()
     NfInstModel.objects.all().delete()
     VNFCInstModel.objects.all().delete()
     NfInstModel(nfinstid="vnf_inst_1",
                 ns_inst_id="ns_inst_1",
                 vnf_id="vnf_1",
                 vnfd_model=json.dumps(vnfd_model_dict1)).save()
     NfInstModel(nfinstid="vnf_inst_2",
                 vnf_id="vnf_2",
                 ns_inst_id="ns_inst_1",
                 vnfd_model=json.dumps(vnfd_model_dict2)).save()
     VNFCInstModel(nfinstid="vnf_inst_1",
                   vnfcinstanceid="vnfc_instance_id_1").save()
     VNFCInstModel(nfinstid="vnf_inst_2",
                   vnfcinstanceid="vnfc_instance_id_2").save()
     CPInstModel(cpinstanceid="cp_instance_id_1",
                 cpdid="cpd_1",
                 cpinstancename="cpinstancename_1",
                 ownertype=3,
                 ownerid="vnfc_instance_id_1",
                 relatedtype=1,
                 relatedvl="relatedvl_1",
                 relatedcp="relatedcp_1",
                 relatedport="relatedport_1",
                 status="ACTIVE").save()
     CPInstModel(cpinstanceid="cp_instance_id_2",
                 cpdid="cpd_2",
                 cpinstancename="cpinstancename_2",
                 ownertype=3,
                 ownerid="vnfc_instance_id_2",
                 relatedtype=1,
                 relatedvl="relatedvl_2",
                 relatedcp="relatedcp_2",
                 relatedport="relatedport_2",
                 status="ACTIVE").save()
     PortInstModel(portid="relatedport_1").save()
     PortInstModel(portid="relatedport_2").save()
     FPInstModel(fpid="fpd_1",
                 fpinstid="fp_inst_1",
                 nsinstid="ns_inst_1",
                 vnffginstid="vnffg_inst_1",
                 policyinfo=[{
                     "type": "ACL",
                     "criteria": {
                         "dest_port_range": [80, 1024],
                         "source_port_range": [80, 1024],
                         "ip_protocol": "tcp",
                         "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
                         "source_ip_range":
                         ["192.168.1.2", "192.168.1.100"],
                         "dscp": 100,
                     }
                 }],
                 status="enabled",
                 sdncontrollerid="sdn_controller_1").save()
Exemplo n.º 3
0
 def test_operate_vnf_conflict(self):
     req_data = {"changeStateTo": "STARTED"}
     NfInstModel(nfinstid='12', nf_name='VNF1',
                 status='NOT_INSTANTIATED').save()
     response = self.client.post("/api/vnflcm/v1/vnf_instances/12/operate",
                                 data=req_data,
                                 format='json')
     self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
     NfInstModel(nfinstid='12', nf_name='VNF1',
                 status='NOT_INSTANTIATED').delete()
Exemplo n.º 4
0
 def test_operate_vnf_success(self, mock_run):
     req_data = {"changeStateTo": "STARTED"}
     NfInstModel(nfinstid='12', nf_name='VNF1',
                 status='INSTANTIATED').save()
     response = self.client.post("/api/vnflcm/v1/vnf_instances/12/operate",
                                 data=req_data,
                                 format='json')
     mock_run.re.return_value = None
     self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
     NfInstModel(nfinstid='12', nf_name='VNF1',
                 status='INSTANTIATED').delete()
Exemplo n.º 5
0
 def test_update_vnf_etag_match(self, mock_run):
     instanceid = "18"
     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()
     resp = self.client.get("/api/vnflcm/v1/vnf_instances/18",
                            format='json')
     etag = resp["ETag"]
     response = self.rc.patch(
         "http://localhost:8801/api/vnflcm/v1/vnf_instances/18",
         json=self.upd_data,
         headers={
             "Accept": "application/json",
             "Content-Type": "application/json",
             "If-Match": etag
         })
     NfInstModel.objects.filter(nfinstid=instanceid).delete()
     self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
Exemplo n.º 6
0
 def test_heal_vnf_success(self, mock_run):
     req_data = {}
     NfInstModel(nfinstid='12',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='INSTANTIATED').save()
     response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')
     mock_run.re.return_value = None
     self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
     NfInstModel(nfinstid='12').delete()
Exemplo n.º 7
0
 def test_delete_pending_csar_when_in_using(self, mock_call_req):
     mock_call_req.return_value = [0, json.JSONEncoder().encode({
         "processState": "normal"}), "200"]
     NfPackageModel(uuid="01", nfpackageid="1").save()
     NfInstModel(nfinstid="01", package_id="1").save()
     NfPkgDeletePendingThread(csar_id="1", job_id='2').run()
     self.assert_job_result("2", 100, "CSAR(1) is in using, cannot be deleted.")
Exemplo n.º 8
0
 def test_get_scale_vnf_data_info_list(self, mock_abspath):
     NSInstModel(id='ns_instanceId_02', nsd_id='02').save()
     NfInstModel(package_id='nf_hw_cscf',
                 status=VNF_STATUS.ACTIVE,
                 nfinstid='nfinst_01').save()
     mock_abspath.return_value = 'lcm/1/2/3.py'
     scale_ns_data = {
         'scaleNsByStepsData': {
             'aspectId': 'TIC_EDGE_HW',
             'numberOfSteps': 4,
             'scalingDirection': 'r'
         }
     }
     ns_instance_id = 'ns_instanceId_02'
     scale_vnf_data_info_list = get_scale_vnf_data_info_list(
         scale_ns_data, ns_instance_id)
     success_list = [{
         'vnfInstanceId': 'nfinst_01',
         'scaleByStepData': {
             'type': 'r',
             'aspectId': 'gsu',
             'numberOfSteps': '1'
         }
     }]
     self.assertEqual(scale_vnf_data_info_list, success_list)
Exemplo n.º 9
0
    def test_ns_terminate_asynchronous_tasks_when_no_new_progress(
            self, mock_request, mock_sleep):
        ns_instance_id = 'test_ns_terminate_when_no_new_progress'
        NSInstModel(id=ns_instance_id).save()
        NfInstModel(ns_inst_id=ns_instance_id).save()
        mock_request.side_effect = [
            ({
                'status': '200'
            }, '{"jobId": "zzz"}'.encode('utf-8')),
            ({
                'status': '200'
            }, '{}'.encode('utf-8')),
            ({
                'status': '200'
            }, '{"responseDescriptor": {"progress": 100, "responseId": 1, '
             '"statusDescription": ""}}'.encode('utf-8'))
        ]
        mock_sleep.return_value = None

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE,
                                    ns_instance_id)
        TerminateNsService(ns_instance_id, job_id, TERMINATE_NS_DICT).run()
        self.assertEqual(
            JobModel.objects.filter(jobid=job_id).first().progress,
            JOB_PROGRESS.FINISHED)
Exemplo n.º 10
0
    def save_vnf_inst_data(self):
        NfInstModel(
            nfinstid="vnf_inst_1",
            ns_inst_id="ns_inst_1",
            vnf_id="vnf_1",
            vnfd_model=json.dumps(vnfd_model_dict1)

        ).save()

        NfInstModel(
            nfinstid="vnf_inst_2",
            vnf_id="vnf_2",
            ns_inst_id="ns_inst_1",
            vnfd_model=json.dumps(vnfd_model_dict2)

        ).save()
Exemplo n.º 11
0
 def setUp(self):
     self.scaling_map_json = SCALING_MAP_DICT
     self.ns_inst_id = str(uuid.uuid4())
     self.job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.MANUAL_SCALE,
                                      self.ns_inst_id)
     self.client = APIClient()
     self.package_id = '7'
     NSInstModel(id=self.ns_inst_id,
                 name='abc',
                 nspackage_id=self.package_id,
                 nsd_id='test_ns_manual_scale').save()
     NfInstModel(package_id='nf_001',
                 status=VNF_STATUS.ACTIVE,
                 nfinstid='nf_001').save()
     NfInstModel(package_id='nf_002',
                 status=VNF_STATUS.ACTIVE,
                 nfinstid='nf_002').save()
Exemplo n.º 12
0
 def test_instantiate_badreq(self):
     NfInstModel(nfinstid='144', nf_name='VNF1',
                 status='NOT_INSTANTIATED').save()
     response = self.client.post(
         '/api/vnflcm/v1/vnf_instances/144/instantiate',
         data={},
         format='json')
     NfInstModel.objects.filter(nfinstid='144').delete()
     self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Exemplo n.º 13
0
 def test_instantiate_vnf(self, mock_run):
     NfInstModel(nfinstid='12', nf_name='VNF1',
                 status='NOT_INSTANTIATED').save()
     mock_run.re.return_value = None
     response = self.client.post(
         '/api/vnflcm/v1/vnf_instances/12/instantiate',
         data=inst_req_data,
         format='json')
     self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
Exemplo n.º 14
0
 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.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
     NfInstModel.objects.filter(nfinstid='1267').delete()
Exemplo n.º 15
0
def prepare_create_params():
    nf_inst_id = str(uuid.uuid4())
    NfInstModel(nfinstid=nf_inst_id,
                status=VNF_STATUS.INSTANTIATING,
                create_time=now_time(),
                lastuptime=now_time()).save()
    job_id = JobUtil.create_job(INST_TYPE_NAME.VNF, JOB_TYPE.CREATE_VNF,
                                nf_inst_id)
    JobUtil.add_job_status(job_id, 0, 'create vnf record in database.', 0)
    return nf_inst_id, job_id
Exemplo n.º 16
0
 def setUp(self):
     self.client = Client()
     self.nf_inst_id = str(uuid.uuid4())
     NfInstModel(nfinstid=self.nf_inst_id,
                 nf_name='vnf1',
                 vnfm_inst_id='1',
                 vnf_id='vnf_id1',
                 status=VNF_STATUS.ACTIVE,
                 create_time=now_time(),
                 lastuptime=now_time()).save()
Exemplo n.º 17
0
 def test_instantiate_vnf_conflict(self, mock_run):
     NfInstModel(nfinstid='1123', nf_name='VNF1',
                 status='INSTANTIATED').save()
     mock_run.re.return_value = None
     response = self.client.post(
         '/api/vnflcm/v1/vnf_instances/1123/instantiate',
         data=inst_req_data,
         format='json')
     self.assertEqual(status.HTTP_409_CONFLICT, response.status_code,
                      response.content)
Exemplo n.º 18
0
 def do_biz(self):
     try:
         NfInstModel(nfinstid=str(uuid.uuid4()),
                     mnfinstid=self.m_vnf_instance_id,
                     vnfm_inst_id=self.vnfm_id,
                     create_time=self.time_stamp).save()
         logger.debug("Notify VNF identifier creation end.")
     except Exception:
         logger.error(traceback.format_exc())
         exception('unexpected exception')
Exemplo n.º 19
0
 def test_instantiate_inner_error(self, mock_run):
     NfInstModel(nfinstid='144', nf_name='VNF1',
                 status='NOT_INSTANTIATED').save()
     mock_run.return_value = NFLCMException('Boom!')
     response = self.client.post(
         '/api/vnflcm/v1/vnf_instances/144/instantiate',
         data=inst_req_data,
         format='json')
     NfInstModel.objects.filter(nfinstid='144').delete()
     self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,
                      response.status_code)
Exemplo n.º 20
0
def prepare_create_params():
    nf_inst_id = str(uuid.uuid4())
    NfInstModel(nfinstid=nf_inst_id,
                status=VNF_STATUS.INSTANTIATING,
                create_time=now_time(),
                lastuptime=now_time()).save()
    job_id = JobUtil.create_job(JOB_TYPE.VNF, JOB_ACTION.CREATE, nf_inst_id)
    JobUtil.add_job_status(job_id, JOB_PROGRESS.STARTED,
                           'create vnf record in database.',
                           JOB_ERROR_CODE.NO_ERROR)
    return nf_inst_id, job_id
Exemplo n.º 21
0
 def test_get_vnfs(self):
     for i in range(1, 3):
         NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save()
         StorageInstModel(storageid='s0%s' % i,
                          vimid='vim0%s' % i,
                          resouceid='resource0%s' % i,
                          insttype=1,
                          instid='%s' % i).save()
     response = self.client.get("/openoapi/vnflcm/v1/vnf_instances",
                                format='json')
     self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
     self.assertEqual(self.test_data_multi_vnf, response.data)
Exemplo n.º 22
0
 def setUp(self):
     self.client = APIClient()
     NfInstModel(nfinstid='12345',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='NOT_INSTANTIATED').save()
     self.req_data = {"type": "SCALE_IN", "aspectId": "sunshine_aspect"}
Exemplo n.º 23
0
 def test_get_vnf(self):
     vnf_inst_id = "1"
     NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
     StorageInstModel(storageid='s02',
                      vimid='vim01',
                      resouceid='resource01',
                      insttype=1,
                      instid=vnf_inst_id).save()
     response = self.client.get("/openoapi/vnflcm/v1/vnf_instances/%s" %
                                vnf_inst_id,
                                format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(self.test_data_single_vnf, response.data)
Exemplo n.º 24
0
 def setUp(self):
     self.client = APIClient()
     self.ns_inst_id = 'test_ns_terminate_001'
     self.url = '/api/nslcm/v1/ns/%s/terminate' % self.ns_inst_id
     self.job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE,
                                      self.ns_inst_id)
     NSInstModel(id=self.ns_inst_id).save()
     NSInstModel(id='test_ns_terminate_002').save()
     FPInstModel(nsinstid=self.ns_inst_id,
                 sfcid='test_sfc_inst_001',
                 fpname='xxx',
                 status='zzz').save()
     NfInstModel(ns_inst_id=self.ns_inst_id).save()
     VLInstModel(ownertype=OWNER_TYPE.NS, ownerid=self.ns_inst_id).save()
     PNFInstModel(nsInstances=self.ns_inst_id).save()
Exemplo n.º 25
0
 def test_operate_vnf_badreq(self):
     NfInstModel(nfinstid='345',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='INSTANTIATED').save()
     url = "/api/vnflcm/v1/vnf_instances/345/operate"
     response = self.client.post(url, data={}, format='json')
     NfInstModel.objects.filter(nfinstid='345').delete()
     self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
Exemplo n.º 26
0
 def setUp(self):
     self.client = APIClient()
     self.req_data = {
         "instantiationLevelId": "instantiation_level_2",
         "scaleInfo": []
     }
     NfInstModel(nfinstid='98765',
                 nf_name='VNF1',
                 nf_desc="VNF DESC",
                 vnfdid="1",
                 netype="XGW",
                 vendor="ZTE",
                 vnfSoftwareVersion="V1",
                 version="V1",
                 package_id="2",
                 status='NOT_INSTANTIATED').save()
Exemplo n.º 27
0
    def test_ns_terminate_asynchronous_tasks_when_terminate_vnf_failed(
            self, mock_request, mock_sleep):
        ns_instance_id = 'test_ns_terminate_when_terminate_vnf_failed'
        NSInstModel(id=ns_instance_id).save()
        NfInstModel(ns_inst_id=ns_instance_id).save()
        mock_request.side_effect = [({
            'status': '404'
        }, '{"jobId": "zzz"}'.encode('utf-8'))]
        mock_sleep.return_value = None

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE,
                                    ns_instance_id)
        TerminateNsService(ns_instance_id, job_id, TERMINATE_NS_DICT).run()
        self.assertEqual(
            JobModel.objects.filter(jobid=job_id).first().progress,
            JOB_PROGRESS.FINISHED)
Exemplo n.º 28
0
 def test_get_csar_successfully(self, mock_call_req):
     mock_call_req.return_value = [0, json.JSONEncoder().encode({
         "name": "1", "provider": "2", "version": "3", "operationalState": "4",
         "usageState": "5", "onBoardState": "6", "processState": "7",
         "deletionPending": "8", "downloadUri": "9", "createTime": "10",
         "modifyTime": "11", "format": "12", "size": "13"
         }), '200']
     NfPackageModel(uuid="1", vnfdid="001", vendor="vendor",
                    vnfdversion="1.2.0", vnfversion="1.1.0", nfpackageid="13").save()
     VnfPackageFileModel(id="1", filename="filename", imageid="00001",
                         vimid="1", vimuser="******", tenant="12", status="1", vnfpid="13").save()
     NfInstModel(nfinstid="1", mnfinstid="001", nf_name="name", package_id="13").save()
     resp = self.client.get("/openoapi/nslcm/v1/vnfpackage/13")
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     expect_data = {
         "csarId": '13',
         "packageInfo": {
             "vnfdId": "001",
             "vnfdProvider": "vendor",
             "vnfdVersion": "1.2.0",
             "vnfVersion": "1.1.0",
             "name": "1",
             "provider": "2",
             "version": "3",
             "operationalState": "4",
             "usageState": "5",
             "onBoardState": "6",
             "processState": "7",
             "deletionPending": "8",
             "downloadUri": "9",
             "createTime": "10",
             "modifyTime": "11",
             "format": "12",
             "size": "13"},
         "imageInfo": [{
             "index": "0",
             "fileName": "filename",
             "imageId": "00001",
             "vimId": "1",
             "vimUser": "******",
             "tenant": "12",
             "status": "1"}],
         "vnfInstanceInfo": [{
             "vnfInstanceId": "1",
             "vnfInstanceName": "name"}]}
     self.assertEqual(expect_data, resp.data)
Exemplo n.º 29
0
 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
     NfInstModel.objects.filter(nfinstid=instanceid).delete()
     self.assertEqual("vnf new name", name)
Exemplo n.º 30
0
 def test_get_vnfs(self):
     for i in range(1, 3):
         NfInstModel(nfinstid='%s' % i,
                     nf_name='VNF%s' % i,
                     nf_desc="VNF DESC",
                     vnfdid="1",
                     netype="XGW",
                     vendor="ZTE",
                     vnfSoftwareVersion="V1",
                     version="V1",
                     package_id="2",
                     status='INSTANTIATED').save()
         StorageInstModel(storageid='s0%s' % i,
                          vimid='vim0%s' % i,
                          resourceid='resource0%s' % i,
                          insttype=1,
                          instid='%s' % i).save()
     response = self.client.get("/api/vnflcm/v1/vnf_instances",
                                format='json')
     self.assertEqual(status.HTTP_200_OK, response.status_code)
     self.assertEqual(self.test_data_multi_vnf, response.data)