mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Split out integration tests from pure unit tests.
Integration tests requiring a salt master and daemon were seperated from pure unit tests. For now both are run with runtest.py. In the future it could take arguments for which type of tests to run.
This commit is contained in:
parent
bc33a00ce7
commit
ab7ace6aa5
18 changed files with 116 additions and 105 deletions
94
tests/integration/__init__.py
Normal file
94
tests/integration/__init__.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
import multiprocessing
|
||||
import os
|
||||
|
||||
import salt
|
||||
import salt.config
|
||||
import salt.master
|
||||
import salt.minion
|
||||
|
||||
from saltunittest import TestCase
|
||||
|
||||
INTEGRATION_TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
||||
|
||||
TMP = os.path.join(INTEGRATION_TEST_DIR, 'tmp')
|
||||
FILES = os.path.join(INTEGRATION_TEST_DIR, 'files')
|
||||
|
||||
class TestDaemon(object):
|
||||
'''
|
||||
Set up the master and minion daemons, and run related cases
|
||||
'''
|
||||
|
||||
def __enter__(self):
|
||||
'''
|
||||
Start a master and minion
|
||||
'''
|
||||
self.master_opts = salt.config.master_config(os.path.join(INTEGRATION_TEST_DIR, 'files/conf/master'))
|
||||
self.minion_opts = salt.config.minion_config(os.path.join(INTEGRATION_TEST_DIR, 'files/conf/minion'))
|
||||
salt.verify_env([os.path.join(self.master_opts['pki_dir'], 'minions'),
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(self.master_opts['cachedir'], 'jobs'),
|
||||
os.path.dirname(self.master_opts['log_file']),
|
||||
self.minion_opts['extension_modules'],
|
||||
self.master_opts['sock_dir'],
|
||||
])
|
||||
|
||||
master = salt.master.Master(self.master_opts)
|
||||
self.master_process = multiprocessing.Process(target=master.start)
|
||||
self.master_process.start()
|
||||
|
||||
minion = salt.minion.Minion(self.minion_opts)
|
||||
self.minion_process = multiprocessing.Process(target=minion.tune_in)
|
||||
self.minion_process.start()
|
||||
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
'''
|
||||
Kill the minion and master processes
|
||||
'''
|
||||
self.minion_process.terminate()
|
||||
self.master_process.terminate()
|
||||
|
||||
|
||||
|
||||
class ModuleCase(TestCase):
|
||||
'''
|
||||
Execute a module function
|
||||
'''
|
||||
def setUp(self):
|
||||
'''
|
||||
Generate the tools to test a module
|
||||
'''
|
||||
self.client = salt.client.LocalClient(os.path.join(INTEGRATION_TEST_DIR, 'files/conf/master'))
|
||||
|
||||
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('minion', function, arg)
|
||||
return orig['minion']
|
||||
|
||||
def minion_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.minion_config(
|
||||
os.path.join(
|
||||
INTEGRATION_TEST_DIR,
|
||||
'files/conf/minion'
|
||||
)
|
||||
)
|
||||
|
||||
def master_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.minion_config(
|
||||
os.path.join(
|
||||
INTEGRATION_TEST_DIR,
|
||||
'files/conf/master'
|
||||
)
|
||||
)
|
|
@ -11,7 +11,7 @@ log_file: /tmp/salttest/minion
|
|||
|
||||
# module extension
|
||||
test.foo: baz
|
||||
hosts.file: tmp/hosts
|
||||
hosts.file: integration/tmp/hosts
|
||||
|
||||
# Grains addons
|
||||
grains:
|
|
@ -2,11 +2,9 @@
|
|||
Test the grains module
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
# Import Salt libs
|
||||
import saltunittest
|
||||
import integration
|
||||
|
||||
class TestModulesGrains(saltunittest.ModuleCase):
|
||||
class TestModulesGrains(integration.ModuleCase):
|
||||
'''
|
||||
Test the grains module
|
||||
'''
|
|
@ -6,11 +6,11 @@ import os
|
|||
import shutil
|
||||
|
||||
# Import Salt libs
|
||||
import saltunittest
|
||||
import integration
|
||||
|
||||
HFN = os.path.join(saltunittest.TMP, 'hosts')
|
||||
HFN = os.path.join(integration.TMP, 'hosts')
|
||||
|
||||
class HostsModuleTest(saltunittest.ModuleCase):
|
||||
class HostsModuleTest(integration.ModuleCase):
|
||||
'''
|
||||
Test the hosts module
|
||||
'''
|
||||
|
@ -18,7 +18,7 @@ class HostsModuleTest(saltunittest.ModuleCase):
|
|||
'''
|
||||
Clean out the hosts file
|
||||
'''
|
||||
shutil.copyfile(os.path.join(saltunittest.FILES, 'hosts'), HFN)
|
||||
shutil.copyfile(os.path.join(integration.FILES, 'hosts'), HFN)
|
||||
|
||||
def __clear_hosts(self):
|
||||
'''
|
|
@ -2,9 +2,9 @@
|
|||
import os
|
||||
|
||||
# Import salt libs
|
||||
import saltunittest
|
||||
import integration
|
||||
|
||||
class TestModuleTest(saltunittest.ModuleCase):
|
||||
class TestModuleTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the test module
|
||||
'''
|
||||
|
@ -40,7 +40,7 @@ class TestModuleTest(saltunittest.ModuleCase):
|
|||
import salt.config
|
||||
opts = salt.config.minion_config(
|
||||
os.path.join(
|
||||
saltunittest.TEST_DIR,
|
||||
integration.INTEGRATION_TEST_DIR,
|
||||
'files/conf/minion'
|
||||
)
|
||||
)
|
|
@ -6,15 +6,22 @@ Discover all instances of unittest.TestCase in this directory.
|
|||
import os
|
||||
# Import salt libs
|
||||
import saltunittest
|
||||
from integration import TestDaemon
|
||||
|
||||
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
||||
|
||||
def main():
|
||||
with saltunittest.TestDaemon():
|
||||
def run_integration_tests():
|
||||
with TestDaemon():
|
||||
loader = saltunittest.TestLoader()
|
||||
tests = loader.discover(os.path.join(TEST_DIR, 'modules'), '*.py')
|
||||
tests = loader.discover(os.path.join(TEST_DIR, 'integration', 'modules'), '*.py')
|
||||
saltunittest.TextTestRunner(verbosity=1).run(tests)
|
||||
|
||||
def run_unit_tests():
|
||||
loader = saltunittest.TestLoader()
|
||||
tests = loader.discover(os.path.join(TEST_DIR, 'unit', 'templates'), '*.py')
|
||||
saltunittest.TextTestRunner(verbosity=1).run(tests)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
run_integration_tests()
|
||||
run_unit_tests()
|
||||
|
|
|
@ -8,7 +8,6 @@ test from here
|
|||
"""
|
||||
|
||||
# Import python libs
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -25,97 +24,10 @@ else:
|
|||
from unittest import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure, \
|
||||
TestSuite
|
||||
|
||||
# Set up paths
|
||||
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
||||
SALT_LIBS = os.path.dirname(TEST_DIR)
|
||||
TMP = os.path.join(TEST_DIR, 'tmp')
|
||||
FILES = os.path.join(TEST_DIR, 'files')
|
||||
|
||||
sys.path.insert(0, TEST_DIR)
|
||||
sys.path.insert(0, SALT_LIBS)
|
||||
|
||||
# Import salt libs
|
||||
import salt
|
||||
import salt.config
|
||||
import salt.master
|
||||
import salt.minion
|
||||
|
||||
|
||||
class TestDaemon(object):
|
||||
'''
|
||||
Set up the master and minion daemons, and run related cases
|
||||
'''
|
||||
|
||||
def __enter__(self):
|
||||
'''
|
||||
Start a master and minion
|
||||
'''
|
||||
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'))
|
||||
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'],
|
||||
])
|
||||
|
||||
master = salt.master.Master(master_opts)
|
||||
self.master_process = multiprocessing.Process(target=master.start)
|
||||
self.master_process.start()
|
||||
|
||||
minion = salt.minion.Minion(minion_opts)
|
||||
self.minion_process = multiprocessing.Process(target=minion.tune_in)
|
||||
self.minion_process.start()
|
||||
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
'''
|
||||
Kill the minion and master processes
|
||||
'''
|
||||
self.minion_process.terminate()
|
||||
self.master_process.terminate()
|
||||
|
||||
|
||||
class ModuleCase(TestCase):
|
||||
'''
|
||||
Execute a module function
|
||||
'''
|
||||
def setUp(self):
|
||||
'''
|
||||
Generate the tools to test a module
|
||||
'''
|
||||
self.client = salt.client.LocalClient('files/conf/master')
|
||||
|
||||
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('minion', function, arg)
|
||||
return orig['minion']
|
||||
|
||||
def minion_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.minion_config(
|
||||
os.path.join(
|
||||
TEST_DIR,
|
||||
'files/conf/minion'
|
||||
)
|
||||
)
|
||||
|
||||
def master_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.minion_config(
|
||||
os.path.join(
|
||||
TEST_DIR,
|
||||
'files/conf/master'
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue