def test_nsd_content_upload_normal(self, mock_parse_nsd):
        user_defined_data_json = json.JSONEncoder().encode(
            self.user_defined_data)
        mock_parse_nsd.return_value = json.JSONEncoder().encode(nsd_data)
        VnfPackageModel(vnfPackageId="111", vnfdId="vcpe_vfw_zte_1_0").save()

        PnfPackageModel(pnfPackageId="112", pnfdId="m6000_s").save()

        NSPackageModel(
            nsPackageId='22',
            operationalState='DISABLED',
            usageState='NOT_IN_USE',
            userDefinedData=user_defined_data_json,
        ).save()

        with open('nsd_content.txt', 'wt') as fp:
            fp.write('test')
        with open('nsd_content.txt', 'rt') as fp:
            resp = self.client.put(
                "/api/nsd/v1/ns_descriptors/22/nsd_content",
                {'file': fp},
            )
        file_content = ''
        with open(os.path.join(GENERICPARSER_ROOT_PATH,
                               '22/nsd_content.txt')) as fp:
            data = fp.read()
            file_content = '%s%s' % (file_content, data)
        ns_pkg = NSPackageModel.objects.filter(nsPackageId="22")
        self.assertEqual("VCPE_NS", ns_pkg[0].nsdId)
        self.assertEqual(PKG_STATUS.ONBOARDED, ns_pkg[0].onboardingState)
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(None, resp.data)
        self.assertEqual(file_content, 'test')
        os.remove('nsd_content.txt')
 def test_pnfd_content_upload_when_pnfd_exist(self, mock_parse_pnfd):
     with open('pnfd_content.txt', 'wt') as fp:
         fp.write('test')
     PnfPackageModel(pnfPackageId='22',
                     usageState=PKG_STATUS.NOT_IN_USE,
                     pnfdId="zte-1.1").save()
     PnfPackageModel(pnfPackageId='23',
                     usageState=PKG_STATUS.NOT_IN_USE,
                     pnfdId="zte-1.0").save()
     mock_parse_pnfd.return_value = json.JSONEncoder().encode(pnfd_data)
     with open('pnfd_content.txt', 'rt') as fp:
         resp = self.client.put(
             "/api/nsd/v1/pnf_descriptors/22/pnfd_content",
             {'file': fp},
         )
     self.assertEqual(resp.status_code,
                      status.HTTP_500_INTERNAL_SERVER_ERROR)
 def test_pnfd_parse_normal(self, mock_parse_pnfd):
     PnfPackageModel(pnfPackageId="8", pnfdId="10").save()
     mock_parse_pnfd.return_value = json.JSONEncoder().encode({"c": "d"})
     req_data = {"csarId": "8", "inputs": []}
     resp = self.client.post("/api/parser/v1/parserpnfd",
                             req_data,
                             format='json')
     self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
     self.assertEqual({"model": '{"c": "d"}'}, resp.data)
 def test_delete_single_pnfd_normal(self):
     user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
     PnfPackageModel(pnfPackageId='22',
                     usageState=PKG_STATUS.NOT_IN_USE,
                     userDefinedData=user_defined_data,
                     pnfdModel='test').save()
     NSPackageModel.objects.create(nsPackageId="111",
                                   nsdModel=json.JSONEncoder().encode(
                                       self.nsdModel))
     resp = self.client.delete("/api/nsd/v1/pnf_descriptors/22",
                               format='json')
     self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
     self.assertEqual(None, resp.data)
