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

Proposed by Xav Paice
Status: Merged
Approved by: Paul Goins
Approved revision: e7592deed7d181b683b62f15f4b97d927fa4a4ab
Merged at revision: 9f83e6177ea72883b973c50c97307b1d8e3f7baf
Proposed branch: ~xavpaice/charm-logrotated:bug_1833722
Merge into: charm-logrotated:master
Diff against target: 67 lines (+29/-11)
1 file modified
src/actions/actions.py (+29/-11)
Reviewer Review Type Date Requested Status
Paul Goins Approve
Peter Sabaini (community) Approve
Canonical IS Reviewers Pending
Drew Freiberger Pending
BootStack Reviewers Pending
Tom Haddon Pending
Review via email: mp+396711@code.launchpad.net

This proposal supersedes a proposal from 2020-06-01.

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 : Posted in a previous version of this proposal

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Paul Goins (vultaire) wrote : Posted in a previous version of this proposal

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) : Posted in a previous version of this proposal
Revision history for this message
Drew Freiberger (afreiberger) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

Leaving for bootstack-reviewers

review: Abstain
Revision history for this message
Drew Freiberger (afreiberger) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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

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
Peter Sabaini (peter-sabaini) wrote :

lgtm

review: Approve
Revision history for this message
Alvaro Uria (aluria) wrote :

The change looks good. However, I think actions.py should call #!/usr/local/sbin/charm-env python3 so the active_venv() part is automatically done and "lib" is also included by default.

Other than that, +1

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

I agree with aluria's comment, but that can be fixed another time; I don't think it's important enough to block on. I'm +1'ing this.

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

> The change looks good. However, I think actions.py should call
> #!/usr/local/sbin/charm-env python3 so the active_venv() part is automatically
> done and "lib" is also included by default.
>
> Other than that, +1

Good point btw; I wasn't aware of that methodology.

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

Change successfully merged at revision 9f83e6177ea72883b973c50c97307b1d8e3f7baf

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/actions/actions.py b/src/actions/actions.py
index dd311d4..65ee216 100755
--- a/src/actions/actions.py
+++ b/src/actions/actions.py
@@ -4,33 +4,51 @@
4import os4import os
5import sys5import sys
66
7from charmhelpers.core import hookenv7sys.path.append("lib")
88
9from lib_cron import CronHelper9from charms.layer.basic import activate_venv # NOQA E402
1010
11from lib_logrotate import LogrotateHelper11activate_venv()
1212
13sys.path.insert(0, os.path.join(os.environ["CHARM_DIR"], "lib"))13from charmhelpers.core.hookenv import action_fail # NOQA E402
14from lib_cron import CronHelper # NOQA E402
15from lib_logrotate import LogrotateHelper # NOQA E402
1416
15hooks = hookenv.Hooks()
16logrotate = LogrotateHelper()17logrotate = LogrotateHelper()
17cron = CronHelper()18cron = CronHelper()
1819
1920
20@hooks.hook("update-logrotate-files")21def update_logrotate_files(args):
21def update_logrotate_files():
22 """Update the logrotate files."""22 """Update the logrotate files."""
23 logrotate.read_config()23 logrotate.read_config()
24 logrotate.modify_configs()24 logrotate.modify_configs()
2525
2626
27@hooks.hook("update-cronjob")27def update_cronjob(args):
28def update_cronjob():
29 """Update the cronjob file."""28 """Update the cronjob file."""
30 cron.read_config()29 cron.read_config()
31 cron.install_cronjob()30 cron.install_cronjob()
3231
3332
33ACTIONS = {
34 "update-cronjob": update_cronjob,
35 "update-logrotate-files": update_logrotate_files,
36}
37
38
39def main(args):
40 """Run assigned action."""
41 action_name = os.path.basename(args[0])
42 try:
43 action = ACTIONS[action_name]
44 except KeyError:
45 return "Action {} undefined".format(action_name)
46 else:
47 try:
48 action(args)
49 except Exception as e:
50 action_fail(str(e))
51
52
34if __name__ == "__main__":53if __name__ == "__main__":
35 """Main function."""54 sys.exit(main(sys.argv))
36 hooks.execute(sys.argv)

Subscribers

People subscribed via source and target branches

to all changes: