Merge lp:~hloeung/ubuntu-repository-cache/show-status-metadata-sync-leader into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 364
Merged at revision: 363
Proposed branch: lp:~hloeung/ubuntu-repository-cache/show-status-metadata-sync-leader
Merge into: lp:ubuntu-repository-cache
Diff against target: 80 lines (+36/-3)
2 files modified
reactive/ubuntu_repository_cache.py (+11/-1)
tests/unit/test_ubuntu_repository_cache.py (+25/-2)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/show-status-metadata-sync-leader
Reviewer Review Type Date Requested Status
James Simpson Approve
Canonical IS Reviewers Pending
Review via email: mp+427652@code.launchpad.net

Commit message

Update status msg showing current metadata sync leader

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.

363. By Haw Loeung

Update status msg showing current metadata sync leader

364. By Haw Loeung

Include which unit is the metadata sync leader in status msg

Revision history for this message
James Simpson (jsimpso) wrote :

LGTM

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

Change successfully merged at revision 363

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'reactive/ubuntu_repository_cache.py'
2--- reactive/ubuntu_repository_cache.py 2022-07-25 00:19:34 +0000
3+++ reactive/ubuntu_repository_cache.py 2022-08-01 01:25:54 +0000
4@@ -85,6 +85,15 @@
5 @reactive.when('ubuntu-repository-cache.started')
6 @reactive.when_not('ubuntu-repository-cache.active', 'ubuntu-repository-cache.apache2-restart-required')
7 def set_active(version_file='version'):
8+ config = hookenv.config()
9+
10+ leader = ''
11+ leader_unit = config['leader_unit']
12+ if leader_unit == '':
13+ leader_unit = hookenv.leader_get(attribute="leader_id")
14+ if hookenv.local_unit() == leader_unit:
15+ leader = ', metadata sync leader {}'.format(leader_unit)
16+
17 revision = ''
18 if os.path.exists(version_file):
19 with open(version_file) as f:
20@@ -100,7 +109,8 @@
21 revision = ' (source version/commit {}-{})'.format(date, ver)
22 else:
23 revision = ' (source version/commit {})'.format(ver)
24- status.active('Ready{}'.format(revision))
25+
26+ status.active('Ready{}{}'.format(leader, revision))
27 reactive.set_flag('ubuntu-repository-cache.active')
28
29
30
31=== modified file 'tests/unit/test_ubuntu_repository_cache.py'
32--- tests/unit/test_ubuntu_repository_cache.py 2022-07-25 00:19:34 +0000
33+++ tests/unit/test_ubuntu_repository_cache.py 2022-08-01 01:25:54 +0000
34@@ -43,7 +43,7 @@
35 patcher = mock.patch('charmhelpers.core.hookenv.local_unit')
36 self.mock_local_unit = patcher.start()
37 self.addCleanup(patcher.stop)
38- self.mock_local_unit.return_value = 'mock-ubuntu-repository-cache/0'
39+ self.mock_local_unit.return_value = 'ubuntu-repository-cache/0'
40
41 patcher = mock.patch('charmhelpers.core.hookenv.config')
42 self.mock_config = patcher.start()
43@@ -62,13 +62,36 @@
44 if os.path.exists('.juju-persistent-config'):
45 os.unlink('.juju-persistent-config')
46
47+ @mock.patch('charmhelpers.core.hookenv.leader_get')
48 @mock.patch('charms.reactive.set_flag')
49- def test_set_active(self, set_flag):
50+ def test_set_active(self, set_flag, leader_get):
51+ self.mock_config.return_value['leader_unit'] = ''
52 ubuntu_repository_cache.set_active()
53 status.active.assert_called_once_with('Ready')
54 set_flag.assert_called_once_with('ubuntu-repository-cache.active')
55
56 status.active.reset_mock()
57+ self.mock_config.return_value['leader_unit'] = 'ubuntu-repository-cache/0'
58+ ubuntu_repository_cache.set_active()
59+ status.active.assert_called_once_with('Ready, metadata sync leader ubuntu-repository-cache/0')
60+
61+ status.active.reset_mock()
62+ self.mock_config.return_value['leader_unit'] = ''
63+ leader_get.return_value = 'ubuntu-repository-cache/0'
64+ ubuntu_repository_cache.set_active()
65+ status.active.assert_called_once_with('Ready, metadata sync leader ubuntu-repository-cache/0')
66+ status.active.reset_mock()
67+ self.mock_config.return_value['leader_unit'] = 'ubuntu-repository-cache/0'
68+ # bzr - "revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp"
69+ ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))
70+ status.active.assert_called_once_with(
71+ 'Ready, metadata sync leader ubuntu-repository-cache/0 (source version/commit 20210131-uax4glwg)'
72+ )
73+
74+ self.mock_config.return_value['leader_unit'] = ''
75+ leader_get.return_value = ''
76+
77+ status.active.reset_mock()
78 # bzr - "revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp"
79 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))
80 status.active.assert_called_once_with('Ready (source version/commit 20210131-uax4glwg)')

Subscribers

People subscribed via source and target branches