Merge lp:~hloeung/landscape-client-charm/show-charm-source-version into lp:landscape-client-charm

Proposed by Haw Loeung
Status: Merged
Approved by: Simon Poirier
Approved revision: 73
Merged at revision: 72
Proposed branch: lp:~hloeung/landscape-client-charm/show-charm-source-version
Merge into: lp:landscape-client-charm
Diff against target: 38 lines (+20/-1)
1 file modified
hooks/common.py (+20/-1)
To merge this branch: bzr merge lp:~hloeung/landscape-client-charm/show-charm-source-version
Reviewer Review Type Date Requested Status
Simon Poirier (community) Approve
Haw Loeung Needs Resubmitting
Colin Misare Approve
Review via email: mp+397480@code.launchpad.net

Commit message

Add showing charm source version/commit in juju status output

To post a comment you must log in.
72. By Haw Loeung

Add showing charm source version/commit in juju status output

Revision history for this message
Colin Misare (cmisare) wrote :
Revision history for this message
Colin Misare (cmisare) :
review: Approve
Revision history for this message
Simon Poirier (simpoir) wrote :

Although I do like some useful debug info, I see a few small things:
1) Obvious but essential nitpick. please run `make lint`. Some lines are too long.
2) I see no reason to truncate revisions. This is not git and we're not saving saving bytes here.
3) The truncated version is useless as this is a bzr repo (e.g. <email address hidden> truncates to 'haw.loeu…')
4) This seems like it would be more useful in the debug logs than just in the ephemeral status line. What's the exact use case?

review: Needs Fixing
73. By Haw Loeung

Fixed based on review

Revision history for this message
Haw Loeung (hloeung) wrote :

> Although I do like some useful debug info, I see a few small things:
> 1) Obvious but essential nitpick. please run `make lint`. Some lines are too
> long.

Fixed.

> 2) I see no reason to truncate revisions. This is not git and we're not saving
> saving bytes here.
> 3) The truncated version is useless as this is a bzr repo (e.g.
> <email address hidden> truncates to
> 'haw.loeu…')

It's shown in the juju status output, we usually use juju status --format=tabular so would be useful to try keep this short. I've fixed it now, it should show:

| 20200222-auxx19qq

Elsewhere, we're using this. e.g.:

| $ jsft | grep 'Ready.*source'
| apt-stresstest/0* active idle 3 52.224.81.63 Ready (source version/commit efcc988-…)
| ubuntu-repository-cache/0* active idle 0 52.146.31.10 80/tcp Ready (source version/commit 20210217-q3mg90b4)

> 4) This seems like it would be more useful in the debug logs than just in the
> ephemeral status line. What's the exact use case?

status_set() is also logged in the juju unit logs.

In our use case, we have periodic jobs to dump out juju status info. This allows us to use tools such as grep to check across multiple environments/models and find old and outdated charms to upgrade.

review: Needs Resubmitting
Revision history for this message
Simon Poirier (simpoir) wrote :

Thanks. LGTM.

Did you want to tell yourself to resubmit that MP or was that review status just by mistake?

review: Approve
Revision history for this message
Simon Poirier (simpoir) wrote :

FYI this is also published to the cs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2019-02-03 14:50:36 +0000
3+++ hooks/common.py 2021-02-18 02:38:19 +0000
4@@ -85,6 +85,20 @@
5 def local_unit(self):
6 return local_unit()
7
8+ def get_charm_version(self):
9+ revision = ''
10+ if os.path.exists('version'):
11+ with open('version') as f:
12+ line = f.readline().strip().split('-')
13+ # We only want the first 8 characters, that's enough to tell which
14+ # version of the charm we're using.
15+ ver = line[-1][:8]
16+ # We also want to include the date, again first 8 chars.
17+ date = line[-2][:8]
18+ revision = '{}-{})'.format(date, ver)
19+
20+ return revision
21+
22 def update_client_config(self, service_config, try_to_register=True):
23 """Update the client config.
24
25@@ -118,7 +132,12 @@
26 if is_configured_enough:
27 exit_code = self.try_to_register()
28 if exit_code == 0:
29- self.status_set("active", "System successfully registered")
30+ ver_str = ''
31+ ver = self.get_charm_version()
32+ if ver:
33+ ver_str = ' (source version/commit {})'.format(ver)
34+ self.status_set("active", "System successfully registered{}"
35+ .format(ver_str))
36 else:
37 if not self.config.get("account_name"):
38 self.status_set(

Subscribers

People subscribed via source and target branches

to all changes: