{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/comments/106544649","pull_request_review_id":27473443,"id":106544649,"diff_hunk":"@@ -0,0 +1,145 @@\n+# pylint: disable=missing-docstring\n+from openshift_checks import OpenShiftCheck, get_var\n+\n+\n+class DockerImageAvailability(OpenShiftCheck):\n+    \"\"\"Check that required Docker images are available.\n+\n+    This check attempts to pull required docker images and fail if\n+    any image is missing or an error occurs during pull.\n+    \"\"\"\n+\n+    name = \"docker_image_availability\"\n+    tags = [\"preflight\"]\n+\n+    skopeo_image = \"juanvallejo/skopeo:v3.4\"\n+\n+    registry_prefix = {\n+        \"origin\": {\n+            \"repo\": \"openshift\",\n+            \"image\": \"origin\",\n+        },\n+        \"openshift-enterprise\": {\n+            \"repo\": \"openshift3\",\n+            \"image\": \"ose\",\n+        },\n+    }\n+\n+    def run(self, _, task_vars):\n+        is_containerized = get_var(task_vars, \"openshift\", \"common\", \"is_containerized\")\n+        openshift_release = get_var(task_vars, \"openshift_release\")\n+        openshift_image_tag = get_var(task_vars, \"openshift_image_tag\")\n+        deployment_type = get_var(task_vars, \"deployment_type\")\n+\n+        reg_prefix = self.registry_prefix[deployment_type]\n+        required_images = self.get_required_images(is_containerized, reg_prefix, openshift_release)\n+\n+        # append images with qualified image tags to our list of required images.\n+        # these are images with a (v0.0.0.0) tag, rather than a standard release\n+        # format tag (v0.0). We want to check this set in both containerized and\n+        # non-containerized installations.\n+        qualified_imgs = self.qualified_docker_images(self.image_from_reg_prefix(reg_prefix), \"v\" + openshift_image_tag)\n+        required_images.update(qualified_imgs)\n+\n+        # use docker_image_facts to inspect local images before attempting to use Skopeo\n+        required_images = self.inspect_local_images(required_images, task_vars)\n+\n+        # exit successfully if all required images were present locally\n+        if not required_images:\n+            return {\"changed\": False}\n+\n+        # ensure skopeo image exists or that latest version can be pulled\n+        skopeo_update_output = self.update_skopeo_image(task_vars)\n+        changed = skopeo_update_output.get(\"changed\", False)\n+        if skopeo_update_output.get(\"failed\", False):\n+            msg = \"Failed to pull required Skopeo image: {msg}\".format(msg=skopeo_update_output.get(\"msg\", \"\"))\n+            return {\"failed\": True, \"msg\": msg, changed: changed}\n+\n+        # use docker info to determine which registries\n+        # Skopeo should inspect for required images\n+        docker_info = self.get_docker_info(task_vars)\n+        if not docker_info:\n+            return {\"failed\": True, \"msg\": \"Unable to get docker info. Is `docker-py` installed?\", \"changed\": changed}\n+\n+        registries = [registry.get(\"Name\", \"\") for registry in docker_info.get(\"Registries\", {})]\n+        if not registries:\n+            return {\"failed\": True, \"msg\": \"Unable to read docker registry data from host.\", \"changed\": changed}\n+\n+        # inspect all rpm or containerized docker images for every docker registry found\n+        while registries and required_images:\n+            registry = registries.pop(0)\n+            required_images = self.inspect_images(registry, required_images, task_vars)\n+\n+        # if there are required images left, fail the check\n+        if required_images:\n+            msg = \"Unable to find required images in any docker registries: {imgs}\".format(imgs=list(required_images))\n+            return {\"failed\": True, \"changed\": changed, \"msg\": msg}\n+\n+        return {\"changed\": True}","path":"roles/openshift_health_checker/openshift_checks/docker_image_availability.py","position":null,"original_position":78,"commit_id":"0c64437f457d0606b7e39693f17c3b446a406827","original_commit_id":"53308f9ca8e1c1ca38e4bc0e8f24b95b8d65002c","user":{"login":"juanvallejo","id":3902875,"avatar_url":"https://avatars1.githubusercontent.com/u/3902875?v=3","gravatar_id":"","url":"https://api.github.com/users/juanvallejo","html_url":"https://github.com/juanvallejo","followers_url":"https://api.github.com/users/juanvallejo/followers","following_url":"https://api.github.com/users/juanvallejo/following{/other_user}","gists_url":"https://api.github.com/users/juanvallejo/gists{/gist_id}","starred_url":"https://api.github.com/users/juanvallejo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanvallejo/subscriptions","organizations_url":"https://api.github.com/users/juanvallejo/orgs","repos_url":"https://api.github.com/users/juanvallejo/repos","events_url":"https://api.github.com/users/juanvallejo/events{/privacy}","received_events_url":"https://api.github.com/users/juanvallejo/received_events","type":"User","site_admin":false},"body":"Thanks, this definitely seems cleaner, will refactor","created_at":"2017-03-16T22:15:01Z","updated_at":"2017-03-16T22:15:01Z","html_url":"https://github.com/openshift/openshift-ansible/pull/3461#discussion_r106544649","pull_request_url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461","_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/comments/106544649"},"html":{"href":"https://github.com/openshift/openshift-ansible/pull/3461#discussion_r106544649"},"pull_request":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461","id":107529584,"html_url":"https://github.com/openshift/openshift-ansible/pull/3461","diff_url":"https://github.com/openshift/openshift-ansible/pull/3461.diff","patch_url":"https://github.com/openshift/openshift-ansible/pull/3461.patch","issue_url":"https://api.github.com/repos/openshift/openshift-ansible/issues/3461","number":3461,"state":"open","locked":false,"title":"add docker_image_availability check","user":{"login":"juanvallejo","id":3902875,"avatar_url":"https://avatars1.githubusercontent.com/u/3902875?v=3","gravatar_id":"","url":"https://api.github.com/users/juanvallejo","html_url":"https://github.com/juanvallejo","followers_url":"https://api.github.com/users/juanvallejo/followers","following_url":"https://api.github.com/users/juanvallejo/following{/other_user}","gists_url":"https://api.github.com/users/juanvallejo/gists{/gist_id}","starred_url":"https://api.github.com/users/juanvallejo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanvallejo/subscriptions","organizations_url":"https://api.github.com/users/juanvallejo/orgs","repos_url":"https://api.github.com/users/juanvallejo/repos","events_url":"https://api.github.com/users/juanvallejo/events{/privacy}","received_events_url":"https://api.github.com/users/juanvallejo/received_events","type":"User","site_admin":false},"body":"Something to get a rough idea of how this check might be implemented.\r\n\r\ncc @rhcarvalho @brenton ","created_at":"2017-02-23T00:17:44Z","updated_at":"2017-03-16T22:15:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32fe3adc3178742578f1168246ab8430e8509459","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461/commits","review_comments_url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461/comments","review_comment_url":"https://api.github.com/repos/openshift/openshift-ansible/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/openshift-ansible/issues/3461/comments","statuses_url":"https://api.github.com/repos/openshift/openshift-ansible/statuses/0c64437f457d0606b7e39693f17c3b446a406827","head":{"label":"juanvallejo:jvallejo/add-docker-image-check","ref":"jvallejo/add-docker-image-check","sha":"0c64437f457d0606b7e39693f17c3b446a406827","user":{"login":"juanvallejo","id":3902875,"avatar_url":"https://avatars1.githubusercontent.com/u/3902875?v=3","gravatar_id":"","url":"https://api.github.com/users/juanvallejo","html_url":"https://github.com/juanvallejo","followers_url":"https://api.github.com/users/juanvallejo/followers","following_url":"https://api.github.com/users/juanvallejo/following{/other_user}","gists_url":"https://api.github.com/users/juanvallejo/gists{/gist_id}","starred_url":"https://api.github.com/users/juanvallejo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanvallejo/subscriptions","organizations_url":"https://api.github.com/users/juanvallejo/orgs","repos_url":"https://api.github.com/users/juanvallejo/repos","events_url":"https://api.github.com/users/juanvallejo/events{/privacy}","received_events_url":"https://api.github.com/users/juanvallejo/received_events","type":"User","site_admin":false},"repo":{"id":82593304,"name":"openshift-ansible","full_name":"juanvallejo/openshift-ansible","owner":{"login":"juanvallejo","id":3902875,"avatar_url":"https://avatars1.githubusercontent.com/u/3902875?v=3","gravatar_id":"","url":"https://api.github.com/users/juanvallejo","html_url":"https://github.com/juanvallejo","followers_url":"https://api.github.com/users/juanvallejo/followers","following_url":"https://api.github.com/users/juanvallejo/following{/other_user}","gists_url":"https://api.github.com/users/juanvallejo/gists{/gist_id}","starred_url":"https://api.github.com/users/juanvallejo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanvallejo/subscriptions","organizations_url":"https://api.github.com/users/juanvallejo/orgs","repos_url":"https://api.github.com/users/juanvallejo/repos","events_url":"https://api.github.com/users/juanvallejo/events{/privacy}","received_events_url":"https://api.github.com/users/juanvallejo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/juanvallejo/openshift-ansible","description":"OpenShift Installation and Configuration Management","fork":true,"url":"https://api.github.com/repos/juanvallejo/openshift-ansible","forks_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/forks","keys_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/teams","hooks_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/hooks","issue_events_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/issues/events{/number}","events_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/events","assignees_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/assignees{/user}","branches_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/branches{/branch}","tags_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/tags","blobs_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/git/refs{/sha}","trees_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/statuses/{sha}","languages_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/languages","stargazers_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/stargazers","contributors_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/contributors","subscribers_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/subscribers","subscription_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/subscription","commits_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/commits{/sha}","git_commits_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/git/commits{/sha}","comments_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/comments{/number}","issue_comment_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/issues/comments{/number}","contents_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/contents/{+path}","compare_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/merges","archive_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/downloads","issues_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/issues{/number}","pulls_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/pulls{/number}","milestones_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/milestones{/number}","notifications_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/labels{/name}","releases_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/releases{/id}","deployments_url":"https://api.github.com/repos/juanvallejo/openshift-ansible/deployments","created_at":"2017-02-20T19:18:13Z","updated_at":"2017-02-20T19:18:19Z","pushed_at":"2017-03-16T22:14:31Z","git_url":"git://github.com/juanvallejo/openshift-ansible.git","ssh_url":"git@github.com:juanvallejo/openshift-ansible.git","clone_url":"https://github.com/juanvallejo/openshift-ansible.git","svn_url":"https://github.com/juanvallejo/openshift-ansible","homepage":"https://install.openshift.com","size":11565,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"608b6debb28d9b477d21cd78f01d0bfbcd04cd01","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars0.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":24109199,"name":"openshift-ansible","full_name":"openshift/openshift-ansible","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars0.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/openshift-ansible","description":"OpenShift Installation and Configuration Management","fork":false,"url":"https://api.github.com/repos/openshift/openshift-ansible","forks_url":"https://api.github.com/repos/openshift/openshift-ansible/forks","keys_url":"https://api.github.com/repos/openshift/openshift-ansible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/openshift-ansible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/openshift-ansible/teams","hooks_url":"https://api.github.com/repos/openshift/openshift-ansible/hooks","issue_events_url":"https://api.github.com/repos/openshift/openshift-ansible/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/openshift-ansible/events","assignees_url":"https://api.github.com/repos/openshift/openshift-ansible/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/openshift-ansible/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/openshift-ansible/tags","blobs_url":"https://api.github.com/repos/openshift/openshift-ansible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/openshift-ansible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/openshift-ansible/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/openshift-ansible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/openshift-ansible/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/openshift-ansible/languages","stargazers_url":"https://api.github.com/repos/openshift/openshift-ansible/stargazers","contributors_url":"https://api.github.com/repos/openshift/openshift-ansible/contributors","subscribers_url":"https://api.github.com/repos/openshift/openshift-ansible/subscribers","subscription_url":"https://api.github.com/repos/openshift/openshift-ansible/subscription","commits_url":"https://api.github.com/repos/openshift/openshift-ansible/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/openshift-ansible/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/openshift-ansible/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/openshift-ansible/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/openshift-ansible/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/openshift-ansible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/openshift-ansible/merges","archive_url":"https://api.github.com/repos/openshift/openshift-ansible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/openshift-ansible/downloads","issues_url":"https://api.github.com/repos/openshift/openshift-ansible/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/openshift-ansible/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/openshift-ansible/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/openshift-ansible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/openshift-ansible/labels{/name}","releases_url":"https://api.github.com/repos/openshift/openshift-ansible/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/openshift-ansible/deployments","created_at":"2014-09-16T17:07:51Z","updated_at":"2017-03-16T19:19:32Z","pushed_at":"2017-03-16T22:14:32Z","git_url":"git://github.com/openshift/openshift-ansible.git","ssh_url":"git@github.com:openshift/openshift-ansible.git","clone_url":"https://github.com/openshift/openshift-ansible.git","svn_url":"https://github.com/openshift/openshift-ansible","homepage":"https://install.openshift.com","size":11789,"stargazers_count":370,"watchers_count":370,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":593,"mirror_url":null,"open_issues_count":352,"forks":593,"open_issues":352,"watchers":370,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461"},"html":{"href":"https://github.com/openshift/openshift-ansible/pull/3461"},"issue":{"href":"https://api.github.com/repos/openshift/openshift-ansible/issues/3461"},"comments":{"href":"https://api.github.com/repos/openshift/openshift-ansible/issues/3461/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/openshift-ansible/pulls/3461/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/openshift-ansible/statuses/0c64437f457d0606b7e39693f17c3b446a406827"}}}}
{"actor":{"display_login":"juanvallejo"}}