mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Support adding files to the testing prod state env.
This commit is contained in:
parent
9a22d3053e
commit
962f8d4149
@ -55,10 +55,11 @@ import yaml
|
||||
SYS_TMP_DIR = os.environ.get('TMPDIR', tempfile.gettempdir())
|
||||
TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir')
|
||||
FILES = os.path.join(INTEGRATION_TEST_DIR, 'files')
|
||||
PYEXEC = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
|
||||
PYEXEC = 'python{0}.{1}'.format(*sys.version_info)
|
||||
MOCKBIN = os.path.join(INTEGRATION_TEST_DIR, 'mockbin')
|
||||
SCRIPT_DIR = os.path.join(CODE_DIR, 'scripts')
|
||||
TMP_STATE_TREE = os.path.join(SYS_TMP_DIR, 'salt-temp-state-tree')
|
||||
TMP_PRODENV_STATE_TREE = os.path.join(SYS_TMP_DIR, 'salt-temp-prodenv-state-tree')
|
||||
TMP_CONF_DIR = os.path.join(TMP, 'config')
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -168,7 +169,8 @@ class TestDaemon(object):
|
||||
],
|
||||
# Alternate root to test __env__ choices
|
||||
'prod': [
|
||||
os.path.join(FILES, 'file', 'prod')
|
||||
os.path.join(FILES, 'file', 'prod'),
|
||||
TMP_PRODENV_STATE_TREE
|
||||
]
|
||||
}
|
||||
self.master_opts['ext_pillar'].append(
|
||||
@ -179,7 +181,11 @@ class TestDaemon(object):
|
||||
)
|
||||
)}
|
||||
)
|
||||
self.master_opts['extension_modules'] = os.path.join(INTEGRATION_TEST_DIR, 'files', 'extension_modules')
|
||||
|
||||
self.master_opts['extension_modules'] = os.path.join(
|
||||
INTEGRATION_TEST_DIR, 'files', 'extension_modules'
|
||||
)
|
||||
|
||||
# clean up the old files
|
||||
self._clean()
|
||||
|
||||
@ -210,7 +216,8 @@ class TestDaemon(object):
|
||||
self.sub_minion_opts['sock_dir'],
|
||||
self.minion_opts['sock_dir'],
|
||||
TMP_STATE_TREE,
|
||||
TMP
|
||||
TMP_PRODENV_STATE_TREE,
|
||||
TMP,
|
||||
],
|
||||
running_tests_user)
|
||||
|
||||
@ -414,8 +421,10 @@ class TestDaemon(object):
|
||||
shutil.rmtree(self.master_opts['root_dir'])
|
||||
if os.path.isdir(self.smaster_opts['root_dir']):
|
||||
shutil.rmtree(self.smaster_opts['root_dir'])
|
||||
if os.path.isdir(TMP):
|
||||
shutil.rmtree(TMP)
|
||||
|
||||
for dirname in (TMP, TMP_STATE_TREE, TMP_PRODENV_STATE_TREE):
|
||||
if os.path.isdir(dirname):
|
||||
shutil.rmtree(dirname)
|
||||
|
||||
def wait_for_jid(self, targets, jid, timeout=120):
|
||||
time.sleep(1) # Allow some time for minions to accept jobs
|
||||
|
@ -26,6 +26,7 @@ ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
|
||||
class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
@ -192,7 +193,7 @@ class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
'Failed to create testcase virtual environment: {0}'.format(
|
||||
ret
|
||||
venv_create
|
||||
)
|
||||
)
|
||||
|
||||
@ -228,8 +229,8 @@ class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
req_filename = os.path.join(
|
||||
integration.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
||||
)
|
||||
with open(req_filename, 'wb') as f:
|
||||
f.write('pep8')
|
||||
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
||||
reqf.write('pep8')
|
||||
|
||||
try:
|
||||
ret = self.run_state(
|
||||
@ -295,8 +296,8 @@ class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
req_filename = os.path.join(
|
||||
integration.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
||||
)
|
||||
with open(req_filename, 'wb') as f:
|
||||
f.write('pep8')
|
||||
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
||||
reqf.write('pep8')
|
||||
|
||||
try:
|
||||
ret = self.run_state(
|
||||
@ -381,6 +382,60 @@ class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
|
||||
def test_pip_installed_specific_env(self):
|
||||
# Create the testing virtualenv
|
||||
venv_dir = os.path.join(
|
||||
integration.TMP, 'pip-installed-specific-env'
|
||||
)
|
||||
|
||||
# Let's write a requirements file
|
||||
requirements_file = os.path.join(
|
||||
integration.TMP_PRODENV_STATE_TREE, 'prod-env-requirements.txt'
|
||||
)
|
||||
with salt.utils.fopen(requirements_file, 'wb') as reqf:
|
||||
reqf.write('pep8\n')
|
||||
|
||||
try:
|
||||
ret = self.run_function('virtualenv.create', [venv_dir])
|
||||
|
||||
# The requirements file should not be found the base environment
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='', bin_env=venv_dir,
|
||||
requirements='salt://prod-env-requirements.txt'
|
||||
)
|
||||
self.assertSaltFalseReturn(ret)
|
||||
self.assertInSaltComment(
|
||||
"'salt://prod-env-requirements.txt' not found", ret
|
||||
)
|
||||
|
||||
# The requirements file must be found in the prod environment
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='', bin_env=venv_dir, __env__='prod',
|
||||
requirements='salt://prod-env-requirements.txt'
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertInSaltComment(
|
||||
'Successfully processed requirements file '
|
||||
'salt://prod-env-requirements.txt', ret
|
||||
)
|
||||
|
||||
# We're using the base environment but we're passing the prod
|
||||
# environment as an url arg to salt://
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='', bin_env=venv_dir,
|
||||
requirements='salt://prod-env-requirements.txt?env=prod'
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertInSaltComment(
|
||||
'Successfully processed requirements file '
|
||||
'salt://prod-env-requirements.txt', ret
|
||||
)
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
if os.path.isfile(requirements_file):
|
||||
os.unlink(requirements_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
Loading…
Reference in New Issue
Block a user