ovs_version_test.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import pytest
  2. from openshift_checks.ovs_version import OvsVersion, OpenShiftCheckException
  3. def test_openshift_version_not_supported():
  4. def execute_module(*_):
  5. return {}
  6. openshift_release = '111.7.0'
  7. task_vars = dict(
  8. openshift=dict(common=dict(service_type='origin')),
  9. openshift_release=openshift_release,
  10. openshift_image_tag='v' + openshift_release,
  11. openshift_deployment_type='origin',
  12. )
  13. with pytest.raises(OpenShiftCheckException) as excinfo:
  14. OvsVersion(execute_module, task_vars).run()
  15. assert "no recommended version of Open vSwitch" in str(excinfo.value)
  16. def test_invalid_openshift_release_format():
  17. def execute_module(*_):
  18. return {}
  19. task_vars = dict(
  20. openshift=dict(common=dict(service_type='origin')),
  21. openshift_image_tag='v0',
  22. openshift_deployment_type='origin',
  23. )
  24. with pytest.raises(OpenShiftCheckException) as excinfo:
  25. OvsVersion(execute_module, task_vars).run()
  26. assert "invalid version" in str(excinfo.value)
  27. @pytest.mark.parametrize('openshift_release,expected_ovs_version', [
  28. ("3.7", ["2.6", "2.7", "2.8"]),
  29. ("3.5", ["2.6", "2.7"]),
  30. ("3.6", ["2.6", "2.7", "2.8"]),
  31. ("3.4", "2.4"),
  32. ("3.3", "2.4"),
  33. ("1.0", "2.4"),
  34. ])
  35. def test_ovs_package_version(openshift_release, expected_ovs_version):
  36. task_vars = dict(
  37. openshift=dict(common=dict(service_type='origin')),
  38. openshift_release=openshift_release,
  39. openshift_image_tag='v' + openshift_release,
  40. )
  41. return_value = {} # note: check.execute_module modifies return hash contents
  42. def execute_module(module_name=None, module_args=None, *_):
  43. assert module_name == 'rpm_version'
  44. assert "package_list" in module_args
  45. for pkg in module_args["package_list"]:
  46. if pkg["name"] == "openvswitch":
  47. assert pkg["version"] == expected_ovs_version
  48. return return_value
  49. result = OvsVersion(execute_module, task_vars).run()
  50. assert result is return_value
  51. @pytest.mark.parametrize('group_names,is_containerized,is_active', [
  52. (['oo_masters_to_config'], False, True),
  53. # ensure check is skipped on containerized installs
  54. (['oo_masters_to_config'], True, False),
  55. (['oo_nodes_to_config'], False, True),
  56. (['oo_masters_to_config', 'oo_nodes_to_config'], False, True),
  57. (['oo_masters_to_config', 'oo_etcd_to_config'], False, True),
  58. ([], False, False),
  59. (['oo_etcd_to_config'], False, False),
  60. (['lb'], False, False),
  61. (['nfs'], False, False),
  62. ])
  63. def test_ovs_version_skip_when_not_master_nor_node(group_names, is_containerized, is_active):
  64. task_vars = dict(
  65. group_names=group_names,
  66. openshift=dict(common=dict(is_containerized=is_containerized)),
  67. )
  68. assert OvsVersion(None, task_vars).is_active() == is_active