Skip to content

Commit

Permalink
Move daemons run tests to a separate Travis test suite
Browse files Browse the repository at this point in the history
Let a daemons run test in the unit tests to improve code coverage
  • Loading branch information
mohierf committed May 26, 2017
1 parent 3128e52 commit 04da021
Show file tree
Hide file tree
Showing 321 changed files with 12,491 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -48,8 +48,8 @@ docs/tools/pages/
test/.coverage
test/.coverage.*

test/cfg/run_test_launch_daemons
test/cfg/run_test_launch_daemons_modules
test/run/
test_run/run/

# Pbr
pbr-*.egg/
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -7,6 +7,8 @@ python:

env:
- TEST_SUITE=unit
# Alignak daemons run tests
- TEST_SUITE=run
- TEST_SUITE=codingstandard
- TEST_SUITE=virtualenv

Expand All @@ -29,7 +31,7 @@ script:
# so to help eventual debug: know what exact versions are in use can be rather useful.
- pip freeze
# run test suite (wait no more than 30 minutes)
- travis_wait 30 ./.travis/$TEST_SUITE.sh
- travis_wait 60 ./.travis/$TEST_SUITE.sh

# specific call to launch coverage data into coveralls.io
after_success:
Expand Down
14 changes: 14 additions & 0 deletions .travis/run.sh
@@ -0,0 +1,14 @@
#!/bin/sh

set -ev

cd test_run
# Delete previously existing coverage results
coverage erase

# Run test suite with py.test running its coverage plugin
pytest -v --cov=alignak --cov-config .coveragerc test_*.py

# Report about coverage
coverage report -m
cd ..
6 changes: 3 additions & 3 deletions alignak/scheduler.py
Expand Up @@ -831,7 +831,7 @@ def get_to_run_checks(self, do_checks=False, do_actions=False,
logger.debug("%d actions for reactionner tags: %s", len(self.actions), reactionner_tags)
for act in self.actions.values():
is_master = (act.is_a == 'notification' and not act.contact)
logger.error("Action: %s (%s / %s)", act.uuid, act.reactionner_tag, act.module_type)
logger.debug("Action: %s (%s / %s)", act.uuid, act.reactionner_tag, act.module_type)

if not is_master:
# if do_action, call the reactionner,
Expand Down Expand Up @@ -1139,10 +1139,10 @@ def get_actions_from_passives_satellites(self):
results = unserialize(results, no_load=True)

nb_received = len(results)
logger.warning("Received %d passive results from %s", nb_received, poll['name'])
logger.debug("Received %d passive results from %s", nb_received, poll['name'])
self.nb_check_received += nb_received
for result in results:
logger.warning("-> result: %s", result)
logger.debug("-> result: %s", result)
result.set_type_passive()
self.waiting_results.put(result)
except HTTPEXCEPTIONS as exp: # pragma: no cover, simple protection
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 9 additions & 7 deletions test/test_launch_daemons_realms_and_checks.py
Expand Up @@ -60,7 +60,9 @@ def run_and_check_alignak_daemons(self, runtime=10):
self.print_header()

# Load and test the configuration
self.setup_with_file('cfg/alignak_full_run_realms/alignak.cfg')
cfg_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cfg/run_realms')

self.setup_with_file(cfg_folder + '/alignak.cfg')
assert self.conf_is_correct

self.procs = {}
Expand All @@ -79,13 +81,13 @@ def run_and_check_alignak_daemons(self, runtime=10):
os.remove('/tmp/%s.log' % daemon)
print("- removed /tmp/%s.log" % daemon)

shutil.copy('./cfg/alignak_full_run_realms/dummy_command.sh', '/tmp/dummy_command.sh')
shutil.copy(cfg_folder + '/dummy_command.sh', '/tmp/dummy_command.sh')

print("Launching the daemons...")
for daemon in daemons_list:
alignak_daemon = "../alignak/bin/alignak_%s.py" % daemon.split('-')[0]

args = [alignak_daemon, "-c", "./cfg/alignak_full_run_realms/daemons/%s.ini" % daemon]
args = [alignak_daemon, "-c", cfg_folder + "/daemons/%s.ini" % daemon]
self.procs[daemon] = \
subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("- %s launched (pid=%d)" % (daemon, self.procs[daemon].pid))
Expand All @@ -109,8 +111,8 @@ def run_and_check_alignak_daemons(self, runtime=10):

print("Launching arbiter...")
args = ["../alignak/bin/alignak_arbiter.py",
"-c", "cfg/alignak_full_run_realms/daemons/arbiter.ini",
"-a", "cfg/alignak_full_run_realms/alignak.cfg"]
"-c", cfg_folder + "/daemons/arbiter.ini",
"-a", cfg_folder + "/alignak.cfg"]
self.procs['arbiter'] = \
subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("- %s launched (pid=%d)" % ('arbiter', self.procs['arbiter'].pid))
Expand Down Expand Up @@ -143,7 +145,7 @@ def run_and_check_alignak_daemons(self, runtime=10):
with open('/tmp/%s.log' % daemon) as f:
for line in f:
if 'WARNING' in line or daemon_errors:
print(line)
print(line[:-1])
if daemon == 'arbiter' \
and 'Cannot call the additional groups setting with initgroups (Operation not permitted)' not in line \
and 'Cannot call the additional groups setting with setgroups' not in line:
Expand Down Expand Up @@ -181,7 +183,7 @@ def test_correct_checks_launch_and_result(self):

# Set an environment variable to activate the logging of checks execution
# With this the pollers/schedulers will raise WARNING logs about the checks execution
os.environ['TEST_LOG_ACTIONS'] = 'Yes'
os.environ['TEST_LOG_ACTIONS'] = 'WARNING'

# Run daemons for 2 minutes
self.run_and_check_alignak_daemons(120)
Expand Down
Empty file added test_run/__init__.py
Empty file.

0 comments on commit 04da021

Please sign in to comment.