Merge lp:~abentley/juju-ci-tools/industrial-agent-stream into lp:juju-ci-tools

Proposed by Aaron Bentley
Status: Needs review
Proposed branch: lp:~abentley/juju-ci-tools/industrial-agent-stream
Merge into: lp:juju-ci-tools
Diff against target: 476 lines (+109/-50)
3 files modified
industrial_test.py (+26/-14)
run-reliability-test.bash (+4/-2)
tests/test_industrial_test.py (+79/-34)
To merge this branch: bzr merge lp:~abentley/juju-ci-tools/industrial-agent-stream
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+282668@code.launchpad.net

Commit message

Add --agent-stream to industrial_test.

Description of the change

Add --agent-stream support to industrial_test.

This allows running industrial tests of arbitrary builds without the candidate urls.

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

thank you.

review: Approve (code)

Unmerged revisions

1244. By Aaron Bentley

Fix lint.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'industrial_test.py'
2--- industrial_test.py 2016-01-13 21:31:55 +0000
3+++ industrial_test.py 2016-01-14 21:01:47 +0000
4@@ -72,6 +72,7 @@
5 :ivar new_juju_path: Path to the non-system juju.
6 :ivar stages: A list of StageAttempts.
7 :ivar attempt_count: The number of attempts needed for each stage.
8+ :ivar agent_stream: The agent stream to use for testing.
9 """
10
11 @classmethod
12@@ -80,7 +81,8 @@
13 stages = cls.get_stages(suite, config)
14 return cls(args.env, args.new_juju_path,
15 stages, args.log_dir, args.attempts, args.attempts * 2,
16- args.new_agent_url, args.debug, args.old_stable)
17+ args.new_agent_url, args.debug, args.old_stable,
18+ args.agent_stream)
19
20 @staticmethod
21 def get_stages(suite, config):
22@@ -88,7 +90,7 @@
23
24 def __init__(self, env, new_juju_path, stages, log_dir, attempt_count=2,
25 max_attempts=1, new_agent_url=None, debug=False,
26- really_old_path=None):
27+ really_old_path=None, agent_stream=None):
28 self.env = env
29 self.really_old_path = really_old_path
30 self.new_juju_path = new_juju_path
31@@ -98,6 +100,7 @@
32 self.max_attempts = max_attempts
33 self.debug = debug
34 self.log_parent_dir = log_dir
35+ self.agent_stream = agent_stream
36
37 def make_results(self):
38 """Return a results list for use in run_tests."""
39@@ -150,7 +153,8 @@
40 paths = [self.really_old_path, stable_path, self.new_juju_path]
41 upgrade_sequence = [p for p in paths if p is not None]
42 stage_attempts = [self.stages.factory(upgrade_sequence,
43- self.log_parent_dir)]
44+ self.log_parent_dir,
45+ self.agent_stream)]
46 return IndustrialTest.from_args(self.env, self.new_juju_path,
47 stage_attempts, self.new_agent_url,
48 self.debug)
49@@ -273,7 +277,7 @@
50 """
51
52 @classmethod
53- def factory(cls, upgrade_sequence):
54+ def factory(cls, upgrade_sequence, agent_stream):
55 return cls()
56
57 @staticmethod
58@@ -428,7 +432,7 @@
59 return dict([cls.prepare_upgrade.as_tuple()])
60
61 @classmethod
62- def factory(cls, upgrade_sequence):
63+ def factory(cls, upgrade_sequence, agent_stream):
64 if len(upgrade_sequence) < 2:
65 raise ValueError('Not enough paths for upgrade.')
66 bootstrap_paths = dict(
67@@ -821,14 +825,15 @@
68 result.update(DestroyEnvironmentAttempt.get_test_info())
69 return result
70
71- def factory(self, upgrade_sequence, log_dir):
72+ def factory(self, upgrade_sequence, log_dir, agent_stream):
73 """Emit an AttemptSuite.
74
75 :param upgrade_sequence: The sequence of jujus to upgrade, for
76 UpgradeJujuAttempt.
77 :param log_dir: Directory to store logs and other artifacts in.
78+ :param agent_stream: The agent stream to use for testing.
79 """
80- return AttemptSuite(self, upgrade_sequence, log_dir)
81+ return AttemptSuite(self, upgrade_sequence, log_dir, agent_stream)
82
83
84 class AttemptSuite(SteppedStageAttempt):
85@@ -839,12 +844,14 @@
86 :ivar upgrade_sequence: The sequence of jujus to upgrade, for
87 UpgradeJujuAttempt.
88 :ivar log_dir: Directory to store logs and other artifacts in.
89+ :ivar agent_stream: The agent stream to use for testing.
90 """
91
92- def __init__(self, attempt_list, upgrade_sequence, log_dir):
93+ def __init__(self, attempt_list, upgrade_sequence, log_dir, agent_stream):
94 self.attempt_list = attempt_list
95 self.upgrade_sequence = upgrade_sequence
96 self.log_dir = log_dir
97+ self.agent_stream = agent_stream
98
99 def get_test_info(self):
100 """Describe the tests provided by this Stage."""
101@@ -862,15 +869,16 @@
102 The actual generator is _iter_bs_manager_steps, to simplify testing.
103 """
104 bootstrap_attempt = self.attempt_list.bootstrap_attempt.factory(
105- self.upgrade_sequence)
106+ self.upgrade_sequence, self.agent_stream)
107 bs_client = bootstrap_attempt.get_bootstrap_client(client)
108 bs_jes_enabled = bs_client.is_jes_enabled()
109 jes_enabled = client.is_jes_enabled()
110 bs_manager = BootstrapManager(
111 client.env.environment, bs_client, bs_client,
112 bootstrap_host=None,
113- machines=[], series=None, agent_url=None, agent_stream=None,
114- region=None, log_dir=make_log_dir(self.log_dir), keep_env=True,
115+ machines=[], series=None, agent_url=None,
116+ agent_stream=self.agent_stream, region=None,
117+ log_dir=make_log_dir(self.log_dir), keep_env=True,
118 permanent=jes_enabled, jes_enabled=bs_jes_enabled)
119 return self._iter_bs_manager_steps(bs_manager, client,
120 bootstrap_attempt, jes_enabled)
121@@ -890,8 +898,9 @@
122 bs_manager.client = client
123 bs_manager.tear_down_client = client
124 bs_manager.jes_enabled = jes_enabled
125- attempts = [a.factory(self.upgrade_sequence) for a in
126- self.attempt_list.attempt_list]
127+ attempts = [
128+ a.factory(self.upgrade_sequence, self.agent_stream)
129+ for a in self.attempt_list.attempt_list]
130 yield self.attempt_list.prepare_suite.as_result(True)
131 for attempt in attempts:
132 for result in attempt.iter_steps(client):
133@@ -958,6 +967,8 @@
134 parser.add_argument('--new-agent-url')
135 parser.add_argument('--single', action='store_true')
136 parser.add_argument('--debug', action='store_true', default=False)
137+ parser.add_argument('--agent-stream',
138+ help='Agent stream to use for tests.')
139 parser.add_argument(
140 '--old-stable', help='Path to a version of juju that stable can'
141 ' upgrade from.')
142@@ -981,7 +992,8 @@
143 for suite in args.suite:
144 factory = MultiIndustrialTest.get_stages(suite, env.config)
145 upgrade_sequence = [upgrade_client.full_path, client.full_path]
146- suite = factory.factory(upgrade_sequence, args.log_dir)
147+ suite = factory.factory(upgrade_sequence, args.log_dir,
148+ args.agent_stream)
149 steps_iter = suite.iter_steps(client)
150 for step in steps_iter:
151 print(step)
152
153=== modified file 'run-reliability-test.bash'
154--- run-reliability-test.bash 2015-03-02 21:22:28 +0000
155+++ run-reliability-test.bash 2016-01-14 21:01:47 +0000
156@@ -15,11 +15,13 @@
157 fi
158 set -x
159 # Delete all files in $WORKSPACE, but no error if empty.
160-find $WORKSPACE -type f -delete
161+find $WORKSPACE -mindepth 1 -delete
162+logs=$WORKSPACE/logs
163+mkdir $logs
164 $SCRIPTS/write_industrial_test_metadata.py $new_juju_dir/buildvars.json \
165 $environment metadata.json
166 s3cmd -c $s3cfg put metadata.json $s3base-metadata.json
167 timeout -sINT -k 10m 1d $SCRIPTS/industrial_test.py $environment $new_juju \
168- --old-stable $old_stable_juju $suite --attempts $attempts \
169+ $logs --old-stable $old_stable_juju $suite --attempts $attempts \
170 --json-file results.json $extra_args
171 s3cmd -c $s3cfg put results.json $s3base-results.json
172
173=== modified file 'tests/test_industrial_test.py'
174--- tests/test_industrial_test.py 2016-01-13 21:33:11 +0000
175+++ tests/test_industrial_test.py 2016-01-14 21:01:47 +0000
176@@ -164,6 +164,7 @@
177 self.assertEqual(args.new_juju_path, 'new-juju')
178 self.assertEqual(args.log_dir, 'log-dir')
179 self.assertEqual(args.suite, [QUICK])
180+ self.assertIs(args.agent_stream, None)
181
182 def test_parse_args_attempts(self):
183 args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
184@@ -221,6 +222,13 @@
185 args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
186 self.assertIs(args.old_stable, None)
187
188+ def test_parse_args_agent_stream(self):
189+ args = parse_args(['rai', 'new-juju', QUICK, 'log-dir',
190+ '--agent-stream', 'asdf'])
191+ self.assertEqual(args.agent_stream, 'asdf')
192+ args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
193+ self.assertIs(args.old_stable, None)
194+
195
196 class FakeStepAttempt:
197
198@@ -265,7 +273,7 @@
199 normal methods on FakeAttemptClass.
200 """
201
202- def factory(self, upgrade_sequence):
203+ def factory(self, upgrade_sequence, attempt_stream):
204 return self()
205
206 def __init__(self, title, *result, **kwargs):
207@@ -301,7 +309,7 @@
208 args = Namespace(
209 env='foo', new_juju_path='new-path', attempts=7, suite=[DENSITY],
210 log_dir='log-dir', new_agent_url=None, debug=False,
211- old_stable=None)
212+ old_stable=None, agent_stream=None)
213 with temp_env('foo'):
214 mit = MultiIndustrialTest.from_args(args, QUICK)
215 self.assertEqual(mit.env, 'foo')
216@@ -309,12 +317,13 @@
217 self.assertEqual(mit.attempt_count, 7)
218 self.assertEqual(mit.max_attempts, 14)
219 self.assertEqual(mit.log_parent_dir, 'log-dir')
220+ self.assertIs(mit.agent_stream, None)
221 self.assertEqual(
222 mit.stages, AttemptSuiteFactory([]))
223 args = Namespace(
224 env='bar', new_juju_path='new-path2', attempts=6, suite=[FULL],
225 log_dir='log-dir2', new_agent_url=None, debug=False,
226- old_stable=None)
227+ old_stable=None, agent_stream=None)
228 with temp_env('bar'):
229 mit = MultiIndustrialTest.from_args(args, FULL)
230 self.assertEqual(mit.env, 'bar')
231@@ -322,6 +331,7 @@
232 self.assertEqual(mit.attempt_count, 6)
233 self.assertEqual(mit.max_attempts, 12)
234 self.assertEqual(mit.log_parent_dir, 'log-dir2')
235+ self.assertIs(mit.agent_stream, None)
236 self.assertEqual(
237 mit.stages, AttemptSuiteFactory([
238 UpgradeCharmAttempt, DeployManyAttempt,
239@@ -330,7 +340,8 @@
240 def test_from_args_maas(self):
241 args = Namespace(
242 env='foo', new_juju_path='new-path', log_dir='log-dir',
243- attempts=7, new_agent_url=None, debug=False, old_stable=None)
244+ attempts=7, new_agent_url=None, debug=False, old_stable=None,
245+ agent_stream=None)
246 with temp_env('foo', {'type': 'maas'}):
247 mit = MultiIndustrialTest.from_args(args, DENSITY)
248 self.assertEqual(
249@@ -339,7 +350,8 @@
250 def test_from_args_debug(self):
251 args = Namespace(
252 env='foo', new_juju_path='new-path', log_dir='log-dir',
253- attempts=7, new_agent_url=None, debug=False, old_stable=None)
254+ attempts=7, new_agent_url=None, debug=False, old_stable=None,
255+ agent_stream=None)
256 with temp_env('foo', {'type': 'maas'}):
257 mit = MultiIndustrialTest.from_args(args, DENSITY)
258 self.assertEqual(mit.debug, False)
259@@ -351,17 +363,30 @@
260 args = Namespace(
261 env='foo', new_juju_path='new-path', log_dir='log-dir',
262 attempts=7, new_agent_url=None, debug=False,
263- old_stable='really-old-path')
264+ old_stable='really-old-path', agent_stream=None)
265 with temp_env('foo'):
266 mit = MultiIndustrialTest.from_args(args, FULL)
267 self.assertEqual(mit.really_old_path, 'really-old-path')
268 args = Namespace(
269 env='bar', new_juju_path='new-path2', log_dir='log-dir',
270- attempts=6, new_agent_url=None, debug=False, old_stable=None)
271+ attempts=6, new_agent_url=None, debug=False, old_stable=None,
272+ agent_stream=None)
273 with temp_env('bar'):
274 mit = MultiIndustrialTest.from_args(args, FULL)
275 self.assertIs(mit.really_old_path, None)
276
277+ def test_from_args_agent_stream(self):
278+ args = Namespace(
279+ env='foo', new_juju_path='new-path', log_dir='log-dir',
280+ attempts=7, new_agent_url=None, debug=False, old_stable=None,
281+ agent_stream='foo-stream')
282+ with temp_env('foo', {'type': 'maas'}):
283+ mit = MultiIndustrialTest.from_args(args, DENSITY)
284+ self.assertEqual(mit.debug, False)
285+ args.debug = True
286+ mit = MultiIndustrialTest.from_args(args, DENSITY)
287+ self.assertEqual(mit.agent_stream, 'foo-stream')
288+
289 def test_get_stages(self):
290 self.assertEqual(
291 MultiIndustrialTest.get_stages(QUICK, {'type': 'foo'}),
292@@ -399,7 +424,7 @@
293 args = Namespace(
294 env='foo', new_juju_path='new-path', attempts=7,
295 log_dir='log-dir', new_agent_url=None, debug=False,
296- old_stable=None)
297+ old_stable=None, agent_stream=None)
298 with temp_env('foo'):
299 mit = MultiIndustrialTest.from_args(args, DENSITY)
300 self.assertEqual(
301@@ -409,7 +434,7 @@
302 args = Namespace(
303 env='foo', new_juju_path='new-path', attempts=7,
304 log_dir='log-dir', new_agent_url=None, debug=False,
305- old_stable=None)
306+ old_stable=None, agent_stream=None)
307 with temp_env('foo'):
308 mit = MultiIndustrialTest.from_args(args, BACKUP)
309 self.assertEqual(
310@@ -419,7 +444,7 @@
311 args = Namespace(
312 env='foo', new_juju_path='new-path', attempts=7,
313 log_dir='log-dir', new_agent_url='http://example.net',
314- debug=False, old_stable=None)
315+ debug=False, old_stable=None, agent_stream=None)
316 with temp_env('foo'):
317 mit = MultiIndustrialTest.from_args(args, suite=QUICK)
318 self.assertEqual(mit.new_agent_url, 'http://example.net')
319@@ -872,7 +897,7 @@
320 FakeAttemptClass('foo', False, True, new_path='bar-path'),
321 FakeAttemptClass('bar', True, True, new_path='bar-path')])
322 log_dir = use_context(self, temp_dir())
323- suite = suite_factory.factory([], log_dir)
324+ suite = suite_factory.factory([], log_dir, None)
325 industrial = IndustrialTest(old_client, new_client, [suite])
326 with patch('industrial_test.BootstrapManager',
327 fake_bootstrap_manager):
328@@ -891,7 +916,7 @@
329 suite_factory = AttemptSuiteFactory([
330 FakeAttemptClass('foo', True, False, new_path='bar-path'),
331 FakeAttemptClass('bar', True, True, new_path='bar-path')])
332- suite = suite_factory.factory([], log_dir)
333+ suite = suite_factory.factory([], log_dir, None)
334 industrial = IndustrialTest(old_client, new_client, [suite])
335 with patch('industrial_test.BootstrapManager',
336 fake_bootstrap_manager):
337@@ -909,7 +934,8 @@
338 log_dir = use_context(self, temp_dir())
339 suite = AttemptSuiteFactory([
340 FakeAttemptClass('foo', False, False),
341- FakeAttemptClass('bar', True, True)]).factory([], log_dir)
342+ FakeAttemptClass('bar', True, True)]).factory([], log_dir,
343+ 'foo-stream')
344 industrial = IndustrialTest(old_client, new_client, [suite])
345 with patch('industrial_test.BootstrapManager',
346 fake_bootstrap_manager):
347@@ -968,7 +994,7 @@
348 new_client = FakeJujuClient()
349 attempt = FakeStepAttempt.from_result(True, True)
350 log_dir = use_context(self, temp_dir())
351- suite = AttemptSuiteFactory([attempt]).factory([], log_dir)
352+ suite = AttemptSuiteFactory([attempt]).factory([], log_dir, None)
353 industrial = IndustrialTest(old_client, new_client,
354 [suite])
355
356@@ -1145,7 +1171,7 @@
357 def __init__(self):
358 super(StubSA, self).__init__()
359
360- self.assertIs(type(StubSA.factory(['a', 'b', 'c'])), StubSA)
361+ self.assertIs(type(StubSA.factory(['a', 'b', 'c'], None)), StubSA)
362
363 def test_get_test_info(self):
364
365@@ -1670,21 +1696,22 @@
366 class TestPrepareUpgradeJujuAttempt(JujuPyTestCase):
367
368 def test_factory(self):
369- uj_attempt = PrepareUpgradeJujuAttempt.factory(['a', 'b', 'c'])
370+ uj_attempt = PrepareUpgradeJujuAttempt.factory(
371+ ['a', 'b', 'c'], None)
372 self.assertIs(type(uj_attempt), PrepareUpgradeJujuAttempt)
373 self.assertEqual(uj_attempt.bootstrap_paths, {'b': 'a', 'c': 'b'})
374
375 def test_factory_empty(self):
376 with self.assertRaisesRegexp(
377 ValueError, 'Not enough paths for upgrade.'):
378- PrepareUpgradeJujuAttempt.factory(['a'])
379+ PrepareUpgradeJujuAttempt.factory(['a'], None)
380 with self.assertRaisesRegexp(
381 ValueError, 'Not enough paths for upgrade.'):
382- PrepareUpgradeJujuAttempt.factory([])
383+ PrepareUpgradeJujuAttempt.factory([], None)
384
385 def test_get_bootstrap_client(self):
386 client = FakeJujuClient(full_path='c', debug=True)
387- puj_attempt = PrepareUpgradeJujuAttempt.factory(['a', 'b', 'c'])
388+ puj_attempt = PrepareUpgradeJujuAttempt.factory(['a', 'b', 'c'], None)
389 bootstrap_client = puj_attempt.get_bootstrap_client(client)
390 self.assertIsNot(bootstrap_client, client)
391 self.assertIs(client.debug, bootstrap_client.debug)
392@@ -1918,10 +1945,11 @@
393 fake_bootstrap = FakeAttemptClass('bootstrap')
394 factory = AttemptSuiteFactory([],
395 bootstrap_attempt=fake_bootstrap)
396- attempt_suite = factory.factory(['1', '2'], 'log-1')
397+ attempt_suite = factory.factory(['1', '2'], 'log-1', 'foo-stream')
398 self.assertEqual(factory, attempt_suite.attempt_list)
399 self.assertEqual(['1', '2'], attempt_suite.upgrade_sequence)
400 self.assertEqual('log-1', attempt_suite.log_dir)
401+ self.assertEqual('foo-stream', attempt_suite.agent_stream)
402
403 def test_get_test_info(self):
404 fake_bootstrap = FakeAttemptClass('fake-bootstrap')
405@@ -1950,7 +1978,7 @@
406 fake_2 = FakeAttemptClass('fake-2')
407 factory = AttemptSuiteFactory([fake_1, fake_2],
408 bootstrap_attempt=fake_bootstrap)
409- attempt_suite = AttemptSuite(factory, None, None)
410+ attempt_suite = AttemptSuite(factory, None, None, None)
411 self.assertEqual(OrderedDict([
412 ('fake-bootstrap-id', {'title': 'fake-bootstrap'}),
413 ('prepare-suite', {'title': 'Prepare suite tests',
414@@ -1963,24 +1991,41 @@
415 'report_on': True}),
416 ]), attempt_suite.get_test_info())
417
418+ @contextmanager
419+ def iter_steps_cxt(self, attempt_suite):
420+ with patch('industrial_test.BootstrapManager') as mock_bm:
421+ with patch.object(attempt_suite,
422+ '_iter_bs_manager_steps') as mock_ibms:
423+ with patch('industrial_test.make_log_dir',
424+ return_value='qux-1'):
425+ yield (mock_ibms, mock_bm)
426+
427 def test_iter_steps(self):
428 fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
429- with temp_dir() as log_dir:
430- factory = AttemptSuiteFactory([], bootstrap_attempt=fake_bootstrap)
431- attempt_suite = AttemptSuite(factory, None, log_dir)
432- client = FakeJujuClient()
433- with patch('industrial_test.BootstrapManager') as mock_bm:
434- with patch.object(attempt_suite,
435- '_iter_bs_manager_steps') as mock_ibms:
436- iterator = attempt_suite.iter_steps(client)
437+ factory = AttemptSuiteFactory([], bootstrap_attempt=fake_bootstrap)
438+ attempt_suite = AttemptSuite(factory, None, 'asdf', None)
439+ with self.iter_steps_cxt(attempt_suite) as (mock_ibms, mock_bm):
440+ client = FakeJujuClient()
441+ attempt_suite.iter_steps(client)
442+ mock_bm.assert_called_once_with(
443+ 'name', client, client, agent_stream=None, agent_url=None,
444+ bootstrap_host=None, jes_enabled=False, keep_env=True,
445+ log_dir='qux-1', machines=[], permanent=False,
446+ region=None, series=None)
447+
448+ def test_iter_steps_agent_stream(self):
449+ fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
450+ factory = AttemptSuiteFactory([], bootstrap_attempt=fake_bootstrap)
451+ attempt_suite = AttemptSuite(factory, None, 'asdf', 'bar-stream')
452+ with self.iter_steps_cxt(attempt_suite) as (mock_ibms, mock_bm):
453+ client = FakeJujuClient()
454+ iterator = attempt_suite.iter_steps(client)
455 self.assertEqual(iterator, mock_ibms.return_value)
456 mock_bm.assert_called_once_with(
457- 'name', client, client, agent_stream=None, agent_url=None,
458+ 'name', client, client, agent_stream='bar-stream', agent_url=None,
459 bootstrap_host=None, jes_enabled=False, keep_env=True,
460- log_dir=os.path.join(log_dir, '0'), machines=[], permanent=False,
461+ log_dir='qux-1', machines=[], permanent=False,
462 region=None, series=None)
463- mock_ibms.assert_called_once_with(mock_bm.return_value, client,
464- fake_bootstrap(), False)
465
466 def test__iter_bs_manager_steps(self):
467 fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
468@@ -1988,7 +2033,7 @@
469 fake_2 = FakeAttemptClass('fake-2', '1', '2')
470 factory = AttemptSuiteFactory([fake_1, fake_2],
471 bootstrap_attempt=fake_bootstrap)
472- attempt_suite = AttemptSuite(factory, None, None)
473+ attempt_suite = AttemptSuite(factory, None, None, None)
474 client = FakeJujuClient()
475 bs_manager = FakeBootstrapManager(client)
476 steps = list(attempt_suite._iter_bs_manager_steps(

Subscribers

People subscribed via source and target branches