Merge lp:~hloeung/ubuntu-repository-cache/charm-env-fixes into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 289
Merged at revision: 288
Proposed branch: lp:~hloeung/ubuntu-repository-cache/charm-env-fixes
Merge into: lp:ubuntu-repository-cache
Diff against target: 49 lines (+6/-4)
4 files modified
lib/ubuntu_repository_cache/metadata_sync.py (+3/-2)
lib/ubuntu_repository_cache/service.py (+1/-0)
lib/ubuntu_repository_cache/tests/test_metadata_sync.py (+1/-1)
templates/cron/ubuntu-repository-cache_rsync.cron (+1/-1)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/charm-env-fixes
Reviewer Review Type Date Requested Status
Thomas Cuthbert (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+392157@code.launchpad.net

Commit message

Switch to the charm-env shipped with the charm, it's the latest and fixes GH#144

Description of the change

The latest charm-env fixes these import warnings/errors:

| root@machine-0:/etc/cron.d# . /etc/repository-sync/ubuntu-repository-cache && run-one /usr/local/sbin/charm-env --charm ubuntu-repository-cache | python3 -m ubuntu_repository_cache.metadata_sync
| Traceback (most recent call last):
| File "<string>", line 1, in <module>
| ModuleNotFoundError: No module named 'charmhelpers'
| Traceback (most recent call last):
| File "<string>", line 1, in <module>
| ModuleNotFoundError: No module named 'charmhelpers'

This is https://github.com/juju-solutions/layer-basic/commit/0845a8429aae4eb1c32131ef37235f2ac196676c

Sadly, /usr/local/sbin/charm-env is rarely updated, likely shipped out on unit provision / charm install. Switch to the version shipped out with the charm instead.

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.

289. By Haw Loeung

Cron job too

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 288

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/ubuntu_repository_cache/metadata_sync.py'
2--- lib/ubuntu_repository_cache/metadata_sync.py 2020-10-06 10:04:18 +0000
3+++ lib/ubuntu_repository_cache/metadata_sync.py 2020-10-13 04:39:12 +0000
4@@ -274,8 +274,9 @@
5
6 # Call the sync hook inside the juju environment to propagate changes to
7 # other units
8- path = '/usr/local/sbin/charm-env /var/lib/juju/agents/{}/charm/hooks/ubuntu-repository-cache-sync {}'
9- path = path.format(unit_path, meta_ver)
10+ charm_env = '/var/lib/juju/agents/{}/charm/bin/charm-env'.format(unit_path)
11+ path = '{} /var/lib/juju/agents/{}/charm/hooks/ubuntu-repository-cache-sync {}'
12+ path = path.format(charm_env, unit_path, meta_ver)
13 cmd = ['juju-run', local_unit, path]
14
15 log("Executing hook: {}".format(cmd))
16
17=== modified file 'lib/ubuntu_repository_cache/service.py'
18--- lib/ubuntu_repository_cache/service.py 2020-10-06 10:04:18 +0000
19+++ lib/ubuntu_repository_cache/service.py 2020-10-13 04:39:12 +0000
20@@ -276,6 +276,7 @@
21 cron_context['UnitPath'] = '-'.join(('unit', hookenv.local_unit().replace('/', '-')))
22 cron_context['MirrorSeries'] = config['mirror-series'].strip()
23 cron_context['ConfigPath'] = urc_config_path
24+ cron_context['CharmEnvPath'] = os.path.join(hookenv.charm_dir(), 'bin', 'charm-env')
25 templating.render('cron/ubuntu-repository-cache_rsync.cron', cron_filename, cron_context)
26 templating.render('cron/ubuntu-repository-cache-config', urc_config_path, cron_context)
27 else:
28
29=== modified file 'lib/ubuntu_repository_cache/tests/test_metadata_sync.py'
30--- lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2020-10-06 10:04:18 +0000
31+++ lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2020-10-13 04:39:12 +0000
32@@ -187,7 +187,7 @@
33 [
34 'juju-run',
35 'unit/0',
36- '/usr/local/sbin/charm-env '
37+ '/var/lib/juju/agents/something/charm/bin/charm-env '
38 '/var/lib/juju/agents/something/charm/hooks/'
39 'ubuntu-repository-cache-sync some_meta_var',
40 ],
41
42=== modified file 'templates/cron/ubuntu-repository-cache_rsync.cron'
43--- templates/cron/ubuntu-repository-cache_rsync.cron 2020-07-09 02:35:50 +0000
44+++ templates/cron/ubuntu-repository-cache_rsync.cron 2020-10-13 04:39:12 +0000
45@@ -1,4 +1,4 @@
46 # This cronjob will make the leader sync its view of the metadata with upstream
47 # It will then trigger a juju-run to let its peers synchronise.
48-{{ Minutes }} * * * * root . {{ ConfigPath }} && run-one /usr/local/sbin/charm-env --charm ubuntu-repository-cache python3 -m ubuntu_repository_cache.metadata_sync
49+{{ Minutes }} * * * * root . {{ ConfigPath }} && run-one {{ CharmEnvPath }} --charm ubuntu-repository-cache python3 -m ubuntu_repository_cache.metadata_sync
50

Subscribers

People subscribed via source and target branches