Beispiel #5
0
    def test_parse_serviced_and_save(self, mock_parse_sd):
        mock_parse_sd.return_value = json.JSONEncoder().encode(self.sd_data)
        servcie_desc = ServiceDescriptor()
        csar_id = '0b667470-e6b3-4ee8-8f08-186317a04dc2'
        servcie_desc.create(self.data, csar_id)
        VnfPackageModel(vnfPackageId="1",
                        vnfdId="cd557883-ac4b-462d-aa01-421b5fa606b1").save()
        PnfPackageModel(pnfPackageId="1", pnfdId="m6000_s").save()
        local_file_name = "/test.csar"
        servcie_desc.parse_serviced_and_save(csar_id, local_file_name)

        service_package = ServicePackageModel.objects.filter(
            servicePackageId=csar_id)[0]
        self.assertIsNotNone(service_package)
    def test_query_single_pnfd_normal(self):
        expected_reponse_data = copy.deepcopy(self.expected_pnfd_info)
        expected_reponse_data['id'] = '22'

        user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
        PnfPackageModel(pnfPackageId='22',
                        onboardingState='CREATED',
                        usageState='NOT_IN_USE',
                        userDefinedData=user_defined_data).save()

        response = self.client.get('/api/nsd/v1/pnf_descriptors/22',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(expected_reponse_data, response.data)
    def test_service_pkg_distribute_when_fail_download_artifacts(
            self, mock_get_asset, mock_download_artifacts):
        mock_get_asset.return_value = self.asset_data
        mock_download_artifacts.side_effect = GenericparserException(
            "Failed to download 1 from sdc.")
        csar_id = "1"
        VnfPackageModel(vnfPackageId="cd557883-ac4b-462d-aa01-421b5fa606b1",
                        vnfdId="cd557883-ac4b-462d-aa01-421b5fa606b1").save()
        PnfPackageModel(pnfPackageId="m6000_s", pnfdId="m6000_s").save()

        try:
            ServicePackage().on_distribute(csar_id)
        except Exception as e:
            self.assertTrue(isinstance(e, GenericparserException))
            self.assertEqual("Failed to download 1 from sdc.", e.args[0])
 def test_pnfd_download_when_not_on_boarded(self):
     with open('pnfd_content.txt', 'wt') as fp:
         fp.writelines('test1')
         fp.writelines('test2')
     user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
     PnfPackageModel(pnfPackageId='22',
                     usageState=PKG_STATUS.NOT_IN_USE,
                     onboardingState=PKG_STATUS.CREATED,
                     userDefinedData=user_defined_data,
                     localFilePath="pnfd_content.txt",
                     pnfdModel='test').save()
     response = self.client.get(
         "/api/nsd/v1/pnf_descriptors/22/pnfd_content")
     self.assertEqual(response.status_code,
                      status.HTTP_500_INTERNAL_SERVER_ERROR)
     os.remove('pnfd_content.txt')
    def test_service_pkg_distribute(self, mock_parse_sd,
                                    mock_download_artifacts, mock_get_asset):
        mock_parse_sd.return_value = json.JSONEncoder().encode(self.sd_data)
        mock_download_artifacts.return_value = "/test.csar"
        mock_get_asset.return_value = self.asset_data
        VnfPackageModel(vnfPackageId="cd557883-ac4b-462d-aa01-421b5fa606b1",
                        vnfdId="cd557883-ac4b-462d-aa01-421b5fa606b1").save()
        PnfPackageModel(pnfPackageId="m6000_s", pnfdId="m6000_s").save()
        ServicePackage().on_distribute(csar_id="1")

        service_package = ServicePackageModel.objects.filter(
            servicePackageId="1").first()
        self.assertEqual("5de07996-7ff0-4ec1-b93c-e3a00bb3f207",
                         service_package.invariantId)
        self.assertEqual("Enhance_Service", service_package.servicedName)
        self.assertEqual(PKG_STATUS.ONBOARDED, service_package.onboardingState)
        self.assertEqual(PKG_STATUS.ENABLED, service_package.operationalState)
        self.assertEqual(PKG_STATUS.NOT_IN_USE, service_package.usageState)
    def test_query_multiple_pnfds_normal(self):
        expected_reponse_data = [
            copy.deepcopy(self.expected_pnfd_info),
            copy.deepcopy(self.expected_pnfd_info)
        ]
        expected_reponse_data[0]['id'] = '0'
        expected_reponse_data[1]['id'] = '1'

        user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
        for i in range(2):
            PnfPackageModel(pnfPackageId=str(i),
                            onboardingState='CREATED',
                            usageState='NOT_IN_USE',
                            userDefinedData=user_defined_data).save()
        response = self.client.get('/api/nsd/v1/pnf_descriptors',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(expected_reponse_data, response.data)
 def test_pnfd_download_normal(self):
     with open('pnfd_content.txt', 'wt') as fp:
         fp.writelines('test1')
         fp.writelines('test2')
     user_defined_data = json.JSONEncoder().encode(self.user_defined_data)
     PnfPackageModel(pnfPackageId='22',
                     usageState=PKG_STATUS.NOT_IN_USE,
                     onboardingState=PKG_STATUS.ONBOARDED,
                     userDefinedData=user_defined_data,
                     localFilePath="pnfd_content.txt",
                     pnfdModel='test').save()
     resp = self.client.get("/api/nsd/v1/pnf_descriptors/22/pnfd_content")
     file_content = ""
     for data in resp.streaming_content:
         file_content = '%s%s' % (file_content, data)
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     self.assertEqual("b'test1test2'", file_content)
     os.remove('pnfd_content.txt')
 def test_ns_pkg_distribute_when_successfully(self, mock_parse_nsd,
                                              mock_download_artifacts,
                                              mock_call_req):
     mock_parse_nsd.return_value = json.JSONEncoder().encode(self.nsd_data)
     mock_download_artifacts.return_value = "/home/vcpe.csar"
     mock_call_req.return_value = [
         0,
         json.JSONEncoder().encode([{
             "uuid": "1",
             "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar",
             "distributionStatus": "DISTRIBUTED"
         }]), '200'
     ]
     VnfPackageModel(vnfPackageId="1", vnfdId="vcpe_vfw_zte_1_0").save()
     PnfPackageModel(pnfPackageId="1", pnfdId="m6000_s").save()
     resp = self.client.post("/api/parser/v1/nspackages", {"csarId": "1"},
                             format='json')
     self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
     self.assertEqual("success", resp.data["status"])
     self.assertEqual("CSAR(1) distributed successfully.",
                      resp.data["statusDescription"])
    def test_pnfd_content_upload_normal(self, mock_parse_pnfd):
        user_defined_data_json = json.JSONEncoder().encode(
            self.user_defined_data)
        PnfPackageModel(
            pnfPackageId='22',
            usageState=PKG_STATUS.NOT_IN_USE,
            userDefinedData=user_defined_data_json,
        ).save()
        mock_parse_pnfd.return_value = json.JSONEncoder().encode(pnfd_data)
        with open('pnfd_content.txt', 'wt') as fp:
            fp.write('test')

        with open('pnfd_content.txt', 'rt') as fp:
            resp = self.client.put(
                "/api/nsd/v1/pnf_descriptors/22/pnfd_content",
                {'file': fp},
            )
        pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId="22")
        self.assertEqual(pnf_pkg[0].pnfdId, "zte-1.0")
        self.assertEqual(pnf_pkg[0].onboardingState, PKG_STATUS.ONBOARDED)
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(None, resp.data)
        os.remove('pnfd_content.txt')