From ef56aab29cc12ee8c82b48f68655713a35b0285f Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Mar 14 2018 07:48:54 +0000 Subject: fixed standard-inventory-docker code using inspekt --- diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker index cb1df71..cfe597f 100755 --- a/inventory/standard-inventory-docker +++ b/inventory/standard-inventory-docker @@ -1,5 +1,28 @@ #!/usr/bin/env python +# The MIT License (MIT) +# +# Copyright (c) 2017-2018 Red Hat Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Author: Merlin Mathesius + import argparse import errno import json @@ -7,14 +30,13 @@ import os import shutil import shlex import signal -import socket import subprocess import sys import tempfile import time -import traceback import distutils.util + def main(argv): parser = argparse.ArgumentParser(description="Inventory for a container image in a registry") parser.add_argument("--list", action="store_true", help="Verbose output") @@ -36,9 +58,10 @@ def main(argv): return 0 + def list(subjects, docker_extra_args): - hosts = [ ] - variables = { } + hosts = [] + variables = {} for subject in subjects: if subject.startswith("docker:"): image = subject[7:] @@ -46,7 +69,8 @@ def list(subjects, docker_extra_args): if vars: hosts.append(name) variables[name] = vars - return { "localhost": { "hosts": hosts, "vars": { } }, "subjects": { "hosts": hosts, "vars": { } }, "_meta": { "hostvars": variables } } + return {"localhost": {"hosts": hosts, "vars": {}}, "subjects": {"hosts": hosts, "vars": {}}, "_meta": {"hostvars": variables}} + def host(image, docker_extra_args): null = open(os.devnull, 'w') @@ -116,7 +140,7 @@ def host(image, docker_extra_args): except subprocess.CalledProcessError as ex: # Could not install necessary packages to run the tests. # Need to stop and remove the container. - subprocess.call(["/usr/bin/docker", "rm", "-f", name ], stdout=null) + subprocess.call(["/usr/bin/docker", "rm", "-f", name], stdout=null) raise RuntimeError("Could not install Ansible dependencies in launched container") # Directory to place artifacts @@ -154,7 +178,7 @@ def host(image, docker_extra_args): try: os.kill(ppid, 0) except OSError: - break # Either of the processes no longer exist + break # Either of the processes no longer exist if diagnose: sys.stderr.write("\n") @@ -177,11 +201,12 @@ def host(image, docker_extra_args): # Kill the container with open(log, "w") as f: - subprocess.call(["/usr/bin/docker", "logs", name ], stdout=f.fileno()) - subprocess.call(["/usr/bin/docker", "rm", "-f", name ], stdout=null) + subprocess.call(["/usr/bin/docker", "logs", name], stdout=f.fileno()) + subprocess.call(["/usr/bin/docker", "rm", "-f", name], stdout=null) shutil.rmtree(directory) sys.exit(0) + if __name__ == '__main__': sys.exit(main(sys.argv))