diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-08-11 14:37:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 14:37:54 -0400 |
commit | 8daf3d92028cc6643cee438754ea3c08af540bef (patch) | |
tree | d5dd27ca9a7857c4d5df286df5380688c5271210 /roles/openshift_health_checker/openshift_checks/__init__.py | |
parent | be7e7308764eebdc30ec14d5dfaa49faa7f41d6d (diff) | |
parent | 3c71d009c034c4a0f795ae0fb939746aea80fbca (diff) | |
download | openshift-8daf3d92028cc6643cee438754ea3c08af540bef.tar.gz openshift-8daf3d92028cc6643cee438754ea3c08af540bef.tar.bz2 openshift-8daf3d92028cc6643cee438754ea3c08af540bef.tar.xz openshift-8daf3d92028cc6643cee438754ea3c08af540bef.zip |
Merge pull request #4944 from sosiouxme/20170728-refactor-ansible-mounts
openshift_checks: refactor find_ansible_mount
Diffstat (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py')
-rw-r--r-- | roles/openshift_health_checker/openshift_checks/__init__.py | 25 |
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 09139408c..07ec6f7ef 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -197,6 +197,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", |