Merge lp:~abentley/juju-ci-tools/hammer-time-juju-2 into lp:juju-ci-tools

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 1992
Proposed branch: lp:~abentley/juju-ci-tools/hammer-time-juju-2
Merge into: lp:juju-ci-tools
Diff against target: 144 lines (+67/-3)
5 files modified
hammer-time-job.bash (+6/-0)
jujupy/client.py (+13/-2)
jujupy/tests/test_client.py (+9/-0)
tests/test_deploy_stack.py (+0/-1)
wait_for.py (+39/-0)
To merge this branch: bzr merge lp:~abentley/juju-ci-tools/hammer-time-juju-2
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+322298@code.launchpad.net

Commit message

Add version check to hammer-time job.

Description of the change

This branch adds a version check to the hammer time job.

Hammer time only works with juju 2.0. This should prevent further instances of
"Hammertime called switch with juju 1.25" http://reports.vapour.ws/releases/issue/58d3c5a2749a56711208a31b

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hammer-time-job.bash'
2--- hammer-time-job.bash 2017-04-05 14:51:17 +0000
3+++ hammer-time-job.bash 2017-04-10 15:17:31 +0000
4@@ -18,11 +18,17 @@
5 export ARTIFACTS=$WORKSPACE/artifacts
6 export MODEL_NAME=$JOB_NAME
7 export DATA_DIR=$JUJU_HOME/jes-homes/$MODEL_NAME
8+export S3_CONFIG=$JUJU_HOME/juju-qa.s3cfg
9 export PLAN=$ARTIFACTS/plan.yaml
10 export HAMMER_DIR=$(dirname $(dirname $HAMMER_TIME))
11 : ${TIMEOUT=30m}
12 set -x
13 s3ci.py get-summary $revision_build $base_config
14+source $(s3ci.py get --config $S3_CONFIG $REVISION_BUILD build-revision buildvars.bash)
15+if [[ $VERSION =~ ^1\..*$ ]]; then
16+ echo "$VERSION is not supported for hammer-time."
17+ exit 0
18+fi
19 jujuci.py -v setup-workspace $WORKSPACE
20 if [ -n "${replay_build_number-}" ]; then
21 export ARTIFACT_URL=http://juju-ci.vapour.ws/job/$JOB_NAME/\
22
23=== modified file 'jujupy/client.py'
24--- jujupy/client.py 2017-04-07 20:20:17 +0000
25+++ jujupy/client.py 2017-04-10 15:17:31 +0000
26@@ -138,6 +138,10 @@
27 """Raised when the provided auth was not accepted."""
28
29
30+class NoActiveModel(Exception):
31+ """Raised when no active model could be found."""
32+
33+
34 def get_timeout_prefix(duration, timeout_path=None):
35 """Return extra arguments to run a command with a timeout."""
36 if timeout_path is None:
37@@ -1286,8 +1290,14 @@
38
39 def get_active_model(self, juju_data_dir):
40 """Determine the active model in a juju data dir."""
41- current = self.get_juju_output(
42- 'switch', (), set(), juju_data_dir, model=None).decode('ascii')
43+ try:
44+ current = self.get_juju_output(
45+ 'switch', (), set(), juju_data_dir, model=None).decode('ascii')
46+ except subprocess.CalledProcessError as e:
47+ if b'no currently specified model' not in e.stderr:
48+ raise
49+ raise NoActiveModel(
50+ 'No active model for {}'.format(juju_data_dir))
51 controller_name, user_model = current.split(':', 1)
52 user_name, model_name = user_model.split('/', 1)
53 return controller_name, user_name, model_name.rstrip('\n')
54@@ -1452,6 +1462,7 @@
55
56
57 class WaitAgentsStarted(BaseCondition):
58+ """Wait until all agents are idle or started."""
59
60 def __init__(self, timeout=1200):
61 super(WaitAgentsStarted, self).__init__(timeout)
62
63=== modified file 'jujupy/tests/test_client.py'
64--- jujupy/tests/test_client.py 2017-04-07 20:20:17 +0000
65+++ jujupy/tests/test_client.py 2017-04-10 15:17:31 +0000
66@@ -70,6 +70,7 @@
67 make_safe_config,
68 ModelClient,
69 NameNotAccepted,
70+ NoActiveModel,
71 NoopCondition,
72 NoProvider,
73 parse_new_state_server_from_error,
74@@ -321,6 +322,14 @@
75 result = backend.get_active_model('/foo/bar')
76 self.assertEqual(('ctrl1', 'user1', 'model1'), result)
77
78+ def test_get_active_model_none(self):
79+ backend = Juju2Backend('/bin/path', '2.0', set(), debug=False,
80+ soft_deadline=None)
81+ with patch('subprocess.Popen', autospec=True, return_value=FakePopen(
82+ '', 'ERROR no currently specified model', 1)):
83+ with self.assertRaises(NoActiveModel):
84+ backend.get_active_model('/foo/bar')
85+
86
87 def backend_call(client, cmd, args, model=None, check=True, timeout=None,
88 extra_env=None):
89
90=== modified file 'tests/test_deploy_stack.py'
91--- tests/test_deploy_stack.py 2017-04-05 23:07:51 +0000
92+++ tests/test_deploy_stack.py 2017-04-10 15:17:31 +0000
93@@ -71,7 +71,6 @@
94 )
95
96 from jujupy.client import (
97- NoopCondition,
98 CommandTime,
99 )
100 from jujupy.configuration import (
101
102=== added file 'wait_for.py'
103--- wait_for.py 1970-01-01 00:00:00 +0000
104+++ wait_for.py 2017-04-10 15:17:31 +0000
105@@ -0,0 +1,39 @@
106+#!/usr/bin/env python
107+
108+from __future__ import print_function
109+
110+
111+from argparse import ArgumentParser
112+import sys
113+
114+from jujupy import (
115+ client_for_existing,
116+ get_juju_data,
117+ )
118+from jujupy.client import (
119+ NoActiveModel,
120+ WaitAgentsStarted,
121+ )
122+
123+
124+def main():
125+ parser = ArgumentParser()
126+ subparsers = parser.add_subparsers(dest='cmd')
127+ started_parser = subparsers.add_parser(
128+ 'agents-started', description=WaitAgentsStarted.__doc__,
129+ )
130+ started_parser.set_defaults(factory=WaitAgentsStarted)
131+ started_parser.add_argument('--timeout', type=int)
132+ args = parser.parse_args()
133+ try:
134+ client = client_for_existing(None, get_juju_data())
135+ except NoActiveModel as e:
136+ print(e, file=sys.stderr)
137+ sys.exit(1)
138+ kwargs = dict((k, v) for k, v in vars(args).items()
139+ if k not in ('factory', 'cmd'))
140+ client.wait_for(args.factory(**kwargs))
141+
142+
143+if __name__ == '__main__':
144+ main()

Subscribers

People subscribed via source and target branches