don't crash when calling swapctl fails, i.e. when there's no swap configured

spotted by juanfra@
This commit is contained in:
jasper 2018-05-17 12:51:10 +00:00
parent fe370f3df9
commit ed98ae7fcd
2 changed files with 22 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.127 2018/05/14 19:16:50 jasper Exp $
# $OpenBSD: Makefile,v 1.128 2018/05/17 12:51:10 jasper Exp $
# optional dependencies
# https://github.com/saltstack/salt/blob/develop/doc/conf.py#L54
@ -20,7 +20,7 @@ COMMENT = remote execution and configuration management system
MODPY_EGG_VERSION = 2018.3.0
DISTNAME = salt-${MODPY_EGG_VERSION}
REVISION = 1
REVISION = 2
CATEGORIES = sysutils net devel

View File

@ -0,0 +1,20 @@
$OpenBSD: patch-salt_grains_core_py,v 1.1 2018/05/17 12:51:10 jasper Exp $
don't crash when calling swapctl fails, i.e. when there's no swap configured.
Index: salt/grains/core.py
--- salt/grains/core.py.orig
+++ salt/grains/core.py
@@ -452,7 +452,11 @@ def _bsd_memdata(osdata):
if osdata['kernel'] == 'OpenBSD':
swapctl = salt.utils.path.which('swapctl')
- swap_total = __salt__['cmd.run']('{0} -sk'.format(swapctl)).split(' ')[1]
+ ret = __salt__['cmd.run_all']('{0} -sk'.format(swapctl))
+ if ret['retcode'] != 0:
+ swap_total = 0
+ else:
+ swap_total = ret['stdout'].split(' ')[1]
else:
swap_total = __salt__['cmd.run']('{0} -n vm.swap_total'.format(sysctl))
grains['swap_total'] = int(swap_total) // 1024 // 1024