package_version_test.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import pytest
  2. from openshift_checks.package_version import PackageVersion
  3. from openshift_checks import OpenShiftCheckException
  4. def task_vars_for(openshift_release, deployment_type):
  5. service_type_dict = {'origin': 'origin',
  6. 'openshift-enterprise': 'atomic-openshift'}
  7. service_type = service_type_dict[deployment_type]
  8. return dict(
  9. ansible_pkg_mgr='yum',
  10. openshift_service_type=service_type,
  11. openshift_release=openshift_release,
  12. openshift_image_tag='v' + openshift_release,
  13. openshift_deployment_type=deployment_type,
  14. )
  15. def test_openshift_version_not_supported():
  16. check = PackageVersion(None, task_vars_for("1.2.3", 'origin'))
  17. check.get_major_minor_version = lambda: (3, 4, 1) # won't be in the dict
  18. with pytest.raises(OpenShiftCheckException) as excinfo:
  19. check.get_required_ovs_version()
  20. assert "no recommended version of Open vSwitch" in str(excinfo.value)
  21. with pytest.raises(OpenShiftCheckException) as excinfo:
  22. check.get_required_docker_version()
  23. assert "no recommended version of Docker" in str(excinfo.value)
  24. def test_invalid_openshift_release_format():
  25. task_vars = dict(
  26. ansible_pkg_mgr='yum',
  27. openshift_service_type='origin',
  28. openshift_image_tag='v0',
  29. openshift_deployment_type='origin',
  30. )
  31. check = PackageVersion(lambda *_: {}, task_vars)
  32. with pytest.raises(OpenShiftCheckException) as excinfo:
  33. check.run()
  34. assert "invalid version" in str(excinfo.value)
  35. @pytest.mark.parametrize('openshift_release', [
  36. "111.7.0",
  37. "3.7",
  38. "3.6",
  39. "3.5.1.2.3",
  40. "3.5",
  41. "3.4",
  42. "3.3",
  43. "2.1.0",
  44. ])
  45. def test_package_version(openshift_release):
  46. return_value = {"foo": object()}
  47. def execute_module(module_name=None, module_args=None, tmp=None, task_vars=None, *_):
  48. assert module_name == 'aos_version'
  49. assert "package_list" in module_args
  50. for pkg in module_args["package_list"]:
  51. if "-master" in pkg["name"] or "-node" in pkg["name"]:
  52. assert pkg["version"] == task_vars["openshift_release"]
  53. return return_value
  54. check = PackageVersion(execute_module, task_vars_for(openshift_release, 'origin'))
  55. result = check.run()
  56. assert result == return_value
  57. @pytest.mark.parametrize('deployment_type,openshift_release,expected_docker_version', [
  58. ("origin", "3.5", "1.12"),
  59. ("origin", "1.3", "1.10"),
  60. ("origin", "1.1", "1.8"),
  61. ("openshift-enterprise", "3.4", "1.12"),
  62. ("openshift-enterprise", "3.2", "1.10"),
  63. ("openshift-enterprise", "3.1", "1.8"),
  64. ])
  65. def test_docker_package_version(deployment_type, openshift_release, expected_docker_version):
  66. return_value = {"foo": object()}
  67. def execute_module(module_name=None, module_args=None, *_):
  68. assert module_name == 'aos_version'
  69. assert "package_list" in module_args
  70. for pkg in module_args["package_list"]:
  71. if pkg["name"] == "docker":
  72. assert pkg["version"] == expected_docker_version
  73. return return_value
  74. check = PackageVersion(execute_module, task_vars_for(openshift_release, deployment_type))
  75. result = check.run()
  76. assert result == return_value
  77. @pytest.mark.parametrize('group_names,openshift_is_containerized,is_active', [
  78. (['oo_masters_to_config'], False, True),
  79. # ensure check is skipped on containerized installs
  80. (['oo_masters_to_config'], True, False),
  81. (['oo_nodes_to_config'], False, True),
  82. (['oo_masters_to_config', 'oo_nodes_to_config'], False, True),
  83. (['oo_masters_to_config', 'oo_etcd_to_config'], False, True),
  84. ([], False, False),
  85. (['oo_etcd_to_config'], False, False),
  86. (['lb'], False, False),
  87. (['nfs'], False, False),
  88. ])
  89. def test_package_version_skip_when_not_master_nor_node(group_names, openshift_is_containerized, is_active):
  90. task_vars = dict(
  91. group_names=group_names,
  92. openshift_is_containerized=openshift_is_containerized,
  93. )
  94. assert PackageVersion(None, task_vars).is_active() == is_active