etcd_traffic_test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import pytest
  2. from openshift_checks.etcd_traffic import EtcdTraffic
  3. @pytest.mark.parametrize('group_names,version,is_active', [
  4. (['masters'], "3.5", False),
  5. (['masters'], "3.6", False),
  6. (['nodes'], "3.4", False),
  7. (['etcd'], "3.4", True),
  8. (['etcd'], "3.5", True),
  9. (['etcd'], "3.1", False),
  10. (['masters', 'nodes'], "3.5", False),
  11. (['masters', 'etcd'], "3.5", True),
  12. ([], "3.4", False),
  13. ])
  14. def test_is_active(group_names, version, is_active):
  15. task_vars = dict(
  16. group_names=group_names,
  17. openshift=dict(
  18. common=dict(short_version=version),
  19. ),
  20. )
  21. assert EtcdTraffic(task_vars=task_vars).is_active() == is_active
  22. @pytest.mark.parametrize('group_names,matched,failed,extra_words', [
  23. (["masters"], True, True, ["Higher than normal", "traffic"]),
  24. (["masters", "etcd"], False, False, []),
  25. (["etcd"], False, False, []),
  26. ])
  27. def test_log_matches_high_traffic_msg(group_names, matched, failed, extra_words):
  28. def execute_module(module_name, *_):
  29. return {
  30. "matched": matched,
  31. "failed": failed,
  32. }
  33. task_vars = dict(
  34. group_names=group_names,
  35. openshift=dict(
  36. common=dict(service_type="origin", is_containerized=False),
  37. )
  38. )
  39. result = EtcdTraffic(execute_module, task_vars).run()
  40. for word in extra_words:
  41. assert word in result.get("msg", "")
  42. assert result.get("failed", False) == failed
  43. @pytest.mark.parametrize('is_containerized,expected_unit_value', [
  44. (False, "etcd"),
  45. (True, "etcd_container"),
  46. ])
  47. def test_systemd_unit_matches_deployment_type(is_containerized, expected_unit_value):
  48. task_vars = dict(
  49. openshift=dict(
  50. common=dict(is_containerized=is_containerized),
  51. )
  52. )
  53. def execute_module(module_name, args, *_):
  54. assert module_name == "search_journalctl"
  55. matchers = args["log_matchers"]
  56. for matcher in matchers:
  57. assert matcher["unit"] == expected_unit_value
  58. return {"failed": False}
  59. EtcdTraffic(execute_module, task_vars).run()