Merge ~dparv/charm-logrotated:bug_1833722 into charm-logrotated:master

Proposed by Diko Parvanov
Status: Superseded
Proposed branch: ~dparv/charm-logrotated:bug_1833722
Merge into: charm-logrotated:master
Diff against target: 75 lines (+34/-11)
1 file modified
actions/actions.py (+34/-11)
Reviewer Review Type Date Requested Status
Drew Freiberger (community) Abstain
Tom Haddon Abstain
Paul Goins Needs Fixing
BootStack Reviewers Pending
Review via email: mp+384891@code.launchpad.net

This proposal has been superseded by a proposal from 2021-01-22.

Commit message

Re-worked actions.py

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.

Revision history for this message
Paul Goins (vultaire) wrote :

I would prefer if we leverage charms.layer.basic.activate_venv(), as described in one of the diff comments here, to better ensure consistency of behavior between actions and hooks. (In conjunction with reverting the sshebang line.)

Other than that, the other changes seem okay, although I don't think they really change behavior.

review: Needs Fixing
Revision history for this message
Paul Goins (vultaire) :
Revision history for this message
Drew Freiberger (afreiberger) wrote :

There's nothing in this change discussing why any of these actions must run in the venv. the only thing setup in the venv is layer basic's charmhelpers wheelhouse. This should be imported with the snippet suggested by Paul.

Also, there's some iterative leftovers in the code like args that aren't passed or used. linting should have caught that these references are never used.

review: Needs Fixing
Revision history for this message
Tom Haddon (mthaddon) wrote :

Leaving for bootstack-reviewers

review: Abstain
Revision history for this message
Drew Freiberger (afreiberger) wrote :

taking another look, this looks like a pretty standard actions.py update other than the venv reference in the #! line.

review: Abstain
Revision history for this message
Paul Goins (vultaire) wrote :

Minor comment in reply to one of Drew's. My other feedback still stands.

Unmerged commits

f3fab36... by Diko Parvanov

Re-worked actions.py

Closes-Bug: #1833722

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/actions/actions.py b/actions/actions.py
2index 8178850..0cc7b99 100755
3--- a/actions/actions.py
4+++ b/actions/actions.py
5@@ -1,36 +1,59 @@
6-#!/usr/bin/env python3
7+#!/usr/bin/env ../.venv/bin/python3
8 """Actions module."""
9
10 import os
11 import sys
12
13-from charmhelpers.core import hookenv
14+
15+_path = os.path.dirname(os.path.realpath(__file__))
16+_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
17+_lib = os.path.abspath(os.path.join(_path, '../lib'))
18+
19+
20+def _add_path(path):
21+ if path not in sys.path:
22+ sys.path.insert(1, path)
23+
24+_add_path(_hooks)
25+_add_path(_lib)
26+
27+from charmhelpers.core.hookenv import action_fail
28
29 from lib_cron import CronHelper
30
31 from lib_logrotate import LogrotateHelper
32
33-sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
34-
35-hooks = hookenv.Hooks()
36 logrotate = LogrotateHelper()
37 cron = CronHelper()
38
39
40-@hooks.hook("update-logrotate-files")
41-def update_logrotate_files():
42+def update_logrotate_files(args):
43 """Update the logrotate files."""
44 logrotate.read_config()
45 logrotate.modify_configs()
46
47
48-@hooks.hook("update-cronjob")
49-def update_cronjob():
50+def update_cronjob(args):
51 """Update the cronjob file."""
52 cron.read_config()
53 cron.install_cronjob()
54
55+ACTIONS = {"update-cronjob": update_cronjob, "update-logrotate-files": update_logrotate_files}
56+
57+
58+def main(args):
59+ action_name = os.path.basename(args[0])
60+ try:
61+ action = ACTIONS[action_name]
62+ except KeyError:
63+ return "Action {} undefined".format(action_name)
64+ else:
65+ try:
66+ action(args)
67+ except Exception as e:
68+ action_fail(str(e))
69+
70
71 if __name__ == "__main__":
72- """Main function."""
73- hooks.execute(sys.argv)
74+ sys.exit(main(sys.argv))
75+

Subscribers

People subscribed via source and target branches

to all changes: