summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/openshift_checks/__init__.py
diff options
context:
space:
mode:
authorLuke Meyer <lmeyer@redhat.com>2017-07-28 17:06:54 -0400
committerLuke Meyer <lmeyer@redhat.com>2017-08-08 15:42:28 -0400
commit3c71d009c034c4a0f795ae0fb939746aea80fbca (patch)
tree86a3b227f2322300ba23999843ac6d8bead27a61 /roles/openshift_health_checker/openshift_checks/__init__.py
parent566731dc4dd1aebbbf0244dc8a31eefb8cd42de5 (diff)
downloadopenshift-3c71d009c034c4a0f795ae0fb939746aea80fbca.tar.gz
openshift-3c71d009c034c4a0f795ae0fb939746aea80fbca.tar.bz2
openshift-3c71d009c034c4a0f795ae0fb939746aea80fbca.tar.xz
openshift-3c71d009c034c4a0f795ae0fb939746aea80fbca.zip
openshift_checks: refactor find_ansible_mount
Reuse the code for finding the ansible_mounts mount for a path.
Diffstat (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py')
-rw-r--r--roles/openshift_health_checker/openshift_checks/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py
index f26008c9f..0390aa80f 100644
--- a/roles/openshift_health_checker/openshift_checks/__init__.py
+++ b/roles/openshift_health_checker/openshift_checks/__init__.py
@@ -153,6 +153,31 @@ class OpenShiftCheck(object):
components = tuple(int(x) for x in components[:2])
return components
+ def find_ansible_mount(self, path):
+ """Return the mount point for path from ansible_mounts."""
+
+ # reorganize list of mounts into dict by path
+ mount_for_path = {
+ mount['mount']: mount
+ for mount
+ in self.get_var('ansible_mounts')
+ }
+
+ # NOTE: including base cases '/' and '' to ensure the loop ends
+ mount_targets = set(mount_for_path.keys()) | {'/', ''}
+ mount_point = path
+ while mount_point not in mount_targets:
+ mount_point = os.path.dirname(mount_point)
+
+ try:
+ return mount_for_path[mount_point]
+ except KeyError:
+ known_mounts = ', '.join('"{}"'.format(mount) for mount in sorted(mount_for_path))
+ raise OpenShiftCheckException(
+ 'Unable to determine mount point for path "{}".\n'
+ 'Known mount points: {}.'.format(path, known_mounts or 'none')
+ )
+
LOADER_EXCLUDES = (
"__init__.py",