Exemplo n.º 1
0
class TestGetContentUnitIDs(unittest.TestCase):
    def setUp(self):
        super(TestGetContentUnitIDs, self).setUp()
        self.manager = ContentQueryManager()

    def test_returns_generator(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a',)
        mock_type_collection.return_value.find.return_value = []

        ret = self.manager.get_content_unit_ids('fake_type', [])

        self.assertTrue(inspect.isgenerator(ret))

    def test_returns_ids(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a',)
        mock_type_collection.return_value.find.return_value = [{'_id': 'abc'}, {'_id': 'def'}]

        ret = self.manager.get_content_unit_ids('fake_type', [{'a': 'foo'}, {'a': 'bar'}])

        self.assertEqual(list(ret), ['abc', 'def'])

    def test_calls_find(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a',)
        mock_find = mock_type_collection.return_value.find
        mock_find.return_value = [{'_id': 'abc'}, {'_id': 'def'}]

        ret = self.manager.get_content_unit_ids('fake_type', [{'a': 'foo'}, {'a': 'bar'}])

        # evaluate the generator so the code actually runs
        list(ret)
        expected_spec = {'$or': ({'a': 'foo'}, {'a': 'bar'})}
        mock_find.assert_called_once_with(expected_spec, projection=['_id'])
def _migrate_rpm_unit_changelog_files():
    """
    Looks up rpm unit collection in the db and computes the changelog and filelist data
    if not already available; If the package path is missing,
    the fields are defaulted to empty list.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    ts = rpmUtils.transaction.initReadOnlyTransaction()
    for rpm_unit in collection.find():
        pkg_path = rpm_unit['_storage_path']
        if not os.path.exists(pkg_path):
            # if pkg doesnt exist, we cant get the pkg object, continue
            continue
        po = yumbased.CreateRepoPackage(ts, pkg_path)
        for key in ["changelog", "filelist", "files"]:
            if key not in rpm_unit or not rpm_unit[key]:
                if key == "changelog":
                    data = map(lambda x: __encode_changelog(x), po[key])
                else:
                    data = getattr(po, key)
                rpm_unit[key] = data
                _log.debug("missing pkg: %s ; key %s" % (rpm_unit, key))
        collection.save(rpm_unit, safe=True)
    _log.info("Migrated rpms to include rpm changelog and filelist metadata")
def migrate(*args, **kwargs):
    """
    Looks up rpm unit collection in the db and computes the changelog and filelist data
    if not already available; If the package path is missing,
    the fields are defaulted to empty list.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    ts = rpmUtils.transaction.initReadOnlyTransaction()
    for rpm_unit in collection.find():
        _migrate_unit(rpm_unit, ts, collection)
    _LOGGER.info("Migrated rpms to include rpm changelog and filelist metadata")
def migrate(*args, **kwargs):
    """
    for each puppet module, calculate a checksum for the source file on the filesystem
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id=constants.TYPE_PUPPET_MODULE)
    for puppet_unit in collection.find():
        storage_path = puppet_unit['_storage_path']
        checksum = metadata.calculate_checksum(storage_path)
        puppet_unit['checksum'] = checksum
        puppet_unit['checksum_type'] = constants.DEFAULT_HASHLIB
        collection.save(puppet_unit)
    _log.info("Migrated puppet modules to include checksum")
Exemplo n.º 5
0
def migrate(*args, **kwargs):
    """
    Looks up rpm unit collection in the db and computes the changelog and filelist data
    if not already available; If the package path is missing,
    the fields are defaulted to empty list.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    ts = rpmUtils.transaction.initReadOnlyTransaction()
    for rpm_unit in collection.find():
        _migrate_unit(rpm_unit, ts, collection)
    _LOGGER.info(
        "Migrated rpms to include rpm changelog and filelist metadata")
Exemplo n.º 6
0
def _migrate_rpm_unit_repodata():
    """
    Looks up rpm unit collection in the db and computes the repodata if not already available;
    If the package path is missing, the repodata if stored as an empty dict.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    for rpm_unit in collection.find():
        if "repodata" not in rpm_unit or not rpm_unit["repodata"]:
            # if repodata is not in the schema or repodata is empty
            rpm_unit["repodata"] = metadata.get_package_xml(rpm_unit['_storage_path'])
            collection.save(rpm_unit, safe=True)
    _log.info("Migrated rpms to include rpm metadata")
Exemplo n.º 7
0
def _migrate_rpm_unit_repodata():
    """
    Looks up rpm unit collection in the db and computes the repodata if nto already available;
    If the package path is missing, the repodata if stored as an empty dict.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    for rpm_unit in collection.find():
        modified = False
        if "repodata" not in rpm_unit:
            rpm_unit["repodata"] = get_package_xml(rpm_unit['_storage_path'])
            modified = True
        if modified:
            collection.save(rpm_unit, safe=True)
Exemplo n.º 8
0
def _migrate_rpm_unit_repodata():
    """
    Looks up rpm unit collection in the db and computes the repodata if nto already available;
    If the package path is missing, the repodata if stored as an empty dict.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    for rpm_unit in collection.find():
        modified = False
        if "repodata" not in rpm_unit:
            rpm_unit["repodata"] = get_package_xml(rpm_unit['_storage_path'])
            modified = True
        if modified:
            collection.save(rpm_unit)
Exemplo n.º 9
0
def _migrate_rpm_unit_repodata():
    """
    Looks up rpm unit collection in the db and computes the repodata if not already available;
    If the package path is missing, the repodata if stored as an empty dict.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(type_id="rpm")
    for rpm_unit in collection.find():
        if "repodata" not in rpm_unit or not rpm_unit["repodata"]:
            # if repodata is not in the schema or repodata is empty
            rpm_unit["repodata"] = metadata.get_package_xml(
                rpm_unit['_storage_path'])
            collection.save(rpm_unit, safe=True)
    _log.info("Migrated rpms to include rpm metadata")
Exemplo n.º 10
0
def migrate(*args, **kwargs):
    """
    For each puppet module, calculate a checksum for the source file on the filesystem.
    """
    query_manager = ContentQueryManager()
    collection = query_manager.get_content_unit_collection(
        type_id=constants.TYPE_PUPPET_MODULE)
    for puppet_unit in collection.find():
        storage_path = puppet_unit['_storage_path']
        checksum = metadata.calculate_checksum(storage_path)
        puppet_unit['checksum'] = checksum
        puppet_unit['checksum_type'] = constants.DEFAULT_HASHLIB
        collection.save(puppet_unit)
    _log.info("Migrated puppet modules to include checksum")
Exemplo n.º 11
0
 def test_request_content_unit_file_path_no_error(self, mock_root_dir,
                                                  mock_makedirs):
     mock_root_dir.return_value = '/var/lib/pulp/content/rpm/'
     mock_makedirs.return_value = '/var/lib/pulp/content/rpm/name'
     ContentQueryManager().request_content_unit_file_path(
         'rpm', '/name/blah')
     mock_makedirs.assert_called_once_with('/var/lib/pulp/content/rpm/name')
Exemplo n.º 12
0
 def test_request_content_unit_file_path_exists(self, mock_root_dir,
                                                mock_makedirs):
     mock_root_dir.return_value = '/var/lib/pulp/content/rpm/'
     mock_makedirs.side_effect = OSError(errno.EEXIST,
                                         os.strerror(errno.EEXIST))
     ContentQueryManager().request_content_unit_file_path(
         'rpm', '/name/blah')
     mock_makedirs.assert_called_once_with('/var/lib/pulp/content/rpm/name')
Exemplo n.º 13
0
 def test_request_content_unit_file_path_random_os_error(
         self, mock_root_dir, mock_makedirs):
     mock_root_dir.return_value = '/var/lib/pulp/content/rpm/'
     mock_makedirs.side_effect = OSError(errno.EACCES,
                                         os.strerror(errno.EACCES))
     self.assertRaises(OSError,
                       ContentQueryManager().request_content_unit_file_path,
                       'rpm', '/name/blah')
     mock_makedirs.assert_called_once_with('/var/lib/pulp/content/rpm/name')
Exemplo n.º 14
0
class TestGetContentUnitIDs(unittest.TestCase):
    def setUp(self):
        super(TestGetContentUnitIDs, self).setUp()
        self.manager = ContentQueryManager()

    def test_returns_generator(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a', )
        mock_type_collection.return_value.find.return_value = []

        ret = self.manager.get_content_unit_ids('fake_type', [])

        self.assertTrue(inspect.isgenerator(ret))

    def test_returns_ids(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a', )
        mock_type_collection.return_value.find.return_value = [{
            '_id': 'abc'
        }, {
            '_id': 'def'
        }]

        ret = self.manager.get_content_unit_ids('fake_type', [{
            'a': 'foo'
        }, {
            'a': 'bar'
        }])

        self.assertEqual(list(ret), ['abc', 'def'])

    def test_calls_find(self, mock_type_collection, mock_type_unit_key):
        mock_type_unit_key.return_value = ('a', )
        mock_find = mock_type_collection.return_value.find
        mock_find.return_value = [{'_id': 'abc'}, {'_id': 'def'}]

        ret = self.manager.get_content_unit_ids('fake_type', [{
            'a': 'foo'
        }, {
            'a': 'bar'
        }])

        # evaluate the generator so the code actually runs
        list(ret)
        expected_spec = {'$or': ({'a': 'foo'}, {'a': 'bar'})}
        mock_find.assert_called_once_with(expected_spec, fields=['_id'])
Exemplo n.º 15
0
 def test_get_content_unit_collection(self):
     manager = ContentQueryManager()
     collection = manager.get_content_unit_collection('deb')
     self.assertTrue(isinstance(collection, PulpCollection))
     self.assertEqual(collection.name, 'units_deb')
Exemplo n.º 16
0
 def setUp(self):
     super(TestGetContentUnitIDs, self).setUp()
     self.manager = ContentQueryManager()
Exemplo n.º 17
0
 def test_get_content_unit_collection(self):
     manager = ContentQueryManager()
     collection = manager.get_content_unit_collection('deb')
     self.assertTrue(isinstance(collection, PulpCollection))
     self.assertEqual(collection.name, 'units_deb')
Exemplo n.º 18
0
 def setUp(self):
     super(TestGetContentUnitIDs, self).setUp()
     self.manager = ContentQueryManager()
Exemplo n.º 19
0
 def setUp(self):
     super(PulpContentTests, self).setUp()
     database.update_database([TYPE_1_DEF, TYPE_2_DEF])
     self.cud_manager = ContentManager()
     self.query_manager = ContentQueryManager()