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
=== modified file 'turku_agent/ping.py'
--- turku_agent/ping.py 2019-04-22 01:39:55 +0000
+++ turku_agent/ping.py 2020-03-23 22:32:41 +0000
@@ -19,6 +19,7 @@
19import os19import os
20import json20import json
21import random21import random
22import shlex
22import subprocess23import subprocess
23import tempfile24import tempfile
24import time25import time
@@ -34,7 +35,8 @@
34 parser.add_argument('--wait', '-w', type=float)35 parser.add_argument('--wait', '-w', type=float)
35 parser.add_argument('--restore', action='store_true')36 parser.add_argument('--restore', action='store_true')
36 parser.add_argument('--restore-storage', type=str, default=None)37 parser.add_argument('--restore-storage', type=str, default=None)
37 parser.add_argument('--gonogo-program', type=str, default=None)38 parser.add_argument('--gonogo-program', type=str, default=None,
39 help='Go/no-go program run each time to determine whether to ping')
38 return parser.parse_args()40 return parser.parse_args()
3941
4042
@@ -93,9 +95,21 @@
93 return95 return
9496
95 # If a go/no-go program is defined, run it and only go if it exits 0.97 # If a go/no-go program is defined, run it and only go if it exits 0.
96 if args.gonogo_program is not None:98 # Example: prevent backups during high-load for sensitive systems:
99 # ['check_load', '-c', '1,5,15']
100 gonogo_program = args.gonogo_program if args.gonogo_program else config['gonogo_program']
101 if isinstance(gonogo_program, (list, tuple)):
102 # List, program name first, optional arguments after
103 gonogo_program_and_args = list(gonogo_program)
104 elif isinstance(gonogo_program, str):
105 # String, shlex split it
106 gonogo_program_and_args = shlex.split(gonogo_program)
107 else:
108 # None
109 gonogo_program_and_args = []
110 if gonogo_program_and_args:
97 try:111 try:
98 subprocess.check_call([args.gonogo_program])112 subprocess.check_call(gonogo_program_and_args)
99 except (subprocess.CalledProcessError, OSError):113 except (subprocess.CalledProcessError, OSError):
100 return114 return
101115
102116
=== modified file 'turku_agent/utils.py'
--- turku_agent/utils.py 2019-04-22 01:19:36 +0000
+++ turku_agent/utils.py 2020-03-23 22:32:41 +0000
@@ -160,6 +160,11 @@
160 if 'ssh_command' not in config:160 if 'ssh_command' not in config:
161 config['ssh_command'] = ['ssh']161 config['ssh_command'] = ['ssh']
162162
163 # If a go/no-go program is defined, run it and only go if it exits 0.
164 # Type: String (program with no args) or list (program first, optional arguments after)
165 if 'gonogo_program' not in config:
166 config['gonogo_program'] = None
167
163 var_sources_d = os.path.join(config['var_dir'], 'sources.d')168 var_sources_d = os.path.join(config['var_dir'], 'sources.d')
164169
165 # Validate the unit name170 # Validate the unit name

Subscribers

People subscribed via source and target branches

to all changes: