Merge lp:~johnsca/charms/trusty/nagios/pagerduty-test-race into lp:~brad-marshall/charms/trusty/nagios/add-extra-config-options

Proposed by Cory Johns
Status: Needs review
Proposed branch: lp:~johnsca/charms/trusty/nagios/pagerduty-test-race
Merge into: lp:~brad-marshall/charms/trusty/nagios/add-extra-config-options
Diff against target: 49 lines (+18/-8)
1 file modified
tests/24-pagerduty-test (+18/-8)
To merge this branch: bzr merge lp:~johnsca/charms/trusty/nagios/pagerduty-test-race
Reviewer Review Type Date Requested Status
Brad Marshall Pending
Review via email: mp+269401@code.launchpad.net

Description of the change

Work-around for race condition in pagerduty test

To post a comment you must log in.

Unmerged revisions

49. By Cory Johns

Work-around for race condition in pagerduty test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/24-pagerduty-test'
2--- tests/24-pagerduty-test 2015-07-22 06:19:11 +0000
3+++ tests/24-pagerduty-test 2015-08-27 15:57:56 +0000
4@@ -1,5 +1,6 @@
5 #!/usr/bin/python3
6
7+from time import sleep
8 import amulet
9 # import requests
10
11@@ -33,21 +34,30 @@
12
13
14 def test_pagerduty_path_exists():
15- pagerduty_path = nagios_unit.run('config-get pagerduty_path')
16- try:
17- pagerduty_file = nagios_unit.file(pagerduty_path[0])
18- except OSError:
19+ for i in range(3): # try three times before failing
20+ pagerduty_path = nagios_unit.run('config-get pagerduty_path')
21+ try:
22+ nagios_unit.file(pagerduty_path[0])
23+ break
24+ except OSError:
25+ sleep(5)
26+ else:
27 message = "Can't find pagerduty directory"
28 amulet.raise_status(amulet.FAIL, msg=message)
29
30
31 def test_pagerduty_config():
32- pagerduty_cfg = '/etc/nagios3/conf.d/pagerduty_nagios.cfg'
33- try:
34- pagerduty_cfg_file = nagios_unit.file(pagerduty_cfg)
35- except OSError:
36+ for i in range(3): # try three times before failing
37+ pagerduty_cfg = '/etc/nagios3/conf.d/pagerduty_nagios.cfg'
38+ try:
39+ nagios_unit.file(pagerduty_cfg)
40+ break
41+ except OSError:
42+ sleep(5)
43+ else:
44 message = "Can't find pagerduty config file"
45 amulet.raise_status(amulet.FAIL, msg=message)
46
47+
48 test_pagerduty_path_exists()
49 test_pagerduty_config()

Subscribers

People subscribed via source and target branches

to all changes: