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: 5ccc842b2c6ec6398f09e62bd8127fd3531e126a
Merged at revision: 95ec8b03d9d440fc0267af381ab5b0d5130e2a49
Proposed branch: ~hloeung/ubuntu-repository-cache:reduce-cron-spam
Merge into: ubuntu-repository-cache:master
Diff against target: 186 lines (+157/-0)
2 files modified
reactive/ubuntu_repository_cache.py (+56/-0)
tests/unit/test_ubuntu_repository_cache.py (+101/-0)
Reviewer Review Type Date Requested Status
Barry Price Approve
Canonical IS Reviewers Pending
Review via email: mp+431874@code.launchpad.net

Commit message

Reduce cron spam

Description of the change

These are the changes from testing:

| ubuntu@ip-172-31-17-35:/etc$ sudo bzr st
| modified:
| .bzrignore
| cron.monthly/ieee-data
| etckeeper/etckeeper.conf
| ubuntu@ip-172-31-17-35:/etc$ sudo bzr di
| === modified file '.bzrignore'
| --- .bzrignore 2022-07-25 02:20:44 +0000
| +++ .bzrignore 2022-10-20 02:33:52 +0000
| @@ -102,3 +102,12 @@
| DEADJOE
|
| # end section managed by etckeeper
| +# ignore due to LP#1598304
| +apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
| +systemd/system/multi-user.target.wants/snap-*.mount
| +systemd/system/multi-user.target.wants/snap.*.service
| +systemd/system/default.target.wants/snap-*.mount
| +systemd/system/default.target.wants/snap-*.service
| +systemd/system/snap-*.mount
| +systemd/system/snap.*.service
| +# end section ignore due to LP#1598304
|
| === modified file 'cron.monthly/ieee-data'
| --- cron.monthly/ieee-data 2017-10-26 01:43:49 +0000
| +++ cron.monthly/ieee-data 2022-10-20 02:08:30 +0000
| @@ -1,3 +1,2 @@
| #!/bin/sh
| -test -x /usr/bin/update-oui || exit 0
| -BASEDIR=/var/lib/ieee-data/ /usr/bin/update-oui -f -q
| +# https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
|
| === modified file 'etckeeper/etckeeper.conf'
| --- etckeeper/etckeeper.conf 2022-07-25 02:20:44 +0000
| +++ etckeeper/etckeeper.conf 2022-10-20 02:03:16 +0000
| @@ -11,7 +11,7 @@
| HG_COMMIT_OPTIONS=""
|
| # Options passed to bzr commit when run by etckeeper.
| -BZR_COMMIT_OPTIONS=""
| +BZR_COMMIT_OPTIONS="--quiet"
|
| # Options passed to darcs record when run by etckeeper.
| DARCS_COMMIT_OPTIONS="-a"
|
| ubuntu@ip-172-31-17-35:/etc$

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
Barry Price (barryprice) wrote :

