Merge ~hloeung/ubuntu-repository-cache:master into ubuntu-repository-cache:master

Proposed by Haw Loeung
Status: Merged
Approved by: Colin Misare
Approved revision: 7d9b6f512cd7d7341477793d306eb004ac2ac127
Merged at revision: 830c883d1749b953ab7993332a2ac5e28951c0bb
Proposed branch: ~hloeung/ubuntu-repository-cache:master
Merge into: ubuntu-repository-cache:master
Diff against target: 105 lines (+37/-7)
4 files modified
lib/ubuntu_repository_cache/metadata_sync.py (+3/-3)
reactive/ubuntu_repository_cache.py (+7/-3)
templates/systemd/mtr-synchost.service (+1/-1)
tests/unit/test_ubuntu_repository_cache.py (+26/-0)
Reviewer Review Type Date Requested Status
Colin Misare Approve
Canonical IS Reviewers Pending
Review via email: mp+429457@code.launchpad.net

Commit message

Fix mtr metrics to use IPv4 when squid_dns_v4_first to match

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
Colin Misare (cmisare) wrote :

LGTM

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

Change successfully merged at revision 830c883d1749b953ab7993332a2ac5e28951c0bb

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/ubuntu_repository_cache/metadata_sync.py b/lib/ubuntu_repository_cache/metadata_sync.py
2index b2da773..79acaf9 100644
3--- a/lib/ubuntu_repository_cache/metadata_sync.py
4+++ b/lib/ubuntu_repository_cache/metadata_sync.py
5@@ -155,9 +155,9 @@ def mirror_archive(hostname, apache_root, local_unit, log, mirror_series, rsync_
6 max_retries = 5
7 for attempt in range(1, max_retries):
8 try:
9- # The archive may have multiple IP addresses, try each several times.
10- archive_ips = [i for i in socket.gethostbyname_ex(hostname)[-1]]
11- archive_ip_iterator = cycle(archive_ips)
12+ # The archive may have multiple IP addresses, try each several times.
13+ archive_ips = [i for i in socket.gethostbyname_ex(hostname)[-1]]
14+ archive_ip_iterator = cycle(archive_ips)
15 except socket.gaierror as e:
16 # Save the exact exception and reuse when we need to
17 # reraise it after exhausting all available attempts.
18diff --git a/reactive/ubuntu_repository_cache.py b/reactive/ubuntu_repository_cache.py
19index d8b8221..5fedca0 100755
20--- a/reactive/ubuntu_repository_cache.py
21+++ b/reactive/ubuntu_repository_cache.py
22@@ -324,7 +324,11 @@ def leader_settings_changed():
23 update_website_relation_data()
24
25
26-@reactive.when_any('config.changed.sync-host', 'config.changed.enable_sync-host_monitoring')
27+@reactive.when_any(
28+ 'config.changed.enable_sync-host_monitoring',
29+ 'config.changed.squid_dns_v4_first',
30+ 'config.changed.sync-host',
31+)
32 def update_systemd_mtr_required():
33 reactive.set_flag('ubuntu-repository-cache.update-systemd-mtr-required')
34
35@@ -341,11 +345,11 @@ def update_systemd_mtr(etc_systemd_path='/etc/systemd/system'):
36 status.maintenance('Updating systemd mtr timer & service with sync-host {}'.format(config['sync-host']))
37
38 changed = False
39-
40+ context = {'protocol': '-4 ' if config['squid_dns_v4_first'] else '', 'sync_host': config['sync-host']}
41 base = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
42 env = jinja2.Environment(loader=jinja2.FileSystemLoader(base), keep_trailing_newline=True)
43 template = env.get_template('templates/systemd/mtr-synchost.service')
44- contents = template.render({'sync_host': config['sync-host']})
45+ contents = template.render(context)
46 changed = _write_file(contents, mtr_service) or changed
47 changed = _copy_file('files/systemd/mtr-synchost.timer', mtr_timer) or changed
48
49diff --git a/templates/systemd/mtr-synchost.service b/templates/systemd/mtr-synchost.service
50index 477024d..538e9ba 100644
51--- a/templates/systemd/mtr-synchost.service
52+++ b/templates/systemd/mtr-synchost.service
53@@ -5,7 +5,7 @@ After=network-online.target
54
55 [Service]
56 Type=simple
57-ExecStart=/usr/bin/mtr -bz -c7 --tcp -P 80 --report-wide {{sync_host}}
58+ExecStart=/usr/bin/mtr {{protocol}}-bz -c7 --tcp -P 80 --report-wide {{sync_host}}
59 ExecStop=
60 User=nobody
61 Restart=on-failure
62diff --git a/tests/unit/test_ubuntu_repository_cache.py b/tests/unit/test_ubuntu_repository_cache.py
63index 17f0c06..14ec2a7 100644
64--- a/tests/unit/test_ubuntu_repository_cache.py
65+++ b/tests/unit/test_ubuntu_repository_cache.py
66@@ -138,6 +138,7 @@ class TestCharm(unittest.TestCase):
67 @mock.patch('subprocess.call')
68 def test_update_systemd_mtr(self, call, clear_flag):
69 self.mock_config.return_value['enable_sync-host_monitoring'] = True
70+ self.mock_config.return_value['squid_dns_v4_first'] = False
71 ubuntu_repository_cache.update_systemd_mtr(self.tmpdir)
72 want = [
73 mock.call('ubuntu-repository-cache.active'),
74@@ -223,6 +224,31 @@ WantedBy=multi-user.target
75 ]
76 call.assert_has_calls(want, any_order=True)
77
78+ @mock.patch('subprocess.call')
79+ def test_update_systemd_mtr_ipv4(self, call):
80+ self.mock_config.return_value['enable_sync-host_monitoring'] = True
81+ self.mock_config.return_value['squid_dns_v4_first'] = True
82+ ubuntu_repository_cache.update_systemd_mtr(self.tmpdir)
83+ want = '''[Unit]
84+Description=Monitor path to sync host regularly
85+Wants=network-online.target
86+After=network-online.target
87+
88+[Service]
89+Type=simple
90+ExecStart=/usr/bin/mtr -4 -bz -c7 --tcp -P 80 --report-wide archive.ubuntu.com
91+ExecStop=
92+User=nobody
93+Restart=on-failure
94+TimeoutSec=5m
95+
96+[Install]
97+WantedBy=multi-user.target
98+''' # NOQA: E501
99+ with open(os.path.join(self.tmpdir, 'mtr-synchost.service'), 'r', encoding='utf-8') as f:
100+ got = f.read()
101+ self.assertEqual(want, got)
102+
103 def test__copy_file(self):
104 source = os.path.join(self.charm_dir, 'metadata.yaml')
105 dest = os.path.join(self.tmpdir, os.path.basename(source))

Subscribers

People subscribed via source and target branches