Muehlenhoff has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/373048 )
Change subject: Sort output of programs needing a restart
......................................................................
Sort output of programs needing a restart
And various PEP8 fixes.
Change-Id: Ic0f7f3bc0fa766f8223b05830390400c29c80189
---
M clients/debdeploy-restarts
M server/debdeploy.py
2 files changed, 83 insertions(+), 47 deletions(-)
Approvals:
Muehlenhoff: Looks good to me, approved
jenkins-bot: Verified
diff --git a/clients/debdeploy-restarts b/clients/debdeploy-restarts
index f36e982..ed1cb90 100755
--- a/clients/debdeploy-restarts
+++ b/clients/debdeploy-restarts
@@ -96,9 +96,9 @@
'''
if json_output:
- return json.dumps([status, restarts_needed])
+ return status + " " + json.dumps(restarts_needed)
else:
- return [status, restarts_needed]
+ return status + " " + restarts_needed
def main():
@@ -112,26 +112,28 @@
deleted_files = get_deleted_files()
restarts_needed = {}
+ return_restarts = {}
for i in deleted_files:
procname, pid, fname = (i)
for libname in args.libname:
if fname.find(libname) != -1:
- if not restarts_needed.get(procname, None):
- restarts_needed[procname] = {}
+ if not restarts_needed.get(fname, None):
+ restarts_needed[fname] = set()
+ restarts_needed[fname].add(procname)
+ else:
+ restarts_needed[fname].add(procname)
- if not restarts_needed[procname].get(pid, None):
- restarts_needed[procname][pid] = []
-
- restarts_needed[procname][pid].append(fname)
+ for i in restarts_needed.keys():
+ return_restarts[i] = list(restarts_needed[i])
if len(restarts_needed) == 0:
return result("OK", "No service needs a restart", args.json)
else:
logger.info("These services need a restart:")
for i in restarts_needed:
- logger.info(i + " (" + str(len(restarts_needed[i].keys())) + "
processes)")
- return result("OK", restarts_needed, args.json)
+ logger.info(i + " (" + str(len(restarts_needed)) + " processes)")
+ return result("OK", return_restarts, args.json)
if __name__ == '__main__':
diff --git a/server/debdeploy.py b/server/debdeploy.py
index e3894ff..2ea9d6d 100755
--- a/server/debdeploy.py
+++ b/server/debdeploy.py
@@ -20,42 +20,49 @@
import cumin
from cumin import backends, query, transport, transports
+from debdeploy_conf import *
+import pydoc
+from debdeploy_updatespec import *
if os.geteuid() != 0:
print "debdeploy needs to be run as root"
sys.exit(1)
-from debdeploy_conf import *
cumin_config = cumin.Config()
conf = DebDeployConfig("/etc/debdeploy.conf")
if conf.debug:
- logging.basicConfig(filename='/var/log/debdeploy/debdeploy.log',
format='%(levelname)s: %(asctime)s : %(funcName)s : %(message)s',
level=logging.DEBUG)
+ logging.basicConfig(filename='/var/log/debdeploy/debdeploy.log',
+ format='%(levelname)s: %(asctime)s : %(funcName)s :
%(message)s',
+ level=logging.DEBUG)
else:
- logging.basicConfig(filename='/var/log/debdeploy/debdeploy.log',
format='%(levelname)s: %(asctime)s : %(funcName)s : %(message)s',
level=logging.INFO)
+ logging.basicConfig(filename='/var/log/debdeploy/debdeploy.log',
+ format='%(levelname)s: %(asctime)s : %(funcName)s :
%(message)s',
+ level=logging.INFO)
-import pydoc
-from debdeploy_updatespec import *
class logpager:
- threshold = 20 # if pager buffer contains more than <threshold> lines, use
the pager
+ threshold = 20 # if pager buffer contains more than <threshold> lines,
use the pager
+
def __init__(self):
self.buf = ""
+
def add(self, *args):
for i in args:
self.buf += str(i)
self.buf += "\n"
+
def add_nb(self, *args):
for i in args:
self.buf += str(i)
+
def show(self):
if self.buf.count("\n") > self.threshold:
pydoc.pager(self.buf)
else:
print self.buf
-
def deploy_update(source, update_type, update_file, servergroup,
supported_distros, fixes):
@@ -76,19 +83,19 @@
print "Rolling out", source, ":",
print update_desc[update_type]
-
+
worker = transport.Transport.new(cumin_config, logging)
hosts = query.Query(cumin_config).execute('A:all')
- cmd = '/usr/bin/debdeploy-deploy --source ' + source + ' --updatespec '
-
+ cmd = '/usr/bin/debdeploy-deploy --source ' + source + ' --updatespec '
for distro in fixes:
if fixes[distro]:
- cmd += str(supported_distros[distro][0][0]) + "_" +
str(supported_distros[distro][0][1]) + "_" + str(fixes[distro]) + " "
-
+ cmd += str(supported_distros[distro][0][0]) + "_" +
str(supported_distros[distro][0][1])
+ + "_" + str(fixes[distro]) + " "
+
worker.target = transports.Target(hosts, batch_size=100, batch_sleep=None,
logger=logging)
- worker.commands = [ cmd ]
+ worker.commands = [cmd]
worker.timeout = None
worker.handler = 'sync'
@@ -101,7 +108,7 @@
# sys.stdout = discard_output
# exit_code = worker.execute()
# sys.stdout = oldstdout
-
+
exit_code = worker.execute()
out = {}
@@ -111,23 +118,25 @@
# print worker.handler.counters
-def detect_restarts(libnames, servergroup):
+def detect_restarts(libnames, servergroup, verbose):
'''
Query for necessary restarts after a library or interpreter upgrade
- libnames : A list of library base names, e.g. libssl for
/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (list of strings)
+ libnames : A list of library base names, e.g. libssl for
+ /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (list of strings)
servergroup : The name of the server group for which process restarts
should be queried (string)
+ verbose : If enabled, the full of hosts needing a restart is shown
(boolean)
'''
worker = transport.Transport.new(cumin_config, logging)
hosts = query.Query(cumin_config).execute('A:all')
- cmd = '/usr/bin/debdeploy-restarts --libname '
+ cmd = '/usr/bin/debdeploy-restarts --json --libname '
for lib in libnames:
cmd += lib + " "
worker.target = transports.Target(hosts, batch_size=100, batch_sleep=None,
logger=logging)
- worker.commands = [ cmd ]
+ worker.commands = [cmd]
worker.timeout = None
worker.handler = 'sync'
@@ -143,25 +152,55 @@
exit_code = worker.execute()
+ restarts_per_lib = {}
+
out = {}
for nodeset, output in worker.get_results():
- print output
+ msg = str(output)
+ hostname = str(nodeset)
+ if msg.startswith("OK "):
+ restarts = json.loads(msg[3:])
+ for library in restarts.keys():
+ if not restarts_per_lib.get(library, None):
+ restarts_per_lib[library] = {}
+
+ for program in restarts[library]:
+ if not restarts_per_lib[library].get(program, None):
+ restarts_per_lib[library][program] = []
+ restarts_per_lib[library][program].append(hostname)
+
+ for lib in restarts_per_lib:
+ print "Restarts for", lib
+ for program in restarts_per_lib[lib]:
+ out = " " + program
+ if verbose:
+ for host in sorted(restarts_per_lib[lib][program]):
+ out += "\n " + host
+ else:
+ out += " (" + str(len(restarts_per_lib[lib][program])) + "
hosts)"
+ print out
def main():
- p = argparse.ArgumentParser(usage="debdeploy-master [options] command
<cmd-option>\n \
- The following commands are supported: \n\n \
- deploy : Install a software update, requires --update
and --servers \n \
- query_restart : Query for necessary restarts after a library
or interpreter upgrade \n \
- rollback : Rollback a software deployment")
+ p = argparse.ArgumentParser(usage="""debdeploy-master [options] command
<cmd-option> \n
+ The following commands are supported: \n\n
+ deploy Install a software update, requires --update
and --servers \n
+ query_restart Query for necessary restarts after a library
or interpreter \n
+ upgrade \n
+ rollback Rollback a software deployment""")
- p.add_argument("-u", "--update", action="store", type=str,
dest="updatefile", help="A YAML file containing the update specification (which
source package to update and the respective fixed versions")
- p.add_argument("-s", "--servers", action="store", type=str,
dest="serverlist", help="The group of servers on which the update should be
applied")
- p.add_argument("--verbose", action="store_true", dest="verbose",
help="Enable verbose output, e.g. show full apt output in status-deploy and
status-rollback")
+ p.add_argument("-u", "--update", action="store", type=str,
dest="updatefile",
+ help="A YAML file containing the update specification
(which source package to \
+ update and the respective fixed versions")
+ p.add_argument("-s", "--servers", action="store", type=str,
dest="serverlist",
+ help="The group of servers on which the update should be
applied")
+ p.add_argument("--verbose", action="store_true", dest="verbose",
+ help="Enable verbose output, e.g. show full apt output in
status-deploy and \
+ status-rollback")
p.add_argument("command")
p.add_argument("command_option", nargs="?", default="unset")
-
+
opt = p.parse_args()
if opt.command in ("deploy", "rollback", "restart", "query_restart"):
@@ -178,15 +217,16 @@
if opt.command == "deploy":
update = DebDeployUpdateSpec(opt.updatefile, conf.supported_distros)
- deploy_update(update.source, update.update_type, opt.updatefile,
opt.serverlist, conf.supported_distros, update.fixes)
+ deploy_update(update.source, update.update_type, opt.updatefile,
opt.serverlist,
+ conf.supported_distros, update.fixes)
elif opt.command == "query_restart":
update = DebDeployUpdateSpec(opt.updatefile, conf.supported_distros)
- detect_restarts(update.libraries, opt.serverlist)
+ detect_restarts(update.libraries, opt.serverlist, opt.verbose)
elif opt.command == "status-rollback":
display_status(rollback_mode=True)
-
+
elif opt.command == "rollback":
rollback(opt.serverlist, opt.updatefile)
@@ -198,9 +238,3 @@
# Local variables:
# mode: python
# End:
-
-
-
-
-
-
--
To view, visit https://gerrit.wikimedia.org/r/373048
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic0f7f3bc0fa766f8223b05830390400c29c80189
Gerrit-PatchSet: 2
Gerrit-Project: operations/debs/debdeploy
Gerrit-Branch: master
Gerrit-Owner: Muehlenhoff <[email protected]>
Gerrit-Reviewer: Muehlenhoff <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits