Merge pull request #41382 from DSRCorporation/bugs/py3_tests_nitrogen

Bugs/py3 tests nitrogen
This commit is contained in:
Mike Place 2017-05-24 14:06:38 -05:00 committed by GitHub
commit 78078cb62d
5 changed files with 59 additions and 10 deletions

View file

@ -2879,6 +2879,14 @@ def repack_dictlist(data,
return ret
def get_default_group(user):
if HAS_GRP is False or HAS_PWD is False:
# We don't work on platforms that don't have grp and pwd
# Just return an empty list
return None
return grp.getgrgid(pwd.getpwnam(user).pw_gid).gr_name
def get_group_list(user=None, include_default=True):
'''
Returns a list of all of the system group names of which the user
@ -2917,7 +2925,7 @@ def get_group_list(user=None, include_default=True):
log.trace('Trying generic group list for \'{0}\''.format(user))
group_names = [g.gr_name for g in grp.getgrall() if user in g.gr_mem]
try:
default_group = grp.getgrgid(pwd.getpwnam(user).pw_gid).gr_name
default_group = get_default_group(user)
if default_group not in group_names:
group_names.append(default_group)
except KeyError:

View file

@ -114,7 +114,7 @@ class TestModulesGrains(ModuleCase):
for grain in grains:
get_grain = self.run_function('grains.get', [grain])
if os == 'Arch' and grain in ['osmajorrelease', 'osrelease']:
if os == 'Arch' and grain in ['osmajorrelease']:
self.assertEqual(get_grain, '')
continue
if os == 'Windows' and grain in ['osmajorrelease']:

View file

@ -59,11 +59,13 @@ class LinuxAclModuleTest(ModuleCase, AdaptedConfigurationTestCaseMixin):
def test_getfacl_w_single_file_without_acl(self):
ret = self.run_function('acl.getfacl', arg=[self.myfile])
user = salt.utils.get_user()
group = salt.utils.get_default_group(user)
self.maxDiff = None
self.assertEqual(
ret,
{self.myfile: {'other': [{'': {'octal': 4, 'permissions': {'read': True, 'write': False, 'execute': False}}}],
'user': [{'root': {'octal': 6, 'permissions': {'read': True, 'write': True, 'execute': False}}}],
'group': [{'root': {'octal': 4, 'permissions': {'read': True, 'write': False, 'execute': False}}}],
'comment': {'owner': 'root', 'group': 'root', 'file': self.myfile}}}
'user': [{user: {'octal': 6, 'permissions': {'read': True, 'write': True, 'execute': False}}}],
'group': [{group: {'octal': 4, 'permissions': {'read': True, 'write': False, 'execute': False}}}],
'comment': {'owner': user, 'group': group, 'file': self.myfile}}}
)

View file

@ -157,3 +157,16 @@ class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
stderr=tests.integration.utils.decode_byte_list(stderr)
)
master.shutdown()
# Do the test again to check does master shut down correctly
stdout, stderr, status = master.run(
args=['-d'],
catch_stderr=True,
with_retcode=True,
)
self.assert_exit_status(
status, 'EX_OK',
message='correct usage',
stdout=stdout,
stderr=tests.integration.utils.decode_byte_list(stderr)
)
master.shutdown()

View file

@ -35,9 +35,24 @@ from salt.exceptions import CommandExecutionError
import salt.ext.six as six
class VirtualEnv(object):
def __init__(self, test, venv_dir):
self.venv_dir = venv_dir
self.test = test
def __enter__(self):
ret = self.test.run_function('virtualenv.create', [self.venv_dir])
self.test.assertEqual(ret['retcode'], 0)
def __exit__(self, exc_type, exc_value, traceback):
if os.path.isdir(self.venv_dir):
shutil.rmtree(self.venv_dir)
@skipIf(salt.utils.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
@skip_if_not_root
def test_pip_installed_removed(self):
'''
Tests installed and removed states
@ -50,6 +65,17 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
ret = self.run_state('pip.removed', name=name)
self.assertSaltTrueReturn(ret)
def test_pip_installed_removed_venv(self):
venv_dir = os.path.join(
RUNTIME_VARS.TMP, 'pip_installed_removed'
)
with VirtualEnv(self, venv_dir):
name = 'pudb'
ret = self.run_state('pip.installed', name=name, bin_env=venv_dir)
self.assertSaltTrueReturn(ret)
ret = self.run_state('pip.removed', name=name, bin_env=venv_dir)
self.assertSaltTrueReturn(ret)
def test_pip_installed_errors(self):
venv_dir = os.path.join(
RUNTIME_VARS.TMP, 'pip-installed-errors'
@ -378,7 +404,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
# Let's install a fixed version pip over whatever pip was
# previously installed
ret = self.run_function(
'pip.install', ['pip==6.0'], upgrade=True,
'pip.install', ['pip==8.0'], upgrade=True,
bin_env=venv_dir
)
try:
@ -392,15 +418,15 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
pprint.pprint(ret)
raise
# Let's make sure we have pip 6.0 installed
# Let's make sure we have pip 8.0 installed
self.assertEqual(
self.run_function('pip.list', ['pip'], bin_env=venv_dir),
{'pip': '6.0'}
{'pip': '8.0.0'}
)
# Now the actual pip upgrade pip test
ret = self.run_state(
'pip.installed', name='pip==6.0.7', upgrade=True,
'pip.installed', name='pip==8.0.1', upgrade=True,
bin_env=venv_dir
)
try:
@ -408,7 +434,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
self.assertInSaltReturn(
'Installed',
ret,
['changes', 'pip==6.0.7']
['changes', 'pip==8.0.1']
)
except AssertionError:
import pprint