Skip to content

Commit

Permalink
Some more tests, add a new scheduler get_host endpoint - 2 - try to i…
Browse files Browse the repository at this point in the history
…mprove Python 2.6 tests
  • Loading branch information
mohierf committed Mar 23, 2018
1 parent a25eb86 commit 58c6bc9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Presentation of the Alignak project
:alt: Development code tests coverage

.. image:: https://readthedocs.org/projects/alignak-doc/badge/?version=latest
:target: http://alignak-doc.readthedocs.org/en/latest/?badge=latest
:target: http://alignak-doc.readthedocs.org/en/latest
:alt: Lastest documentation Status

.. image:: https://readthedocs.org/projects/alignak-doc/badge/?version=develop
:target: http://alignak-doc.readthedocs.org/en/update/?badge=develop
:target: http://alignak-doc.readthedocs.org/en/develop
:alt: Development branch documentation Status

.. image:: https://img.shields.io/badge/IRC-%23alignak-1e72ff.svg?style=flat
Expand Down
23 changes: 22 additions & 1 deletion alignak/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ def wait_for_initial_conf(self, timeout=1.0):
"""Wait initial configuration from the arbiter.
Basically sleep 1.0 and check if new_conf is here
:param timeout: timeout to wait from socket read
:param timeout: timeout to wait
:type timeout: int
:return: None
"""
Expand All @@ -1838,6 +1838,27 @@ def wait_for_initial_conf(self, timeout=1.0):
else:
logger.info("Interrupted before getting the initial configuration")

def wait_for_new_conf(self, timeout=1.0):
"""Wait for a new configuration from the arbiter.
Basically the same as waiting for an initial configuration (wait_for_initial_conf)
:param timeout: timeout to wait
:type timeout: int
:return: None
"""
logger.info("Waiting for a new configuration")
# Arbiter do not already set our have_conf param
_ts = time.time()
while not self.new_conf and not self.interrupted:
# Make a pause and check if the system time changed
_, _ = self.make_a_pause(timeout, check_time_change=True)

if not self.interrupted:
logger.info("Got the new configuration, waited for: %.2f", time.time() - _ts)
statsmgr.timer('new-configuration', time.time() - _ts)
else:
logger.info("Interrupted before getting the new configuration")

def watch_for_new_conf(self, timeout=0):
"""Check if a new configuration was sent to the daemon
Expand Down
9 changes: 5 additions & 4 deletions alignak/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@

from alignak.brok import Brok

if sys.version_info < (2, 7):
from alignak.misc.dictconfig import dictConfig as logger_dictConfig
else:
from logging.config import dictConfig as logger_dictConfig
from alignak.misc.dictconfig import dictConfig as logger_dictConfig
# if sys.version_info < (2, 7):
# from alignak.misc.dictconfig import dictConfig as logger_dictConfig
# else:
# from logging.config import dictConfig as logger_dictConfig

# Default values for root logger
ALIGNAK_LOGGER_NAME = 'alignak'
Expand Down
17 changes: 10 additions & 7 deletions test/alignak_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def setUp(self):
self.logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
self.logger_.info("Test: %s", self.id())

# Only for Python < 2.7, DEBUG logs ...
print("OS version: %s" % os.sys.version_info)
if os.sys.version_info < (2, 7):
print("-> add a logger handler for Python 2.6")
# Add collector for test purpose.
collector_h = CollectorHandler()
collector_h.setFormatter(Formatter('[%(created)i] %(levelname)s: [%(name)s] %(message)s'))
collector_h.setLevel(logging.DEBUG)
logger_.addHandler(collector_h)

# To make sure that no running daemon exist
print("Checking Alignak running daemons...")
for daemon in ['broker', 'poller', 'reactionner', 'receiver', 'scheduler', 'arbiter']:
Expand Down Expand Up @@ -165,13 +175,6 @@ def set_debug_log(self):
handler.setLevel(logging.DEBUG)
print("Unit tests handler is set at debug!")
break
# Only for Python < 2.7, DEBUG logs ...
if os.sys.version_info < (2, 7):
# Add collector for test purpose.
collector_h = CollectorHandler()
collector_h.setFormatter(Formatter('[%(created)i] %(levelname)s: [%(name)s] %(message)s'))
collector_h.setLevel(logging.DEBUG)
logger_.addHandler(collector_h)

def _files_update(self, files, replacements):
"""Update files content with the defined replacements
Expand Down

0 comments on commit 58c6bc9

Please sign in to comment.