Skip to content

Commit

Permalink
collect all pull failures before returning with fail
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 27, 2017
1 parent 5f93de9 commit a325632
Showing 1 changed file with 28 additions and 25 deletions.
Expand Up @@ -9,25 +9,31 @@ class DockerImageAvailability(NotContainerizedMixin, OpenShiftCheck):
name = "docker_image_availability"
tags = ["preflight"]

# attempt to pull required docker images and fail if
# any images are missing, or error occurs during pull
def run(self, tmp, task_vars):
openshift_release = get_var(task_vars, "openshift_release")
openshift_image_tag = get_var(task_vars, "openshift_image_tag")

# attempt to fetch fully qualified image tag
openshift_facts = self.module_executor("openshift_facts", {}, tmp, task_vars)
openshift_image_tag = self.get_image_tag(openshift_facts)
failed_pulls = set()

# attempt to pull each image and fail on
# the first one that cannot be fetched
res = self.pull_images(self.rpm_docker_images(), openshift_release, tmp, task_vars)
if "failed" in res:
return res
pulled_images = self.pull_images(self.rpm_docker_images(), openshift_release, tmp, task_vars)
if "failed_images" in pulled_images:
failed_pulls.update(pulled_images["failed_images"])

if not openshift_image_tag:
return {"failed": True, "msg": "Unable to retrieve fully qualified image tag. Failed to fetch images: %s" % self.rpm_qualified_docker_images()}
return {"failed": True, "msg": "Unable to retrieve fully qualified image tag. Failed to fetch images: %s" % (set(failed_pulls).update(self.rpm_qualified_docker_images()))}

# pull each required image that requires a qualified image
# tag (v0.0.0.0) rather than a standard release format tag (v0.0)
return self.pull_images(self.rpm_qualified_docker_images(), "v" + openshift_image_tag, tmp, task_vars)
pulled_qualified_images = self.pull_images(self.rpm_qualified_docker_images(), "v" + openshift_image_tag, tmp, task_vars)
if "failed" in pulled_qualified_images and "failed_images" in pulled_qualified_images:
failed_pulls.update(pulled_qualified_images["failed_images"])

if failed_pulls:
return {"failed": True, "msg": "Failed to pull required docker images: %s" % failed_pulls}

return {"changed": True}

@staticmethod
def rpm_docker_images():
Expand All @@ -44,24 +50,21 @@ def rpm_qualified_docker_images():
"openshift3/ose-pod",
]

def pull_images(self, images, tag, tmp, task_vars):
for image in images:
def pull_images(self, images_without_tag, tag, tmp, task_vars):
images_with_tag = [image + ":" + tag for image in images_without_tag]

failed = set()
for image in images_with_tag:
args = {
"name": image + ":" + tag
"name": image
}

res = self.module_executor("docker_image", args, tmp, task_vars)
if "failed" in res:
return {"failed": True, "msg": "Failed to find required docker image for OpenShift version %s: %s" % (tag, res['msg'])}
if "failed" in res and res["failed"]:
failed.add(args["name"])

return {"changed": True}
if failed:
return {"failed": True, "failed_images": failed}

return {"changed": True}

@staticmethod
def get_image_tag(facts):
if 'ansible_facts' in facts:
if 'openshift' in facts['ansible_facts']:
if 'common' in facts['ansible_facts']['openshift']:
if 'version' in facts['ansible_facts']['openshift']['common']:
return facts['ansible_facts']['openshift']['common']['version']

return None

0 comments on commit a325632

Please sign in to comment.