Merge lp:~cjohnston/uci-engine/wait into lp:uci-engine

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 475
Merged at revision: 475
Proposed branch: lp:~cjohnston/uci-engine/wait
Merge into: lp:uci-engine
Diff against target: 52 lines (+22/-8)
1 file modified
tests/deployers.py (+22/-8)
To merge this branch: bzr merge lp:~cjohnston/uci-engine/wait
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Andy Doan (community) Approve
Review via email: mp+219039@code.launchpad.net

Commit message

Fix issue where get_ip_and_port returns KeyError

Description of the change

For a while now on some of the amulet tests where we need to get the IP and port we have been seeing KeyError because open-ports was not found. There are two things going on here that contributed to the problem.

1) The way that juju works is that just because it says it's done deploying, that doesn't mean that it actually is done deploying. This was causing the tests to start running before things were actually ready.

2) The call to check the status was made during setUp, so, no matter how many times we may check, the status didn't change as it wasn't called again.

I moved the status check into the try so that it gets refreshed every time we need to check it. I also added a loop to try every 5 seconds for 40 seconds to get the IP and open-ports. This will allow juju time to actually finish what it's supposed to do.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

30 + except KeyError:
31 + tries += 1
32 + import time
33 + time.sleep(5)

can we move the import to the top of the module. Also - might be worth a log.info('open-ports not found waiting...')

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:474
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/612/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/612/rebuild

review: Approve (continuous-integration)
lp:~cjohnston/uci-engine/wait updated
475. By Chris Johnston

Changes per Andy's review

Revision history for this message
Andy Doan (doanac) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:475
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/616/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/616/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/deployers.py'
2--- tests/deployers.py 2014-05-07 10:01:50 +0000
3+++ tests/deployers.py 2014-05-12 14:18:01 +0000
4@@ -17,10 +17,14 @@
5 import os
6 import subprocess
7 import sys
8-
9+import time
10+import logging
11 import yaml
12 import amulet
13
14+logging.basicConfig(level=logging.INFO, format='%(msg)s')
15+log = logging.getLogger('integration-test-runner-deployers')
16+
17 HERE = os.path.abspath(os.path.dirname(__file__))
18 # We need access to ci_utils
19 sys.path.append(os.path.join(HERE, '..', 'ci-utils'))
20@@ -75,15 +79,25 @@
21 os.path.join(os.environ['JUJU_DEPLOYER_DIR'], self.deployer_cfg))
22 self.addCleanup(self.deployer.tearDown)
23 self.deployer.setUp(self.timeout)
24- self.status = amulet.waiter.status(self.deployer.deployment.juju_env)
25
26 def get_ip_and_port(self, service, unit=0):
27- units = self.status['services'][service]['units']
28- ip = units['%s/%d' % (service, unit)]['public-address']
29- # FIXME: Can fail with KeyError: 'open-ports'. Need to refresh status ?
30- # -- vila 2014-04-10
31- port, _ = units['%s/%d' % (service, unit)]['open-ports'][0].split('/')
32- return ip, int(port)
33+ tries = 0
34+ # this sometimes takes up to 30 seconds for the port to become
35+ # available Lets try for 40 seconds just incase.
36+ while tries < 8:
37+ try:
38+ status = amulet.waiter.status(
39+ self.deployer.deployment.juju_env)
40+ units = status['services'][service]['units']
41+ ip = units['%s/%d' % (service, unit)]['public-address']
42+ port, _ = units[
43+ '%s/%d' % (service, unit)]['open-ports'][0].split('/')
44+ return ip, int(port)
45+ break
46+ except KeyError:
47+ tries += 1
48+ log.warn("open-ports not found waiting...")
49+ time.sleep(5)
50
51 def assert_job_running(self, upstart_job, service, unit=0):
52 '''ensure the given upstart job is running on a unit'''

Subscribers

People subscribed via source and target branches