Esempio n. 1
0
    def _create_and_upload_vnf(self, sample_name):
        body = jsonutils.dumps({"userDefinedData": {"foo": "bar"}})
        vnf_package = self._create_vnf_package(body)
        csar_dir = self._get_csar_dir_path(sample_name)
        if os.path.exists(os.path.join(csar_dir, 'TOSCA-Metadata')) and \
                sample_name != 'vnfpkgm2':
            file_path = utils.create_csar_with_unique_artifact(csar_dir)
        else:
            file_path, vnfd_id = utils.create_csar_with_unique_vnfd_id(
                csar_dir)
        self.addCleanup(os.remove, file_path)

        with open(file_path, 'rb') as file_object:
            resp, resp_body = self.http_client.do_request(
                '{base_path}/{id}/package_content'.format(
                    id=vnf_package['id'], base_path=self.base_url),
                "PUT",
                body=file_object,
                content_type='application/zip')

        self.assertEqual(202, resp.status_code)

        self._wait_for_onboard(vnf_package['id'])

        return vnf_package['id']
Esempio n. 2
0
    def test_patch_in_onboarded_state(self):
        user_data = jsonutils.dumps({
            "userDefinedData": {
                "key1": "val1",
                "key2": "val2",
                "key3": "val3"
            }
        })
        vnf_package = self._create_vnf_package(user_data)

        update_req_body = jsonutils.dumps({
            "operationalState": "DISABLED",
            "userDefinedData": {
                "key1": "changed_val1",
                "key2": "val2",
                "new_key": "new_val"
            }
        })

        expected_result = {
            "operationalState": "DISABLED",
            "userDefinedData": {
                "key1": "changed_val1",
                "new_key": "new_val"
            }
        }

        csar_dir = self._get_csar_dir_path("vnfpkgm1")
        file_path = utils.create_csar_with_unique_artifact(csar_dir)
        self.addCleanup(os.remove, file_path)
        with open(file_path, 'rb') as file_object:
            resp, resp_body = self.http_client.do_request(
                '{base_path}/{id}/package_content'.format(
                    id=vnf_package['id'], base_path=self.base_url),
                "PUT",
                body=file_object,
                content_type='application/zip')

        self.assertEqual(202, resp.status_code)
        self._wait_for_onboard(vnf_package['id'])

        # Update vnf package which is onboarded
        resp, resp_body = self.http_client.do_request(
            '{base_path}/{id}'.format(id=vnf_package['id'],
                                      base_path=self.base_url),
            "PATCH",
            content_type='application/json',
            body=update_req_body)

        self.assertEqual(200, resp.status_code)
        self.assertEqual(expected_result, resp_body)
        self._delete_vnf_package(vnf_package['id'])
        self._wait_for_delete(vnf_package['id'])
Esempio n. 3
0
 def test_load_csar_data_false_source_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_in_meta_and_manifest_false_source')
     self.addCleanup(os.remove, file_path)
     exc = self.assertRaises(exceptions.InvalidCSAR,
                             csar_utils.load_csar_data, self.context,
                             constants.UUID, file_path)
     artifact_path = 'Scripts/install.s'
     msg = (('The path("%(artifact_path)s") of '
             'artifact Source is an invalid value.') % {
                 'artifact_path': artifact_path
             })
     self.assertEqual(msg, exc.format_message())
Esempio n. 4
0
 def test_load_csar_data_missing_value_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_in_meta_and_manifest_missing_value')
     self.addCleanup(os.remove, file_path)
     exc = self.assertRaises(exceptions.InvalidCSAR,
                             csar_utils.load_csar_data, self.context,
                             constants.UUID, file_path)
     key_name = 'Algorithm'
     msg = (('One of the artifact information may not have '
             'the key value("%(key)s")') % {
                 'key': key_name
             })
     self.assertEqual(msg, exc.format_message())
