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)
Ejemplo n.º 4
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 = CatalogException(
            "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, CatalogException))
            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_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.decode())
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     self.assertEqual("test1test2", file_content)
     os.remove('pnfd_content.txt')
Ejemplo n.º 10
0
 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/catalog/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_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)
Ejemplo n.º 12
0
    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(CATALOG_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("b632bddc-bccd-4180-bd8d-4e8a9578eff7", 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_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')
    def test_nsdm_subscribe_trigger_notification(self, mock_uuid4,
                                                 mock_requests, mock_nowtime,
                                                 mock_parse_nsd,
                                                 mock_requests_post):
        mock_requests.return_value.status_code = 204
        mock_requests.get.return_value.status_code = 204
        mock_uuid4.return_value = "1111"
        mock_nowtime.return_value = "nowtime()"

        subscription_req = {
            "callbackUri": "http://callbackuri.com",
            "authentication": {
                "authType": ["BASIC"],
                "paramsBasic": {
                    "userName": "******",
                    "password": "******"
                }
            },
            "filter": {
                "nsdId": ["b632bddc-bccd-4180-bd8d-4e8a9578eff7"]
            }
        }
        response = self.client.post("/api/nsd/v1/subscriptions",
                                    data=subscription_req,
                                    format='json')
        self.assertEqual(201, response.status_code)

        self.user_defined_data = {
            'key1': 'value1',
            'key2': 'value2',
            'key3': 'value3',
        }
        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='d0ea5ec3-0b98-438a-9bea-488230cff174',
            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/d0ea5ec3-0b98-438a-9bea-488230cff174/nsd_content",
                {'file': fp},
            )
        file_content = ''
        with open(
                os.path.join(
                    CATALOG_ROOT_PATH,
                    'd0ea5ec3-0b98-438a-9bea-488230cff174/nsd_content.txt')
        ) as fp:
            data = fp.read()
            file_content = '%s%s' % (file_content, data)
        ns_pkg = NSPackageModel.objects.filter(
            nsPackageId="d0ea5ec3-0b98-438a-9bea-488230cff174")
        self.assertEqual("b632bddc-bccd-4180-bd8d-4e8a9578eff7",
                         ns_pkg[0].nsdId)
        self.assertEqual(const.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')
        expect_callbackuri = "http://callbackuri.com"
        expect_notification = {
            'id': "1111",
            'notificationType': const.NSD_NOTIFICATION_TYPE.NSD_ONBOARDING,
            'timeStamp': "nowtime()",
            'nsdInfoId': "d0ea5ec3-0b98-438a-9bea-488230cff174",
            'nsdId': "b632bddc-bccd-4180-bd8d-4e8a9578eff7",
            '_links': {
                'nsdInfo': {
                    'href':
                    '/%s/ns_descriptors/%s' %
                    (const.NSD_URL_PREFIX,
                     "d0ea5ec3-0b98-438a-9bea-488230cff174")
                },
                'subscription': {
                    'href':
                    '/%s%s' % (const.NSDM_SUBSCRIPTION_ROOT_URI, "1111")
                }
            },
            "subscriptionId": "1111"
        }
        mock_requests_post.assert_called_with(
            expect_callbackuri,
            data=json.dumps(expect_notification),
            auth=HTTPBasicAuth("username", "password"),
            headers={
                'Connection': 'close',
                'content-type': 'application/json',
                'accept': 'application/json'
            },
            verify=False)