Skip to content

Commit 1f21d78

Browse files
committed
Python3 version:
- some cleanings in the notifications tests
1 parent d3d6b39 commit 1f21d78

9 files changed

+346
-186
lines changed

alignak/objects/schedulingitem.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ def scatter_notification(self, notif, contacts, notifways, timeperiods, macromod
22442244
notification_contacts = self.contacts
22452245

22462246
recipients = []
2247-
recipients_names = []
2247+
recipients_names = set()
22482248
for contact_uuid in notification_contacts:
22492249
# We do not want to notify again a contact with notification interval == 0
22502250
# if has been already notified except if the item hard state changed!
@@ -2253,11 +2253,11 @@ def scatter_notification(self, notif, contacts, notifways, timeperiods, macromod
22532253
if notif.type == u'PROBLEM' and self.notification_interval == 0 \
22542254
and self.state_type == 'HARD' and self.last_state_type == self.state_type \
22552255
and self.state == self.last_state \
2256-
and contact.uuid in self.notified_contacts:
2256+
and contact_uuid in self.notified_contacts:
22572257
# Do not send notification
22582258
continue
22592259
recipients.append(contact_uuid)
2260-
recipients_names.append(contacts[contact_uuid].contact_name)
2260+
recipients_names.add(contacts[contact_uuid].contact_name)
22612261

22622262
for contact_uuid in recipients:
22632263
contact = contacts[contact_uuid]
@@ -2274,7 +2274,7 @@ def scatter_notification(self, notif, contacts, notifways, timeperiods, macromod
22742274
'ref': self.uuid,
22752275
'contact': contact.uuid,
22762276
'contact_name': contact.contact_name,
2277-
'recipients': recipients_names,
2277+
'recipients': ','.join(recipients_names),
22782278
't_to_go': notif.t_to_go,
22792279
'escalated': escalated,
22802280
'timeout': cls.notification_timeout,

test/cfg/run_realms/alignak.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ _dist_LOG=%(_dist)s
1010
config_name=Alignak configuration
1111

1212
#-- Username and group to run (defaults to current user)
13-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;user=alignak
14-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;group=alignak
13+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;user=alignak
14+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;group=alignak
1515
# Disabling security means allowing the daemons to run under root account
1616
# idontcareaboutsecurity=0
1717

test/cfg/run_realms_manage_sub_realms/alignak.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ _dist_LOG=%(_dist)s
1010
config_name=Alignak configuration
1111

1212
#-- Username and group to run (defaults to current user)
13-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;user=alignak
14-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;group=alignak
13+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;user=alignak
14+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;group=alignak
1515
# Disabling security means allowing the daemons to run under root account
1616
# idontcareaboutsecurity=0
1717

test/test_dateranges.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ def test_monthdatedaterange_start_end_time(self):
268268
with freeze_time(date_now, tz_offset=0):
269269
print("Date: %s" % date_now)
270270
ret = caldate.get_start_and_end_time()
271-
print("* %s / %s" % (ret[0], ret[1]))
271+
print("* %s / %s" % (type(ret[0]), type(data[date_now]['start'])))
272+
print("* %s / %s" % (int(ret[0]), int(ret[1])))
272273
assert data[date_now]['start'] == int(ret[0])
273274
assert data[date_now]['end'] == int(ret[1])
274275

test/test_dependencies.py

+45-15
Original file line numberDiff line numberDiff line change
@@ -569,22 +569,23 @@ def test_a_s_service_host_up(self):
569569
host.max_check_attempts = 1
570570
host.event_handler_enabled = False
571571

572-
svc = self._scheduler.services.find_srv_by_name_and_hostname(
573-
"test_host_00", "test_ok_0")
572+
svc = self._scheduler.services.find_srv_by_name_and_hostname("test_host_00", "test_ok_0")
574573
# To make tests quicker we make notifications send very quickly
575574
svc.notification_interval = 0.001
576575
svc.max_check_attempts = 1
577576
svc.checks_in_progress = []
578577
svc.event_handler_enabled = False
579578

580579
self.scheduler_loop(1, [[host, 0, 'UP'], [svc, 0, 'OK']])
581-
time.sleep(0.1)
580+
time.sleep(1.0)
581+
self.scheduler_loop(1)
582582
assert 0 == svc.current_notification_number, 'All OK no notifications'
583583
self.assert_actions_count(0)
584-
self.assert_checks_count(10)
584+
self.assert_checks_count(12)
585585

586586
self.scheduler_loop(1, [[svc, 2, 'CRITICAL']])
587-
time.sleep(0.1)
587+
time.sleep(1.0)
588+
self.scheduler_loop(1)
588589
assert "HARD" == svc.state_type
589590
assert "OK" == svc.state
590591
self.assert_actions_count(0)
@@ -599,18 +600,29 @@ def test_a_s_service_host_up(self):
599600
self.assert_checks_match(11, 'waitdep', 'status')
600601

601602
self.scheduler_loop(1, [[host, 0, 'UP']])
602-
time.sleep(0.1)
603+
time.sleep(1.0)
604+
self.scheduler_loop(1)
603605
assert "HARD" == svc.state_type
604606
assert "CRITICAL" == svc.state
605607
assert 1 == svc.current_notification_number, 'Critical HARD'
606608
self.assert_actions_count(2)
607609

608-
self.assert_actions_match(0, 'notifier.pl --hostname test_host_00 --servicedesc test_ok_0 --notificationtype PROBLEM --servicestate CRITICAL --serviceoutput CRITICAL', 'command')
609-
self.assert_actions_match(0, 'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=n/a, NOTIFICATIONAUTHORNAME=n/a, NOTIFICATIONAUTHORALIAS=n/a, NOTIFICATIONCOMMENT=n/a, HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1', 'command')
610+
self.assert_actions_match(0,
611+
'notifier.pl --hostname test_host_00 --servicedesc test_ok_0 '
612+
'--notificationtype PROBLEM --servicestate CRITICAL '
613+
'--serviceoutput CRITICAL',
614+
'command')
615+
self.assert_actions_match(0,
616+
'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact, '
617+
'NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=n/a, '
618+
'NOTIFICATIONAUTHORNAME=n/a, NOTIFICATIONAUTHORALIAS=n/a, '
619+
'NOTIFICATIONCOMMENT=n/a, HOSTNOTIFICATIONNUMBER=1, '
620+
'SERVICENOTIFICATIONNUMBER=1',
621+
'command')
610622

611623
self.assert_actions_match(1, 'VOID', 'command')
612624

613-
self.assert_checks_count(10)
625+
self.assert_checks_count(12)
614626

615627
def test_a_s_service_host_down(self):
616628
""" Test dependency (checks and notifications) between the service and the host (case 2)
@@ -981,7 +993,7 @@ def test_a_m_services(self):
981993

982994
print("====================== host UP ===================")
983995
self.scheduler_loop(1, [[host, 0, 'UP']])
984-
time.sleep(0.1)
996+
time.sleep(1.0)
985997
self.scheduler_loop(1)
986998
assert "UP" == host.state
987999
assert "CRITICAL" == svc1.state
@@ -993,11 +1005,29 @@ def test_a_m_services(self):
9931005
self.assert_actions_count(4)
9941006

9951007
# Both services have a notification
996-
self.assert_actions_match(-1, 'notifier.pl --hostname test_host_00 --servicedesc test_ok_0 --notificationtype PROBLEM --servicestate CRITICAL --serviceoutput CRITICAL', 'command')
997-
self.assert_actions_match(-1, 'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=n/a, NOTIFICATIONAUTHORNAME=n/a, NOTIFICATIONAUTHORALIAS=n/a, NOTIFICATIONCOMMENT=n/a, HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1', 'command')
998-
999-
self.assert_actions_match(-1, 'notifier.pl --hostname test_host_00 --servicedesc test_ok_1 --notificationtype PROBLEM --servicestate CRITICAL --serviceoutput CRITICAL', 'command')
1000-
self.assert_actions_match(-1, 'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=n/a, NOTIFICATIONAUTHORNAME=n/a, NOTIFICATIONAUTHORALIAS=n/a, NOTIFICATIONCOMMENT=n/a, HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1', 'command')
1008+
self.assert_actions_match(-1,
1009+
'notifier.pl --hostname test_host_00 --servicedesc test_ok_0 '
1010+
'--notificationtype PROBLEM --servicestate CRITICAL '
1011+
'--serviceoutput CRITICAL',
1012+
'command')
1013+
self.assert_actions_match(-1,
1014+
'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact',
1015+
'command')
1016+
self.assert_actions_match(-1,
1017+
'HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1',
1018+
'command')
1019+
1020+
self.assert_actions_match(-1,
1021+
'notifier.pl --hostname test_host_00 --servicedesc test_ok_1 '
1022+
'--notificationtype PROBLEM --servicestate CRITICAL '
1023+
'--serviceoutput CRITICAL',
1024+
'command')
1025+
self.assert_actions_match(-1,
1026+
'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact',
1027+
'command')
1028+
self.assert_actions_match(-1,
1029+
'HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1',
1030+
'command')
10011031

10021032
self.assert_actions_match(2, 'VOID', 'command')
10031033
self.assert_actions_match(3, 'VOID', 'command')

test/test_downtimes.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,22 @@ def test_schedule_fixed_svc_downtime(self):
178178
self.assert_actions_count(1)
179179
self.show_actions()
180180
# 1st notification for downtime start
181-
self.assert_actions_match(0, 'notifier.pl --hostname test_host_0 --servicedesc test_ok_0 --notificationtype DOWNTIMESTART --servicestate OK --serviceoutput OK', 'command')
182-
self.assert_actions_match(0, 'NOTIFICATIONTYPE=DOWNTIMESTART, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=downtime author, NOTIFICATIONAUTHORNAME=Not available, NOTIFICATIONAUTHORALIAS=Not available, NOTIFICATIONCOMMENT=downtime comment, HOSTNOTIFICATIONNUMBER=0, SERVICENOTIFICATIONNUMBER=0', 'command')
181+
self.assert_actions_match(0,
182+
'notifier.pl --hostname test_host_0 --servicedesc test_ok_0 '
183+
'--notificationtype DOWNTIMESTART --servicestate OK '
184+
'--serviceoutput OK',
185+
'command')
186+
self.assert_actions_match(0,
187+
'NOTIFICATIONTYPE=DOWNTIMESTART, '
188+
'NOTIFICATIONRECIPIENTS=test_contact, '
189+
'NOTIFICATIONISESCALATED=False, '
190+
'NOTIFICATIONAUTHOR=downtime author, '
191+
'NOTIFICATIONAUTHORNAME=Not available, '
192+
'NOTIFICATIONAUTHORALIAS=Not available, '
193+
'NOTIFICATIONCOMMENT=downtime comment, '
194+
'HOSTNOTIFICATIONNUMBER=0, '
195+
'SERVICENOTIFICATIONNUMBER=0',
196+
'command')
183197

184198
# A comment exist in our service
185199
assert 1 == len(svc.comments)
@@ -598,8 +612,22 @@ def test_schedule_fixed_host_downtime(self):
598612
self.assert_actions_count(1)
599613
# The downtime started
600614
self.show_actions()
601-
self.assert_actions_match(0, 'notifier.pl --hostname test_host_0 --notificationtype DOWNTIMESTART --hoststate UP --hostoutput UP', 'command')
602-
self.assert_actions_match(0, 'NOTIFICATIONTYPE=DOWNTIMESTART, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=downtime author, NOTIFICATIONAUTHORNAME=Not available, NOTIFICATIONAUTHORALIAS=Not available, NOTIFICATIONCOMMENT=downtime comment, HOSTNOTIFICATIONNUMBER=0, SERVICENOTIFICATIONNUMBER=0', 'command')
615+
self.assert_actions_match(0,
616+
'notifier.pl --hostname test_host_0 '
617+
'--notificationtype DOWNTIMESTART '
618+
'--hoststate UP --hostoutput UP',
619+
'command')
620+
self.assert_actions_match(0,
621+
'NOTIFICATIONTYPE=DOWNTIMESTART, '
622+
'NOTIFICATIONRECIPIENTS=test_contact, '
623+
'NOTIFICATIONISESCALATED=False, '
624+
'NOTIFICATIONAUTHOR=downtime author, '
625+
'NOTIFICATIONAUTHORNAME=Not available, '
626+
'NOTIFICATIONAUTHORALIAS=Not available, '
627+
'NOTIFICATIONCOMMENT=downtime comment, '
628+
'HOSTNOTIFICATIONNUMBER=0, '
629+
'SERVICENOTIFICATIONNUMBER=0',
630+
'command')
603631

604632
# A comment exists in our host
605633
assert 1 == len(host.comments)

test/test_escalations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def setUp(self):
7575
def test_wildcard_in_service_description(self):
7676
""" Test wildcards in service description """
7777
self_generated = [e for e in self._scheduler.pushed_conf.escalations
78-
if e.escalation_name.startswith('Generated-ServiceEscalation-')]
78+
if e.escalation_name.startswith('Generated-SE-')]
7979
host_services = self._scheduler.services.find_srvs_by_hostname("test_host_0_esc")
8080

8181
# Todo: confirm this assertion
@@ -101,7 +101,7 @@ def test_simple_escalation(self):
101101
host.act_depend_of = [] # ignore the router
102102

103103
svc = self._scheduler.services.find_srv_by_name_and_hostname("test_host_0_esc",
104-
"test_svc_esc")
104+
"test_svc_esc")
105105
svc.checks_in_progress = []
106106
svc.act_depend_of = [] # ignore the host
107107
svc.event_handler_enabled = False

test/test_external_commands.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -1378,20 +1378,38 @@ def test_host_downtimes_host_down(self):
13781378
excmd = '[%d] PROCESS_HOST_CHECK_RESULT;test_host_0;2;Host is dead' % time.time()
13791379
self._scheduler.run_external_commands([excmd])
13801380
self.external_command_loop()
1381+
# The notifications are created to be launched in the next second when they happen !
1382+
# Time warp 1 second
1383+
frozen_datetime.tick(delta=datetime.timedelta(seconds=1))
1384+
13811385
assert 'DOWN' == host.state
13821386
assert 'HARD' == host.state_type
13831387
assert 'Host is dead' == host.output
13841388

13851389
# Time warp 1 second
1386-
frozen_datetime.tick()
1390+
frozen_datetime.tick(delta=datetime.timedelta(seconds=1))
13871391

13881392
self.external_command_loop()
13891393
# Host problem only...
13901394
self.show_actions()
13911395
self.assert_actions_count(2)
13921396
# The host problem is notified
1393-
self.assert_actions_match(0, 'notifier.pl --hostname test_host_0 --notificationtype PROBLEM --hoststate DOWN --hostoutput Host is dead ', 'command')
1394-
self.assert_actions_match(0, 'NOTIFICATIONTYPE=PROBLEM, NOTIFICATIONRECIPIENTS=test_contact, NOTIFICATIONISESCALATED=False, NOTIFICATIONAUTHOR=n/a, NOTIFICATIONAUTHORNAME=n/a, NOTIFICATIONAUTHORALIAS=n/a, NOTIFICATIONCOMMENT=n/a, HOSTNOTIFICATIONNUMBER=1, SERVICENOTIFICATIONNUMBER=1', 'command')
1397+
self.assert_actions_match(0,
1398+
'notifier.pl --hostname test_host_0 '
1399+
'--notificationtype PROBLEM --hoststate DOWN '
1400+
'--hostoutput Host is dead ',
1401+
'command')
1402+
self.assert_actions_match(0,
1403+
'NOTIFICATIONTYPE=PROBLEM, '
1404+
'NOTIFICATIONRECIPIENTS=test_contact, '
1405+
'NOTIFICATIONISESCALATED=False, '
1406+
'NOTIFICATIONAUTHOR=n/a, '
1407+
'NOTIFICATIONAUTHORNAME=n/a, '
1408+
'NOTIFICATIONAUTHORALIAS=n/a, '
1409+
'NOTIFICATIONCOMMENT=n/a, '
1410+
'HOSTNOTIFICATIONNUMBER=1, '
1411+
'SERVICENOTIFICATIONNUMBER=1',
1412+
'command')
13951413

13961414
self.assert_actions_match(1, 'VOID', 'command')
13971415

0 commit comments

Comments
 (0)