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
=== modified file 'tests/deployers.py'
--- tests/deployers.py 2014-05-07 10:01:50 +0000
+++ tests/deployers.py 2014-05-12 14:18:01 +0000
@@ -17,10 +17,14 @@
17import os17import os
18import subprocess18import subprocess
19import sys19import sys
2020import time
21import logging
21import yaml22import yaml
22import amulet23import amulet
2324
25logging.basicConfig(level=logging.INFO, format='%(msg)s')
26log = logging.getLogger('integration-test-runner-deployers')
27
24HERE = os.path.abspath(os.path.dirname(__file__))28HERE = os.path.abspath(os.path.dirname(__file__))
25# We need access to ci_utils29# We need access to ci_utils
26sys.path.append(os.path.join(HERE, '..', 'ci-utils'))30sys.path.append(os.path.join(HERE, '..', 'ci-utils'))
@@ -75,15 +79,25 @@
75 os.path.join(os.environ['JUJU_DEPLOYER_DIR'], self.deployer_cfg))79 os.path.join(os.environ['JUJU_DEPLOYER_DIR'], self.deployer_cfg))
76 self.addCleanup(self.deployer.tearDown)80 self.addCleanup(self.deployer.tearDown)
77 self.deployer.setUp(self.timeout)81 self.deployer.setUp(self.timeout)
78 self.status = amulet.waiter.status(self.deployer.deployment.juju_env)
7982
80 def get_ip_and_port(self, service, unit=0):83 def get_ip_and_port(self, service, unit=0):
81 units = self.status['services'][service]['units']84 tries = 0
82 ip = units['%s/%d' % (service, unit)]['public-address']85 # this sometimes takes up to 30 seconds for the port to become
83 # FIXME: Can fail with KeyError: 'open-ports'. Need to refresh status ?86 # available Lets try for 40 seconds just incase.
84 # -- vila 2014-04-1087 while tries < 8:
85 port, _ = units['%s/%d' % (service, unit)]['open-ports'][0].split('/')88 try:
86 return ip, int(port)89 status = amulet.waiter.status(
90 self.deployer.deployment.juju_env)
91 units = status['services'][service]['units']
92 ip = units['%s/%d' % (service, unit)]['public-address']
93 port, _ = units[
94 '%s/%d' % (service, unit)]['open-ports'][0].split('/')
95 return ip, int(port)
96 break
97 except KeyError:
98 tries += 1
99 log.warn("open-ports not found waiting...")
100 time.sleep(5)
87101
88 def assert_job_running(self, upstart_job, service, unit=0):102 def assert_job_running(self, upstart_job, service, unit=0):
89 '''ensure the given upstart job is running on a unit'''103 '''ensure the given upstart job is running on a unit'''

Subscribers

People subscribed via source and target branches