Merge lp:~hloeung/ubuntu-repository-cache/status-show-charm-revno into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 302
Merged at revision: 299
Proposed branch: lp:~hloeung/ubuntu-repository-cache/status-show-charm-revno
Merge into: lp:ubuntu-repository-cache
Diff against target: 216 lines (+110/-9)
5 files modified
reactive/ubuntu_repository_cache.py (+27/-9)
tests/unit/files/version (+5/-0)
tests/unit/files/version2 (+1/-0)
tests/unit/files/version3 (+1/-0)
tests/unit/test_ubuntu_repository_cache.py (+76/-0)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/status-show-charm-revno
Reviewer Review Type Date Requested Status
Thomas Cuthbert (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+397197@code.launchpad.net

Commit message

Add showing charm revno in juju status output

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.

300. By Haw Loeung

Support when revision-id: doesn't exist, e.g. charm pushed

301. By Haw Loeung

Capitolise

302. By Haw Loeung

status.maintenance() in favor of LOG() for when we want to update and show what's currently in progress

Revision history for this message
Thomas Cuthbert (tcuthbert) wrote :

LGTM +1

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

Change successfully merged at revision 299

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== renamed file 'reactive/ubuntu-repository-cache.py' => 'reactive/ubuntu_repository_cache.py'
--- reactive/ubuntu-repository-cache.py 2021-01-08 02:57:34 +0000
+++ reactive/ubuntu_repository_cache.py 2021-02-01 00:23:42 +0000
@@ -8,6 +8,7 @@
8import pwd8import pwd
99
10from charms import reactive10from charms import reactive
11from charms.layer import status
11from charmhelpers.core import hookenv, host, unitdata12from charmhelpers.core import hookenv, host, unitdata
12from charmhelpers.contrib import unison13from charmhelpers.contrib import unison
1314
@@ -26,7 +27,8 @@
26def install():27def install():
27 '''Perform service installation'''28 '''Perform service installation'''
2829
29 LOG('Installing %s' % SERVICE)30 status.maintenance('Installing %s' % SERVICE)
31 reactive.clear_flag('ubuntu-repository-cache.active')
30 service.install()32 service.install()
31 reactive.set_flag('ubuntu-repository-cache.installed')33 reactive.set_flag('ubuntu-repository-cache.installed')
32 # Needed to make sure any initial MPM tuning and mode will be made live.34 # Needed to make sure any initial MPM tuning and mode will be made live.
@@ -37,7 +39,8 @@
37def config_changed():39def config_changed():
38 '''Handle charm configuration changes'''40 '''Handle charm configuration changes'''
3941
40 LOG('Config changed for %s' % SERVICE)42 status.maintenance('Config changed for %s' % SERVICE)
43 reactive.clear_flag('ubuntu-repository-cache.active')
41 reactive.clear_flag('ubuntu-repository-cache.configured')44 reactive.clear_flag('ubuntu-repository-cache.configured')
42 reactive.clear_flag('nagios-nrpe.configured')45 reactive.clear_flag('nagios-nrpe.configured')
4346
@@ -68,6 +71,20 @@
68 reactive.set_flag('ubuntu-repository-cache.configured')71 reactive.set_flag('ubuntu-repository-cache.configured')
6972
7073
74@reactive.when('ubuntu-repository-cache.configured')
75@reactive.when_not('ubuntu-repository-cache.active', 'ubuntu-repository-cache.apache2-restart-required')
76def set_active(version_file='version'):
77 revno = ''
78 if os.path.exists(version_file):
79 with open(version_file) as f:
80 revno = f.readline().strip().split('-')[-1]
81 # We only want the first 8 characters, that's enough to tell
82 # which version of the charm we're using.
83 revno = ' ({})'.format(revno[:8])
84 status.active('Ready{}'.format(revno))
85 reactive.set_flag('ubuntu-repository-cache.active')
86
87
71def update_website_relation_data():88def update_website_relation_data():
72 relation_id = None89 relation_id = None
73 for relid in hookenv.relation_ids('website'):90 for relid in hookenv.relation_ids('website'):
@@ -85,7 +102,7 @@
85@reactive.when('ubuntu-repository-cache.configured')102@reactive.when('ubuntu-repository-cache.configured')
86@reactive.when('ubuntu-repository-cache.apache2-restart-required')103@reactive.when('ubuntu-repository-cache.apache2-restart-required')
87def apache2_restart():104def apache2_restart():
88 LOG('Restarting apache2 as MPM settings have changed')105 status.maintenance('Restarting apache2 as MPM settings have changed')
89 host.service_restart('apache2')106 host.service_restart('apache2')
90 reactive.clear_flag('ubuntu-repository-cache.apache2-restart-required')107 reactive.clear_flag('ubuntu-repository-cache.apache2-restart-required')
91108
@@ -94,7 +111,8 @@
94def upgrade_charm():111def upgrade_charm():
95 '''Handle charm updates'''112 '''Handle charm updates'''
96113
97 LOG('Upgrading %s' % SERVICE)114 status.maintenance('Upgrading %s' % SERVICE)
115 reactive.clear_flag('ubuntu-repository-cache.active')
98 reactive.clear_flag('ubuntu-repository-cache.configured')116 reactive.clear_flag('ubuntu-repository-cache.configured')
99 reactive.clear_flag('nagios-nrpe.configured')117 reactive.clear_flag('nagios-nrpe.configured')
100118
@@ -103,14 +121,14 @@
103def start():121def start():
104 '''Start the charm's services'''122 '''Start the charm's services'''
105123
106 LOG('Starting %s' % SERVICE)124 status.maintenance('Starting %s' % SERVICE)
107 service.render_configs()125 service.render_configs()
108126
109 sync_host = hookenv.config()['sync-host']127 sync_host = hookenv.config()['sync-host']
110 mirror_series = hookenv.config()['mirror-series'].strip()128 mirror_series = hookenv.config()['mirror-series'].strip()
111 config = hookenv.config()129 config = hookenv.config()
112 if config['sync-on-start']:130 if config['sync-on-start']:
113 LOG('Performing initial sync from %s' % sync_host)131 status.maintenance('Performing initial sync from %s' % sync_host)
114 # This creates a semaphore to prevent cronjobs form eventually running132 # This creates a semaphore to prevent cronjobs form eventually running
115 # while this is still syncing.133 # while this is still syncing.
116 try:134 try:
@@ -126,10 +144,10 @@
126 raise144 raise
127145
128 if meta_ver:146 if meta_ver:
129 LOG('Initial sync from {} completed ver={}.'.format(sync_host, meta_ver))147 status.maintenance('Initial sync from {} completed ver={}.'.format(sync_host, meta_ver))
130 service.start()148 service.start()
131 else:149 else:
132 LOG('Leader could not gather new metadata', hookenv.WARNING)150 status.maintenance('Leader could not gather new metadata', hookenv.WARNING)
133 else:151 else:
134 LOG('Skipping initial content sync, "sync-on-start" config ' 'option was not set')152 LOG('Skipping initial content sync, "sync-on-start" config ' 'option was not set')
135153
@@ -138,7 +156,7 @@
138def stop():156def stop():
139 '''Stop the charm's services'''157 '''Stop the charm's services'''
140158
141 LOG('Stopping %s' % SERVICE)159 status.maintenance('Stopping %s' % SERVICE)
142 service.stop()160 service.stop()
143161
144162
145163
=== added directory 'tests/unit/files'
=== added file 'tests/unit/files/version'
--- tests/unit/files/version 1970-01-01 00:00:00 +0000
+++ tests/unit/files/version 2021-02-01 00:23:42 +0000
@@ -0,0 +1,5 @@
1revision-id: haw.loeung@canonical.com-20210131223324-uax4glwgttv0wftp
2date: 2021-02-01 09:33:24 +1100
3build-date: 2021-02-01 09:41:04 +1100
4revno: 298
5branch-nick: ubuntu-repository-cache
0\ No newline at end of file6\ No newline at end of file
17
=== added file 'tests/unit/files/version2'
--- tests/unit/files/version2 1970-01-01 00:00:00 +0000
+++ tests/unit/files/version2 2021-02-01 00:23:42 +0000
@@ -0,0 +1,1 @@
1uax4glw
02
=== added file 'tests/unit/files/version3'
--- tests/unit/files/version3 1970-01-01 00:00:00 +0000
+++ tests/unit/files/version3 2021-02-01 00:23:42 +0000
@@ -0,0 +1,1 @@
1haw.loeung@canonical.com-20210131233021-66dfilb1615jppxt
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'tests/unit/test_ubuntu_repository_cache.py'
--- tests/unit/test_ubuntu_repository_cache.py 1970-01-01 00:00:00 +0000
+++ tests/unit/test_ubuntu_repository_cache.py 2021-02-01 00:23:42 +0000
@@ -0,0 +1,76 @@
1import os
2import shutil
3import sys
4import tempfile
5import unittest
6from unittest import mock
7
8# We also need to mock up charms.layer so we can run unit tests without having
9# to build the charm and pull in layers such as layer-status.
10sys.modules['charms.layer'] = mock.MagicMock()
11
12from charms.layer import status # NOQA: E402
13from charmhelpers.core import unitdata # NOQA: E402
14
15# Add path to where our reactive layer lives and import.
16sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
17from reactive import ubuntu_repository_cache # NOQA: E402
18
19
20class TestCharm(unittest.TestCase):
21 def setUp(self):
22 self.maxDiff = None
23 self.tmpdir = tempfile.mkdtemp(prefix='charm-unittests-')
24 self.addCleanup(shutil.rmtree, self.tmpdir)
25 os.environ['UNIT_STATE_DB'] = os.path.join(self.tmpdir, '.unit-state.db')
26
27 unitdata.kv().set('test', {})
28
29 self.charm_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
30
31 patcher = mock.patch('charmhelpers.core.hookenv.log')
32 self.mock_log = patcher.start()
33 self.addCleanup(patcher.stop)
34 self.mock_log.return_value = ''
35
36 patcher = mock.patch('charmhelpers.core.hookenv.charm_dir')
37 self.mock_charm_dir = patcher.start()
38 self.addCleanup(patcher.stop)
39 self.mock_charm_dir.return_value = self.charm_dir
40
41 patcher = mock.patch('charmhelpers.core.hookenv.local_unit')
42 self.mock_local_unit = patcher.start()
43 self.addCleanup(patcher.stop)
44 self.mock_local_unit.return_value = 'mock-ubuntu-repository-cache/0'
45
46 patcher = mock.patch('charmhelpers.core.hookenv.config')
47 self.mock_config = patcher.start()
48 self.addCleanup(patcher.stop)
49 self.mock_config.return_value = {'nagios_context': 'juju'}
50
51 patcher = mock.patch('charmhelpers.core.host.log')
52 self.mock_log = patcher.start()
53 self.addCleanup(patcher.stop)
54 self.mock_log.return_value = ''
55
56 status.active.reset_mock()
57 status.blocked.reset_mock()
58 status.maintenance.reset_mock()
59
60 @mock.patch('charms.reactive.set_flag')
61 def test_set_active(self, set_flag):
62 ubuntu_repository_cache.set_active()
63 status.active.assert_called_once_with('Ready')
64 set_flag.assert_called_once_with('ubuntu-repository-cache.active')
65
66 status.active.reset_mock()
67 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version'))
68 status.active.assert_called_once_with('Ready (uax4glwg)')
69
70 status.active.reset_mock()
71 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version2'))
72 status.active.assert_called_once_with('Ready (uax4glw)')
73
74 status.active.reset_mock()
75 ubuntu_repository_cache.set_active(os.path.join(self.charm_dir, 'tests/unit/files/version3'))
76 status.active.assert_called_once_with('Ready (66dfilb1)')

Subscribers

People subscribed via source and target branches