docker_image_availability_test.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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(None, task_vars).is_active() == 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, *_):
  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, 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. )).run()
  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, *_):
  58. if module_name == 'docker_image_facts':
  59. return {'images': [], 'failed': available_locally}
  60. return {'changed': False}
  61. check = DockerImageAvailability(execute_module, 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. check._module_retry_interval = 0
  75. result = check.run()
  76. assert not result.get('failed', False)
  77. def test_all_images_unavailable():
  78. def execute_module(module_name=None, *_):
  79. if module_name == "command":
  80. return {
  81. 'failed': True,
  82. }
  83. return {
  84. 'changed': False,
  85. }
  86. check = DockerImageAvailability(execute_module, task_vars=dict(
  87. openshift=dict(
  88. common=dict(
  89. service_type='origin',
  90. is_containerized=False,
  91. is_atomic=False,
  92. ),
  93. docker=dict(additional_registries=["docker.io"]),
  94. ),
  95. openshift_deployment_type="openshift-enterprise",
  96. openshift_image_tag='latest',
  97. group_names=['nodes', 'masters'],
  98. ))
  99. check._module_retry_interval = 0
  100. actual = check.run()
  101. assert actual['failed']
  102. assert "required Docker images are not available" in actual['msg']
  103. @pytest.mark.parametrize("message,extra_words", [
  104. (
  105. "docker image update failure",
  106. ["docker image update failure"],
  107. ),
  108. (
  109. "No package matching 'skopeo' found available, installed or updated",
  110. ["dependencies can be installed via `yum`"]
  111. ),
  112. ])
  113. def test_skopeo_update_failure(message, extra_words):
  114. def execute_module(module_name=None, *_):
  115. if module_name == "yum":
  116. return {
  117. "failed": True,
  118. "msg": message,
  119. "changed": False,
  120. }
  121. return {'changed': False}
  122. check = DockerImageAvailability(execute_module, task_vars=dict(
  123. openshift=dict(
  124. common=dict(
  125. service_type='origin',
  126. is_containerized=False,
  127. is_atomic=False,
  128. ),
  129. docker=dict(additional_registries=["unknown.io"]),
  130. ),
  131. openshift_deployment_type="openshift-enterprise",
  132. openshift_image_tag='',
  133. group_names=['nodes', 'masters'],
  134. ))
  135. check._module_retry_interval = 0
  136. actual = check.run()
  137. assert actual["failed"]
  138. for word in extra_words:
  139. assert word in actual["msg"]
  140. @pytest.mark.parametrize("deployment_type,registries", [
  141. ("origin", ["unknown.io"]),
  142. ("openshift-enterprise", ["registry.access.redhat.com"]),
  143. ("openshift-enterprise", []),
  144. ])
  145. def test_registry_availability(deployment_type, registries):
  146. def execute_module(module_name=None, *_):
  147. return {
  148. 'changed': False,
  149. }
  150. actual = DockerImageAvailability(execute_module, task_vars=dict(
  151. openshift=dict(
  152. common=dict(
  153. service_type='origin',
  154. is_containerized=False,
  155. is_atomic=False,
  156. ),
  157. docker=dict(additional_registries=registries),
  158. ),
  159. openshift_deployment_type=deployment_type,
  160. openshift_image_tag='',
  161. group_names=['nodes', 'masters'],
  162. )).run()
  163. assert not actual.get("failed", False)
  164. @pytest.mark.parametrize("deployment_type, is_containerized, groups, oreg_url, expected", [
  165. ( # standard set of stuff required on nodes
  166. "origin", False, ['nodes'], None,
  167. set([
  168. 'openshift/origin-pod:vtest',
  169. 'openshift/origin-deployer:vtest',
  170. 'openshift/origin-docker-registry:vtest',
  171. 'openshift/origin-haproxy-router:vtest',
  172. 'cockpit/kubernetes', # origin version of registry-console
  173. ])
  174. ),
  175. ( # set a different URL for images
  176. "origin", False, ['nodes'], 'foo.io/openshift/origin-${component}:${version}',
  177. set([
  178. 'foo.io/openshift/origin-pod:vtest',
  179. 'foo.io/openshift/origin-deployer:vtest',
  180. 'foo.io/openshift/origin-docker-registry:vtest',
  181. 'foo.io/openshift/origin-haproxy-router:vtest',
  182. 'cockpit/kubernetes', # AFAICS this is not built from the URL
  183. ])
  184. ),
  185. (
  186. "origin", True, ['nodes', 'masters', 'etcd'], None,
  187. set([
  188. # images running on top of openshift
  189. 'openshift/origin-pod:vtest',
  190. 'openshift/origin-deployer:vtest',
  191. 'openshift/origin-docker-registry:vtest',
  192. 'openshift/origin-haproxy-router:vtest',
  193. 'cockpit/kubernetes',
  194. # containerized component images
  195. 'openshift/origin:vtest',
  196. 'openshift/node:vtest',
  197. 'openshift/openvswitch:vtest',
  198. 'registry.access.redhat.com/rhel7/etcd',
  199. ])
  200. ),
  201. ( # enterprise images
  202. "openshift-enterprise", True, ['nodes'], 'foo.io/openshift3/ose-${component}:f13ac45',
  203. set([
  204. 'foo.io/openshift3/ose-pod:f13ac45',
  205. 'foo.io/openshift3/ose-deployer:f13ac45',
  206. 'foo.io/openshift3/ose-docker-registry:f13ac45',
  207. 'foo.io/openshift3/ose-haproxy-router:f13ac45',
  208. # registry-console is not constructed/versioned the same as the others.
  209. 'registry.access.redhat.com/openshift3/registry-console',
  210. # containerized images aren't built from oreg_url
  211. 'openshift3/node:vtest',
  212. 'openshift3/openvswitch:vtest',
  213. ])
  214. ),
  215. (
  216. "openshift-enterprise", True, ['etcd', 'lb'], 'foo.io/openshift3/ose-${component}:f13ac45',
  217. set([
  218. 'registry.access.redhat.com/rhel7/etcd',
  219. # lb does not yet come in a containerized version
  220. ])
  221. ),
  222. ])
  223. def test_required_images(deployment_type, is_containerized, groups, oreg_url, expected):
  224. task_vars = dict(
  225. openshift=dict(
  226. common=dict(
  227. is_containerized=is_containerized,
  228. is_atomic=False,
  229. ),
  230. ),
  231. openshift_deployment_type=deployment_type,
  232. group_names=groups,
  233. oreg_url=oreg_url,
  234. openshift_image_tag='vtest',
  235. )
  236. assert expected == DockerImageAvailability("DUMMY", task_vars).required_images()
  237. def test_containerized_etcd():
  238. task_vars = dict(
  239. openshift=dict(
  240. common=dict(
  241. is_containerized=True,
  242. ),
  243. ),
  244. openshift_deployment_type="origin",
  245. group_names=['etcd'],
  246. )
  247. expected = set(['registry.access.redhat.com/rhel7/etcd'])
  248. assert expected == DockerImageAvailability("DUMMY", task_vars).required_images()