docker_image_availability_test.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import pytest
  2. from openshift_checks.docker_image_availability import DockerImageAvailability
  3. @pytest.mark.parametrize('deployment_type,is_active', [
  4. ("origin", True),
  5. ("openshift-enterprise", True),
  6. ("enterprise", False),
  7. ("online", False),
  8. ("invalid", False),
  9. ("", False),
  10. ])
  11. def test_is_active(deployment_type, is_active):
  12. task_vars = dict(
  13. openshift_deployment_type=deployment_type,
  14. )
  15. assert DockerImageAvailability.is_active(task_vars=task_vars) == is_active
  16. @pytest.mark.parametrize("is_containerized", [
  17. True,
  18. False,
  19. ])
  20. def test_all_images_available_locally(is_containerized):
  21. def execute_module(module_name, args, task_vars):
  22. assert module_name == "docker_image_facts"
  23. assert 'name' in args
  24. assert args['name']
  25. return {
  26. 'images': [args['name']],
  27. }
  28. result = DockerImageAvailability(execute_module=execute_module).run(tmp=None, task_vars=dict(
  29. openshift=dict(common=dict(
  30. service_type='origin',
  31. is_containerized=is_containerized,
  32. )),
  33. openshift_deployment_type='origin',
  34. openshift_release='v3.4',
  35. openshift_image_tag='3.4',
  36. ))
  37. assert not result.get('failed', False)
  38. @pytest.mark.parametrize("module_failure", [
  39. True,
  40. False,
  41. ])
  42. def test_all_images_available_remotely(module_failure):
  43. def execute_module(module_name, args, task_vars):
  44. return {
  45. 'docker_image_facts': {'images': [], 'failed': module_failure},
  46. 'docker_info': {'info': {'Registries': [{'Name': 'docker.io'}, {'Name': 'registry.access.redhat.com'}]}},
  47. }.get(module_name, {'changed': False})
  48. result = DockerImageAvailability(execute_module=execute_module).run(tmp=None, task_vars=dict(
  49. openshift=dict(common=dict(
  50. service_type='origin',
  51. is_containerized=False,
  52. )),
  53. openshift_deployment_type='origin',
  54. openshift_release='3.4'
  55. ))
  56. assert not result.get('failed', False)
  57. def test_all_images_unavailable():
  58. def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
  59. if module_name == "docker_info":
  60. return {
  61. 'info': {
  62. 'Registries': [
  63. {
  64. 'Name': 'docker.io'
  65. },
  66. {
  67. 'Name': 'registry.access.redhat.com'
  68. }
  69. ]
  70. }
  71. }
  72. if module_name == "docker_container":
  73. return {
  74. 'failed': True,
  75. }
  76. return {
  77. 'changed': False,
  78. }
  79. check = DockerImageAvailability(execute_module=execute_module)
  80. actual = check.run(tmp=None, task_vars=dict(
  81. openshift=dict(common=dict(
  82. service_type='origin',
  83. is_containerized=False,
  84. )),
  85. openshift_deployment_type="openshift-enterprise",
  86. openshift_release=None,
  87. ))
  88. assert actual['failed']
  89. assert "required images are not available" in actual['msg']
  90. @pytest.mark.parametrize("message,extra_words", [
  91. (
  92. "docker image update failure",
  93. ["docker image update failure"],
  94. ),
  95. (
  96. "Error connecting: Error while fetching server API version",
  97. ["Docker is not running"]
  98. ),
  99. (
  100. "Failed to import docker-py",
  101. ["docker-py module is not installed", "install the python docker-py package"]
  102. )
  103. ])
  104. def test_skopeo_update_failure(message, extra_words):
  105. def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
  106. if module_name == "docker_image":
  107. return {
  108. "failed": True,
  109. "msg": message,
  110. "changed": False,
  111. }
  112. return {
  113. 'changed': False,
  114. }
  115. actual = DockerImageAvailability(execute_module=execute_module).run(tmp=None, task_vars=dict(
  116. openshift=dict(common=dict(
  117. service_type='origin',
  118. is_containerized=False,
  119. )),
  120. openshift_deployment_type="openshift-enterprise",
  121. openshift_release='',
  122. ))
  123. assert actual["failed"]
  124. for word in extra_words:
  125. assert word in actual["msg"]
  126. @pytest.mark.parametrize("module_failure", [
  127. True,
  128. False,
  129. ])
  130. def test_no_registries_available(module_failure):
  131. def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None):
  132. if module_name == "docker_info":
  133. return {
  134. 'changed': False,
  135. 'failed': module_failure,
  136. 'info': {
  137. 'Registries': [],
  138. }
  139. }
  140. return {
  141. 'changed': False,
  142. }
  143. actual = DockerImageAvailability(execute_module=execute_module).run(tmp=None, task_vars=dict(
  144. openshift=dict(common=dict(
  145. service_type='origin',
  146. is_containerized=False,
  147. )),
  148. openshift_deployment_type="openshift-enterprise",
  149. openshift_release='',
  150. ))
  151. assert actual['failed']
  152. assert "docker registries" in actual['msg']