Ejemplo n.º 1
0
    def setUp(self):
        super(RepoManagerTests, self).setUp()

        plugin_api._create_manager()
        mock_plugins.install()

        # Create the manager instance to test
        self.manager = managers.RepoManager()
Ejemplo n.º 2
0
def migrate(*args, **kwargs):
    """
    Regenerates the 'content_unit_counts' attribute of each repository, and
    removes the obsolete attribute 'content_unit_count'. The normal use case
    will be that the 'content_unit_counts' attribute does not yet exist, but
    this migration is idempotent just in case.
    """
    managers.RepoManager().rebuild_content_unit_counts()
    repo_collection = connection.get_collection('repos')
    repo_collection.update({}, {'$unset': {'content_unit_count': 1}})
Ejemplo n.º 3
0
def preserve_custom_metadata_on_repo_scratchpad():
    """
     Lookups all the yum based repos in pulp; grabs any custom metadata
     and set the the data on repo scratchpad.
    """
    factory.initialize()
    repos = managers.RepoManager().find_with_importer_type("yum_importer")
    if not repos:
        _log.debug("No repos found to perform db migrate")
        return
    repo_ids = [repo['id'] for repo in repos]
    for repo_id in repo_ids:
        _log.debug("Processing repo %s" % repo_id)
        repo_scratchpad = factory.repo_manager().get_repo_scratchpad(repo_id)
        if "repodata" in repo_scratchpad and repo_scratchpad["repodata"]:
            # repo scratchpad already has repodata, skip migration
            _log.debug(
                "repo [%s] scratchpad already has repodata, skip migration" %
                repo_id)
            continue
        repo_working_dir = importer_working_dir('yum_importer', repo_id)
        importer_repodata_dir = os.path.join(repo_working_dir, repo_id,
                                             "repodata")
        repomd_xml_path = os.path.join(importer_repodata_dir, "repomd.xml")
        if not os.path.exists(repomd_xml_path):
            # repodata doesn't exist on filesystem cannot lookup custom data, continue to next
            continue
        ftypes = util.get_repomd_filetypes(repomd_xml_path)
        base_ftypes = [
            'primary', 'primary_db', 'filelists_db', 'filelists', 'other',
            'other_db', 'group', 'group_gz', 'updateinfo', 'updateinfo_db'
        ]
        for ftype in ftypes:
            if ftype in base_ftypes:
                # no need to process these again
                continue
            filetype_path = os.path.join(
                importer_repodata_dir,
                os.path.basename(
                    util.get_repomd_filetype_path(repomd_xml_path, ftype)))
            if filetype_path.endswith('.gz'):
                # if file is gzipped, decompress
                data = gzip.open(filetype_path).read().decode(
                    "utf-8", "replace")
            else:
                data = open(filetype_path).read().decode("utf-8", "replace")
            repo_scratchpad["repodata"].update({ftype: data})
        # set the custom metadata on scratchpad
        factory.repo_manager().set_repo_scratchpad(repo_id, repo_scratchpad)
        _log.info("Updated repo [%s] scratchpad with new custom repodata" %
                  repo_id)
Ejemplo n.º 4
0
    def test_find_with_importer_type(self, mock_importer_coll, mock_repo_qs,
                                     mock_repo_ser):
        """
        Ensure that repos are found and importers are placed into them.
        """
        mock_repos = {'repo_id': 'repo-a'}
        mock_importers = [{'id': 'imp1', 'repo_id': 'repo-a'}]
        mock_importer_coll().find.return_value = mock_importers
        mock_repo_ser().data = mock_repos

        repos = managers.RepoManager().find_with_importer_type('mock-imp-type')
        self.assertEqual(1, len(repos))

        self.assertEqual(repos[0]['repo_id'], 'repo-a')
        self.assertEqual(1, len(repos[0]['importers']))
        self.assertEqual(repos[0]['importers'][0]['id'], 'imp1')
from pulp.server.db.migrations.lib import managers
from pulp.server.managers import factory
from pulp.server.controllers import repository as repo_controller
from pulp.server.db.model.repository import RepoContentUnit
from pulp.server.managers.repo.unit_association_query import UnitAssociationCriteria

from pulp_rpm.common import ids

_log = logging.getLogger('pulp')

# Initialize plugin loader api and other managers
factory.initialize()
ass_query_mgr = factory.repo_unit_association_query_manager()
ass_mgr = factory.repo_unit_association_manager()
content_mgr = factory.content_manager()
repo_mgr = managers.RepoManager()


def _get_repos():
    """
     Lookups all the yum based repos in pulp.
     @return a list of repoids
    """
    repos = repo_mgr.find_with_importer_type("yum_importer")
    if not repos:
        _log.debug("No repos found to perform db migrate")
        return []
    repo_ids = [repo['id'] for repo in repos]
    return repo_ids