package_version_test.py 3.7 KB

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