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
1diff --git a/reactive/ubuntu_repository_cache.py b/reactive/ubuntu_repository_cache.py
2index 5ec909d..cadfd89 100755
3--- a/reactive/ubuntu_repository_cache.py
4+++ b/reactive/ubuntu_repository_cache.py
5@@ -374,7 +374,7 @@ def update_systemd_mtr(etc_systemd_path='/etc/systemd/system'):
6
7
8 @reactive.when_not('reduce-cron-spam.configured')
9-def reduce_cron_spam(etc_path='/etc'):
10+def reduce_cron_spam(etc_path='/etc'): # NOQA: C901
11 # https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
12 ieee_data_path = os.path.join(etc_path, 'cron.monthly/ieee-data')
13 if os.path.exists(ieee_data_path):
14@@ -425,6 +425,20 @@ systemd/system/snap.*.service
15 '''
16 _write_file('\n'.join(new) + ignore_snaps, bzrignore_path, perms=0o600)
17
18+ # https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1940011
19+ update_notifier_cron_path = os.path.join(etc_path, 'cron.weekly/update-notifier-common')
20+ if os.path.exists(update_notifier_cron_path):
21+ update_notifier_cron = []
22+ with open(update_notifier_cron_path, 'r', encoding='utf-8') as f:
23+ update_notifier_cron = f.read().split('\n')
24+ new = []
25+ for line in update_notifier_cron:
26+ if line.endswith('/usr/lib/ubuntu-release-upgrader/release-upgrade-motd'):
27+ new.append(line + ' >/dev/null')
28+ else:
29+ new.append(line)
30+ _write_file('\n'.join(new), update_notifier_cron_path, perms=0o755)
31+
32 reactive.set_flag('reduce-cron-spam.configured')
33
34
35diff --git a/tests/unit/test_ubuntu_repository_cache.py b/tests/unit/test_ubuntu_repository_cache.py
36index 5f70bb4..0bac880 100644
37--- a/tests/unit/test_ubuntu_repository_cache.py
38+++ b/tests/unit/test_ubuntu_repository_cache.py
39@@ -179,6 +179,19 @@ systemd/system/snap.*.service
40 got = f.read()
41 self.assertEqual(want2, got)
42
43+ @mock.patch('charms.reactive.set_flag')
44+ def test_reduce_cron_spam_update_notifier(self, set_flag):
45+ update_notifier_cron_path = os.path.join(self.tmpdir, 'cron.weekly/update-notifier-common')
46+ os.mkdir(os.path.join(self.tmpdir, 'cron.weekly'))
47+ with open(update_notifier_cron_path, 'w') as f:
48+ f.write(' /usr/lib/ubuntu-release-upgrader/release-upgrade-motd\n')
49+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
50+ set_flag.assert_called_once_with('reduce-cron-spam.configured')
51+ want = ' /usr/lib/ubuntu-release-upgrader/release-upgrade-motd >/dev/null\n'
52+ with open(update_notifier_cron_path, 'r', encoding='utf-8') as f:
53+ got = f.read()
54+ self.assertEqual(want, got)
55+
56 @mock.patch('charmhelpers.core.hookenv.leader_get')
57 @mock.patch('charms.reactive.set_flag')
58 def test_set_active(self, set_flag, leader_get):

Subscribers

People subscribed via source and target branches