mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Initial push towards active unit testing
After a great deal of thought, I feel that the only way to reliably run a test suite it to start a minion and master, and condition the data to reflect the literal returns (take out the transport overhead). This commit is the initial push towards this method of unit testing, these test will be able to acctually test every aspect of salt.
This commit is contained in:
parent
5cb36f320d
commit
07b4320a89
2 changed files with 52 additions and 4 deletions
|
@ -4,9 +4,19 @@ Discover all instances of unittest.TestCase in this directory.
|
|||
|
||||
The current working directory must be set to the build of the salt you want to test.
|
||||
'''
|
||||
from saltunittest import TestLoader, TextTestRunner
|
||||
|
||||
# Import python libs
|
||||
from os.path import dirname, abspath, relpath, splitext, normpath
|
||||
import sys, os, fnmatch
|
||||
import sys
|
||||
import os
|
||||
import fnmatch
|
||||
|
||||
# Import salt libs
|
||||
from saltunittest import TestLoader, TextTestRunner, TestCase
|
||||
import salt
|
||||
import salt.config
|
||||
import salt.master
|
||||
import salt.minion
|
||||
|
||||
TEST_DIR = dirname(normpath(abspath(__file__)))
|
||||
SALT_BUILD = os.getcwd()
|
||||
|
@ -35,5 +45,41 @@ def get_test_name(root, name):
|
|||
prefix = "%s." % rel.replace('/','.') if rel else ""
|
||||
return "".join((prefix, splitext(name)[0]))
|
||||
|
||||
|
||||
class DaemonCase(TestCase):
|
||||
'''
|
||||
Set up the master and minion daemons, and run related cases
|
||||
'''
|
||||
def setUp():
|
||||
'''
|
||||
Start a master and minion
|
||||
'''
|
||||
master_opts = salt.config.master_config('files/conf/master')
|
||||
minion_opts = salt.config.minion_config('files/conf/minion')
|
||||
salt.verify_env([os.path.join(self.opts['pki_dir'], 'minions'),
|
||||
os.path.join(self.opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(self.opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(self.opts['cachedir'], 'jobs'),
|
||||
os.path.dirname(self.opts['log_file']),
|
||||
self.opts['extension_modules'],
|
||||
self.opts['sock_dir'],
|
||||
])
|
||||
# Start the master
|
||||
master = salt.master.Master(master_opts)
|
||||
multiprocessing.Process(target=master.start).start()
|
||||
# Start the minion
|
||||
minion = salt.minion.Minion(minion_opts)
|
||||
multiprocessing.Process(target=minion.tune_in).start()
|
||||
|
||||
def tearDown():
|
||||
'''
|
||||
Kill the minion and master processes
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -13,10 +13,12 @@ import sys
|
|||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure
|
||||
TestCase, expectedFailure, \
|
||||
TestSuite
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure
|
||||
TestCase, expectedFailure, \
|
||||
TestSuite
|
||||
|
|
Loading…
Add table
Reference in a new issue