Skip to content

Commit

Permalink
Merge pull request #1058 from daviddavis/27713
Browse files Browse the repository at this point in the history
Fixing dupe ISO units after file update
  • Loading branch information
daviddavis committed Jul 3, 2017
2 parents ffb3938 + 4db15dc commit cda2310
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 7 additions & 1 deletion plugins/pulp_rpm/plugins/importers/iso/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mongoengine import NotUniqueError
from mongoengine import NotUniqueError, Q

from pulp.common import config as config_utils
from pulp.common.plugins import importer_constants
Expand Down Expand Up @@ -151,6 +151,12 @@ def upload_unit(self, transfer_repo, type_id, unit_key, metadata, file_path, con
except NotUniqueError:
iso = iso.__class__.objects.get(**iso.unit_key)

# remove any existing units with the same name
units = repo_controller.find_repo_content_units(transfer_repo.repo_obj,
units_q=Q(name=iso['name']),
yield_content_unit=True)
repo_controller.disassociate_units(transfer_repo.repo_obj, units)

repo_controller.associate_single_unit(transfer_repo.repo_obj, iso)

return {'success_flag': True, 'summary': None, 'details': None}
Expand Down
25 changes: 23 additions & 2 deletions plugins/pulp_rpm/plugins/importers/iso/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def __init__(self, sync_conduit, config):
self.downloader = HTTPThreadedDownloader(downloader_config, self)
self.progress_report = SyncProgressReport(sync_conduit)

self.repo_units = []

@property
def download_deferred(self):
"""
Expand Down Expand Up @@ -162,7 +164,7 @@ def download_succeeded(self, report):
iso.save()
except NotUniqueError:
iso = iso.__class__.objects.filter(**iso.unit_key).first()
repo_controller.associate_single_unit(self.sync_conduit.repo, iso)
self._associate_unit(self.sync_conduit.repo, iso)
iso.safe_import_content(report.destination)

# We can drop this ISO from the url --> ISO map
Expand Down Expand Up @@ -240,7 +242,7 @@ def perform_sync(self):
iso = iso.__class__.objects.filter(**iso.unit_key).first()
else:
self.add_catalog_entries([iso])
repo_controller.associate_single_unit(self.sync_conduit.repo, iso)
self._associate_unit(self.sync_conduit.repo, iso)
else:
self._download_isos(local_missing_isos)

Expand Down Expand Up @@ -316,6 +318,25 @@ def _download_manifest(self):

return manifest

def _associate_unit(self, repo, unit):
"""
Associate an iso unit with a repository but first check if there's already any with the same
name and if so, remove them.
:param repo: An ISO repository that is being synced
:type repo: pulp.server.db.model.Repository
:param unit: An ISO unit to associate with repo
:type unit: pulp_rpm.plugins.db.models.ISO
"""
if not self.repo_units:
# store the existing repo units to prevent querying mongo multiple times
self.repo_units = repo_controller.find_repo_content_units(repo, yield_content_unit=True)

units_to_remove = [iso for iso in self.repo_units if iso['name'] == unit['name']]

repo_controller.disassociate_units(repo, units_to_remove)
repo_controller.associate_single_unit(repo, unit)

def _filter_missing_isos(self, manifest, download_deferred):
"""
Use the sync_conduit and the manifest to determine which ISOs are at the feed_url
Expand Down

0 comments on commit cda2310

Please sign in to comment.