From 09dee3c6114780762feaaf0a0895a68df16c51b2 Mon Sep 17 00:00:00 2001 From: Adam Mendlik Date: Sat, 17 Dec 2016 11:30:02 -0700 Subject: [PATCH] Suppress errors when checking if an alternative exists --- salt/modules/alternatives.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/salt/modules/alternatives.py b/salt/modules/alternatives.py index f1fa7d6d6b..77a2b3affa 100644 --- a/salt/modules/alternatives.py +++ b/salt/modules/alternatives.py @@ -112,12 +112,11 @@ def show_current(name): salt '*' alternatives.show_current editor ''' - alt_link_path = '/etc/alternatives/{0}'.format(name) try: - return os.readlink(alt_link_path) + return _read_link(name) except OSError: log.error( - 'alternatives: path {0} does not exist'.format(alt_link_path) + 'alternative: {0} does not exist'.format(name) ) return False @@ -154,7 +153,10 @@ def check_installed(name, path): salt '*' alternatives.check_installed name path ''' - return show_current(name) == path + try: + return _read_link(name) == path + except OSError: + return False def install(name, link, path, priority): @@ -224,3 +226,13 @@ def set_(name, path): if out['retcode'] > 0: return out['stderr'] return out['stdout'] + + +def _read_link(name): + ''' + Read the link from /etc/alternatives + + Throws an OSError if the link does not exist + ''' + alt_link_path = '/etc/alternatives/{0}'.format(name) + return os.readlink(alt_link_path)