From f139c93b27cc58450f05b183fd21300ed1436d3c Mon Sep 17 00:00:00 2001 From: David Hilton Date: Thu, 27 Jun 2019 15:27:01 -0600 Subject: [PATCH 1/2] kernel, os, os_family may not exist in __grains__ - use get --- salt/beacons/aix_account.py | 2 +- salt/modules/aix_group.py | 2 +- salt/modules/aix_shadow.py | 2 +- salt/modules/aixpkg.py | 2 +- salt/modules/apache.py | 2 +- salt/modules/bridge.py | 2 +- salt/modules/deb_apache.py | 6 +++--- salt/modules/debconfmod.py | 2 +- salt/modules/debian_ip.py | 2 +- salt/modules/debian_service.py | 2 +- salt/modules/dpkg_lowpkg.py | 2 +- salt/modules/ebuildpkg.py | 2 +- salt/modules/eix.py | 2 +- salt/modules/eselect.py | 2 +- salt/modules/freebsd_sysctl.py | 2 +- salt/modules/freebsd_update.py | 2 +- salt/modules/freebsdjail.py | 2 +- salt/modules/freebsdkmod.py | 2 +- salt/modules/freebsdpkg.py | 2 +- salt/modules/freebsdports.py | 2 +- salt/modules/freebsdservice.py | 2 +- salt/modules/gentoo_service.py | 4 ++-- salt/modules/gentoolkitmod.py | 2 +- salt/modules/groupadd.py | 2 +- salt/modules/grub_legacy.py | 2 +- salt/modules/keyboard.py | 2 +- salt/modules/kmod.py | 2 +- salt/modules/layman.py | 2 +- salt/modules/linux_ip.py | 6 +++--- salt/modules/linux_sysctl.py | 2 +- salt/modules/logadm.py | 2 +- salt/modules/mac_group.py | 2 +- salt/modules/mac_sysctl.py | 2 +- salt/modules/mac_xattr.py | 2 +- salt/modules/makeconf.py | 2 +- salt/modules/mdadm_raid.py | 2 +- salt/modules/netbsd_sysctl.py | 2 +- salt/modules/netbsdservice.py | 2 +- salt/modules/nilrt_ip.py | 2 +- salt/modules/nspawn.py | 2 +- salt/modules/openbsd_sysctl.py | 2 +- salt/modules/openbsdpkg.py | 2 +- salt/modules/openbsdrcctl_service.py | 2 +- salt/modules/openbsdservice.py | 2 +- salt/modules/pacmanpkg.py | 2 +- salt/modules/pf.py | 4 ++-- salt/modules/pkgin.py | 3 +-- salt/modules/pkgng.py | 6 +++--- salt/modules/pkgutil.py | 2 +- salt/modules/portage_config.py | 2 +- salt/modules/poudriere.py | 2 +- salt/modules/pw_group.py | 2 +- salt/modules/pw_user.py | 2 +- salt/modules/rbac_solaris.py | 2 +- salt/modules/rh_ip.py | 2 +- salt/modules/rh_service.py | 2 +- salt/modules/selinux.py | 2 +- salt/modules/service.py | 2 +- salt/modules/smf_service.py | 2 +- salt/modules/solaris_group.py | 2 +- salt/modules/solaris_user.py | 2 +- salt/modules/solarisipspkg.py | 2 +- salt/modules/solarispkg.py | 2 +- salt/modules/suse_apache.py | 2 +- salt/modules/systemd_service.py | 2 +- salt/modules/upstart_service.py | 4 ++-- salt/modules/useradd.py | 2 +- salt/modules/vmctl.py | 2 +- salt/modules/xapi_virt.py | 2 +- salt/modules/xbpspkg.py | 2 +- salt/modules/zoneadm.py | 2 +- salt/modules/zonecfg.py | 2 +- salt/states/debconfmod.py | 2 +- salt/states/mac_xattr.py | 2 +- salt/states/mdadm_raid.py | 2 +- salt/states/rbac_solaris.py | 2 +- salt/states/service.py | 2 +- salt/states/zfs.py | 2 +- salt/states/zpool.py | 2 +- 79 files changed, 88 insertions(+), 89 deletions(-) diff --git a/salt/beacons/aix_account.py b/salt/beacons/aix_account.py index 8cb9c13ae8f..7087d23a6c4 100644 --- a/salt/beacons/aix_account.py +++ b/salt/beacons/aix_account.py @@ -20,7 +20,7 @@ def __virtual__(): ''' Only load if kernel is AIX ''' - if __grains__['kernel'] == ('AIX'): + if __grains__.get('kernel') == 'AIX': return __virtualname__ return (False, 'The aix_account beacon module failed to load: ' diff --git a/salt/modules/aix_group.py b/salt/modules/aix_group.py index f7f9b776c46..6eeafaf3e06 100644 --- a/salt/modules/aix_group.py +++ b/salt/modules/aix_group.py @@ -30,7 +30,7 @@ def __virtual__(): ''' Set the group module if the kernel is AIX ''' - if __grains__['kernel'] == 'AIX': + if __grains__.get('kernel') == 'AIX': return __virtualname__ return (False, 'The aix_group execution module failed to load: ' 'only available on AIX systems.') diff --git a/salt/modules/aix_shadow.py b/salt/modules/aix_shadow.py index dd6e9c9d4c5..ce91f301094 100644 --- a/salt/modules/aix_shadow.py +++ b/salt/modules/aix_shadow.py @@ -23,7 +23,7 @@ def __virtual__(): ''' Only load if kernel is AIX ''' - if __grains__['kernel'] == 'AIX': + if __grains__.get('kernel') == 'AIX': return __virtualname__ return (False, 'The aix_shadow execution module failed to load: ' 'only available on AIX systems.') diff --git a/salt/modules/aixpkg.py b/salt/modules/aixpkg.py index 5919d97948a..682acc1810a 100644 --- a/salt/modules/aixpkg.py +++ b/salt/modules/aixpkg.py @@ -33,7 +33,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is AIX ''' - if __grains__['os_family'] == 'AIX': + if __grains__.get('os_family') == 'AIX': return __virtualname__ return (False, 'Did not load AIX module on non-AIX OS.') diff --git a/salt/modules/apache.py b/salt/modules/apache.py index 83df8a09483..5692a4e68bb 100644 --- a/salt/modules/apache.py +++ b/salt/modules/apache.py @@ -53,7 +53,7 @@ def _detect_os(): Apache commands and paths differ depending on packaging ''' # TODO: Add pillar support for the apachectl location - os_family = __grains__['os_family'] + os_family = __grains__.get('os_family') if os_family == 'RedHat': return 'apachectl' elif os_family == 'Debian' or os_family == 'Suse': diff --git a/salt/modules/bridge.py b/salt/modules/bridge.py index dc5e5f10e77..49aeead6360 100644 --- a/salt/modules/bridge.py +++ b/salt/modules/bridge.py @@ -29,7 +29,7 @@ def __virtual__(): 'NetBSD': 'brconfig', 'OpenBSD': 'ifconfig' } - cur_os = __grains__['kernel'] + cur_os = __grains__.get('kernel') for _os in supported_os_tool: if cur_os == _os and salt.utils.path.which(supported_os_tool[cur_os]): return True diff --git a/salt/modules/deb_apache.py b/salt/modules/deb_apache.py index 9c2fd42af66..940652af42a 100644 --- a/salt/modules/deb_apache.py +++ b/salt/modules/deb_apache.py @@ -28,7 +28,7 @@ def __virtual__(): Only load the module if apache is installed ''' cmd = _detect_os() - if salt.utils.path.which(cmd) and __grains__['os_family'] == 'Debian': + if salt.utils.path.which(cmd) and __grains__.get('os_family') == 'Debian': return __virtualname__ return (False, 'apache execution module not loaded: apache not installed.') @@ -38,9 +38,9 @@ def _detect_os(): Apache commands and paths differ depending on packaging ''' # TODO: Add pillar support for the apachectl location - if __grains__['os_family'] == 'RedHat': + if __grains__.get('os_family') == 'RedHat': return 'apachectl' - elif __grains__['os_family'] == 'Debian': + elif __grains__.get('os_family') == 'Debian': return 'apache2ctl' else: return 'apachectl' diff --git a/salt/modules/debconfmod.py b/salt/modules/debconfmod.py index a4e08870f05..d07883eca48 100644 --- a/salt/modules/debconfmod.py +++ b/salt/modules/debconfmod.py @@ -30,7 +30,7 @@ def __virtual__(): Confirm this module is on a Debian based system and that debconf-utils is installed. ''' - if __grains__['os_family'] != 'Debian': + if __grains__.get('os_family') != 'Debian': return (False, 'The debconfmod module could not be loaded: ' 'unsupported OS family') diff --git a/salt/modules/debian_ip.py b/salt/modules/debian_ip.py index 596c1fef4d8..d4ef1e8c439 100644 --- a/salt/modules/debian_ip.py +++ b/salt/modules/debian_ip.py @@ -49,7 +49,7 @@ def __virtual__(): ''' Confine this module to Debian-based distros ''' - if __grains__['os_family'] == 'Debian': + if __grains__.get('os_family') == 'Debian': return __virtualname__ return (False, 'The debian_ip module could not be loaded: ' 'unsupported OS family') diff --git a/salt/modules/debian_service.py b/salt/modules/debian_service.py index 03ee14827a1..75fe9b49c86 100644 --- a/salt/modules/debian_service.py +++ b/salt/modules/debian_service.py @@ -41,7 +41,7 @@ def __virtual__(): ''' Only work on Debian and when systemd isn't running ''' - if __grains__['os'] in ('Debian', 'Raspbian', 'Devuan', 'NILinuxRT') and not salt.utils.systemd.booted(__context__): + if __grains__.get('os') in ('Debian', 'Raspbian', 'Devuan', 'NILinuxRT') and not salt.utils.systemd.booted(__context__): return __virtualname__ else: return (False, 'The debian_service module could not be loaded: ' diff --git a/salt/modules/dpkg_lowpkg.py b/salt/modules/dpkg_lowpkg.py index 2370fa1298a..f07fc39cbd2 100644 --- a/salt/modules/dpkg_lowpkg.py +++ b/salt/modules/dpkg_lowpkg.py @@ -28,7 +28,7 @@ def __virtual__(): ''' Confirm this module is on a Debian based system ''' - if __grains__['os_family'] == 'Debian': + if __grains__.get('os_family') == 'Debian': return __virtualname__ return (False, 'The dpkg execution module cannot be loaded: ' 'only works on Debian family systems.') diff --git a/salt/modules/ebuildpkg.py b/salt/modules/ebuildpkg.py index 72d8357f425..6ccd79a6d00 100644 --- a/salt/modules/ebuildpkg.py +++ b/salt/modules/ebuildpkg.py @@ -62,7 +62,7 @@ def __virtual__(): ''' Confirm this module is on a Gentoo based system ''' - if HAS_PORTAGE and __grains__['os_family'] == 'Gentoo': + if HAS_PORTAGE and __grains__.get('os_family') == 'Gentoo': return __virtualname__ return (False, 'The ebuild execution module cannot be loaded: either the system is not Gentoo or the portage python library is not available.') diff --git a/salt/modules/eix.py b/salt/modules/eix.py index 3334d533584..5088bbe89a9 100644 --- a/salt/modules/eix.py +++ b/salt/modules/eix.py @@ -12,7 +12,7 @@ def __virtual__(): ''' Only works on Gentoo systems with eix installed ''' - if __grains__['os_family'] == 'Gentoo' and salt.utils.path.which('eix'): + if __grains__.get('os_family') == 'Gentoo' and salt.utils.path.which('eix'): return 'eix' return (False, 'The eix execution module cannot be loaded: either the system is not Gentoo or the eix binary is not in the path.') diff --git a/salt/modules/eselect.py b/salt/modules/eselect.py index 6320a44f537..e9f81652e95 100644 --- a/salt/modules/eselect.py +++ b/salt/modules/eselect.py @@ -17,7 +17,7 @@ def __virtual__(): ''' Only work on Gentoo systems with eselect installed ''' - if __grains__['os_family'] == 'Gentoo' and salt.utils.path.which('eselect'): + if __grains__.get('os_family') == 'Gentoo' and salt.utils.path.which('eselect'): return 'eselect' return (False, 'The eselect execution module cannot be loaded: either the system is not Gentoo or the eselect binary is not in the path.') diff --git a/salt/modules/freebsd_sysctl.py b/salt/modules/freebsd_sysctl.py index e15ed15febc..1f14d8473b0 100644 --- a/salt/modules/freebsd_sysctl.py +++ b/salt/modules/freebsd_sysctl.py @@ -24,7 +24,7 @@ def __virtual__(): ''' Only runs on FreeBSD systems ''' - if __grains__['os'] == 'FreeBSD': + if __grains__.get('os') == 'FreeBSD': return __virtualname__ return (False, 'The freebsd_sysctl execution module cannot be loaded: ' 'only available on FreeBSD systems.') diff --git a/salt/modules/freebsd_update.py b/salt/modules/freebsd_update.py index 32274f657a1..94c95781b04 100644 --- a/salt/modules/freebsd_update.py +++ b/salt/modules/freebsd_update.py @@ -33,7 +33,7 @@ def __virtual__(): Only work on FreeBSD RELEASEs >= 6.2, where freebsd-update was introduced. ''' - if __grains__['os'] != 'FreeBSD': + if __grains__.get('os') != 'FreeBSD': return (False, 'The freebsd_update execution module cannot be loaded: only available on FreeBSD systems.') if float(__grains__['osrelease']) < 6.2: return (False, 'freebsd_update is only available on FreeBSD versions >= 6.2-RELESE') diff --git a/salt/modules/freebsdjail.py b/salt/modules/freebsdjail.py index 9ccec04d53d..e32f6efe6e8 100644 --- a/salt/modules/freebsdjail.py +++ b/salt/modules/freebsdjail.py @@ -22,7 +22,7 @@ def __virtual__(): ''' Only runs on FreeBSD systems ''' - if __grains__['os'] == 'FreeBSD': + if __grains__.get('os') == 'FreeBSD': return __virtualname__ return (False, 'The freebsdjail execution module cannot be loaded: ' 'only available on FreeBSD systems.') diff --git a/salt/modules/freebsdkmod.py b/salt/modules/freebsdkmod.py index ad47eab10cb..89087f3bc23 100644 --- a/salt/modules/freebsdkmod.py +++ b/salt/modules/freebsdkmod.py @@ -25,7 +25,7 @@ def __virtual__(): ''' Only runs on FreeBSD systems ''' - if __grains__['kernel'] == 'FreeBSD': + if __grains__.get('kernel') == 'FreeBSD': return __virtualname__ return (False, 'The freebsdkmod execution module cannot be loaded: only available on FreeBSD systems.') diff --git a/salt/modules/freebsdpkg.py b/salt/modules/freebsdpkg.py index 0bae7a3baba..46334939562 100644 --- a/salt/modules/freebsdpkg.py +++ b/salt/modules/freebsdpkg.py @@ -98,7 +98,7 @@ def __virtual__(): Don't load on FreeBSD 9 when the config option ``providers:pkg`` is set to 'pkgng'. ''' - if __grains__['os'] == 'FreeBSD' and float(__grains__['osrelease']) < 10: + if __grains__.get('os') == 'FreeBSD' and float(__grains__['osrelease']) < 10: providers = {} if 'providers' in __opts__: providers = __opts__['providers'] diff --git a/salt/modules/freebsdports.py b/salt/modules/freebsdports.py index 76231934d82..3aabc160f13 100644 --- a/salt/modules/freebsdports.py +++ b/salt/modules/freebsdports.py @@ -40,7 +40,7 @@ def __virtual__(): ''' Only runs on FreeBSD systems ''' - if __grains__['os'] == 'FreeBSD': + if __grains__.get('os') == 'FreeBSD': return __virtualname__ return (False, 'The freebsdports execution module cannot be loaded: ' 'only available on FreeBSD systems.') diff --git a/salt/modules/freebsdservice.py b/salt/modules/freebsdservice.py index bc4b95d5fea..f5d0b28038e 100644 --- a/salt/modules/freebsdservice.py +++ b/salt/modules/freebsdservice.py @@ -37,7 +37,7 @@ def __virtual__(): Only work on FreeBSD ''' # Disable on these platforms, specific service modules exist: - if __grains__['os'] == 'FreeBSD': + if __grains__.get('os') == 'FreeBSD': return __virtualname__ return (False, 'The freebsdservice execution module cannot be loaded: only available on FreeBSD systems.') diff --git a/salt/modules/gentoo_service.py b/salt/modules/gentoo_service.py index de8ca15f382..496ea18ab0e 100644 --- a/salt/modules/gentoo_service.py +++ b/salt/modules/gentoo_service.py @@ -31,9 +31,9 @@ def __virtual__(): ''' Only work on systems which default to OpenRC ''' - if __grains__['os_family'] == 'Gentoo' and not salt.utils.systemd.booted(__context__): + if __grains__.get('os_family') == 'Gentoo' and not salt.utils.systemd.booted(__context__): return __virtualname__ - if __grains__['os'] == 'Alpine': + if __grains__.get('os') == 'Alpine': return __virtualname__ return (False, 'The gentoo_service execution module cannot be loaded: ' 'only available on Gentoo/Open-RC systems.') diff --git a/salt/modules/gentoolkitmod.py b/salt/modules/gentoolkitmod.py index fb606c6b6a9..0950f5f1df9 100644 --- a/salt/modules/gentoolkitmod.py +++ b/salt/modules/gentoolkitmod.py @@ -24,7 +24,7 @@ def __virtual__(): ''' Only work on Gentoo systems with gentoolkit installed ''' - if __grains__['os_family'] == 'Gentoo' and HAS_GENTOOLKIT: + if __grains__.get('os_family') == 'Gentoo' and HAS_GENTOOLKIT: return __virtualname__ return (False, 'The gentoolkitmod execution module cannot be loaded: ' 'either the system is not Gentoo or the gentoolkit.eclean python module not available') diff --git a/salt/modules/groupadd.py b/salt/modules/groupadd.py index 15dec6e8983..c40fa47e9a1 100644 --- a/salt/modules/groupadd.py +++ b/salt/modules/groupadd.py @@ -34,7 +34,7 @@ def __virtual__(): ''' Set the user module if the kernel is Linux or OpenBSD ''' - if __grains__['kernel'] in ('Linux', 'OpenBSD', 'NetBSD'): + if __grains__.get('kernel') in ('Linux', 'OpenBSD', 'NetBSD'): return __virtualname__ return (False, 'The groupadd execution module cannot be loaded: ' ' only available on Linux, OpenBSD and NetBSD') diff --git a/salt/modules/grub_legacy.py b/salt/modules/grub_legacy.py index 0d840537efc..ebfe0ed2cb4 100644 --- a/salt/modules/grub_legacy.py +++ b/salt/modules/grub_legacy.py @@ -31,7 +31,7 @@ def _detect_conf(): ''' GRUB conf location differs depending on distro ''' - if __grains__['os_family'] == 'RedHat': + if __grains__.get('os_family') == 'RedHat': return '/boot/grub/grub.conf' # Defaults for Ubuntu, Debian, Arch, and others return '/boot/grub/menu.lst' diff --git a/salt/modules/keyboard.py b/salt/modules/keyboard.py index 707dd72f955..7477cba4179 100644 --- a/salt/modules/keyboard.py +++ b/salt/modules/keyboard.py @@ -19,7 +19,7 @@ def __virtual__(): Only works with systemd or on supported POSIX-like systems ''' if salt.utils.path.which('localectl') \ - or __grains__['os_family'] in ('RedHat', 'Debian', 'Gentoo'): + or __grains__.get('os_family') in ('RedHat', 'Debian', 'Gentoo'): return True return (False, 'The keyboard exeuction module cannot be loaded: ' 'only works on Redhat, Debian or Gentoo systems or if localectl binary in path.') diff --git a/salt/modules/kmod.py b/salt/modules/kmod.py index b6080296d87..7d6ade63851 100644 --- a/salt/modules/kmod.py +++ b/salt/modules/kmod.py @@ -20,7 +20,7 @@ def __virtual__(): ''' Only runs on Linux systems ''' - return __grains__['kernel'] == 'Linux' + return __grains__.get('kernel') == 'Linux' def _new_mods(pre_mods, post_mods): diff --git a/salt/modules/layman.py b/salt/modules/layman.py index febe7418ed7..f48e54a754e 100644 --- a/salt/modules/layman.py +++ b/salt/modules/layman.py @@ -12,7 +12,7 @@ def __virtual__(): ''' Only work on Gentoo systems with layman installed ''' - if __grains__['os_family'] == 'Gentoo' and salt.utils.path.which('layman'): + if __grains__.get('os_family') == 'Gentoo' and salt.utils.path.which('layman'): return 'layman' return (False, 'layman execution module cannot be loaded: only available on Gentoo with layman installed.') diff --git a/salt/modules/linux_ip.py b/salt/modules/linux_ip.py index f76497b8ee5..07613b35f27 100644 --- a/salt/modules/linux_ip.py +++ b/salt/modules/linux_ip.py @@ -22,11 +22,11 @@ def __virtual__(): ''' if salt.utils.platform.is_windows(): return (False, 'Module linux_ip: Windows systems are not supported.') - if __grains__['os_family'] == 'RedHat': + if __grains__.get('os_family') == 'RedHat': return (False, 'Module linux_ip: RedHat systems are not supported.') - if __grains__['os_family'] == 'Debian': + if __grains__.get('os_family') == 'Debian': return (False, 'Module linux_ip: Debian systems are not supported.') - if __grains__['os_family'] == 'NILinuxRT': + if __grains__.get('os_family') == 'NILinuxRT': return (False, 'Module linux_ip: NILinuxRT systems are not supported.') if not salt.utils.path.which('ip'): return (False, 'The linux_ip execution module cannot be loaded: ' diff --git a/salt/modules/linux_sysctl.py b/salt/modules/linux_sysctl.py index 272f67dba86..d85b6ad8d27 100644 --- a/salt/modules/linux_sysctl.py +++ b/salt/modules/linux_sysctl.py @@ -32,7 +32,7 @@ def __virtual__(): ''' Only run on Linux systems ''' - if __grains__['kernel'] != 'Linux': + if __grains__.get('kernel') != 'Linux': return (False, 'The linux_sysctl execution module cannot be loaded: only available on Linux systems.') return __virtualname__ diff --git a/salt/modules/logadm.py b/salt/modules/logadm.py index 3b34efd1f08..365bf25f85e 100644 --- a/salt/modules/logadm.py +++ b/salt/modules/logadm.py @@ -53,7 +53,7 @@ def __virtual__(): ''' Only work on Solaris based systems ''' - if 'Solaris' in __grains__['os_family']: + if 'Solaris' in __grains__.get('os_family'): return True return (False, 'The logadm execution module cannot be loaded: only available on Solaris.') diff --git a/salt/modules/mac_group.py b/salt/modules/mac_group.py index 745679c8461..2260e38e9e3 100644 --- a/salt/modules/mac_group.py +++ b/salt/modules/mac_group.py @@ -25,7 +25,7 @@ def __virtual__(): global _dscl, _flush_dscl_cache if (__grains__.get('kernel') != 'Darwin' or - __grains__['osrelease_info'] < (10, 7)): + __grains__.get('osrelease_info') < (10, 7)): return (False, 'The mac_group execution module cannot be loaded: only available on Darwin-based systems >= 10.7') _dscl = salt.utils.functools.namespaced_function(_dscl, globals()) _flush_dscl_cache = salt.utils.functools.namespaced_function( diff --git a/salt/modules/mac_sysctl.py b/salt/modules/mac_sysctl.py index f0f4447e9bc..9f881c666a5 100644 --- a/salt/modules/mac_sysctl.py +++ b/salt/modules/mac_sysctl.py @@ -20,7 +20,7 @@ def __virtual__(): ''' Only run on Darwin (macOS) systems ''' - if __grains__['os'] == 'MacOS': + if __grains__.get('os') == 'MacOS': return __virtualname__ return (False, 'The darwin_sysctl execution module cannot be loaded: ' 'Only available on macOS systems.') diff --git a/salt/modules/mac_xattr.py b/salt/modules/mac_xattr.py index e5bd5d402d2..d8a7684a016 100644 --- a/salt/modules/mac_xattr.py +++ b/salt/modules/mac_xattr.py @@ -28,7 +28,7 @@ def __virtual__(): ''' Only work on Mac OS ''' - if __grains__['os'] in ['MacOS', 'Darwin']: + if __grains__.get('os') in ['MacOS', 'Darwin']: return __virtualname__ return False diff --git a/salt/modules/makeconf.py b/salt/modules/makeconf.py index a286c1c0e8d..474c64456ff 100644 --- a/salt/modules/makeconf.py +++ b/salt/modules/makeconf.py @@ -15,7 +15,7 @@ def __virtual__(): ''' Only work on Gentoo ''' - if __grains__['os_family'] == 'Gentoo': + if __grains__.get('os_family') == 'Gentoo': return 'makeconf' return (False, 'The makeconf execution module cannot be loaded: only available on Gentoo systems.') diff --git a/salt/modules/mdadm_raid.py b/salt/modules/mdadm_raid.py index 2193b596b7e..904ad7f590c 100644 --- a/salt/modules/mdadm_raid.py +++ b/salt/modules/mdadm_raid.py @@ -33,7 +33,7 @@ def __virtual__(): ''' mdadm provides raid functions for Linux ''' - if __grains__['kernel'] != 'Linux': + if __grains__.get('kernel') != 'Linux': return (False, 'The mdadm execution module cannot be loaded: only available on Linux.') if not salt.utils.path.which('mdadm'): return (False, 'The mdadm execution module cannot be loaded: the mdadm binary is not in the path.') diff --git a/salt/modules/netbsd_sysctl.py b/salt/modules/netbsd_sysctl.py index 245162c5f7c..1de02b425a3 100644 --- a/salt/modules/netbsd_sysctl.py +++ b/salt/modules/netbsd_sysctl.py @@ -21,7 +21,7 @@ def __virtual__(): ''' Only run on NetBSD systems ''' - if __grains__['os'] == 'NetBSD': + if __grains__.get('os') == 'NetBSD': return __virtualname__ return (False, 'The netbsd_sysctl execution module failed to load: ' 'only available on NetBSD.') diff --git a/salt/modules/netbsdservice.py b/salt/modules/netbsdservice.py index 2ccddc20432..d542a27cdc9 100644 --- a/salt/modules/netbsdservice.py +++ b/salt/modules/netbsdservice.py @@ -28,7 +28,7 @@ def __virtual__(): ''' Only work on NetBSD ''' - if __grains__['os'] == 'NetBSD' and os.path.exists('/etc/rc.subr'): + if __grains__.get('os') == 'NetBSD' and os.path.exists('/etc/rc.subr'): return __virtualname__ return (False, 'The netbsdservice execution module failed to load: only available on NetBSD.') diff --git a/salt/modules/nilrt_ip.py b/salt/modules/nilrt_ip.py index 3f809cf1644..75d6f9821f8 100644 --- a/salt/modules/nilrt_ip.py +++ b/salt/modules/nilrt_ip.py @@ -70,7 +70,7 @@ def __virtual__(): ''' try: msg = 'The nilrt_ip module could not be loaded: unsupported OS family' - _assume_condition(__grains__['os_family'] == 'NILinuxRT', msg) + _assume_condition(__grains__.get('os_family') == 'NILinuxRT', msg) _assume_condition(CaseInsensitiveDict, 'The python package request is not installed') _assume_condition(pyiface, 'The python pyiface package is not installed') if __grains__['lsb_distrib_id'] != 'nilrt': diff --git a/salt/modules/nspawn.py b/salt/modules/nspawn.py index 7f3d11ab9f5..9f1999f579b 100644 --- a/salt/modules/nspawn.py +++ b/salt/modules/nspawn.py @@ -57,7 +57,7 @@ def __virtual__(): ''' Only work on systems that have been booted with systemd ''' - if __grains__['kernel'] == 'Linux' \ + if __grains__.get('kernel') == 'Linux' \ and salt.utils.systemd.booted(__context__): if salt.utils.systemd.version() is None: log.error('nspawn: Unable to determine systemd version') diff --git a/salt/modules/openbsd_sysctl.py b/salt/modules/openbsd_sysctl.py index b9409851c8b..ed8195be94b 100644 --- a/salt/modules/openbsd_sysctl.py +++ b/salt/modules/openbsd_sysctl.py @@ -21,7 +21,7 @@ def __virtual__(): ''' Only run on OpenBSD systems ''' - if __grains__['os'] == 'OpenBSD': + if __grains__.get('os') == 'OpenBSD': return __virtualname__ return (False, 'The openbsd_sysctl execution module cannot be loaded: ' 'only available on OpenBSD systems.') diff --git a/salt/modules/openbsdpkg.py b/salt/modules/openbsdpkg.py index b5157e925f3..4a13eca57f1 100644 --- a/salt/modules/openbsdpkg.py +++ b/salt/modules/openbsdpkg.py @@ -48,7 +48,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is OpenBSD ''' - if __grains__['os'] == 'OpenBSD': + if __grains__.get('os') == 'OpenBSD': return __virtualname__ return (False, 'The openbsdpkg execution module cannot be loaded: ' 'only available on OpenBSD systems.') diff --git a/salt/modules/openbsdrcctl_service.py b/salt/modules/openbsdrcctl_service.py index 5bafc5bb3cd..b1f880c4749 100644 --- a/salt/modules/openbsdrcctl_service.py +++ b/salt/modules/openbsdrcctl_service.py @@ -24,7 +24,7 @@ def __virtual__(): ''' rcctl(8) is only available on OpenBSD. ''' - if __grains__['os'] == 'OpenBSD' and os.path.exists('/usr/sbin/rcctl'): + if __grains__.get('os') == 'OpenBSD' and os.path.exists('/usr/sbin/rcctl'): return __virtualname__ return (False, 'The openbsdpkg execution module cannot be loaded: ' 'only available on OpenBSD systems.') diff --git a/salt/modules/openbsdservice.py b/salt/modules/openbsdservice.py index 3c88fcdb206..a8ad274b3d4 100644 --- a/salt/modules/openbsdservice.py +++ b/salt/modules/openbsdservice.py @@ -39,7 +39,7 @@ def __virtual__(): ''' Only work on OpenBSD ''' - if __grains__['os'] == 'OpenBSD' and os.path.exists('/etc/rc.d/rc.subr'): + if __grains__.get('os') == 'OpenBSD' and os.path.exists('/etc/rc.d/rc.subr'): krel = list(list(map(int, __grains__['kernelrelease'].split('.')))) # The -f flag, used to force a script to run even if disabled, # was added after the 5.0 release. diff --git a/salt/modules/pacmanpkg.py b/salt/modules/pacmanpkg.py index efaa0d0904d..462ca405a54 100644 --- a/salt/modules/pacmanpkg.py +++ b/salt/modules/pacmanpkg.py @@ -40,7 +40,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is Arch ''' - if __grains__['os_family'] == 'Arch': + if __grains__.get('os_family') == 'Arch': return __virtualname__ return (False, 'The pacman module could not be loaded: unsupported OS family.') diff --git a/salt/modules/pf.py b/salt/modules/pf.py index a21082ba018..1f7b1431126 100644 --- a/salt/modules/pf.py +++ b/salt/modules/pf.py @@ -26,11 +26,11 @@ def __virtual__(): FreeBSD, etc) need to be tested before enabling them. ''' tested_oses = ['FreeBSD', 'OpenBSD'] - if __grains__['os'] in tested_oses and salt.utils.path.which('pfctl'): + if __grains__.get('os') in tested_oses and salt.utils.path.which('pfctl'): return True return (False, 'The pf execution module cannot be loaded: either the ' - 'OS (' + __grains__['os'] + ') is not tested or the pfctl binary ' + 'OS (' + __grains__.get('os', 'None') + ') is not tested or the pfctl binary ' 'was not found') diff --git a/salt/modules/pkgin.py b/salt/modules/pkgin.py index c23caa278df..d2eebc92eb6 100644 --- a/salt/modules/pkgin.py +++ b/salt/modules/pkgin.py @@ -91,12 +91,11 @@ def _supports_parsing(): return tuple([int(i) for i in _get_version()]) > (0, 6) -@decorators.memoize def _get_provider(): ''' Check if we are the default provider for this platform ''' - return __grains__['os'] in ['NetBSD', 'DragonFly', 'Minix', 'Darwin', 'SmartOS'] or 'pkgin' + return __grains__.get('os') in ['NetBSD', 'DragonFly', 'Minix', 'Darwin', 'SmartOS'] or 'pkgin' def __virtual__(): diff --git a/salt/modules/pkgng.py b/salt/modules/pkgng.py index 87b518ff83a..9feb78e9fad 100644 --- a/salt/modules/pkgng.py +++ b/salt/modules/pkgng.py @@ -68,11 +68,11 @@ def __virtual__(): Load as 'pkg' on FreeBSD 9 when config option ``providers:pkg`` is set to 'pkgng'. ''' - if __grains__['kernel'] == 'DragonFly': + if __grains__.get('kernel') == 'DragonFly': return __virtualname__ - if __grains__['os'] == 'FreeBSD' and float(__grains__['osrelease']) >= 10: + if __grains__.get('os') == 'FreeBSD' and float(__grains__['osrelease']) >= 10: return __virtualname__ - if __grains__['os'] == 'FreeBSD' and int(__grains__['osmajorrelease']) == 9: + if __grains__.get('os') == 'FreeBSD' and int(__grains__['osmajorrelease']) == 9: providers = {} if 'providers' in __opts__: providers = __opts__['providers'] diff --git a/salt/modules/pkgutil.py b/salt/modules/pkgutil.py index 8f46295f521..e732b943dee 100644 --- a/salt/modules/pkgutil.py +++ b/salt/modules/pkgutil.py @@ -29,7 +29,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is Solaris ''' - if __grains__['os_family'] == 'Solaris': + if __grains__.get('os_family') == 'Solaris': return __virtualname__ return (False, 'The pkgutil execution module cannot be loaded: ' 'only available on Solaris systems.') diff --git a/salt/modules/portage_config.py b/salt/modules/portage_config.py index 3f076a76ef5..c173ad91b0a 100644 --- a/salt/modules/portage_config.py +++ b/salt/modules/portage_config.py @@ -48,7 +48,7 @@ def __virtual__(): ''' Confirm this module is on a Gentoo based system. ''' - if HAS_PORTAGE and __grains__['os_family'] == 'Gentoo': + if HAS_PORTAGE and __grains__.get('os_family') == 'Gentoo': return 'portage_config' return (False, 'portage_config execution module cannot be loaded: only available on Gentoo with portage installed.') diff --git a/salt/modules/poudriere.py b/salt/modules/poudriere.py index 4b494cf59a7..8d1ab8923e4 100644 --- a/salt/modules/poudriere.py +++ b/salt/modules/poudriere.py @@ -20,7 +20,7 @@ def __virtual__(): ''' Module load on freebsd only and if poudriere installed ''' - if __grains__['os'] == 'FreeBSD' and salt.utils.path.which('poudriere'): + if __grains__.get('os') == 'FreeBSD' and salt.utils.path.which('poudriere'): return 'poudriere' else: return (False, 'The poudriere execution module failed to load: only available on FreeBSD with the poudriere binary in the path.') diff --git a/salt/modules/pw_group.py b/salt/modules/pw_group.py index e9f7988c909..f3445a8cff4 100644 --- a/salt/modules/pw_group.py +++ b/salt/modules/pw_group.py @@ -34,7 +34,7 @@ def __virtual__(): ''' Set the user module if the kernel is FreeBSD or Dragonfly ''' - if __grains__['kernel'] in ('FreeBSD', 'DragonFly'): + if __grains__.get('kernel') in ('FreeBSD', 'DragonFly'): return __virtualname__ return (False, 'The pw_group execution module cannot be loaded: ' 'system is not supported.') diff --git a/salt/modules/pw_user.py b/salt/modules/pw_user.py index 497bfd3c6a9..3f80f87a9c0 100644 --- a/salt/modules/pw_user.py +++ b/salt/modules/pw_user.py @@ -62,7 +62,7 @@ def __virtual__(): ''' Set the user module if the kernel is FreeBSD or DragonFly ''' - if HAS_PWD and __grains__['kernel'] in ('FreeBSD', 'DragonFly'): + if HAS_PWD and __grains__.get('kernel') in ('FreeBSD', 'DragonFly'): return __virtualname__ return (False, 'The pw_user execution module cannot be loaded: the pwd python module is not available or the system is not FreeBSD.') diff --git a/salt/modules/rbac_solaris.py b/salt/modules/rbac_solaris.py index a127e4796cb..144c7d3bacc 100644 --- a/salt/modules/rbac_solaris.py +++ b/salt/modules/rbac_solaris.py @@ -21,7 +21,7 @@ def __virtual__(): ''' Provides rbac if we are running on a solaris like system ''' - if __grains__['kernel'] == 'SunOS' and salt.utils.path.which('profiles'): + if __grains__.get('kernel') == 'SunOS' and salt.utils.path.which('profiles'): return __virtualname__ return ( False, diff --git a/salt/modules/rh_ip.py b/salt/modules/rh_ip.py index e54069d9911..855de8cff7d 100644 --- a/salt/modules/rh_ip.py +++ b/salt/modules/rh_ip.py @@ -39,7 +39,7 @@ def __virtual__(): ''' Confine this module to RHEL/Fedora based distros ''' - if __grains__['os_family'] == 'RedHat': + if __grains__.get('os_family') == 'RedHat': return __virtualname__ return (False, 'The rh_ip execution module cannot be loaded: this module is only available on RHEL/Fedora based distributions.') diff --git a/salt/modules/rh_service.py b/salt/modules/rh_service.py index 63c86fffb43..fbb7fbe872f 100644 --- a/salt/modules/rh_service.py +++ b/salt/modules/rh_service.py @@ -71,7 +71,7 @@ def __virtual__(): 'McAfee OS Server', 'VirtuozzoLinux' )) - if __grains__['os'] in enable: + if __grains__.get('os') in enable: if __grains__['os'] == 'SUSE': if six.text_type(__grains__['osrelease']).startswith('11'): diff --git a/salt/modules/selinux.py b/salt/modules/selinux.py index 7712a3ae70e..1e53edd803b 100644 --- a/salt/modules/selinux.py +++ b/salt/modules/selinux.py @@ -52,7 +52,7 @@ def __virtual__(): if not salt.utils.path.which(cmd): return (False, cmd + ' is not in the path') # SELinux only makes sense on Linux *obviously* - if __grains__['kernel'] == 'Linux': + if __grains__.get('kernel') == 'Linux': return 'selinux' return (False, 'Module only works on Linux with selinux installed') diff --git a/salt/modules/service.py b/salt/modules/service.py index 002b070c303..c9658c734b9 100644 --- a/salt/modules/service.py +++ b/salt/modules/service.py @@ -46,7 +46,7 @@ def __virtual__(): if __grains__.get('os') in disable: return (False, 'Your OS is on the disabled list') # Disable on all non-Linux OSes as well - if __grains__['kernel'] != 'Linux': + if __grains__.get('kernel') != 'Linux': return (False, 'Non Linux OSes are not supported') init_grain = __grains__.get('init') if init_grain not in (None, 'sysvinit', 'unknown'): diff --git a/salt/modules/smf_service.py b/salt/modules/smf_service.py index 837e1463e33..d67e18dee2a 100644 --- a/salt/modules/smf_service.py +++ b/salt/modules/smf_service.py @@ -27,7 +27,7 @@ def __virtual__(): ''' Only work on systems which default to SMF ''' - if 'Solaris' in __grains__['os_family']: + if 'Solaris' in __grains__.get('os_family'): # Don't let this work on Solaris 9 since SMF doesn't exist on it. if __grains__['kernelrelease'] == "5.9": return (False, 'The smf execution module failed to load: SMF not available on Solaris 9.') diff --git a/salt/modules/solaris_group.py b/salt/modules/solaris_group.py index 4138c3f90fa..fe25334f95c 100644 --- a/salt/modules/solaris_group.py +++ b/salt/modules/solaris_group.py @@ -33,7 +33,7 @@ def __virtual__(): ''' Set the group module if the kernel is SunOS ''' - if __grains__['kernel'] == 'SunOS': + if __grains__.get('kernel') == 'SunOS': return __virtualname__ return (False, 'The solaris_group execution module failed to load: ' 'only available on Solaris systems.') diff --git a/salt/modules/solaris_user.py b/salt/modules/solaris_user.py index 5107435cc99..93ea4f97c47 100644 --- a/salt/modules/solaris_user.py +++ b/salt/modules/solaris_user.py @@ -37,7 +37,7 @@ def __virtual__(): ''' Set the user module if the kernel is SunOS ''' - if __grains__['kernel'] == 'SunOS' and HAS_PWD: + if __grains__.get('kernel') == 'SunOS' and HAS_PWD: return __virtualname__ return (False, 'The solaris_user execution module failed to load: ' 'only available on Solaris systems with pwd module installed.') diff --git a/salt/modules/solarisipspkg.py b/salt/modules/solarisipspkg.py index 197d82772ae..fbc584a7dfc 100644 --- a/salt/modules/solarisipspkg.py +++ b/salt/modules/solarisipspkg.py @@ -62,7 +62,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is Solaris 11 ''' - if __grains__['os_family'] == 'Solaris' \ + if __grains__.get('os_family') == 'Solaris' \ and float(__grains__['kernelrelease']) > 5.10 \ and salt.utils.path.which('pkg'): return __virtualname__ diff --git a/salt/modules/solarispkg.py b/salt/modules/solarispkg.py index 50bdc3ebfaf..298209c2b0d 100644 --- a/salt/modules/solarispkg.py +++ b/salt/modules/solarispkg.py @@ -32,7 +32,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is Solaris ''' - if __grains__['os_family'] == 'Solaris' and float(__grains__['kernelrelease']) <= 5.10: + if __grains__.get('os_family') == 'Solaris' and float(__grains__['kernelrelease']) <= 5.10: return __virtualname__ return (False, 'The solarispkg execution module failed to load: only available ' diff --git a/salt/modules/suse_apache.py b/salt/modules/suse_apache.py index 9607b9bc49c..fd6c556b097 100644 --- a/salt/modules/suse_apache.py +++ b/salt/modules/suse_apache.py @@ -23,7 +23,7 @@ def __virtual__(): ''' Only load the module if apache is installed. ''' - if salt.utils.path.which('apache2ctl') and __grains__['os_family'] == 'Suse': + if salt.utils.path.which('apache2ctl') and __grains__.get('os_family') == 'Suse': return __virtualname__ return (False, 'apache execution module not loaded: apache not installed.') diff --git a/salt/modules/systemd_service.py b/salt/modules/systemd_service.py index 668e88a37a6..da2a1406869 100644 --- a/salt/modules/systemd_service.py +++ b/salt/modules/systemd_service.py @@ -60,7 +60,7 @@ def __virtual__(): ''' Only work on systems that have been booted with systemd ''' - if __grains__['kernel'] == 'Linux' \ + if __grains__.get('kernel') == 'Linux' \ and salt.utils.systemd.booted(__context__): return __virtualname__ return ( diff --git a/salt/modules/upstart_service.py b/salt/modules/upstart_service.py index bf455d7756d..e4696b92c88 100644 --- a/salt/modules/upstart_service.py +++ b/salt/modules/upstart_service.py @@ -74,9 +74,9 @@ def __virtual__(): # Disable on these platforms, specific service modules exist: if salt.utils.systemd.booted(__context__): return (False, 'The upstart execution module failed to load: this system was booted with systemd.') - elif __grains__['os'] in ('Ubuntu', 'Linaro', 'elementary OS', 'Mint'): + elif __grains__.get('os') in ('Ubuntu', 'Linaro', 'elementary OS', 'Mint'): return __virtualname__ - elif __grains__['os'] in ('Debian', 'Raspbian'): + elif __grains__.get('os') in ('Debian', 'Raspbian'): debian_initctl = '/sbin/initctl' if os.path.isfile(debian_initctl): initctl_version = salt.modules.cmdmod._run_quiet(debian_initctl + ' version') diff --git a/salt/modules/useradd.py b/salt/modules/useradd.py index f6a5f83a7f5..9fb23796d5d 100644 --- a/salt/modules/useradd.py +++ b/salt/modules/useradd.py @@ -42,7 +42,7 @@ def __virtual__(): Set the user module if the kernel is Linux, OpenBSD, NetBSD or AIX ''' - if HAS_PWD and __grains__['kernel'] in ('Linux', 'OpenBSD', 'NetBSD', 'AIX'): + if HAS_PWD and __grains__.get('kernel') in ('Linux', 'OpenBSD', 'NetBSD', 'AIX'): return __virtualname__ return (False, 'useradd execution module not loaded: either pwd python library not available or system not one of Linux, OpenBSD, NetBSD or AIX') diff --git a/salt/modules/vmctl.py b/salt/modules/vmctl.py index e37cdffb406..2f4be9bc160 100644 --- a/salt/modules/vmctl.py +++ b/salt/modules/vmctl.py @@ -30,7 +30,7 @@ def __virtual__(): ''' Only works on OpenBSD with vmctl(8) present. ''' - if __grains__['os'] == 'OpenBSD' and salt.utils.path.which('vmctl'): + if __grains__.get('os') == 'OpenBSD' and salt.utils.path.which('vmctl'): return True return (False, 'The vmm execution module cannot be loaded: either the system is not OpenBSD or the vmctl binary was not found') diff --git a/salt/modules/xapi_virt.py b/salt/modules/xapi_virt.py index c4419ebf13f..7046499f733 100644 --- a/salt/modules/xapi_virt.py +++ b/salt/modules/xapi_virt.py @@ -49,7 +49,7 @@ def _check_xenapi(): - if __grains__['os'] == 'Debian': + if __grains__.get('os') == 'Debian': debian_xen_version = '/usr/lib/xen-common/bin/xen-version' if os.path.isfile(debian_xen_version): # __salt__ is not available in __virtual__ diff --git a/salt/modules/xbpspkg.py b/salt/modules/xbpspkg.py index 65467ad966e..aace84d9367 100644 --- a/salt/modules/xbpspkg.py +++ b/salt/modules/xbpspkg.py @@ -34,7 +34,7 @@ def __virtual__(): ''' Set the virtual pkg module if the os is Void and xbps-install found ''' - if __grains__['os'] in ('Void') and _check_xbps(): + if __grains__.get('os', 'None') in ('Void') and _check_xbps(): return __virtualname__ return False diff --git a/salt/modules/zoneadm.py b/salt/modules/zoneadm.py index 52c7ff18415..b254e2608f6 100644 --- a/salt/modules/zoneadm.py +++ b/salt/modules/zoneadm.py @@ -37,7 +37,7 @@ def _is_globalzone(): ''' Check if we are running in the globalzone ''' - if not __grains__['kernel'] == 'SunOS': + if not __grains__.get('kernel') == 'SunOS': return False zonename = __salt__['cmd.run_all']('zonename') diff --git a/salt/modules/zonecfg.py b/salt/modules/zonecfg.py index 456dfad9a99..01361e1096b 100644 --- a/salt/modules/zonecfg.py +++ b/salt/modules/zonecfg.py @@ -84,7 +84,7 @@ def _is_globalzone(): ''' Check if we are running in the globalzone ''' - if not __grains__['kernel'] == 'SunOS': + if not __grains__.get('kernel') == 'SunOS': return False zonename = __salt__['cmd.run_all']('zonename') diff --git a/salt/states/debconfmod.py b/salt/states/debconfmod.py index a0ef20b1853..39df885a1de 100644 --- a/salt/states/debconfmod.py +++ b/salt/states/debconfmod.py @@ -73,7 +73,7 @@ def __virtual__(): ''' Confirm this module is on a Debian based system ''' - if __grains__['os_family'] != 'Debian': + if __grains__.get('os_family') != 'Debian': return False # Check that debconf was loaded if 'debconf.show' not in __salt__: diff --git a/salt/states/mac_xattr.py b/salt/states/mac_xattr.py index e008197e365..c726a8cf270 100644 --- a/salt/states/mac_xattr.py +++ b/salt/states/mac_xattr.py @@ -27,7 +27,7 @@ def __virtual__(): ''' Only work on Mac OS ''' - if __grains__['os'] in ['MacOS', 'Darwin']: + if __grains__.get('os') in ['MacOS', 'Darwin']: return __virtualname__ return False diff --git a/salt/states/mdadm_raid.py b/salt/states/mdadm_raid.py index 3e10905b2dc..6f25c37ae61 100644 --- a/salt/states/mdadm_raid.py +++ b/salt/states/mdadm_raid.py @@ -38,7 +38,7 @@ def __virtual__(): ''' mdadm provides raid functions for Linux ''' - if __grains__['kernel'] != 'Linux': + if __grains__.get('kernel') != 'Linux': return False if not salt.utils.path.which('mdadm'): return False diff --git a/salt/states/rbac_solaris.py b/salt/states/rbac_solaris.py index feb253ea5e8..485a3bb8912 100644 --- a/salt/states/rbac_solaris.py +++ b/salt/states/rbac_solaris.py @@ -37,7 +37,7 @@ def __virtual__(): ''' if 'rbac.profile_list' in __salt__ and \ 'user.list_users' in __salt__ and \ - __grains__['kernel'] == 'SunOS': + __grains__.get('kernel') == 'SunOS': return True else: return ( diff --git a/salt/states/service.py b/salt/states/service.py index 3bec08bc0dd..ee8dcd6054b 100644 --- a/salt/states/service.py +++ b/salt/states/service.py @@ -86,7 +86,7 @@ def __virtual__(): else: return (False, 'No service execution module loaded: ' 'check support for service management on {0} ' - ''.format(__grains__.get('osfinger', __grains__['os'])) + ''.format(__grains__.get('osfinger', __grains__.get('os', 'NO OS'))) ) diff --git a/salt/states/zfs.py b/salt/states/zfs.py index ff6a642b6b0..1bb914ae59b 100644 --- a/salt/states/zfs.py +++ b/salt/states/zfs.py @@ -68,7 +68,7 @@ def __virtual__(): ''' Provides zfs state ''' - if __grains__['zfs_support']: + if __grains__.get('zfs_support'): return __virtualname__ else: return (False, "The zfs state cannot be loaded: zfs not supported") diff --git a/salt/states/zpool.py b/salt/states/zpool.py index 02e281c3fb2..8e67a816fc1 100644 --- a/salt/states/zpool.py +++ b/salt/states/zpool.py @@ -88,7 +88,7 @@ def __virtual__(): ''' Provides zpool state ''' - if __grains__['zfs_support']: + if __grains__.get('zfs_support'): return __virtualname__ else: return False, 'The zpool state cannot be loaded: zfs not supported' From 5b7c857d9f2852be87b98bf6da7879f8c14f393f Mon Sep 17 00:00:00 2001 From: David Hilton Date: Thu, 27 Jun 2019 15:52:09 -0600 Subject: [PATCH 2/2] look at os_family['Solaris'] instead of checking all* solaris distros --- salt/modules/pkgin.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/salt/modules/pkgin.py b/salt/modules/pkgin.py index d2eebc92eb6..53e175e4def 100644 --- a/salt/modules/pkgin.py +++ b/salt/modules/pkgin.py @@ -91,18 +91,11 @@ def _supports_parsing(): return tuple([int(i) for i in _get_version()]) > (0, 6) -def _get_provider(): - ''' - Check if we are the default provider for this platform - ''' - return __grains__.get('os') in ['NetBSD', 'DragonFly', 'Minix', 'Darwin', 'SmartOS'] or 'pkgin' - - def __virtual__(): ''' Set the virtual pkg module if the os is supported by pkgin ''' - return (_check_pkgin() and _get_provider() or False, + return (__grains__.get('os_family') == 'Solaris' and _check_pkgin(), 'The pkgin execution module cannot be loaded: pkgin was ' 'not detected on this platform.')