From d58422812d21f960b1c709143db1f6111ff648e8 Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Mar 15 2018 15:10:47 +0000 Subject: fixed standard-inventory-docker code using inspekt enabled extra warnings --- diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker index cfe597f..f75e6c6 100755 --- a/inventory/standard-inventory-docker +++ b/inventory/standard-inventory-docker @@ -48,9 +48,9 @@ def main(argv): try: if opts.host: - name, data = host(opts.host, opts.docker_extra_args) + _, data = inv_host(opts.host, opts.docker_extra_args) else: - data = list(opts.subjects, opts.docker_extra_args) + data = inv_list(opts.subjects, opts.docker_extra_args) sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': '))) except RuntimeError as ex: sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex))) @@ -59,20 +59,22 @@ def main(argv): return 0 -def list(subjects, docker_extra_args): +def inv_list(subjects, docker_extra_args): hosts = [] variables = {} for subject in subjects: if subject.startswith("docker:"): image = subject[7:] - name, vars = host(image, docker_extra_args) - if vars: + name, host_vars = inv_host(image, docker_extra_args) + if host_vars: hosts.append(name) - variables[name] = vars - return {"localhost": {"hosts": hosts, "vars": {}}, "subjects": {"hosts": hosts, "vars": {}}, "_meta": {"hostvars": variables}} + variables[name] = host_vars + return {"localhost": {"hosts": hosts, "vars": {}}, + "subjects": {"hosts": hosts, "vars": {}}, + "_meta": {"hostvars": variables}} -def host(image, docker_extra_args): +def inv_host(image, docker_extra_args): null = open(os.devnull, 'w') try: @@ -105,7 +107,7 @@ def host(image, docker_extra_args): ] try: subprocess.check_call(cmd, stdout=sys.stderr.fileno()) - except subprocess.CalledProcessError as ex: + except subprocess.CalledProcessError: raise RuntimeError("Could not start docker service") # And launch the actual container @@ -116,11 +118,11 @@ def host(image, docker_extra_args): ] try: subprocess.check_call(cmd, stdout=sys.stderr.fileno()) - except subprocess.CalledProcessError as ex: + except subprocess.CalledProcessError: raise RuntimeError("Could not start container image: {0}".format(image)) # Read out the container environment variable - for x in range(1, 90): + for _ in range(1, 90): if os.path.exists(cidfile): break time.sleep(1) @@ -137,7 +139,7 @@ def host(image, docker_extra_args): ] try: subprocess.check_call(install, stdout=sys.stderr.fileno()) - except subprocess.CalledProcessError as ex: + except subprocess.CalledProcessError: # 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)