Esempio n. 5
0
 def test_load_csar_data_meta_in_manifest_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_meta_in_manifest')
     self.addCleanup(os.remove, file_path)
     vnf_data, flavours, vnf_artifacts = csar_utils.load_csar_data(
         self.context, constants.UUID, file_path)
     self.assertEqual(vnf_data['descriptor_version'], '1.0')
     self.assertEqual(vnf_data['vnfm_info'], ['Tacker'])
     self.assertEqual(flavours[0]['flavour_id'], 'simple')
     self.assertIsNotNone(flavours[0]['sw_images'])
     self.assertIsNotNone(vnf_artifacts)
     self.assertIsNotNone(vnf_artifacts[0]['Source'])
     self.assertIsNotNone(vnf_artifacts[0]['Hash'])
Esempio n. 6
0
 def test_load_csar_data_false_mf_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_in_meta_and_manifest_false')
     self.addCleanup(os.remove, file_path)
     manifest_path = 'manifest.mf1'
     exc = self.assertRaises(exceptions.InvalidCSAR,
                             csar_utils.load_csar_data, self.context,
                             constants.UUID, file_path)
     msg = (('The file "%(manifest)s" in the CSAR "%(csar)s" does not '
             'contain valid manifest.') % {
                 'manifest': manifest_path,
                 'csar': file_path
             })
     self.assertEqual(msg, exc.format_message())
Esempio n. 7
0
 def test_load_csar_data_false_mf_name_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_in_single_manifest_false_name')
     self.addCleanup(os.remove, file_path)
     manifest_path = 'VNF1.mf'
     exc = self.assertRaises(exceptions.InvalidCSAR,
                             csar_utils.load_csar_data, self.context,
                             constants.UUID, file_path)
     msg = (('The filename "%(manifest)s" is an invalid name.'
             'The name must be the same as the main template '
             'file name.') % {
                 'manifest': manifest_path,
                 'csar': file_path
             })
     self.assertEqual(msg, exc.format_message())
Esempio n. 8
0
 def test_load_csar_data_false_hash_with_vnf_artifact(
         self, mock_extract_csar_zip_file):
     file_path = utils.create_csar_with_unique_artifact(
         './tacker/tests/etc/samples/etsi/nfv/'
         'sample_vnf_package_csar_in_meta_and_manifest_false_hash')
     self.addCleanup(os.remove, file_path)
     exc = self.assertRaises(exceptions.InvalidCSAR,
                             csar_utils.load_csar_data, self.context,
                             constants.UUID, file_path)
     hash_code = '27bbdb25d8f4ed6d07d6f6581b86515e8b2f' \
                 '0059b236ef7b6f50d6674b34f02'
     artifact_path = 'Scripts/install.sh'
     msg = (('The hash "%(hash)s" of artifact file '
             '"%(artifact)s" is an invalid value.') % {
                 'hash': hash_code,
                 'artifact': artifact_path
             })
     self.assertEqual(msg, exc.format_message())
Esempio n. 9
0
def _create_and_upload_vnf_package(tacker_client, csar_package_name,
                                   user_defined_data):
    # create vnf package
    body = jsonutils.dumps({"userDefinedData": user_defined_data})
    resp, vnf_package = tacker_client.do_request(
        '/vnfpkgm/v1/vnf_packages', "POST", body=body)

    # upload vnf package
    csar_package_path = "../../etc/samples/etsi/nfv/%s" % csar_package_name
    file_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                             csar_package_path))

    # Generating unique vnfd id. This is required when multiple workers
    # are running concurrently. The call below creates a new temporary
    # CSAR with unique vnfd id.
    file_path = utils.create_csar_with_unique_artifact(file_path)

    with open(file_path, 'rb') as file_object:
        resp, resp_body = tacker_client.do_request(
            '/vnfpkgm/v1/vnf_packages/{id}/package_content'.format(
                id=vnf_package['id']),
            "PUT", body=file_object, content_type='application/zip')

    # wait for onboard
    timeout = VNF_PACKAGE_UPLOAD_TIMEOUT
    start_time = int(time.time())
    show_url = os.path.join('/vnfpkgm/v1/vnf_packages', vnf_package['id'])
    vnfd_id = None
    while True:
        resp, body = tacker_client.do_request(show_url, "GET")
        if body['onboardingState'] == "ONBOARDED":
            vnfd_id = body['vnfdId']
            break

        if ((int(time.time()) - start_time) > timeout):
            raise Exception("Failed to onboard vnf package")

        time.sleep(1)

    # remove temporarily created CSAR file
    os.remove(file_path)
    return vnf_package['id'], vnfd_id