Skip to content

Commit

Permalink
add docker storage check
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Mar 24, 2017
1 parent 8751f88 commit 0bceb34
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# pylint: disable=missing-docstring
from openshift_checks import OpenShiftCheck, get_var


class DockerStorageCheck(OpenShiftCheck):
"""Check Docker storage sanity.
This check ensures that Docker is using the devicemapper
storage driver, that thinpool usage is not close to 100%,
and that Loopback is not being used.
"""

name = "docker_storage_check"
tags = ["preflight"]

def run(self, tmp, task_vars):
info = self.module_executor("docker_info", {}, task_vars).get("info", {})

if not self.is_devicemapper_used(info):
msg = "Unsupported Docker storage driver detected. Only \"devicemapper\" is currently supported."
return {"failed": True, "msg": msg}

if self.is_using_loopback_device(info):
msg = "Use of loopback devices is discouraged. Try running Docker with `--storage-opt dm.thinpooldev`"
return {"failed": True, "msg": msg}

return {"failed": True, "msg": "%s" % info.get("Data Space Available")}

return {"changed": False}

@staticmethod
def is_devicemapper_used(docker_info):
return docker_info.get("Driver", None) == "devicemapper"

@staticmethod
def is_using_loopback_device(info):
for status in info.get("DriverStatus"):
if status[0] == "Data loop file":
return bool(status[1])

return False

0 comments on commit 0bceb34

Please sign in to comment.