docker_storage_driver.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # pylint: disable=missing-docstring
  2. from openshift_checks import OpenShiftCheck, get_var
  3. class DockerStorageDriver(OpenShiftCheck):
  4. """Check Docker storage driver compatibility.
  5. This check ensures that Docker is using a supported storage driver,
  6. and that Loopback is not being used (if using devicemapper).
  7. """
  8. name = "docker_storage_driver"
  9. tags = ["preflight"]
  10. storage_drivers = ["devicemapper", "overlay2"]
  11. @classmethod
  12. def is_active(cls, task_vars):
  13. """Skip non-containerized installations."""
  14. is_containerized = get_var(task_vars, "openshift", "common", "is_containerized")
  15. return super(DockerStorageDriver, cls).is_active(task_vars) and is_containerized
  16. def run(self, tmp, task_vars):
  17. info = self.execute_module("docker_info", {}, task_vars).get("info", {})
  18. if not self.is_supported_storage_driver(info):
  19. msg = "Unsupported Docker storage driver detected. Supported storage drivers: {drivers}"
  20. return {"failed": True, "msg": msg.format(drivers=', '.join(self.storage_drivers))}
  21. if self.is_using_loopback_device(info):
  22. msg = "Use of loopback devices is discouraged. Try running Docker with `--storage-opt dm.thinpooldev`"
  23. return {"failed": True, "msg": msg}
  24. return {}
  25. def is_supported_storage_driver(self, docker_info):
  26. return docker_info.get("Driver", "") in self.storage_drivers
  27. @staticmethod
  28. def is_using_loopback_device(docker_info):
  29. # Loopback device usage is only an issue if using devicemapper.
  30. # Skip this check if using any other storage driver.
  31. if docker_info.get("Driver", "") != "devicemapper":
  32. return False
  33. for status in docker_info.get("DriverStatus", []):
  34. if status[0] == "Data loop file":
  35. return bool(status[1])
  36. return False