Merge ~hloeung/ubuntu-repository-cache:reduce-cron-spam into ubuntu-repository-cache:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 5351fe750c85bfaf1561ecccc9fa14f99fd3d95b
Merged at revision: c6d063cbb3a8112e7012dba75f0debcbf88b623c
Proposed branch: ~hloeung/ubuntu-repository-cache:reduce-cron-spam
Merge into: ubuntu-repository-cache:master
Diff against target: 58 lines (+28/-1)
2 files modified
reactive/ubuntu_repository_cache.py (+15/-1)
tests/unit/test_ubuntu_repository_cache.py (+13/-0)
Reviewer Review Type Date Requested Status
Loïc Gomez +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+432059@code.launchpad.net

Commit message

Reduce cron spam with update-notifier-common too - LP:1940011

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Loïc Gomez (kotodama) :
review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision c6d063cbb3a8112e7012dba75f0debcbf88b623c

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/reactive/ubuntu_repository_cache.py b/reactive/ubuntu_repository_cache.py
index 5ec909d..cadfd89 100755
--- a/reactive/ubuntu_repository_cache.py
+++ b/reactive/ubuntu_repository_cache.py
@@ -374,7 +374,7 @@ def update_systemd_mtr(etc_systemd_path='/etc/systemd/system'):
374374
375375
376@reactive.when_not('reduce-cron-spam.configured')376@reactive.when_not('reduce-cron-spam.configured')
377def reduce_cron_spam(etc_path='/etc'):377def reduce_cron_spam(etc_path='/etc'): # NOQA: C901
378 # https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960378 # https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
379 ieee_data_path = os.path.join(etc_path, 'cron.monthly/ieee-data')379 ieee_data_path = os.path.join(etc_path, 'cron.monthly/ieee-data')
380 if os.path.exists(ieee_data_path):380 if os.path.exists(ieee_data_path):
@@ -425,6 +425,20 @@ systemd/system/snap.*.service
425'''425'''
426 _write_file('\n'.join(new) + ignore_snaps, bzrignore_path, perms=0o600)426 _write_file('\n'.join(new) + ignore_snaps, bzrignore_path, perms=0o600)
427427
428 # https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1940011
429 update_notifier_cron_path = os.path.join(etc_path, 'cron.weekly/update-notifier-common')
430 if os.path.exists(update_notifier_cron_path):
431 update_notifier_cron = []
432 with open(update_notifier_cron_path, 'r', encoding='utf-8') as f:
433 update_notifier_cron = f.read().split('\n')
434 new = []
435 for line in update_notifier_cron:
436 if line.endswith('/usr/lib/ubuntu-release-upgrader/release-upgrade-motd'):
437 new.append(line + ' >/dev/null')
438 else:
439 new.append(line)
440 _write_file('\n'.join(new), update_notifier_cron_path, perms=0o755)
441
428 reactive.set_flag('reduce-cron-spam.configured')442 reactive.set_flag('reduce-cron-spam.configured')
429443
430444
diff --git a/tests/unit/test_ubuntu_repository_cache.py b/tests/unit/test_ubuntu_repository_cache.py
index 5f70bb4..0bac880 100644
--- a/tests/unit/test_ubuntu_repository_cache.py
+++ b/tests/unit/test_ubuntu_repository_cache.py
@@ -179,6 +179,19 @@ systemd/system/snap.*.service
179 got = f.read()179 got = f.read()
180 self.assertEqual(want2, got)180 self.assertEqual(want2, got)
181181
182 @mock.patch('charms.reactive.set_flag')
183 def test_reduce_cron_spam_update_notifier(self, set_flag):
184 update_notifier_cron_path = os.path.join(self.tmpdir, 'cron.weekly/update-notifier-common')
185 os.mkdir(os.path.join(self.tmpdir, 'cron.weekly'))
186 with open(update_notifier_cron_path, 'w') as f:
187 f.write(' /usr/lib/ubuntu-release-upgrader/release-upgrade-motd\n')
188 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
189 set_flag.assert_called_once_with('reduce-cron-spam.configured')
190 want = ' /usr/lib/ubuntu-release-upgrader/release-upgrade-motd >/dev/null\n'
191 with open(update_notifier_cron_path, 'r', encoding='utf-8') as f:
192 got = f.read()
193 self.assertEqual(want, got)
194
182 @mock.patch('charmhelpers.core.hookenv.leader_get')195 @mock.patch('charmhelpers.core.hookenv.leader_get')
183 @mock.patch('charms.reactive.set_flag')196 @mock.patch('charms.reactive.set_flag')
184 def test_set_active(self, set_flag, leader_get):197 def test_set_active(self, set_flag, leader_get):

Subscribers

People subscribed via source and target branches