Skip to content

Commit

Permalink
AlignakTest: clean broks and logs. @ddurieux: have a look please
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Sep 13, 2016
1 parent 327b4ce commit 7612cfd
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions test/alignak_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def setup_with_file(self, configuration_file):
:type configuration_file: str
:return: None
"""
self.broks = {}
self.schedulers = []
self.arbiter = None

self.arbiter = Arbiter([configuration_file], False, False, False, False,
Expand All @@ -159,7 +161,6 @@ def setup_with_file(self, configuration_file):
self.arbiter.dispatcher = Dispatcher(self.arbiter.conf, self.arbiter.myself)
self.arbiter.dispatcher.prepare_dispatch()

self.schedulers = []
for scheduler in self.arbiter.dispatcher.schedulers:
sched = Alignak([], False, False, True, '/tmp/scheduler.log')
# logger.setLevel('DEBUG')
Expand All @@ -174,7 +175,7 @@ def add(self, b):
self.broks[b.uuid] = b
return
if isinstance(b, ExternalCommand):
self.sched.run_external_command(b.cmd_line)
self.schedulers[0].run_external_command(b.cmd_line)

def fake_check(self, ref, exit_status, output="OK"):
# print "fake", ref
Expand Down Expand Up @@ -267,10 +268,10 @@ def worker_loop(self, verbose=True):

def show_logs(self):
print "--- logs <<<----------------------------------"
if hasattr(self.scheduler, "sched"):
broks = self.scheduler.sched.broks
else:
broks = self.broks
broks = self.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks

for brok in sorted(broks.values(), lambda x, y: cmp(x.uuid, y.uuid)):
if brok.type == 'log':
brok.prepare()
Expand Down Expand Up @@ -308,8 +309,8 @@ def show_and_clear_actions(self):
self.clear_actions()

def count_logs(self):
if hasattr(self.scheduler, "sched"):
broks = self.scheduler.sched.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks
else:
broks = self.broks
return len([b for b in broks.values() if b.type == 'log'])
Expand All @@ -322,10 +323,10 @@ def count_actions(self):
return len(actions.values())

def clear_logs(self):
if hasattr(self.scheduler, "sched"):
broks = self.scheduler.sched.broks
else:
broks = self.broks
broks = self.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks

id_to_del = []
for b in broks.values():
if b.type == 'log':
Expand Down Expand Up @@ -394,7 +395,10 @@ def assert_log_match(self, index, pattern):
"""
regex = re.compile(pattern)
log_num = 1
broks = sorted(self.schedulers[0].sched.broks.values(), key=lambda x: x.creation_time)
broks = self.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks

found = False
for brok in broks:
if brok.type == 'log':
Expand Down Expand Up @@ -457,8 +461,10 @@ def assert_checks_match(self, index, pattern, field):

def _any_log_match(self, pattern, assert_not):
regex = re.compile(pattern)
broks = getattr(self, 'sched', self).broks
broks = sorted(broks.values(), lambda x, y: cmp(x.uuid, y.uuid))
broks = self.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks

for brok in broks:
if brok.type == 'log':
brok.prepare()
Expand All @@ -480,7 +486,11 @@ def assert_no_log_match(self, pattern):
def get_log_match(self, pattern):
regex = re.compile(pattern)
res = []
for brok in sorted(self.sched.broks.values(), lambda x, y: cmp(x.uuid, y.uuid)):
broks = self.broks
if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"):
broks = self.schedulers[0].sched.broks

for brok in broks:
if brok.type == 'log':
if re.search(regex, brok.data['log']):
res.append(brok.data['log'])
Expand Down

0 comments on commit 7612cfd

Please sign in to comment.