docker_image_availability_test.py 8.7 KB

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