docker_image_availability_test.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import pytest
  2. from openshift_checks.docker_image_availability import DockerImageAvailability, DEPLOYMENT_IMAGE_INFO
  3. @pytest.fixture()
  4. def task_vars():
  5. return dict(
  6. openshift_is_atomic=False,
  7. openshift_service_type='origin',
  8. openshift_deployment_type='origin',
  9. openshift_image_tag='',
  10. group_names=['oo_nodes_to_config', 'oo_masters_to_config'],
  11. )
  12. @pytest.mark.parametrize('deployment_type, openshift_is_atomic, group_names, expect_active', [
  13. ("invalid", True, [], False),
  14. ("", True, [], False),
  15. ("origin", False, [], False),
  16. ("openshift-enterprise", False, [], False),
  17. ("origin", False, ["oo_nodes_to_config", "oo_masters_to_config"], True),
  18. ("openshift-enterprise", False, ["oo_etcd_to_config"], False),
  19. ("origin", True, ["nfs"], False),
  20. ("openshift-enterprise", True, ["lb"], False),
  21. ])
  22. def test_is_active(task_vars, deployment_type, openshift_is_atomic, group_names, expect_active):
  23. task_vars['openshift_deployment_type'] = deployment_type
  24. task_vars['openshift_is_atomic'] = openshift_is_atomic
  25. task_vars['group_names'] = group_names
  26. assert DockerImageAvailability(None, task_vars).is_active() == expect_active
  27. @pytest.mark.parametrize("openshift_is_atomic", [
  28. True,
  29. False,
  30. True,
  31. False,
  32. ])
  33. def test_all_images_available_locally(task_vars, openshift_is_atomic):
  34. def execute_module(module_name, module_args, *_):
  35. if module_name == "yum":
  36. return {}
  37. assert module_name == "docker_image_facts"
  38. assert 'name' in module_args
  39. assert module_args['name']
  40. return {
  41. 'images': [module_args['name']],
  42. }
  43. task_vars['openshift_is_atomic'] = openshift_is_atomic
  44. result = DockerImageAvailability(execute_module, task_vars).run()
  45. assert not result.get('failed', False)
  46. @pytest.mark.parametrize("available_locally", [
  47. False,
  48. True,
  49. ])
  50. def test_all_images_available_remotely(task_vars, available_locally):
  51. def execute_module(module_name, *_):
  52. if module_name == 'docker_image_facts':
  53. return {'images': [], 'failed': available_locally}
  54. return {}
  55. task_vars['openshift_docker_additional_registries'] = ["docker.io", "registry.access.redhat.com"]
  56. task_vars['openshift_image_tag'] = 'v3.4'
  57. check = DockerImageAvailability(execute_module, task_vars)
  58. check._module_retry_interval = 0
  59. result = check.run()
  60. assert not result.get('failed', False)
  61. def test_all_images_unavailable(task_vars):
  62. def execute_module(module_name=None, *args):
  63. if module_name == "wait_for":
  64. return {}
  65. elif module_name == "command":
  66. return {'failed': True}
  67. return {} # docker_image_facts failure
  68. task_vars['openshift_docker_additional_registries'] = ["docker.io"]
  69. task_vars['openshift_deployment_type'] = "openshift-enterprise"
  70. task_vars['openshift_image_tag'] = 'latest'
  71. check = DockerImageAvailability(execute_module, task_vars)
  72. check._module_retry_interval = 0
  73. actual = check.run()
  74. assert actual['failed']
  75. assert "required container images are not available" in actual['msg']
  76. @pytest.mark.parametrize("message,extra_words", [
  77. (
  78. "docker image update failure",
  79. ["docker image update failure"],
  80. ),
  81. (
  82. "No package matching 'skopeo' found available, installed or updated",
  83. ["dependencies can be installed via `yum`"]
  84. ),
  85. ])
  86. def test_skopeo_update_failure(task_vars, message, extra_words):
  87. def execute_module(module_name=None, *_):
  88. if module_name == "yum":
  89. return {
  90. "failed": True,
  91. "msg": message,
  92. }
  93. return {}
  94. task_vars['openshift_docker_additional_registries'] = ["unknown.io"]
  95. task_vars['openshift_deployment_type'] = "openshift-enterprise"
  96. check = DockerImageAvailability(execute_module, task_vars)
  97. check._module_retry_interval = 0
  98. actual = check.run()
  99. assert actual["failed"]
  100. for word in extra_words:
  101. assert word in actual["msg"]
  102. @pytest.mark.parametrize(
  103. "image, registries, connection_test_failed, skopeo_failed, "
  104. "expect_success, expect_registries_reached", [
  105. (
  106. "spam/eggs:v1", ["test.reg"],
  107. True, True,
  108. False,
  109. {"test.reg": False, "docker.io": False},
  110. ),
  111. (
  112. "spam/eggs:v1", ["test.reg"],
  113. False, True,
  114. False,
  115. {"test.reg": True, "docker.io": True},
  116. ),
  117. (
  118. "eggs.reg/spam/eggs:v1", ["test.reg"],
  119. False, False,
  120. True,
  121. {"eggs.reg": True},
  122. ),
  123. ])
  124. def test_registry_availability(image, registries, connection_test_failed, skopeo_failed,
  125. expect_success, expect_registries_reached):
  126. def execute_module(module_name=None, *_):
  127. if module_name == "wait_for":
  128. return dict(msg="msg", failed=connection_test_failed)
  129. elif module_name == "command":
  130. return dict(msg="msg", failed=skopeo_failed)
  131. tv = task_vars()
  132. tv.update({"openshift_docker_additional_registries": registries})
  133. check = DockerImageAvailability(execute_module, tv)
  134. check._module_retry_interval = 0
  135. available = check.is_available_skopeo_image(image)
  136. assert available == expect_success
  137. assert expect_registries_reached == check.reachable_registries
  138. @pytest.mark.parametrize("deployment_type, openshift_is_atomic, groups, oreg_url, expected", [
  139. ( # standard set of stuff required on nodes
  140. "origin", False, ['oo_nodes_to_config'], "docker.io/openshift/origin-${component}:${version}",
  141. set([
  142. 'docker.io/openshift/origin-pod:vtest',
  143. 'docker.io/openshift/origin-deployer:vtest',
  144. 'docker.io/openshift/origin-docker-registry:vtest',
  145. 'docker.io/openshift/origin-haproxy-router:vtest',
  146. 'docker.io/cockpit/kubernetes:latest', # origin version of registry-console
  147. ])
  148. ),
  149. ( # set a different URL for images
  150. "origin", False, ['oo_nodes_to_config'], 'foo.io/openshift/origin-${component}:${version}',
  151. set([
  152. 'foo.io/openshift/origin-pod:vtest',
  153. 'foo.io/openshift/origin-deployer:vtest',
  154. 'foo.io/openshift/origin-docker-registry:vtest',
  155. 'foo.io/openshift/origin-haproxy-router:vtest',
  156. 'docker.io/cockpit/kubernetes:latest', # AFAICS this is not built from the URL
  157. ])
  158. ),
  159. (
  160. "origin", True, ['oo_nodes_to_config', 'oo_masters_to_config', 'oo_etcd_to_config'], "docker.io/openshift/origin-${component}:${version}",
  161. set([
  162. # images running on top of openshift
  163. 'docker.io/openshift/origin-pod:vtest',
  164. 'docker.io/openshift/origin-deployer:vtest',
  165. 'docker.io/openshift/origin-docker-registry:vtest',
  166. 'docker.io/openshift/origin-haproxy-router:vtest',
  167. 'docker.io/cockpit/kubernetes:latest',
  168. # containerized component images
  169. 'registry.access.redhat.com/openshift3/ose-node:vtest',
  170. ])
  171. ),
  172. ( # enterprise images
  173. "openshift-enterprise", True, ['oo_nodes_to_config'], 'foo.io/openshift3/ose-${component}:f13ac45',
  174. set([
  175. 'foo.io/openshift3/ose-pod:f13ac45',
  176. 'foo.io/openshift3/ose-deployer:f13ac45',
  177. 'foo.io/openshift3/ose-docker-registry:f13ac45',
  178. 'foo.io/openshift3/ose-haproxy-router:f13ac45',
  179. # registry-console is not constructed/versioned the same as the others.
  180. 'registry.access.redhat.com/openshift3/registry-console:vtest',
  181. # containerized images aren't built from oreg_url
  182. 'registry.access.redhat.com/openshift3/ose-node:vtest',
  183. ])
  184. ),
  185. ])
  186. def test_required_images(deployment_type, openshift_is_atomic, groups, oreg_url, expected):
  187. task_vars = dict(
  188. openshift_is_atomic=openshift_is_atomic,
  189. openshift_deployment_type=deployment_type,
  190. group_names=groups,
  191. oreg_url=oreg_url,
  192. openshift_image_tag='vtest',
  193. osn_image='registry.access.redhat.com/openshift3/ose-node:vtest',
  194. )
  195. assert expected == DockerImageAvailability(task_vars=task_vars).required_images()
  196. @pytest.mark.parametrize("task_vars, expected", [
  197. (
  198. dict(
  199. openshift_deployment_type="origin",
  200. openshift_image_tag="vtest",
  201. ),
  202. "docker.io/cockpit/kubernetes:latest",
  203. ), (
  204. dict(
  205. openshift_deployment_type="openshift-enterprise",
  206. openshift_image_tag="vtest",
  207. ),
  208. "registry.access.redhat.com/openshift3/registry-console:vtest",
  209. ), (
  210. dict(
  211. openshift_deployment_type="openshift-enterprise",
  212. openshift_image_tag="v3.7.0-alpha.0",
  213. openshift_cockpit_deployer_prefix="registry.example.com/spam/",
  214. ),
  215. "registry.example.com/spam/registry-console:v3.7",
  216. ), (
  217. dict(
  218. openshift_deployment_type="origin",
  219. openshift_image_tag="v3.7.0-alpha.0",
  220. openshift_cockpit_deployer_prefix="registry.example.com/eggs/",
  221. openshift_cockpit_deployer_version="spam",
  222. ),
  223. "registry.example.com/eggs/kubernetes:spam",
  224. ),
  225. ])
  226. def test_registry_console_image(task_vars, expected):
  227. info = DEPLOYMENT_IMAGE_INFO[task_vars["openshift_deployment_type"]]
  228. tag = task_vars["openshift_image_tag"]
  229. assert expected == DockerImageAvailability(task_vars=task_vars)._registry_console_image(tag, info)
  230. @pytest.mark.parametrize("task_vars, expected", [
  231. (
  232. dict(
  233. group_names=['oo_nodes_to_config'],
  234. openshift_image_tag="veggs",
  235. osn_image="registry.access.redhat.com/openshift3/ose-node:vtest",
  236. ),
  237. set([
  238. 'registry.access.redhat.com/openshift3/ose-node:vtest', 'docker.io/cockpit/kubernetes:latest',
  239. 'docker.io/openshift/origin-haproxy-router:veggs', 'docker.io/openshift/origin-deployer:veggs',
  240. 'docker.io/openshift/origin-docker-registry:veggs', 'docker.io/openshift/origin-pod:veggs',
  241. ]),
  242. ), (
  243. dict(
  244. group_names=['oo_masters_to_config'],
  245. ),
  246. set(),
  247. ),
  248. ])
  249. def test_containerized(task_vars, expected):
  250. task_vars.update(dict(
  251. openshift_is_atomic=True,
  252. oreg_url="docker.io/openshift/origin-${component}:${version}",
  253. openshift_deployment_type="origin",
  254. ))
  255. assert expected == DockerImageAvailability(task_vars=task_vars).required_images()