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
=== modified file 'reactive/ubuntu_repository_cache.py'
--- reactive/ubuntu_repository_cache.py 2022-07-25 00:19:34 +0000
+++ reactive/ubuntu_repository_cache.py 2022-08-01 01:25:54 +0000
@@ -85,6 +85,15 @@
85@reactive.when('ubuntu-repository-cache.started')85@reactive.when('ubuntu-repository-cache.started')
86@reactive.when_not('ubuntu-repository-cache.active', 'ubuntu-repository-cache.apache2-restart-required')86@reactive.when_not('ubuntu-repository-cache.active', 'ubuntu-repository-cache.apache2-restart-required')
87def set_active(version_file='version'):87def set_active(version_file='version'):
88 config = hookenv.config()
89
90 leader = ''
91 leader_unit = config['leader_unit']
92 if leader_unit == '':
93 leader_unit = hookenv.leader_get(attribute="leader_id")
94 if hookenv.local_unit() == leader_unit:
95 leader = ', metadata sync leader {}'.format(leader_unit)
96
88 revision = ''97 revision = ''
89 if os.path.exists(version_file):98 if os.path.exists(version_file):
90 with open(version_file) as f:99 with open(version_file) as f:
@@ -100,7 +109,8 @@
100 revision = ' (source version/commit {}-{})'.format(date, ver)109 revision = ' (source version/commit {}-{})'.format(date, ver)
101 else:110 else:
102 revision = ' (source version/commit {})'.format(ver)111 revision = ' (source version/commit {})'.format(ver)
103 status.active('Ready{}'.format(revision))112
113 status.active('Ready{}{}'.format(leader, revision))
104 reactive.set_flag('ubuntu-repository-cache.active')114 reactive.set_flag('ubuntu-repository-cache.active')
105115
106116
107117
=== modified file 'tests/unit/test_ubuntu_repository_cache.py'
--- tests/unit/test_ubuntu_repository_cache.py 2022-07-25 00:19:34 +0000
+++ tests/unit/test_ubuntu_repository_cache.py 2022-08-01 01:25:54 +0000
@@ -43,7 +43,7 @@
43 patcher = mock.patch('charmhelpers.core.hookenv.local_unit')43 patcher = mock.patch('charmhelpers.core.hookenv.local_unit')
44 self.mock_local_unit = patcher.start()44 self.mock_local_unit = patcher.start()
45 self.addCleanup(patcher.stop)45 self.addCleanup(patcher.stop)
46 self.mock_local_unit.return_value = 'mock-ubuntu-repository-cache/0'46 self.mock_local_unit.return_value = 'ubuntu-repository-cache/0'
4747
48 patcher = mock.patch('charmhelpers.core.hookenv.config')48 patcher = mock.patch('charmhelpers.core.hookenv.config')
49 self.mock_config = patcher.start()49 self.mock_config = patcher.start()
@@ -62,13 +62,36 @@
62 if os.path.exists('.juju-persistent-config'):62 if os.path.exists('.juju-persistent-config'):
63 os.unlink('.juju-persistent-config')63 os.unlink('.juju-persistent-config')
6464
65 @mock.patch('charmhelpers.core.hookenv.leader_get')
65 @mock.patch('charms.reactive.set_flag')66 @mock.patch('charms.reactive.set_flag')
66 def test_set_active(self, set_flag):67 def test_set_active(self, set_flag, leader_get):
68 self.mock_config.return_value['leader_unit'] = ''
67 ubuntu_repository_cache.set_active()69 ubuntu_repository_cache.set_active()
68 status.active.assert_called_once_with('Ready')70 status.active.assert_called_once_with('Ready')
69 set_flag.assert_called_once_with('ubuntu-repository-cache.active')71 set_flag.assert_called_once_with('ubuntu-repository-cache.active')
7072
71 status.active.reset_mock()73 status.active.reset_mock()
74 self.mock_config.return_value['leader_unit'] = 'ubuntu-repository-cache/0'
75 ubuntu_repository_cache.set_active()
76 status.active.assert_called_once_with('Ready, metadata sync leader ubuntu-repository-cache/0')
77
78 status.active.reset_mock()
79 self.mock_config.return_value['leader_unit'] = ''
80 leader_get.return_value = 'ubuntu-repository-cache/0'
81 ubuntu_repository_cache.set_active()
82 status.active.assert_called_once_with('Ready, metadata sync leader ubuntu-repository-cache/0')
83 status.active.reset_mock()
84 self.mock_config.return_value['leader_unit'] = 'ubuntu-repository-cache/0'
85 # bzr - "revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp"
86 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))
87 status.active.assert_called_once_with(
88 'Ready, metadata sync leader ubuntu-repository-cache/0 (source version/commit 20210131-uax4glwg)'
89 )
90
91 self.mock_config.return_value['leader_unit'] = ''
92 leader_get.return_value = ''
93
94 status.active.reset_mock()
72 # bzr - "revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp"95 # bzr - "revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp"
73 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))96 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))
74 status.active.assert_called_once_with('Ready (source version/commit 20210131-uax4glwg)')97 status.active.assert_called_once_with('Ready (source version/commit 20210131-uax4glwg)')

Subscribers

People subscribed via source and target branches