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