mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge remote-tracking branch 'upstream/2017.7.9' into 2017.7
This commit is contained in:
commit
595303b97a
2 changed files with 47 additions and 38 deletions
37
noxfile.py
37
noxfile.py
|
@ -7,11 +7,13 @@ Nox configuration script
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import pprint
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.stderr.write('Do not execute this file directly. Use nox instead, it will know how to handle this file\n')
|
||||
sys.stderr.flush()
|
||||
|
@ -23,9 +25,6 @@ import nox
|
|||
# Global Path Definitions
|
||||
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||
SITECUSTOMIZE_DIR = os.path.join(REPO_ROOT, 'tests', 'support', 'coverage')
|
||||
|
||||
# We can't just import salt because if this is running under a frozen nox, there
|
||||
# will be no salt to import
|
||||
IS_WINDOWS = sys.platform.lower().startswith('win')
|
||||
REQUIREMENTS_OVERRIDES = {
|
||||
None: [
|
||||
|
@ -45,6 +44,7 @@ nox.options.reuse_existing_virtualenvs = True
|
|||
# Don't fail on missing interpreters
|
||||
nox.options.error_on_missing_interpreters = False
|
||||
|
||||
|
||||
def _create_ci_directories():
|
||||
for dirname in ('logs', 'coverage', 'xml-unittests-output'):
|
||||
path = os.path.join(REPO_ROOT, 'artifacts', dirname)
|
||||
|
@ -53,22 +53,25 @@ def _create_ci_directories():
|
|||
|
||||
|
||||
def _install_requirements(session, *extra_requirements):
|
||||
session.install('distro')
|
||||
output = session.run('distro', '-j', silent=True)
|
||||
distro = json.loads(output.strip())
|
||||
session.log('Distro information:\n%s', pprint.pformat(distro))
|
||||
distro_keys = [
|
||||
'{id}-{version}'.format(**distro),
|
||||
'{id}-{version_parts[major]}'.format(**distro)
|
||||
]
|
||||
|
||||
# Install requirements
|
||||
distro_requirements = None
|
||||
for distro_key in distro_keys:
|
||||
_distro_requirements = os.path.join(REPO_ROOT, 'requirements', 'static', '{}.txt'.format(distro_key))
|
||||
if os.path.exists(_distro_requirements):
|
||||
distro_requirements = _distro_requirements
|
||||
break
|
||||
|
||||
if not IS_WINDOWS:
|
||||
# The distro package doesn't output anything for Windows
|
||||
session.install('distro')
|
||||
output = session.run('distro', '-j', silent=True)
|
||||
distro = json.loads(output.strip())
|
||||
session.log('Distro information:\n%s', pprint.pformat(distro))
|
||||
distro_keys = [
|
||||
'{id}-{version}'.format(**distro),
|
||||
'{id}-{version_parts[major]}'.format(**distro)
|
||||
]
|
||||
for distro_key in distro_keys:
|
||||
_distro_requirements = os.path.join(REPO_ROOT, 'requirements', 'static', '{}.txt'.format(distro_key))
|
||||
if os.path.exists(_distro_requirements):
|
||||
distro_requirements = _distro_requirements
|
||||
break
|
||||
|
||||
if distro_requirements is not None:
|
||||
_requirements_files = [distro_requirements]
|
||||
requirements_files = []
|
||||
|
|
|
@ -16,6 +16,7 @@ from tests.support.helpers import destructiveTest, flaky, skip_if_not_root
|
|||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.modules.shadow
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
|
||||
|
@ -26,12 +27,6 @@ class ShadowModuleTest(ModuleCase):
|
|||
Validate the linux shadow system module
|
||||
'''
|
||||
|
||||
def __init__(self, arg):
|
||||
super(self.__class__, self).__init__(arg)
|
||||
self._test_user = self.__random_string()
|
||||
self._no_user = self.__random_string()
|
||||
self._password = self.run_function('shadow.gen_password', ['Password1234'])
|
||||
|
||||
def setUp(self):
|
||||
'''
|
||||
Get current settings
|
||||
|
@ -44,12 +39,9 @@ class ShadowModuleTest(ModuleCase):
|
|||
**os_grain
|
||||
)
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
'''
|
||||
Reset to original settings
|
||||
'''
|
||||
self.run_function('user.delete', [self._test_user])
|
||||
self._test_user = self.__random_string()
|
||||
self._no_user = self.__random_string()
|
||||
self._password = salt.modules.shadow.gen_password('Password1234')
|
||||
|
||||
def __random_string(self, size=6):
|
||||
'''
|
||||
|
@ -65,6 +57,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.info
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -80,6 +73,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.del_password
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -95,6 +89,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_password
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -108,6 +103,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_inactdays
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -121,6 +117,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_maxdays
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -134,6 +131,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_mindays
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -148,6 +146,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.lock_password
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
self.run_function('shadow.set_password', [self._test_user, self._password])
|
||||
|
||||
|
@ -162,6 +161,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.lock_password
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
self.run_function('shadow.set_password', [self._test_user, self._password])
|
||||
|
||||
|
@ -176,6 +176,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_warndays
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -189,6 +190,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_date
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -202,6 +204,7 @@ class ShadowModuleTest(ModuleCase):
|
|||
'''
|
||||
Test shadow.set_exipre
|
||||
'''
|
||||
self.addCleanup(self.run_function, 'user.delete', [self._test_user])
|
||||
self.run_function('user.add', [self._test_user])
|
||||
|
||||
# Correct Functionality
|
||||
|
@ -218,16 +221,19 @@ class ShadowModuleTest(ModuleCase):
|
|||
# saving shadow file
|
||||
if not os.access("/etc/shadow", os.R_OK | os.W_OK):
|
||||
self.skipTest('Could not save initial state of /etc/shadow')
|
||||
with salt.utils.fopen('/etc/shadow', 'r') as sFile:
|
||||
shadow = sFile.read()
|
||||
|
||||
def restore_shadow_file(contents):
|
||||
# restore shadow file
|
||||
with salt.utils.fopen('/etc/shadow', 'w') as wfh:
|
||||
wfh.write(contents)
|
||||
|
||||
with salt.utils.fopen('/etc/shadow', 'r') as rfh:
|
||||
contents = rfh.read()
|
||||
self.addCleanup(restore_shadow_file, contents)
|
||||
|
||||
# set root password
|
||||
self.assertTrue(self.run_function('shadow.set_password', ['root', self._password]))
|
||||
self.assertEqual(
|
||||
self.run_function('shadow.info', ['root'])['passwd'], self._password)
|
||||
self.assertEqual(self.run_function('shadow.info', ['root'])['passwd'], self._password)
|
||||
# delete root password
|
||||
self.assertTrue(self.run_function('shadow.del_password', ['root']))
|
||||
self.assertEqual(
|
||||
self.run_function('shadow.info', ['root'])['passwd'], '')
|
||||
# restore shadow file
|
||||
with salt.utils.fopen('/etc/shadow', 'w') as sFile:
|
||||
sFile.write(shadow)
|
||||
self.assertEqual(self.run_function('shadow.info', ['root'])['passwd'], '')
|
||||
|
|
Loading…
Add table
Reference in a new issue