LGTM +1

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 95ec8b03d9d440fc0267af381ab5b0d5130e2a49

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 12ff100..5ec909d 100755
3--- a/reactive/ubuntu_repository_cache.py
4+++ b/reactive/ubuntu_repository_cache.py
5@@ -48,6 +48,7 @@ def config_changed():
6 reactive.clear_flag('ubuntu-repository-cache.active')
7 reactive.clear_flag('ubuntu-repository-cache.configured')
8 reactive.clear_flag('nagios-nrpe.configured')
9+ reactive.clear_flag('reduce-cron-spam.configured')
10
11
12 @reactive.when_any(
13@@ -372,6 +373,61 @@ def update_systemd_mtr(etc_systemd_path='/etc/systemd/system'):
14 reactive.clear_flag('ubuntu-repository-cache.update-systemd-mtr-required')
15
16
17+@reactive.when_not('reduce-cron-spam.configured')
18+def reduce_cron_spam(etc_path='/etc'):
19+ # https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
20+ ieee_data_path = os.path.join(etc_path, 'cron.monthly/ieee-data')
21+ if os.path.exists(ieee_data_path):
22+ source = '''#!/bin/sh
23+# https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
24+'''
25+ _write_file(source, ieee_data_path, perms=0o755)
26+
27+ etckeeper_conf_path = os.path.join(etc_path, 'etckeeper/etckeeper.conf')
28+ if os.path.exists(etckeeper_conf_path) and os.path.exists(os.path.join(etc_path, '.bzr')):
29+ # https://bugs.launchpad.net/etckeeper/+bug/1986739
30+ etckeeper_conf = []
31+ with open(etckeeper_conf_path, 'r', encoding='utf-8') as f:
32+ etckeeper_conf = f.read().split('\n')
33+ new = []
34+ for line in etckeeper_conf:
35+ if line == 'BZR_COMMIT_OPTIONS=""':
36+ new.append('BZR_COMMIT_OPTIONS="--quiet"')
37+ else:
38+ new.append(line)
39+ _write_file('\n'.join(new), etckeeper_conf_path)
40+
41+ # https://bugs.launchpad.net/snappy/+bug/1598304
42+ bzrignore_path = os.path.join(etc_path, '.bzrignore')
43+ bzrignore = []
44+ if os.path.exists(bzrignore_path):
45+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
46+ bzrignore = f.read().split('\n')
47+ new = []
48+ pause = False
49+ for line in bzrignore:
50+ if line == "# ignore due to LP#1598304":
51+ pause = True
52+ elif line == "# end section ignore due to LP#1598304":
53+ pause = False
54+ elif not pause:
55+ new.append(line)
56+
57+ ignore_snaps = '''# ignore due to LP#1598304
58+apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
59+systemd/system/multi-user.target.wants/snap-*.mount
60+systemd/system/multi-user.target.wants/snap.*.service
61+systemd/system/default.target.wants/snap-*.mount
62+systemd/system/default.target.wants/snap-*.service
63+systemd/system/snap-*.mount
64+systemd/system/snap.*.service
65+# end section ignore due to LP#1598304
66+'''
67+ _write_file('\n'.join(new) + ignore_snaps, bzrignore_path, perms=0o600)
68+
69+ reactive.set_flag('reduce-cron-spam.configured')
70+
71+
72 # LP:1770071: Work around charm-helper's unison ownership
73 # https://github.com/juju/charm-helpers/issues/487
74 def _fix_ssh_ownership(user='www-sync'):
75diff --git a/tests/unit/test_ubuntu_repository_cache.py b/tests/unit/test_ubuntu_repository_cache.py
76index db0424a..5f70bb4 100644
77--- a/tests/unit/test_ubuntu_repository_cache.py
78+++ b/tests/unit/test_ubuntu_repository_cache.py
79@@ -78,6 +78,107 @@ class TestCharm(unittest.TestCase):
80 clear_flag.assert_has_calls(want, any_order=True)
81 set_flag.assert_called_once_with('ubuntu-repository-cache.update-systemd-mtr-required')
82
83+ @mock.patch('charms.reactive.set_flag')
84+ def test_reduce_cron_spam(self, set_flag):
85+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
86+ set_flag.assert_called_once_with('reduce-cron-spam.configured')
87+
88+ @mock.patch('charms.reactive.set_flag')
89+ def test_reduce_cron_spam_ieee_data(self, set_flag):
90+ ieee_data_path = os.path.join(self.tmpdir, 'cron.monthly/ieee-data')
91+ os.mkdir(os.path.join(self.tmpdir, 'cron.monthly'))
92+ with open(ieee_data_path, 'w') as f:
93+ f.write("Testing")
94+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
95+ set_flag.assert_called_once_with('reduce-cron-spam.configured')
96+ want = '''#!/bin/sh
97+# https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
98+'''
99+ with open(ieee_data_path, 'r', encoding='utf-8') as f:
100+ got = f.read()
101+ self.assertEqual(want, got)
102+
103+ @mock.patch('charms.reactive.set_flag')
104+ def test_reduce_cron_spam_etckeeper(self, set_flag):
105+ etckeeper_conf_path = os.path.join(self.tmpdir, 'etckeeper/etckeeper.conf')
106+ os.mkdir(os.path.join(self.tmpdir, 'etckeeper'))
107+ with open(etckeeper_conf_path, 'w') as f:
108+ f.write('# Options passed to bzr commit when run by etckeeper.\nBZR_COMMIT_OPTIONS=""\n')
109+ os.mkdir(os.path.join(self.tmpdir, '.bzr'))
110+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
111+ set_flag.assert_called_once_with('reduce-cron-spam.configured')
112+ want = '''# Options passed to bzr commit when run by etckeeper.
113+BZR_COMMIT_OPTIONS="--quiet"
114+'''
115+ with open(etckeeper_conf_path, 'r', encoding='utf-8') as f:
116+ got = f.read()
117+ self.assertEqual(want, got)
118+
119+ @mock.patch('charms.reactive.set_flag')
120+ def test_reduce_cron_spam_bzrignore(self, set_flag):
121+ bzrignore_path = os.path.join(self.tmpdir, '.bzrignore')
122+ etckeeper_conf_path = os.path.join(self.tmpdir, 'etckeeper/etckeeper.conf')
123+ os.mkdir(os.path.join(self.tmpdir, 'etckeeper'))
124+ with open(etckeeper_conf_path, 'w') as f:
125+ f.write('# Options passed to bzr commit when run by etckeeper.\nBZR_COMMIT_OPTIONS=""\n')
126+ os.mkdir(os.path.join(self.tmpdir, '.bzr'))
127+
128+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
129+ set_flag.assert_called_once_with('reduce-cron-spam.configured')
130+ want = '''# ignore due to LP#1598304
131+apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
132+systemd/system/multi-user.target.wants/snap-*.mount
133+systemd/system/multi-user.target.wants/snap.*.service
134+systemd/system/default.target.wants/snap-*.mount
135+systemd/system/default.target.wants/snap-*.service
136+systemd/system/snap-*.mount
137+systemd/system/snap.*.service
138+# end section ignore due to LP#1598304
139+'''
140+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
141+ got = f.read()
142+ self.assertEqual(want, got)
143+
144+ # No current snap ignores.
145+ test = 'blahblah\nblah\n'
146+ with open(bzrignore_path, 'w') as f:
147+ f.write(test)
148+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
149+ want2 = test + want
150+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
151+ got = f.read()
152+ self.assertEqual(want2, got)
153+
154+ # Snap ignores exist and at the end.
155+ test = 'blahblah\nblah\n'
156+ with open(bzrignore_path, 'w') as f:
157+ f.write(test + want)
158+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
159+ want2 = test + want
160+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
161+ got = f.read()
162+ self.assertEqual(want2, got)
163+
164+ # Snap ignores exist in between other things, move it to the end.
165+ test = 'blahblah\nblah\n'
166+ with open(bzrignore_path, 'w') as f:
167+ f.write(test + want + test)
168+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
169+ want2 = test + test + want
170+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
171+ got = f.read()
172+ self.assertEqual(want2, got)
173+
174+ # Snap ignores exist at the start, move it to the end.
175+ test = 'blahblah\nblah\n'
176+ with open(bzrignore_path, 'w') as f:
177+ f.write(want + test)
178+ ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
179+ want2 = test + want
180+ with open(bzrignore_path, 'r', encoding='utf-8') as f:
181+ got = f.read()
182+ self.assertEqual(want2, got)
183+
184 @mock.patch('charmhelpers.core.hookenv.leader_get')
185 @mock.patch('charms.reactive.set_flag')
186 def test_set_active(self, set_flag, leader_get):

Subscribers

People subscribed via source and target branches