Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Publish should be operational if override config values were specified
Browse files Browse the repository at this point in the history
  • Loading branch information
ipanova committed May 26, 2016
1 parent 5226260 commit 34a9ba7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
12 changes: 10 additions & 2 deletions server/pulp/server/controllers/repository.py
Expand Up @@ -995,6 +995,7 @@ def check_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit, call_con
"""

force_full = call_config.get('force_full', False)
config_override = call_config.override_config
last_published = conduit.last_publish()
last_unit_removed = repo_obj.last_unit_removed
if last_published:
Expand All @@ -1006,17 +1007,24 @@ def check_publish(repo_obj, dist_id, dist_inst, transfer_repo, conduit, call_con

units_removed = last_unit_removed is not None and last_unit_removed > last_published
dist_updated = dist.last_updated > last_published
same_override = dist.last_override_config == config_override
if not same_override:
# Use raw pymongo not to fire the signal hander
model.Distributor.objects(
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:
not dist_updated and same_override:

publish_result_coll = RepoPublishResult.get_collection()
publish_start_timestamp = _now_timestamp()
publish_end_timestamp = _now_timestamp(string=False)

# Use raw pymongo not to fire the signal hander
model.Distributor.objects(
repo_id=repo_obj.repo_id).update(set__last_publish=publish_end_timestamp)
repo_id=repo_obj.repo_id,
distributor_id=dist_id).update(set__last_publish=publish_end_timestamp)

result_code = RepoPublishResult.RESULT_SKIPPED
_logger.debug('publish skipped for repo [%s] with distributor ID [%s]' % (
Expand Down
18 changes: 0 additions & 18 deletions server/pulp/server/db/migrations/0024_distributor_last_updated.py

This file was deleted.

23 changes: 23 additions & 0 deletions server/pulp/server/db/migrations/0024_distributor_schema_change.py
@@ -0,0 +1,23 @@
from pulp.common import dateutils
from pulp.server.db.connection import get_collection


def migrate(*args, **kwargs):
"""
Add last_updated and last_override_config to the distributor collection.
"""
updated_key = 'last_updated'
config_key = 'last_override_config'
collection = get_collection('repo_distributors')
for distributor in collection.find():
if config_key not in distributor.keys():
distributor[config_key] = {}

if updated_key in distributor.keys():
continue
elif 'last_publish' in distributor.keys():
distributor[updated_key] = distributor['last_publish']
else:
distributor[updated_key] = dateutils.now_utc_datetime_with_tzinfo()

collection.save(distributor)
1 change: 1 addition & 0 deletions server/pulp/server/db/model/__init__.py
Expand Up @@ -1219,6 +1219,7 @@ class Distributor(AutoRetryDocument):
auto_publish = BooleanField(default=False)
last_publish = UTCDateTimeField()
last_updated = UTCDateTimeField()
last_override_config = DictField()
scratchpad = DictField()

_ns = StringField(default='repo_distributors')
Expand Down
2 changes: 2 additions & 0 deletions server/test/unit/server/controllers/test_repository.py
Expand Up @@ -1092,11 +1092,13 @@ def test_no_op_publish(self, m_dist_qs, m_repo_pub_result, mock_call_conf, mock_
Test that publish is no op when there were no changes made since last publish.
"""
mock_call_conf.get.return_value = False
mock_call_conf.override_config = {}
fake_repo = model.Repository(repo_id='repo1')
mock_objects.return_value.count.return_value = 0
mock_inst = mock.MagicMock()
m_dist = m_dist_qs.get_or_404.return_value
m_dist.last_updated = None
m_dist.last_override_config = {}

result = repo_controller.check_publish(fake_repo, 'dist', mock_inst,
fake_repo.to_transfer_repo(), mock_conduit,
Expand Down
Expand Up @@ -7,7 +7,8 @@

LAST_PUBLISH = 'last_publish'
LAST_UPDATED = 'last_updated'
MIGRATION = 'pulp.server.db.migrations.0024_distributor_last_updated'
LAST_OVERRIDE_CONFIG = 'last_override_config'
MIGRATION = 'pulp.server.db.migrations.0024_distributor_schema_change'


class TestMigration(TestCase):
Expand All @@ -19,7 +20,7 @@ class TestMigration(TestCase):
@patch('.'.join((MIGRATION, 'get_collection')))
def test_migrate(self, m_get_collection, now_utc_datetime):
"""
Test last_updated field added.
Test last_updated and last_override_config fields added.
"""
collection = Mock()
found = [
Expand All @@ -39,5 +40,6 @@ def test_migrate(self, m_get_collection, now_utc_datetime):
collection.find.assert_called_once_with()
now_utc_datetime.assert_called_once_with()
self.assertTrue(LAST_UPDATED in dist for dist in collection.save.call_args_list)
self.assertTrue(LAST_OVERRIDE_CONFIG in dist for dist in collection.save.call_args_list)
self.assertEqual(
len(collection.save.call_args_list), 2)
2 changes: 2 additions & 0 deletions server/test/unit/server/db/test_model.py
Expand Up @@ -1193,6 +1193,8 @@ def test_attributes(self):
self.assertFalse(model.Distributor.last_publish.required)
self.assertTrue(isinstance(model.Distributor.last_updated, DateTimeField))
self.assertFalse(model.Distributor.last_updated.required)
self.assertTrue(isinstance(model.Distributor.last_override_config, DictField))
self.assertFalse(model.Distributor.last_override_config.required)
self.assertTrue(isinstance(model.Distributor._ns, StringField))
self.assertEqual(model.Distributor._ns.default, 'repo_distributors')
self.assertTrue(isinstance(model.Distributor.scratchpad, DictField))
Expand Down

0 comments on commit 34a9ba7

Please sign in to comment.