mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
The new unit tests work!
This commit is contained in:
parent
37704129af
commit
71c81ce2e8
6 changed files with 35 additions and 25 deletions
|
@ -47,7 +47,6 @@ def load_config(opts, path, env_var):
|
|||
Attempts to update ``opts`` dict by parsing either the file described by
|
||||
``path`` or the environment variable described by ``env_var`` as YAML.
|
||||
'''
|
||||
|
||||
if not path or not os.path.isfile(path):
|
||||
path = os.environ.get(env_var, path)
|
||||
# If the configuration file is missing, attempt to copy the template,
|
||||
|
|
|
@ -4,10 +4,11 @@ Classes used to set up the main components
|
|||
# Import python libs
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Set up paths
|
||||
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
||||
SALT_LIBS = os.path.join(os.path.dirname(TEST_DIR), 'salt')
|
||||
SALT_LIBS = os.path.dirname(TEST_DIR)
|
||||
|
||||
sys.path.insert(0, TEST_DIR)
|
||||
sys.path.insert(0, SALT_LIBS)
|
||||
|
@ -20,23 +21,24 @@ import salt.master
|
|||
import salt.minion
|
||||
|
||||
|
||||
class DaemonCase(TestCase):
|
||||
class DaemonCase(object):
|
||||
'''
|
||||
Set up the master and minion daemons, and run related cases
|
||||
'''
|
||||
def setUp(self):
|
||||
def __init__(self):
|
||||
'''
|
||||
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'],
|
||||
master_opts = salt.config.master_config(os.path.join(TEST_DIR, 'files/conf/master'))
|
||||
minion_opts = salt.config.minion_config(os.path.join(TEST_DIR, 'files/conf/minion'))
|
||||
print minion_opts
|
||||
salt.verify_env([os.path.join(master_opts['pki_dir'], 'minions'),
|
||||
os.path.join(master_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(master_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(master_opts['cachedir'], 'jobs'),
|
||||
os.path.dirname(master_opts['log_file']),
|
||||
minion_opts['extension_modules'],
|
||||
master_opts['sock_dir'],
|
||||
])
|
||||
# Start the master
|
||||
master = salt.master.Master(master_opts)
|
||||
|
@ -60,14 +62,14 @@ class ModuleCase(TestCase):
|
|||
'''
|
||||
Generate the tools to test a module
|
||||
'''
|
||||
self.client = salt.client.LocalClient(master_opts, 'files/conf/master')
|
||||
self.client = salt.client.LocalClient('files/conf/master')
|
||||
|
||||
def run_function(self, function):
|
||||
def run_function(self, function, arg=()):
|
||||
'''
|
||||
Run a single salt function and condition the return down to match the
|
||||
behavior of the raw function call
|
||||
'''
|
||||
orig = self.client.cmd(function)
|
||||
orig = self.client.cmd('minion', function, arg)
|
||||
return orig['minion']
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ publish_port: 94505
|
|||
ret_port: 94506
|
||||
worker_threads: 1
|
||||
root_dir: /tmp/salttest
|
||||
pidfile: /tmp/salttest/masterpid
|
||||
pki_dir: /tmp/salttest/pki
|
||||
cachedir: /tmp/salttest/cache
|
||||
timeout: 1
|
||||
|
|
|
@ -4,7 +4,7 @@ root_dir: /tmp/salttest
|
|||
pki_dir: /tmp/salttest/pki
|
||||
id: minion
|
||||
cachedir: /tmp/salttest/cachedir
|
||||
acceptance_wait_time = 1
|
||||
acceptance_wait_time: = 1
|
||||
open_mode: True
|
||||
log_file: /tmp/salttest/minion
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import daemon
|
||||
|
||||
class TestModuleTest(ModuleCase):
|
||||
class TestModuleTest(daemon.ModuleCase):
|
||||
'''
|
||||
Validate the test module
|
||||
'''
|
||||
|
|
|
@ -11,12 +11,6 @@ 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()
|
||||
|
@ -25,11 +19,20 @@ TEST_FILES = '*.py'
|
|||
sys.path.insert(0, TEST_DIR)
|
||||
sys.path.insert(0, SALT_BUILD)
|
||||
|
||||
# Import salt libs
|
||||
from saltunittest import TestLoader, TextTestRunner, TestCase
|
||||
import daemon
|
||||
import salt
|
||||
import salt.config
|
||||
import salt.master
|
||||
import salt.minion
|
||||
|
||||
def main():
|
||||
names = find_tests()
|
||||
tests = TestLoader().loadTestsFromNames(names)
|
||||
TextTestRunner(verbosity=1).run(tests)
|
||||
|
||||
|
||||
def find_tests():
|
||||
names = []
|
||||
for root, _, files in os.walk(TEST_DIR):
|
||||
|
@ -39,6 +42,8 @@ def find_tests():
|
|||
module = get_test_name(root, name)
|
||||
if module: names.append(module)
|
||||
return names
|
||||
|
||||
|
||||
def get_test_name(root, name):
|
||||
if name.startswith("_"): return None
|
||||
rel = relpath(root, TEST_DIR).lstrip(".")
|
||||
|
@ -47,4 +52,7 @@ def get_test_name(root, name):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
daemon.DaemonCase()
|
||||
loader = TestLoader()
|
||||
tests = loader.discover(os.path.join(TEST_DIR, 'modules'))
|
||||
TextTestRunner(verbosity=1).run(tests)
|
||||
|
|
Loading…
Add table
Reference in a new issue