| |
@@ -39,16 +39,20 @@
|
| |
def list(subjects, docker_extra_args):
|
| |
hosts = [ ]
|
| |
variables = { }
|
| |
+ rpms = []
|
| |
+ for subject in subjects:
|
| |
+ if subject.endswith(".rpm"):
|
| |
+ rpms.append(subject)
|
| |
for subject in subjects:
|
| |
if subject.startswith("docker:"):
|
| |
image = subject[7:]
|
| |
- name, vars = host(image, docker_extra_args)
|
| |
+ name, vars = host(image, docker_extra_args, rpms)
|
| |
if vars:
|
| |
hosts.append(name)
|
| |
variables[name] = vars
|
| |
return { "localhost": { "hosts": hosts, "vars": { } }, "subjects": { "hosts": hosts, "vars": { } }, "_meta": { "hostvars": variables } }
|
| |
|
| |
- def host(image, docker_extra_args):
|
| |
+ def host(image, docker_extra_args, rpms=None):
|
| |
null = open(os.devnull, 'w')
|
| |
|
| |
try:
|
| |
@@ -79,10 +83,7 @@
|
| |
cmd = [
|
| |
"/usr/sbin/service", "docker", "start"
|
| |
]
|
| |
- try:
|
| |
- subprocess.check_call(cmd, stdout=sys.stderr.fileno())
|
| |
- except subprocess.CalledProcessError as ex:
|
| |
- raise RuntimeError("Could not start docker service")
|
| |
+ run_cmd(cmd, "Could not start docker service")
|
| |
|
| |
# And launch the actual container
|
| |
cmd = [
|
| |
@@ -90,10 +91,7 @@
|
| |
] + extra_arg_list + [
|
| |
"--entrypoint=/bin/sh", image, "-c", "sleep 1000000"
|
| |
]
|
| |
- try:
|
| |
- subprocess.check_call(cmd, stdout=sys.stderr.fileno())
|
| |
- except subprocess.CalledProcessError as ex:
|
| |
- raise RuntimeError("Could not start container image: {0}".format(image))
|
| |
+ run_cmd(cmd, "Could not start container image: {0}".format(image))
|
| |
|
| |
# Read out the container environment variable
|
| |
for x in range(1, 90):
|
| |
@@ -106,15 +104,26 @@
|
| |
with open(cidfile, "r") as f:
|
| |
name = f.read().strip()
|
| |
|
| |
+ if len(rpms) > 0:
|
| |
+ sys.stderr.write("Installing %d extra rpms in container\n" % len(rpms))
|
| |
+
|
| |
+ # Copy the necessary packages in the container
|
| |
+ for rpm in rpms:
|
| |
+ copy = ["/usr/bin/docker", "cp", rpm, '%s:/var/tmp/' % name]
|
| |
+ run_cmd(copy, "Could not copy extra packages in launched container")
|
| |
+
|
| |
+ # Install the necessary packages in the container
|
| |
+ install = ["/usr/bin/docker", "exec", "--user=root", name,
|
| |
+ "/usr/bin/yum", "-y", "install"] + ['/var/tmp/%s' % os.path.basename(rpm) for rpm in rpms]
|
| |
+ run_cmd(install, "Could not install extra packages in launched container")
|
| |
+
|
| |
# Now install the necessary stuff in the container :S
|
| |
+ sys.stderr.write("Installing python runtime in container\n")
|
| |
install = [
|
| |
"/usr/bin/docker", "exec", "--user=root", name, "/usr/bin/yum", "-y", "install",
|
| |
"python2", "python2-dnf", "libselinux-python"
|
| |
]
|
| |
- try:
|
| |
- subprocess.check_call(install, stdout=sys.stderr.fileno())
|
| |
- except subprocess.CalledProcessError as ex:
|
| |
- raise RuntimeError("Could not install Ansible dependencies in launched container")
|
| |
+ run_cmd(install, "Could not install Ansible dependencies in launched container")
|
| |
|
| |
# Directory to place artifacts
|
| |
artifacts = os.environ.get("TEST_ARTIFACTS", os.path.join(os.getcwd(), "artifacts"))
|
| |
@@ -181,5 +190,13 @@
|
| |
shutil.rmtree(directory)
|
| |
sys.exit(0)
|
| |
|
| |
+
|
| |
+ def run_cmd(cmd, error_msg):
|
| |
+ try:
|
| |
+ subprocess.check_call(cmd, stdout=sys.stderr.fileno())
|
| |
+ except subprocess.CalledProcessError as ex:
|
| |
+ raise RuntimeError("%s: %s" % (error_msg, str(ex)))
|
| |
+
|
| |
+
|
| |
if __name__ == '__main__':
|
| |
sys.exit(main(sys.argv))
|
| |
Fedora vs. CentOS/RHEL