From 3c71d009c034c4a0f795ae0fb939746aea80fbca Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Fri, 28 Jul 2017 17:06:54 -0400 Subject: openshift_checks: refactor find_ansible_mount Reuse the code for finding the ansible_mounts mount for a path. --- .../openshift_checks/__init__.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py') 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", -- cgit v1.2.3