Merge lp:~fo0bar/turku/turku-agent-gonogo into lp:turku/turku-agent

Proposed by Ryan Finnie
Status: Merged
Approved by: Tom Haddon
Approved revision: 52
Merged at revision: 52
Proposed branch: lp:~fo0bar/turku/turku-agent-gonogo
Merge into: lp:turku/turku-agent
Diff against target: 61 lines (+22/-3)
2 files modified
turku_agent/ping.py (+17/-3)
turku_agent/utils.py (+5/-0)
To merge this branch: bzr merge lp:~fo0bar/turku/turku-agent-gonogo
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+368854@code.launchpad.net

Commit message

Allow gonogo_program to be stored in config, allow --gonogo-program to be shlex-split

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
Tom Haddon (mthaddon) wrote :

Could you explain a little more about what this change is doing, ideally in the help for the command and comments in the code?

It seems a little confusing to have a variable called "gonogo_program" that's actually a list.

And if I'm understanding this right, this option can be set either via the command line option or via a config option on disk? I'm not entirely sure, but it looks like that's the case from the change to turku_agent/utils.py.

Looks like there's a fair amount of techdebt here in terms of lack of lint or tests. I don't have enough context on the change to understand whether it makes sense to block on those or have those happen as a separate change. Could you explain why this is needed and what the impact is?

review: Needs Information
lp:~fo0bar/turku/turku-agent-gonogo updated
52. By Ryan Finnie

Allow gonogo_program to be stored in config, allow --gonogo-program to be shlex-split

Revision history for this message
Ryan Finnie (fo0bar) wrote :

> Could you explain a little more about what this change is doing, ideally in
> the help for the command and comments in the code?

> Looks like there's a fair amount of techdebt here in terms of lack of lint or
> tests. I don't have enough context on the change to understand whether it
> makes sense to block on those or have those happen as a separate change. Could
> you explain why this is needed and what the impact is?

Change has been updated. Yeah, the codebase could use some large QoL updates, but in a nutshell, the go/no-go program is to prevent pings (and ultimately backups) during sensitive times as determined on the agent machine itself.

> It seems a little confusing to have a variable called "gonogo_program" that's
> actually a list.

Done. The existing command line arg remains --gonogo-program but I've documented it, and kept etc config as gonogo_program to be consistent with the arg, but I've made them loose enough to either be a list (program + args) or string (shlex-split). The post-processed variable has been changed to gonogo_program_and_args to avoid confusion.

> And if I'm understanding this right, this option can be set either via the
> command line option or via a config option on disk? I'm not entirely sure, but
> it looks like that's the case from the change to turku_agent/utils.py.

Yeah. Existing --gonogo-program, but I wanted to add the on-disk etc option so you didn't have to edit a cron file or systemd timer (it was the only thing you couldn't do through etc, and the .cron and .timer files were essentially part of the software package). Added help to --gonogo-program.

This repo could definitely use some documentation, or at least a README.

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

LGTM

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

Change successfully merged at revision 52

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'turku_agent/ping.py'
2--- turku_agent/ping.py 2019-04-22 01:39:55 +0000
3+++ turku_agent/ping.py 2020-03-23 22:32:41 +0000
4@@ -19,6 +19,7 @@
5 import os
6 import json
7 import random
8+import shlex
9 import subprocess
10 import tempfile
11 import time
12@@ -34,7 +35,8 @@
13 parser.add_argument('--wait', '-w', type=float)
14 parser.add_argument('--restore', action='store_true')
15 parser.add_argument('--restore-storage', type=str, default=None)
16- parser.add_argument('--gonogo-program', type=str, default=None)
17+ parser.add_argument('--gonogo-program', type=str, default=None,
18+ help='Go/no-go program run each time to determine whether to ping')
19 return parser.parse_args()
20
21
22@@ -93,9 +95,21 @@
23 return
24
25 # If a go/no-go program is defined, run it and only go if it exits 0.
26- if args.gonogo_program is not None:
27+ # Example: prevent backups during high-load for sensitive systems:
28+ # ['check_load', '-c', '1,5,15']
29+ gonogo_program = args.gonogo_program if args.gonogo_program else config['gonogo_program']
30+ if isinstance(gonogo_program, (list, tuple)):
31+ # List, program name first, optional arguments after
32+ gonogo_program_and_args = list(gonogo_program)
33+ elif isinstance(gonogo_program, str):
34+ # String, shlex split it
35+ gonogo_program_and_args = shlex.split(gonogo_program)
36+ else:
37+ # None
38+ gonogo_program_and_args = []
39+ if gonogo_program_and_args:
40 try:
41- subprocess.check_call([args.gonogo_program])
42+ subprocess.check_call(gonogo_program_and_args)
43 except (subprocess.CalledProcessError, OSError):
44 return
45
46
47=== modified file 'turku_agent/utils.py'
48--- turku_agent/utils.py 2019-04-22 01:19:36 +0000
49+++ turku_agent/utils.py 2020-03-23 22:32:41 +0000
50@@ -160,6 +160,11 @@
51 if 'ssh_command' not in config:
52 config['ssh_command'] = ['ssh']
53
54+ # If a go/no-go program is defined, run it and only go if it exits 0.
55+ # Type: String (program with no args) or list (program first, optional arguments after)
56+ if 'gonogo_program' not in config:
57+ config['gonogo_program'] = None
58+
59 var_sources_d = os.path.join(config['var_dir'], 'sources.d')
60
61 # Validate the unit name

Subscribers

People subscribed via source and target branches

to all changes: