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
=== modified file 'hooks/common.py'
--- hooks/common.py 2019-02-03 14:50:36 +0000
+++ hooks/common.py 2021-02-18 02:38:19 +0000
@@ -85,6 +85,20 @@
85 def local_unit(self):85 def local_unit(self):
86 return local_unit()86 return local_unit()
8787
88 def get_charm_version(self):
89 revision = ''
90 if os.path.exists('version'):
91 with open('version') as f:
92 line = f.readline().strip().split('-')
93 # We only want the first 8 characters, that's enough to tell which
94 # version of the charm we're using.
95 ver = line[-1][:8]
96 # We also want to include the date, again first 8 chars.
97 date = line[-2][:8]
98 revision = '{}-{})'.format(date, ver)
99
100 return revision
101
88 def update_client_config(self, service_config, try_to_register=True):102 def update_client_config(self, service_config, try_to_register=True):
89 """Update the client config.103 """Update the client config.
90104
@@ -118,7 +132,12 @@
118 if is_configured_enough:132 if is_configured_enough:
119 exit_code = self.try_to_register()133 exit_code = self.try_to_register()
120 if exit_code == 0:134 if exit_code == 0:
121 self.status_set("active", "System successfully registered")135 ver_str = ''
136 ver = self.get_charm_version()
137 if ver:
138 ver_str = ' (source version/commit {})'.format(ver)
139 self.status_set("active", "System successfully registered{}"
140 .format(ver_str))
122 else:141 else:
123 if not self.config.get("account_name"):142 if not self.config.get("account_name"):
124 self.status_set(143 self.status_set(

Subscribers

People subscribed via source and target branches

to all changes: