package_version_test.py 4.0 KB

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