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
diff --git a/reactive/ubuntu_repository_cache.py b/reactive/ubuntu_repository_cache.py
index 12ff100..5ec909d 100755
--- a/reactive/ubuntu_repository_cache.py
+++ b/reactive/ubuntu_repository_cache.py
@@ -48,6 +48,7 @@ def config_changed():
48 reactive.clear_flag('ubuntu-repository-cache.active')48 reactive.clear_flag('ubuntu-repository-cache.active')
49 reactive.clear_flag('ubuntu-repository-cache.configured')49 reactive.clear_flag('ubuntu-repository-cache.configured')
50 reactive.clear_flag('nagios-nrpe.configured')50 reactive.clear_flag('nagios-nrpe.configured')
51 reactive.clear_flag('reduce-cron-spam.configured')
5152
5253
53@reactive.when_any(54@reactive.when_any(
@@ -372,6 +373,61 @@ def update_systemd_mtr(etc_systemd_path='/etc/systemd/system'):
372 reactive.clear_flag('ubuntu-repository-cache.update-systemd-mtr-required')373 reactive.clear_flag('ubuntu-repository-cache.update-systemd-mtr-required')
373374
374375
376@reactive.when_not('reduce-cron-spam.configured')
377def reduce_cron_spam(etc_path='/etc'):
378 # https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
379 ieee_data_path = os.path.join(etc_path, 'cron.monthly/ieee-data')
380 if os.path.exists(ieee_data_path):
381 source = '''#!/bin/sh
382# https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
383'''
384 _write_file(source, ieee_data_path, perms=0o755)
385
386 etckeeper_conf_path = os.path.join(etc_path, 'etckeeper/etckeeper.conf')
387 if os.path.exists(etckeeper_conf_path) and os.path.exists(os.path.join(etc_path, '.bzr')):
388 # https://bugs.launchpad.net/etckeeper/+bug/1986739
389 etckeeper_conf = []
390 with open(etckeeper_conf_path, 'r', encoding='utf-8') as f:
391 etckeeper_conf = f.read().split('\n')
392 new = []
393 for line in etckeeper_conf:
394 if line == 'BZR_COMMIT_OPTIONS=""':
395 new.append('BZR_COMMIT_OPTIONS="--quiet"')
396 else:
397 new.append(line)
398 _write_file('\n'.join(new), etckeeper_conf_path)
399
400 # https://bugs.launchpad.net/snappy/+bug/1598304
401 bzrignore_path = os.path.join(etc_path, '.bzrignore')
402 bzrignore = []
403 if os.path.exists(bzrignore_path):
404 with open(bzrignore_path, 'r', encoding='utf-8') as f:
405 bzrignore = f.read().split('\n')
406 new = []
407 pause = False
408 for line in bzrignore:
409 if line == "# ignore due to LP#1598304":
410 pause = True
411 elif line == "# end section ignore due to LP#1598304":
412 pause = False
413 elif not pause:
414 new.append(line)
415
416 ignore_snaps = '''# ignore due to LP#1598304
417apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
418systemd/system/multi-user.target.wants/snap-*.mount
419systemd/system/multi-user.target.wants/snap.*.service
420systemd/system/default.target.wants/snap-*.mount
421systemd/system/default.target.wants/snap-*.service
422systemd/system/snap-*.mount
423systemd/system/snap.*.service
424# end section ignore due to LP#1598304
425'''
426 _write_file('\n'.join(new) + ignore_snaps, bzrignore_path, perms=0o600)
427
428 reactive.set_flag('reduce-cron-spam.configured')
429
430
375# LP:1770071: Work around charm-helper's unison ownership431# LP:1770071: Work around charm-helper's unison ownership
376# https://github.com/juju/charm-helpers/issues/487432# https://github.com/juju/charm-helpers/issues/487
377def _fix_ssh_ownership(user='www-sync'):433def _fix_ssh_ownership(user='www-sync'):
diff --git a/tests/unit/test_ubuntu_repository_cache.py b/tests/unit/test_ubuntu_repository_cache.py
index db0424a..5f70bb4 100644
--- a/tests/unit/test_ubuntu_repository_cache.py
+++ b/tests/unit/test_ubuntu_repository_cache.py
@@ -78,6 +78,107 @@ class TestCharm(unittest.TestCase):
78 clear_flag.assert_has_calls(want, any_order=True)78 clear_flag.assert_has_calls(want, any_order=True)
79 set_flag.assert_called_once_with('ubuntu-repository-cache.update-systemd-mtr-required')79 set_flag.assert_called_once_with('ubuntu-repository-cache.update-systemd-mtr-required')
8080
81 @mock.patch('charms.reactive.set_flag')
82 def test_reduce_cron_spam(self, set_flag):
83 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
84 set_flag.assert_called_once_with('reduce-cron-spam.configured')
85
86 @mock.patch('charms.reactive.set_flag')
87 def test_reduce_cron_spam_ieee_data(self, set_flag):
88 ieee_data_path = os.path.join(self.tmpdir, 'cron.monthly/ieee-data')
89 os.mkdir(os.path.join(self.tmpdir, 'cron.monthly'))
90 with open(ieee_data_path, 'w') as f:
91 f.write("Testing")
92 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
93 set_flag.assert_called_once_with('reduce-cron-spam.configured')
94 want = '''#!/bin/sh
95# https://bugs.launchpad.net/ubuntu/+source/ieee-data/+bug/1922960
96'''
97 with open(ieee_data_path, 'r', encoding='utf-8') as f:
98 got = f.read()
99 self.assertEqual(want, got)
100
101 @mock.patch('charms.reactive.set_flag')
102 def test_reduce_cron_spam_etckeeper(self, set_flag):
103 etckeeper_conf_path = os.path.join(self.tmpdir, 'etckeeper/etckeeper.conf')
104 os.mkdir(os.path.join(self.tmpdir, 'etckeeper'))
105 with open(etckeeper_conf_path, 'w') as f:
106 f.write('# Options passed to bzr commit when run by etckeeper.\nBZR_COMMIT_OPTIONS=""\n')
107 os.mkdir(os.path.join(self.tmpdir, '.bzr'))
108 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
109 set_flag.assert_called_once_with('reduce-cron-spam.configured')
110 want = '''# Options passed to bzr commit when run by etckeeper.
111BZR_COMMIT_OPTIONS="--quiet"
112'''
113 with open(etckeeper_conf_path, 'r', encoding='utf-8') as f:
114 got = f.read()
115 self.assertEqual(want, got)
116
117 @mock.patch('charms.reactive.set_flag')
118 def test_reduce_cron_spam_bzrignore(self, set_flag):
119 bzrignore_path = os.path.join(self.tmpdir, '.bzrignore')
120 etckeeper_conf_path = os.path.join(self.tmpdir, 'etckeeper/etckeeper.conf')
121 os.mkdir(os.path.join(self.tmpdir, 'etckeeper'))
122 with open(etckeeper_conf_path, 'w') as f:
123 f.write('# Options passed to bzr commit when run by etckeeper.\nBZR_COMMIT_OPTIONS=""\n')
124 os.mkdir(os.path.join(self.tmpdir, '.bzr'))
125
126 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
127 set_flag.assert_called_once_with('reduce-cron-spam.configured')
128 want = '''# ignore due to LP#1598304
129apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
130systemd/system/multi-user.target.wants/snap-*.mount
131systemd/system/multi-user.target.wants/snap.*.service
132systemd/system/default.target.wants/snap-*.mount
133systemd/system/default.target.wants/snap-*.service
134systemd/system/snap-*.mount
135systemd/system/snap.*.service
136# end section ignore due to LP#1598304
137'''
138 with open(bzrignore_path, 'r', encoding='utf-8') as f:
139 got = f.read()
140 self.assertEqual(want, got)
141
142 # No current snap ignores.
143 test = 'blahblah\nblah\n'
144 with open(bzrignore_path, 'w') as f:
145 f.write(test)
146 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
147 want2 = test + want
148 with open(bzrignore_path, 'r', encoding='utf-8') as f:
149 got = f.read()
150 self.assertEqual(want2, got)
151
152 # Snap ignores exist and at the end.
153 test = 'blahblah\nblah\n'
154 with open(bzrignore_path, 'w') as f:
155 f.write(test + want)
156 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
157 want2 = test + want
158 with open(bzrignore_path, 'r', encoding='utf-8') as f:
159 got = f.read()
160 self.assertEqual(want2, got)
161
162 # Snap ignores exist in between other things, move it to the end.
163 test = 'blahblah\nblah\n'
164 with open(bzrignore_path, 'w') as f:
165 f.write(test + want + test)
166 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
167 want2 = test + test + want
168 with open(bzrignore_path, 'r', encoding='utf-8') as f:
169 got = f.read()
170 self.assertEqual(want2, got)
171
172 # Snap ignores exist at the start, move it to the end.
173 test = 'blahblah\nblah\n'
174 with open(bzrignore_path, 'w') as f:
175 f.write(want + test)
176 ubuntu_repository_cache.reduce_cron_spam(self.tmpdir)
177 want2 = test + want
178 with open(bzrignore_path, 'r', encoding='utf-8') as f:
179 got = f.read()
180 self.assertEqual(want2, got)
181
81 @mock.patch('charmhelpers.core.hookenv.leader_get')182 @mock.patch('charmhelpers.core.hookenv.leader_get')
82 @mock.patch('charms.reactive.set_flag')183 @mock.patch('charms.reactive.set_flag')
83 def test_set_active(self, set_flag, leader_get):184 def test_set_active(self, set_flag, leader_get):

Subscribers

People subscribed via source and target branches