mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
Add "mockbin" directory and a fake "su" wrapper for tests
While performing integration tests, the "mockbin" directory is inserted in the beginning of the $PATH environment variable. This effectively means that every file placed in this directory will be executed instead of real one from the system, which opens up the opportunity to write more complex integration tests. At the time the only wrapper for "su" command (used in "cmdmod") is placed there.
This commit is contained in:
parent
f1389a1cad
commit
bc1650a085
@ -33,6 +33,7 @@ PYEXEC = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
|
||||
|
||||
TMP = os.path.join(INTEGRATION_TEST_DIR, 'tmp')
|
||||
FILES = os.path.join(INTEGRATION_TEST_DIR, 'files')
|
||||
MOCKBIN = os.path.join(INTEGRATION_TEST_DIR, 'mockbin')
|
||||
|
||||
|
||||
def run_tests(TestCase):
|
||||
@ -148,6 +149,8 @@ class TestDaemon(object):
|
||||
self.minion_opts['sock_dir'],
|
||||
],
|
||||
pwd.getpwuid(os.getuid())[0])
|
||||
# Set up PATH to mockbin
|
||||
self._enter_mockbin()
|
||||
|
||||
master = salt.master.Master(self.master_opts)
|
||||
self.master_process = multiprocessing.Process(target=master.start)
|
||||
@ -182,8 +185,25 @@ class TestDaemon(object):
|
||||
self.master_process.terminate()
|
||||
self.syndic_process.terminate()
|
||||
self.smaster_process.terminate()
|
||||
self._exit_mockbin()
|
||||
self._clean()
|
||||
|
||||
def _enter_mockbin(self):
|
||||
path = os.environ.get('PATH', '')
|
||||
path_items = path.split(os.pathsep)
|
||||
if MOCKBIN not in path_items:
|
||||
path_items.insert(0, MOCKBIN)
|
||||
os.environ['PATH'] = os.pathsep.join(path_items)
|
||||
|
||||
def _exit_mockbin(self):
|
||||
path = os.environ.get('PATH', '')
|
||||
path_items = path.split(os.pathsep)
|
||||
try:
|
||||
path_items.remove(MOCKBIN)
|
||||
except ValueError:
|
||||
pass
|
||||
os.environ['PATH'] = os.pathsep.join(path_items)
|
||||
|
||||
def _clean(self):
|
||||
'''
|
||||
Clean out the tmp files
|
||||
|
12
tests/integration/mockbin/su
Executable file
12
tests/integration/mockbin/su
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# "Fake" su command
|
||||
#
|
||||
# Just executes the command without changing effective uid. Used in integration
|
||||
# tests.
|
||||
while true; do
|
||||
shift
|
||||
test "x$1" == "x-c" && break
|
||||
test "x$1" == "x" && break
|
||||
done
|
||||
shift
|
||||
exec /bin/bash -c "$@"
|
Loading…
Reference in New Issue
Block a user