Volans has uploaded a new change for review.
https://gerrit.wikimedia.org/r/306650
Change subject: salt-misc: fix Flake8
......................................................................
salt-misc: fix Flake8
Skipped only the "usage" string.
Bug: T143559
Change-Id: I939083698abbdae15b782999fe93f6a039cb9aae
---
M salt-misc/do_ssh_commands.py
M salt-misc/parse-minion-output.py
M salt-misc/salt-fixups.py
3 files changed, 70 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/software
refs/changes/50/306650/1
diff --git a/salt-misc/do_ssh_commands.py b/salt-misc/do_ssh_commands.py
index 6df8d7d..e620c09 100755
--- a/salt-misc/do_ssh_commands.py
+++ b/salt-misc/do_ssh_commands.py
@@ -70,8 +70,8 @@
elif target_type == 'grain':
command = ['test.ping']
command.extend(target.split(':'))
- elif (target_type == 'list' or target_type == 'glob'
- or target_type == 'mia'):
+ elif (target_type == 'list' or target_type == 'glob' or
+ target_type == 'mia'):
command = ['test.ping']
if target_type == 'mia':
command.append('-v')
diff --git a/salt-misc/parse-minion-output.py b/salt-misc/parse-minion-output.py
index da605a1..2a68664 100644
--- a/salt-misc/parse-minion-output.py
+++ b/salt-misc/parse-minion-output.py
@@ -1,5 +1,5 @@
-import os
import sys
+
def get_hostinfo(lines):
'''
@@ -18,12 +18,14 @@
hostinfo.append(line)
return hosts
+
def get_date(line):
'''
from a line of ls -lt, get the date
'''
fields = line.split()
- return " ".join([fields[index] for index in range(5,8)])
+ return " ".join([fields[index] for index in range(5, 8)])
+
def get_salt_version(line):
'''
@@ -35,11 +37,13 @@
return field
return ""
+
def get_process(line):
'''
dig out the date and command from a ps line
'''
- # root 361 0.0 0.9 69932 19768 ? Ss Aug19 0:00
/usr/bin/python /usr/bin/salt-minion'
+ # root 361 0.0 0.9 69932 19768 ? Ss Aug19 0:00
+ # /usr/bin/python /usr/bin/salt-minion'
line.strip()
if not line:
return ""
@@ -47,6 +51,7 @@
if len(fields) < 8:
return ""
return " ".join(fields[8:])
+
def get_host_data(hostinfo):
'''
@@ -75,7 +80,8 @@
master:
- labs-puppetmaster-eqiad.wikimedia.org
- labs-puppetmaster-codfw.wikimedia.org
- and this terminates as soon as we see a line with non
whitespace first char.
+ and this terminates as soon as we see a line with non
+ whitespace first char.
'''
want_master = True
else:
@@ -94,7 +100,7 @@
hostdata['salt_version'] = get_salt_version(line)
elif line.startswith("AuthenticationError"):
hostdata['minion_errors'] = line
- elif want_master == True:
+ elif want_master:
stripped = line.lstrip()
if stripped and stripped[0] == '-':
master_name = stripped[1:].lstrip()
@@ -103,16 +109,18 @@
want_master = False
return hostdata
+
def show(hostdata):
'''
given some extracted data about a host, display it
'''
- #yeah. it's cheap. so what.
+ # yeah. it's cheap. so what.
keys = sorted(hostdata.keys())
for key in keys:
if hostdata[key]:
print key, hostdata[key]
print
+
def show_ec2id_salt_ids(summaries):
'''
@@ -123,8 +131,11 @@
print "hosts with ec2id salt ids"
for summary in summaries:
if summary['salt_id'].startswith('i-000'):
- print summary['hostname'], summary['salt_id'], "last puppet run:",
summary['puppet_rundate']
+ print("{} {} last puppet run: {}".format(
+ summary['hostname'], summary['salt_id'],
+ summary['puppet_rundate']))
print
+
def show_oldstyle_salt_ids(summaries):
'''
@@ -140,6 +151,7 @@
print summary['hostname'], summary['salt_id']
print
+
def show_salt_errors(summaries):
'''
given nicely formatted host info summaries,
@@ -151,6 +163,7 @@
if summary['minion_errors']:
print summary['hostname']
print
+
def show_salt_bad_versions(summaries):
'''
@@ -164,6 +177,7 @@
if not summary['salt_version'].startswith('2014.7.5'):
print summary['hostname'], summary['salt_version'],
summary['issue']
print
+
def show_salt_other_masters(summaries):
'''
@@ -181,6 +195,7 @@
print summary['hostname'], summary['masters']
break
print
+
def show_salt_correct_masters(summaries):
'''
@@ -202,6 +217,7 @@
print summary['hostname'], summary['masters']
print
+
def show_salt_no_processes(summaries):
'''
show all hosts where no salt minion is running
@@ -211,6 +227,7 @@
if not summary['processes']:
print summary['hostname']
print
+
def show_salt_too_many_processes(summaries):
'''
@@ -223,6 +240,7 @@
print summary['hostname'], summary['processes']
print
+
def show_salt_no_keysize(summaries):
'''
show all hosts where keysize has not been set
@@ -230,8 +248,10 @@
print "hosts with no keysize specified"
for summary in summaries:
if summary['masters'] and not summary['keysize']:
- print summary['hostname'], 'last puppet run:',
summary['puppet_rundate']
+ print("{} last puppet run: {}".format(
+ summary['hostname'], summary['puppet_rundate']))
print
+
def main():
summaries = []
@@ -253,4 +273,4 @@
show_salt_no_keysize(summaries)
if __name__ == "__main__":
- main()
+ main()
diff --git a/salt-misc/salt-fixups.py b/salt-misc/salt-fixups.py
index 2776f91..2c93d43 100644
--- a/salt-misc/salt-fixups.py
+++ b/salt-misc/salt-fixups.py
@@ -33,6 +33,7 @@
PUPPET_MASTER = 'labs-puppetmaster-eqiad.wikimedia.org'
PUPPETCONF = "/etc/puppet/puppet.conf"
+
def check_master():
masters = get_masters()
if not masters:
@@ -41,6 +42,7 @@
if entry not in MASTERS:
return False
return True
+
def get_masters():
contents = open(SALTCONF, "r").read()
@@ -54,12 +56,13 @@
master:
- labs-puppetmaster-eqiad.wikimedia.org
- labs-puppetmaster-codfw.wikimedia.org
- and this terminates as soon as we see a line with non
whitespace first char.
+ and this terminates as soon as we see a line with non
+ whitespace first char.
'''
want_master = True
else:
masters.append(line[8:])
- elif want_master == True:
+ elif want_master:
stripped = line.lstrip()
if stripped and stripped[0] == '-':
master_name = stripped[1:].lstrip()
@@ -68,12 +71,14 @@
return masters
return masters
+
def restart_salt():
'''
shoot all minions and start one
'''
shoot_salt_processes()
start_salt_process()
+
def check_salt_auth_error():
'''
@@ -94,6 +99,7 @@
return True
return False
+
def apt_update(verbose):
'''
apt-get update and display the results
@@ -103,6 +109,7 @@
'''
return get_popen_output(["apt-get", "update"], "W:", display=verbose)
+
def apt_install_dryrun(verbose):
'''
apt-get install dryrun for minion and display the results
@@ -111,13 +118,17 @@
return get_popen_output(["apt-get", "-y", "--simulate", "-o",
"DPkg::Options::=--force-confold",
"-o", "Apt::Get::AllowUnauthenticated=true",
- "install", "salt-common", "salt-minion"],
display=verbose)
+ "install", "salt-common", "salt-minion"],
+ display=verbose)
+
def apt_install(verbose):
return get_popen_output(["apt-get", "-y", "--force-yes",
"-o", "DPkg::Options::=--force-confold",
"-o", "Apt::Get::AllowUnauthenticated=true",
- "install", "salt-common", "salt-minion"],
display=verbose)
+ "install", "salt-common", "salt-minion"],
+ display=verbose)
+
def fix_salt_version(verbose):
'''
@@ -132,6 +143,7 @@
salt_processes = get_salt_processes()
if not salt_processes:
start_salt_process()
+
def get_popen_output(command, ignore=None, display=False, skipretcode=False):
'''
@@ -155,6 +167,7 @@
print "INFO:", command, output
return output.splitlines()
+
def get_salt_version():
'''
get the installed version of salt-minion via dpkg
@@ -167,6 +180,7 @@
return entry[9:]
return None
+
def check_salt_version(version):
if version is None:
return False
@@ -174,11 +188,13 @@
return False
return True
+
def get_salt_processes():
'''
return list of pids of salt-minions running
'''
return get_popen_output(["pgrep", "salt-minion"], skipretcode=True)
+
def check_salt_processes(processes):
'''
@@ -194,11 +210,13 @@
if len(processes) == 1:
return True
- entries = get_popen_output(["ps", "-p", ",".join(processes), "-o",
"etimes="], skipretcode=True)
+ entries = get_popen_output(
+ ["ps", "-p", ",".join(processes), "-o", "etimes="], skipretcode=True)
for entry in entries:
if int(entry) > OLD_PROC:
return False
return True
+
def do_popen(command):
'''
@@ -214,17 +232,20 @@
print output
return True
+
def do_upstart():
'''
start salt-minion via upstart
'''
return do_popen([UPSTART, "salt-minion"])
+
def do_systemctl():
'''
start salt-minion via systemctl
'''
return do_popen([SYSTEMCTL, "start", "salt-minion.service"])
+
def start_salt_process():
'''
@@ -238,6 +259,7 @@
else:
print "failed to find startup command"
+
def shoot_salt_processes():
'''
shoot all salt-minion processes with prejudice
@@ -249,6 +271,7 @@
print "hrm, still some processes around", salt_processes
return False
return True
+
def usage(message=None):
'''
@@ -278,9 +301,10 @@
don't actually run them
--verbose (-v): display informational messages as this script runs
--help (-h): display this message
-"""
+""" # noqa
sys.stderr.write(usage_message)
sys.exit(1)
+
def do_version(dryrun, verbose):
'''
@@ -297,6 +321,7 @@
fix_salt_version(verbose)
elif dryrun or verbose:
print "salt version is good"
+
def do_count(dryrun, verbose):
'''
@@ -328,6 +353,7 @@
elif dryrun or verbose:
print "salt minion count is good"
+
def do_autherror(dryrun, verbose):
'''
check if the salt log ends with a notification of an authentication
@@ -344,6 +370,7 @@
elif dryrun or verbose:
print "no minion autherror"
+
def check_puppet_master():
contents = open(PUPPETCONF, "r").read()
lines = contents.splitlines()
@@ -352,6 +379,7 @@
if PUPPET_MASTER in entry:
return True
return False
+
def fix_keysize_config(verbose):
# check current contents of config file
@@ -392,11 +420,13 @@
os.rename(new_config, SALTCONF)
return True
+
def remove_minion_key():
if os.path.exists(SALT_MINION_PUB):
os.unlink(SALT_MINION_PUB)
if os.path.exists(SALT_MINION_KEY):
os.unlink(SALT_MINION_KEY)
+
def check_keysize():
if not os.path.exists(SALT_MINION_PUB):
@@ -410,6 +440,7 @@
if SALT_KEYSIZE in entry:
return True
return False
+
def do_regenkey(dryrun, verbose):
'''
@@ -449,6 +480,7 @@
print "starting minion, don't forget to delete key on master"
start_salt_process()
+
def do_actions(actions, dryrun, verbose):
'''
handle user-requested actions
@@ -465,6 +497,7 @@
if "regenkey" in actions:
do_regenkey(dryrun, verbose)
+
def main():
'''
make sure salt version is correct
--
To view, visit https://gerrit.wikimedia.org/r/306650
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I939083698abbdae15b782999fe93f6a039cb9aae
Gerrit-PatchSet: 1
Gerrit-Project: operations/software
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits