Пример #1
0
    def test_extract_metadata(self):
        # Test
        metadata.extract_metadata(self.module, self.module_dir, self.tmp_dir)

        # Verify
        self.assertEqual(self.module.name, 'valid')
        self.assertEqual(self.module.version, '1.0.0')
        self.assertEqual(self.module.author, 'jdob')
        self.assertEqual(self.module.source, 'http://example.org/jdob-valid/source')
        self.assertEqual(self.module.license, 'Apache License, Version 2.0')
        self.assertEqual(self.module.summary, 'Valid Module Summary')
        self.assertEqual(self.module.description, 'Valid Module Description')
        self.assertEqual(self.module.project_page, 'http://example.org/jdob-valid')

        self.assertEqual(2, len(self.module.dependencies))
        sorted_deps = sorted(self.module.dependencies, key=lambda x : x['name'])
        self.assertEqual(sorted_deps[0]['name'], 'jdob/dep-alpha')
        self.assertEqual(sorted_deps[0]['version_requirement'], '>= 1.0.0')
        self.assertEqual(sorted_deps[1]['name'], 'ldob/dep-beta')
        self.assertEqual(sorted_deps[1]['version_requirement'], '>= 2.0.0')

        self.assertEqual(self.module.types, [])
        
        expected_checksums = {
            'Modulefile': '704cecf2957448dcf7fa20cffa2cf7c1',
            'README': '11edd8578497566d8054684a8c89c6cb',
            'manifests/init.pp': '1d1fb26825825b4d64d37d377016869e',
            'spec/spec_helper.rb': 'a55d1e6483344f8ec6963fcb2c220372',
            'tests/init.pp': '7043c7ef0c4b0ac52b4ec6bb76008ebd'
        }
        self.assertEqual(self.module.checksums, expected_checksums)
Пример #2
0
    def test_extract_metadata_no_metadata(self):
        # Setup
        self.module.name = "no-metadata"
        filename = os.path.join(self.module_dir, self.module.filename())

        # Test
        try:
            metadata.extract_metadata(self.module, filename, self.tmp_dir)
            self.fail()
        except metadata.MissingModuleFile, e:
            self.assertEqual(e.module_filename, filename)
Пример #3
0
    def test_extract_metadata_bad_tarball(self):
        # Setup
        self.module.name = "empty"
        filename = os.path.join(self.module_dir, self.module.filename())

        # Test
        try:
            metadata.extract_metadata(self.module, filename, self.tmp_dir)
            self.fail()
        except metadata.ExtractionException, e:
            self.assertEqual(e.module_filename, filename)
Пример #4
0
    def test_extract_metadata(self):
        # Setup
        filename = os.path.join(self.module_dir, self.module.filename())

        # Test
        metadata.extract_metadata(self.module, filename, self.tmp_dir)

        # Verify
        self.assertEqual(self.module.name, "valid")
        self.assertEqual(self.module.version, "1.0.0")
        self.assertEqual(self.module.author, "jdob")

        self._assert_test_module_metadata()
Пример #5
0
def handle_uploaded_unit(repo, type_id, unit_key, metadata, file_path, conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param repo: repository into which the unit is being uploaded
    :type  repo: pulp.plugins.model.Repository
    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module out of the uploaded metadata
    combined = copy.copy(unit_key)
    combined.update(metadata)
    module = Module.from_dict(combined)

    # Extract the metadata from the module
    metadata_parser.extract_metadata(module, file_path, repo.working_dir)

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    
Пример #6
0
    def test_retrieve_module(self):
        module = model.Module('php', '0.2.1', 'thias')

        # Test
        self.downloader.retrieve_module(self.mock_progress_report, module)

        # Verify
        module_dir = os.path.join(self.working_dir, DOWNLOAD_TMP_DIR)
        expected_file = os.path.join(module_dir, module.filename())
        self.assertTrue(os.path.exists(expected_file))

        # Extract the metadata to make sure the tar is valid and we can open it
        metadata.extract_metadata(module, module_dir, self.working_dir)

        # Spot check that something from the metadata was stuffed into the module
        self.assertTrue(module.checksums is not None)
Пример #7
0
    def test_extract_metadata_non_standard_packaging(self):
        # Setup
        self.module = Module("misnamed", "1.0.0", "ldob")
        self.module_dir = os.path.join(DATA_DIR, "bad-modules")
        filename = os.path.join(self.module_dir, self.module.filename())

        # Test
        metadata.extract_metadata(self.module, filename, self.tmp_dir)

        # Verify - contains the same module as jdob-valid-1.0.0, so this is safe
        self.assertEqual(self.module.name, "misnamed")
        self.assertEqual(self.module.version, "1.0.0")
        self.assertEqual(self.module.author, "ldob")

        self._assert_test_module_metadata()

        extraction_root = os.path.join(self.tmp_dir, self.module.author)
        self.assertTrue(not os.path.exists(extraction_root))
Пример #8
0
    def _add_new_module(self, downloader, module):
        """
        Performs the tasks for downloading and saving a new unit in Pulp.

        :param downloader: downloader instance to use for retrieving the unit
        :param module: module instance to download
        :type  module: Module
        """
        # Initialize the unit in Pulp
        type_id = constants.TYPE_PUPPET_MODULE
        unit_key = module.unit_key()
        unit_metadata = {} # populated later but needed for the init call
        relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

        unit = self.sync_conduit.init_unit(type_id, unit_key, unit_metadata,
                                           relative_path)

        try:
            if not self._module_exists(unit.storage_path):
                # Download the bits
                downloaded_filename = downloader.retrieve_module(self.progress_report, module)

                # Copy them to the final location
                shutil.copy(downloaded_filename, unit.storage_path)

            # Extract the extra metadata into the module
            metadata.extract_metadata(module, unit.storage_path, self.repo.working_dir)

            # Update the unit with the extracted metadata
            unit.metadata = module.unit_metadata()

            # Save the unit and associate it to the repository
            self.sync_conduit.save_unit(unit)
        finally:
            # Clean up the temporary module
            downloader.cleanup_module(module)