Fix groupadd tests for Arch Linux

The default /etc/login.defs does not have a value assigned to MOTD_FILE,
which causes a traceback in 2 of the tests.
This commit is contained in:
Erik Johnson 2018-01-27 16:49:02 -06:00
parent e2b8ec9255
commit 227fcbf794
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -3,7 +3,6 @@
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import grp
import os
import random
import string
@ -14,8 +13,8 @@ from tests.support.helpers import destructiveTest, skip_if_not_root
# Import Salt libs
from salt.ext import six
from salt.ext.six.moves import range
import salt.utils.data
import salt.utils.files
import salt.utils.stringutils
@skip_if_not_root
@ -66,15 +65,20 @@ class GroupModuleTest(ModuleCase):
'''
Returns (SYS_GID_MIN, SYS_GID_MAX)
'''
defs_file = '/etc/login.defs'
if os.path.exists(defs_file):
with salt.utils.files.fopen(defs_file) as defs_fd:
lines = salt.utils.data.decode(defs_fd.readlines())
login_defs = dict([x.split()
for x in lines
if x.strip()
and not x.strip().startswith('#')])
try:
login_defs = {}
with salt.utils.files.fopen('/etc/login.defs') as defs_fd:
for line in defs_fd:
line = salt.utils.stringutils.to_unicode(line).strip()
if line.startswith('#'):
continue
try:
key, val = line.split()
except ValueError:
pass
else:
login_defs[key] = val
except OSError:
login_defs = {'SYS_GID_MIN': 101,
'SYS_GID_MAX': 999}