def _drpms(v1_database, v2_database, report): """ Migrate DRPMS from v1 to v2 location on filesystem. DRPMs are not inventoried in the DB in v1. This method looks up each repo in v1 for repodata and pretodelta in particular. If available, it parses the presto, extracts the drpm info and finds the drpms in repo dir in v1 and migrates them to /var/lib/pulp/content/drpm/ in v1. """ v1_coll = v1_database.repos repos = v1_coll.find() for repo in repos: deltarpms = presto_parser.get_deltas(repo) for nevra, dpkg in deltarpms.items(): for drpm in dpkg.deltas.values(): v2_path = os.path.join(DIR_DRPM, drpm.filename) v1_path = os.path.join(V1_DIR_RPMS, drpm.filename) if not os.path.exists(v1_path): # missing source path, skip migrate report.warning("Package %s does not exist" % v1_path) continue try: v2_pkg_dir = os.path.dirname(v2_path) if not os.path.isdir(v2_pkg_dir): os.makedirs(v2_pkg_dir) shutil.move(v1_path, v2_pkg_dir) except (IOError, OSError), e: report.error(str(e)) continue except Exception, e: report.error("Error: %s" % str(e)) continue
def _drpms(v1_database, v2_database, report): """ Migrate DRPMS from v1 to v2 location on filesystem. DRPMs are not inventoried in the DB in v1. This method looks up each repo in v1 for repodata and pretodelta in particular. If available, it parses the presto, extracts the drpm info and finds the drpms in repo dir in v1 and migrates them to /var/lib/pulp/content/drpm/ in v1. """ v1_coll = v1_database.repos repos = v1_coll.find() for repo in repos: deltarpms = presto_parser.get_deltas(repo) for nevra, dpkg in deltarpms.items(): for drpm in dpkg.deltas.values(): v2_path = os.path.join(DIR_DRPM, drpm.filename) v1_path = os.path.join(V1_DIR_RPMS, drpm.filename) if not os.path.exists(v1_path): # missing source path, skip migrate report.warning("Package %s does not exist" % v1_path) continue try: v2_pkg_dir = os.path.dirname(v2_path) if not os.path.isdir(v2_pkg_dir): os.makedirs(v2_pkg_dir) shutil.move(v1_path, v2_pkg_dir) except (IOError, OSError), e: report.error(str(e)) continue except Exception, e: report.error("Error: %s" % str(e)) continue
def test_drpms(self): # Test report = UpgradeStepReport() result = units._drpms(self.v1_test_db.database, self.tmp_test_db.database, report) # Verify self.assertTrue(result) v1_drpms = [] deltarpms = presto_parser.get_deltas(self.v1_test_db.database.repos.find_one({'id' : 'test_drpm_repo'})) for nevra, dpkg in deltarpms.items(): for drpm in dpkg.deltas.values(): v1_drpms.append(drpm) self._assert_upgrade(v1_drpms) self._assert_associations()
def _drpms(v1_database, v2_database, report): v2_coll = v2_database.units_drpm v1_coll = v1_database.repos v2_ass_coll = v2_database.repo_content_units repos = v1_coll.find() for repo in repos: deltarpms = presto_parser.get_deltas(repo) new_associations = [] for nevra, dpkg in deltarpms.items(): for drpm in dpkg.deltas.values(): drpm_id = str(uuid.uuid4()) new_drpm = { "_id" : drpm_id, "_storage_path" : os.path.join(DIR_DRPM, drpm.filename), "_content_type_id" : 'drpm', "checksumtype" : drpm.checksum_type, "sequence" : drpm.sequence, "checksum" : drpm.checksum, "filename" : drpm.filename, "new_package" : nevra, "epoch" : drpm.epoch, "version" : drpm.version, "release" : drpm.release, "size" : drpm.size, } try: v2_coll.insert(new_drpm, safe=True) except DuplicateKeyError: # Still hate this model, still the simplest pass new_association = { '_id' : ObjectId(), 'repo_id' : repo['id'], 'unit_id' : drpm_id, 'unit_type_id' : 'drpm', 'owner_type' : DEFAULT_OWNER_TYPE, 'owner_id' : DEFAULT_OWNER_ID, 'created' : DEFAULT_CREATED, 'updated' : DEFAULT_UPDATED, } new_associations.append(new_association) if new_associations: try: v2_ass_coll.insert(new_associations, safe=True) except DuplicateKeyError, e: pass
def _drpms(v1_database, v2_database, report): v2_coll = v2_database.units_drpm v1_coll = v1_database.repos v2_ass_coll = v2_database.repo_content_units repos = v1_coll.find() for repo in repos: deltarpms = presto_parser.get_deltas(repo) new_associations = [] for nevra, dpkg in deltarpms.items(): for drpm in dpkg.deltas.values(): drpm_id = str(uuid.uuid4()) new_drpm = { "_id": drpm_id, "_storage_path": os.path.join(DIR_DRPM, drpm.filename), "_content_type_id": 'drpm', "checksumtype": drpm.checksum_type, "sequence": drpm.sequence, "checksum": drpm.checksum, "filename": drpm.filename, "new_package": nevra, "epoch": drpm.epoch, "version": drpm.version, "release": drpm.release, "size": drpm.size, } try: v2_coll.insert(new_drpm, safe=True) except DuplicateKeyError: # Still hate this model, still the simplest pass new_association = { '_id': ObjectId(), 'repo_id': repo['id'], 'unit_id': drpm_id, 'unit_type_id': 'drpm', 'owner_type': DEFAULT_OWNER_TYPE, 'owner_id': DEFAULT_OWNER_ID, 'created': DEFAULT_CREATED, 'updated': DEFAULT_UPDATED, } new_associations.append(new_association) if new_associations: try: v2_ass_coll.insert(new_associations, safe=True) except DuplicateKeyError, e: pass