docker_storage_driver_test.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import pytest
  2. from openshift_checks.docker_storage_driver import DockerStorageDriver
  3. @pytest.mark.parametrize('is_containerized,is_active', [
  4. (False, False),
  5. (True, True),
  6. ])
  7. def test_is_active(is_containerized, is_active):
  8. task_vars = dict(
  9. openshift=dict(common=dict(is_containerized=is_containerized)),
  10. )
  11. assert DockerStorageDriver.is_active(task_vars=task_vars) == is_active
  12. @pytest.mark.parametrize('info,failed,extra_words', [
  13. (
  14. {
  15. "Driver": "devicemapper",
  16. "DriverStatus": [("Pool Name", "docker-docker--pool")],
  17. },
  18. False,
  19. [],
  20. ),
  21. (
  22. {
  23. "Driver": "devicemapper",
  24. "DriverStatus": [("Data loop file", "true")],
  25. },
  26. True,
  27. ["Use of loopback devices is discouraged"],
  28. ),
  29. (
  30. {
  31. "Driver": "overlay2",
  32. "DriverStatus": []
  33. },
  34. False,
  35. [],
  36. ),
  37. (
  38. {
  39. "Driver": "overlay",
  40. },
  41. True,
  42. ["Unsupported Docker storage driver"],
  43. ),
  44. (
  45. {
  46. "Driver": "unsupported",
  47. },
  48. True,
  49. ["Unsupported Docker storage driver"],
  50. ),
  51. ])
  52. def test_check_storage_driver(info, failed, extra_words):
  53. def execute_module(module_name, args, tmp=None, task_vars=None):
  54. if module_name != "docker_info":
  55. return {
  56. "changed": False,
  57. }
  58. return {
  59. "info": info
  60. }
  61. task_vars = dict(
  62. openshift=dict(common=dict(is_containerized=True))
  63. )
  64. check = DockerStorageDriver(execute_module=execute_module).run(tmp=None, task_vars=task_vars)
  65. if failed:
  66. assert check["failed"]
  67. else:
  68. assert not check.get("failed", False)
  69. for word in extra_words:
  70. assert word in check["msg"]