Skip to content

Commit

Permalink
Adds predistributor logic to the publish controller
Browse files Browse the repository at this point in the history
If a distributor has a predistributor_id configured, the publish is skipped when the
predistributor has not published since the last publish by the distributor. This includes
situations where the predistributor has not published at all.

re #1887
https://pulp.plan.io/issues/1887
  • Loading branch information
dkliban committed Jul 31, 2016
1 parent 0e34d13 commit 01c02b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/pulp/plugins/rsync/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,4 @@ def _get_predistributor(self):
:return: predistributor that was configured in rsyn distributor's config
:rtype: Distributor
"""
raise NotImplementedError()
return None
24 changes: 21 additions & 3 deletions server/pulp/server/controllers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,14 @@ def check_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit, call_con
updated__gte=the_timestamp).count()
units_removed = last_unit_removed is not None and last_unit_removed > last_published
dist_updated = dist.last_updated > last_published
published_after_predistributor = True
predistributor_id = call_config.get('predistributor_id')
if predistributor_id and last_published:
predistributor = model.Distributor.objects.get_or_404(repo_id=repo_obj.repo_id,
distributor_id=predistributor_id)
predistributor_last_published = predistributor["last_publish"]
if predistributor_last_published:
published_after_predistributor = last_published > predistributor_last_published

same_override = dist.last_override_config == config_override
if not same_override:
Expand All @@ -1014,8 +1022,12 @@ def check_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit, call_con
repo_id=repo_obj.repo_id,
distributor_id=dist_id).update(set__last_override_config=config_override)

if last_published and not force_full and not last_updated and not units_removed and \
not dist_updated and same_override:
# Skip if a predistributor is configured and the predistributor has not published since the
# last publish. Skip if content has not changed since last publish and force_full has not been
# requested and no predistributor is defined.
if (predistributor_id and published_after_predistributor) or \
(last_published and not force_full and not last_updated and not units_removed and
not dist_updated and same_override and not predistributor_id):

publish_result_coll = RepoPublishResult.get_collection()
publish_start_timestamp = _now_timestamp()
Expand All @@ -1029,9 +1041,15 @@ def check_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit, call_con
result_code = RepoPublishResult.RESULT_SKIPPED
_logger.debug('publish skipped for repo [%s] with distributor ID [%s]' % (
repo_obj.repo_id, dist_id))

if predistributor_id:
reason = _('Predistributor %(predistributor_id)s has not published since last '
'publish.') % {'predistributor_id': predistributor_id}
else:
reason = _('Repository content has not changed since last publish.')
result = RepoPublishResult.skipped_result(
repo_obj.repo_id, dist.distributor_id, dist.distributor_type_id,
publish_start_timestamp, publish_end_timestamp, result_code)
publish_start_timestamp, publish_end_timestamp, result_code, reason)
publish_result_coll.save(result)

else:
Expand Down
9 changes: 7 additions & 2 deletions server/pulp/server/db/model/repository.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from gettext import gettext as _
import traceback as traceback_module

from pulp.server.db.model.base import Model
Expand Down Expand Up @@ -245,7 +246,7 @@ def error_result(cls, repo_id, distributor_id, distributor_type_id, started, com

@classmethod
def skipped_result(cls, repo_id, distributor_id, distributor_type_id, started, completed,
result_code):
result_code, translated_message):
"""
Creates a new history entry for a skipped publish.
Expand All @@ -266,11 +267,15 @@ def skipped_result(cls, repo_id, distributor_id, distributor_type_id, started, c
@param result_code: one of the RESULT_* constants in this class
@type result_code: str
@param translated_message: translated reason for skipping
@type translated_message: str
"""

r = cls(repo_id, distributor_id, distributor_type_id, started, completed,
cls.RESULT_SKIPPED)
message = 'Skipped. Nothing changed since last publish'
message = _('Skipped: %(reason)s') % {'reason': translated_message}
r.summary = r.details = message

return r
Expand Down
5 changes: 3 additions & 2 deletions server/test/unit/server/controllers/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,8 @@ def test_no_op_publish(self, m_dist_qs, m_repo_pub_result, mock_call_conf, mock_
m_dist_qs.return_value.update.assert_called_once_with(set__last_publish=mock_now())
m_repo_pub_result.skipped_result.assert_called_once_with(
fake_repo.repo_id, m_dist.distributor_id, m_dist.distributor_type_id, mock_now(),
mock_now(), m_repo_pub_result.RESULT_SKIPPED
mock_now(), m_repo_pub_result.RESULT_SKIPPED, 'Repository content has not changed '
'since last publish.'
)
msg = 'publish skipped for repo [repo1] with distributor ID [dist]'
mock_log.assert_called_once_with(msg)
Expand All @@ -1121,7 +1122,7 @@ def test_force_publish(self, m_dist_qs, m_repo_pub_result, mock_call_conf, mock_
Test that if force option specified, publish happens even if there were no changes made
since last publish.
"""
mock_call_conf.get.return_value = True
mock_call_conf.get.side_effect = [True, None]
fake_repo = model.Repository(repo_id='repo1')
mock_transfer = fake_repo.to_transfer_repo()
mock_objects.return_value.count.return_value = 0
Expand Down

0 comments on commit 01c02b2

Please sign in to comment.