171
143
args = parse_args(['rai', 'new-juju'])
172
144
self.assertRegexpMatches(
173
145
stderr.getvalue(), '.*error: too few arguments.*')
174
with parse_error(self) as stderr:
175
args = parse_args(['rai', 'new-juju', QUICK])
176
self.assertRegexpMatches(
177
stderr.getvalue(), '.*error: too few arguments.*')
178
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
146
args = parse_args(['rai', 'new-juju', QUICK])
179
147
self.assertEqual(args.env, 'rai')
180
148
self.assertEqual(args.new_juju_path, 'new-juju')
181
self.assertEqual(args.log_dir, 'log-dir')
182
149
self.assertEqual(args.suite, [QUICK])
183
self.assertIs(args.agent_stream, None)
185
151
def test_parse_args_attempts(self):
186
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
152
args = parse_args(['rai', 'new-juju', QUICK])
187
153
self.assertEqual(args.attempts, 2)
188
args = parse_args(['rai', 'new-juju', '--attempts', '3', QUICK,
154
args = parse_args(['rai', 'new-juju', '--attempts', '3', QUICK])
190
155
self.assertEqual(args.attempts, 3)
192
157
def test_parse_args_json_file(self):
193
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
158
args = parse_args(['rai', 'new-juju', QUICK])
194
159
self.assertIs(args.json_file, None)
195
args = parse_args(['rai', 'new-juju', '--json-file', 'foobar', QUICK,
160
args = parse_args(['rai', 'new-juju', '--json-file', 'foobar', QUICK])
197
161
self.assertEqual(args.json_file, 'foobar')
199
163
def test_parse_args_suite(self):
200
args = parse_args(['rai', 'new-juju', 'full', 'log-dir'])
164
args = parse_args(['rai', 'new-juju', 'full'])
201
165
self.assertEqual(args.suite, [FULL])
202
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
166
args = parse_args(['rai', 'new-juju', QUICK])
203
167
self.assertEqual(args.suite, [QUICK])
204
args = parse_args(['rai', 'new-juju', DENSITY, 'log-dir'])
168
args = parse_args(['rai', 'new-juju', DENSITY])
205
169
self.assertEqual(args.suite, [DENSITY])
206
args = parse_args(['rai', 'new-juju', BACKUP, 'log-dir'])
170
args = parse_args(['rai', 'new-juju', BACKUP])
207
171
self.assertEqual(args.suite, [BACKUP])
208
172
with parse_error(self) as stderr:
209
args = parse_args(['rai', 'new-juju', 'foo', 'log-dir'])
173
args = parse_args(['rai', 'new-juju', 'foo'])
210
174
self.assertRegexpMatches(
211
175
stderr.getvalue(), ".*argument suite: invalid choice: 'foo'.*")
213
177
def test_parse_args_multi_suite(self):
214
args = parse_args(['rai', 'new-juju', 'full,quick', 'log-dir'])
178
args = parse_args(['rai', 'new-juju', 'full,quick'])
215
179
self.assertEqual(args.suite, [FULL, QUICK])
216
180
with parse_error(self) as stderr:
217
args = parse_args(['rai', 'new-juju', 'full,foo', 'log-dir'])
181
args = parse_args(['rai', 'new-juju', 'full,foo'])
218
182
self.assertRegexpMatches(
219
183
stderr.getvalue(), ".*argument suite: invalid choice: 'foo'.*")
221
185
def test_parse_args_agent_url(self):
222
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
186
args = parse_args(['rai', 'new-juju', QUICK])
223
187
self.assertEqual(args.new_agent_url, None)
224
188
args = parse_args(['rai', 'new-juju', '--new-agent-url',
225
'http://example.org', QUICK, 'log-dir'])
189
'http://example.org', QUICK])
226
190
self.assertEqual(args.new_agent_url, 'http://example.org')
228
192
def test_parse_args_debug(self):
229
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
193
args = parse_args(['rai', 'new-juju', QUICK])
230
194
self.assertEqual(args.debug, False)
231
args = parse_args(['rai', 'new-juju', '--debug', QUICK, 'log-dir'])
195
args = parse_args(['rai', 'new-juju', '--debug', QUICK])
232
196
self.assertEqual(args.debug, True)
234
198
def test_parse_args_old_stable(self):
235
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir',
236
'--old-stable', 'asdf'])
199
args = parse_args(['rai', 'new-juju', QUICK, '--old-stable', 'asdf'])
237
200
self.assertEqual(args.old_stable, 'asdf')
238
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
239
self.assertIs(args.old_stable, None)
241
def test_parse_args_agent_stream(self):
242
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir',
243
'--agent-stream', 'asdf'])
244
self.assertEqual(args.agent_stream, 'asdf')
245
args = parse_args(['rai', 'new-juju', QUICK, 'log-dir'])
201
args = parse_args(['rai', 'new-juju', QUICK])
246
202
self.assertIs(args.old_stable, None)
249
205
class FakeStepAttempt:
251
def __init__(self, result, new_path=None):
207
def __init__(self, result):
252
208
self.result = result
253
self.stage = StageInfo(result[0][0], '{} title'.format(result[0][0]))
254
self.new_path = new_path
257
def from_result(cls, old, new, test_id='foo-id', new_path=None):
258
"""Alternate constructor for backwards-compatibility.
260
Allows tests that used FakeAttempt to be adapted with minimal changes.
262
return cls([(test_id, old, new)], new_path)
264
def __eq__(self, other):
266
type(self) == type(other) and self.result == other.result)
268
def get_test_info(self):
269
return {self.result[0][0]: {'title': self.result[0][0]}}
271
def get_bootstrap_client(self, client):
274
210
def iter_test_results(self, old, new):
275
211
return iter(self.result)
277
def iter_steps(self, client):
278
yield self.stage.as_result()
279
if self.new_path is not None and client.full_path == self.new_path:
280
result_value = self.result[0][2]
282
result_value = self.result[0][1]
283
if isinstance(result_value, BaseException):
285
yield self.stage.as_result(result_value)
214
class FakeAttempt(FakeStepAttempt):
216
def __init__(self, old_result, new_result, test_id='foo-id'):
217
super(FakeAttempt, self).__init__([(test_id, old_result, new_result)])
219
def do_stage(self, old_client, new_client):
220
return self.result[0]
288
223
class FakeAttemptClass:
321
def fake_bootstrap_manager(self, temp_env_name, client, *args, **kwargs):
322
return FakeBootstrapManager(client)
325
260
class TestMultiIndustrialTest(TestCase):
327
262
def test_from_args(self):
328
263
args = Namespace(
329
264
env='foo', new_juju_path='new-path', attempts=7, suite=[DENSITY],
330
log_dir='log-dir', new_agent_url=None, debug=False,
331
old_stable=None, agent_stream=None)
265
new_agent_url=None, debug=False, old_stable=None)
332
266
with temp_env('foo'):
333
267
mit = MultiIndustrialTest.from_args(args, QUICK)
334
268
self.assertEqual(mit.env, 'foo')
335
269
self.assertEqual(mit.new_juju_path, 'new-path')
336
270
self.assertEqual(mit.attempt_count, 7)
337
271
self.assertEqual(mit.max_attempts, 14)
338
self.assertEqual(mit.log_parent_dir, 'log-dir')
339
self.assertIs(mit.agent_stream, None)
340
272
self.assertEqual(
341
mit.stages, AttemptSuiteFactory([]))
273
mit.stages, [BootstrapAttempt, DestroyEnvironmentAttempt])
342
274
args = Namespace(
343
275
env='bar', new_juju_path='new-path2', attempts=6, suite=[FULL],
344
log_dir='log-dir2', new_agent_url=None, debug=False,
345
old_stable=None, agent_stream=None)
276
new_agent_url=None, debug=False, old_stable=None)
346
277
with temp_env('bar'):
347
278
mit = MultiIndustrialTest.from_args(args, FULL)
348
279
self.assertEqual(mit.env, 'bar')
349
280
self.assertEqual(mit.new_juju_path, 'new-path2')
350
281
self.assertEqual(mit.attempt_count, 6)
351
282
self.assertEqual(mit.max_attempts, 12)
352
self.assertEqual(mit.log_parent_dir, 'log-dir2')
353
self.assertIs(mit.agent_stream, None)
354
283
self.assertEqual(
355
mit.stages, AttemptSuiteFactory([
356
UpgradeCharmAttempt, DeployManyAttempt,
357
BackupRestoreAttempt, EnsureAvailabilityAttempt]))
285
BootstrapAttempt, UpgradeCharmAttempt, DeployManyAttempt,
286
BackupRestoreAttempt, EnsureAvailabilityAttempt,
287
DestroyEnvironmentAttempt])
359
289
def test_from_args_maas(self):
360
290
args = Namespace(
361
env='foo', new_juju_path='new-path', log_dir='log-dir',
362
attempts=7, new_agent_url=None, debug=False, old_stable=None,
291
env='foo', new_juju_path='new-path', attempts=7,
292
new_agent_url=None, debug=False, old_stable=None)
364
293
with temp_env('foo', {'type': 'maas'}):
365
294
mit = MultiIndustrialTest.from_args(args, DENSITY)
366
295
self.assertEqual(
367
mit.stages, AttemptSuiteFactory([DeployManyAttempt]))
297
BootstrapAttempt, DeployManyAttempt,
298
DestroyEnvironmentAttempt])
369
300
def test_from_args_debug(self):
370
301
args = Namespace(
371
env='foo', new_juju_path='new-path', log_dir='log-dir',
372
attempts=7, new_agent_url=None, debug=False, old_stable=None,
302
env='foo', new_juju_path='new-path', attempts=7,
303
new_agent_url=None, debug=False, old_stable=None)
374
304
with temp_env('foo', {'type': 'maas'}):
375
305
mit = MultiIndustrialTest.from_args(args, DENSITY)
376
306
self.assertEqual(mit.debug, False)
381
311
def test_from_args_really_old_path(self):
382
312
args = Namespace(
383
env='foo', new_juju_path='new-path', log_dir='log-dir',
384
attempts=7, new_agent_url=None, debug=False,
385
old_stable='really-old-path', agent_stream=None)
313
env='foo', new_juju_path='new-path', attempts=7,
314
new_agent_url=None, debug=False, old_stable='really-old-path')
386
315
with temp_env('foo'):
387
316
mit = MultiIndustrialTest.from_args(args, FULL)
388
317
self.assertEqual(mit.really_old_path, 'really-old-path')
389
318
args = Namespace(
390
env='bar', new_juju_path='new-path2', log_dir='log-dir',
391
attempts=6, new_agent_url=None, debug=False, old_stable=None,
319
env='bar', new_juju_path='new-path2', attempts=6,
320
new_agent_url=None, debug=False, old_stable=None)
393
321
with temp_env('bar'):
394
322
mit = MultiIndustrialTest.from_args(args, FULL)
395
323
self.assertIs(mit.really_old_path, None)
397
def test_from_args_agent_stream(self):
399
env='foo', new_juju_path='new-path', log_dir='log-dir',
400
attempts=7, new_agent_url=None, debug=False, old_stable=None,
401
agent_stream='foo-stream')
402
with temp_env('foo', {'type': 'maas'}):
403
mit = MultiIndustrialTest.from_args(args, DENSITY)
404
self.assertEqual(mit.debug, False)
406
mit = MultiIndustrialTest.from_args(args, DENSITY)
407
self.assertEqual(mit.agent_stream, 'foo-stream')
325
def test_get_stages(self):
327
MultiIndustrialTest.get_stages(QUICK, {'type': 'foo'}),
328
[BootstrapAttempt, DestroyEnvironmentAttempt])
331
MultiIndustrialTest.get_stages(FULL, {'type': 'foo'}), [
332
BootstrapAttempt, UpgradeCharmAttempt, DeployManyAttempt,
333
BackupRestoreAttempt, EnsureAvailabilityAttempt,
334
DestroyEnvironmentAttempt])
336
MultiIndustrialTest.get_stages(DENSITY, {'type': 'foo'}), [
337
BootstrapAttempt, DeployManyAttempt,
338
DestroyEnvironmentAttempt])
340
MultiIndustrialTest.get_stages(BACKUP, {'type': 'foo'}), [
341
BootstrapAttempt, BackupRestoreAttempt,
342
DestroyEnvironmentAttempt])
344
def test_get_stages_maas(self):
346
MultiIndustrialTest.get_stages(QUICK, {'type': 'maas'}),
347
[BootstrapAttempt, DestroyEnvironmentAttempt])
349
MultiIndustrialTest.get_stages(FULL, {'type': 'maas'}), [
350
BootstrapAttempt, UpgradeCharmAttempt,
351
DeployManyAttempt, BackupRestoreAttempt,
352
EnsureAvailabilityAttempt, DestroyEnvironmentAttempt])
354
MultiIndustrialTest.get_stages(DENSITY, {'type': 'maas'}), [
355
BootstrapAttempt, DeployManyAttempt,
356
DestroyEnvironmentAttempt])
409
358
def test_density_suite(self):
410
359
args = Namespace(
411
360
env='foo', new_juju_path='new-path', attempts=7,
412
log_dir='log-dir', new_agent_url=None, debug=False,
413
old_stable=None, agent_stream=None)
361
new_agent_url=None, debug=False, old_stable=None)
414
362
with temp_env('foo'):
415
363
mit = MultiIndustrialTest.from_args(args, DENSITY)
416
364
self.assertEqual(
417
mit.stages, AttemptSuiteFactory([DeployManyAttempt]))
365
mit.stages, [BootstrapAttempt, DeployManyAttempt,
366
DestroyEnvironmentAttempt])
419
368
def test_backup_suite(self):
420
369
args = Namespace(
421
370
env='foo', new_juju_path='new-path', attempts=7,
422
log_dir='log-dir', new_agent_url=None, debug=False,
423
old_stable=None, agent_stream=None)
371
new_agent_url=None, debug=False, old_stable=None)
424
372
with temp_env('foo'):
425
373
mit = MultiIndustrialTest.from_args(args, BACKUP)
426
374
self.assertEqual(
427
mit.stages, AttemptSuiteFactory([BackupRestoreAttempt]))
375
mit.stages, [BootstrapAttempt, BackupRestoreAttempt,
376
DestroyEnvironmentAttempt])
429
378
def test_from_args_new_agent_url(self):
430
379
args = Namespace(
431
380
env='foo', new_juju_path='new-path', attempts=7,
432
log_dir='log-dir', new_agent_url='http://example.net',
433
debug=False, old_stable=None, agent_stream=None)
381
new_agent_url='http://example.net', debug=False, old_stable=None)
434
382
with temp_env('foo'):
435
383
mit = MultiIndustrialTest.from_args(args, suite=QUICK)
436
384
self.assertEqual(mit.new_agent_url, 'http://example.net')
438
386
def test_init(self):
439
387
mit = MultiIndustrialTest('foo-env', 'bar-path', [
440
DestroyEnvironmentAttempt, BootstrapAttempt], 'log-dir', 5)
388
DestroyEnvironmentAttempt, BootstrapAttempt], 5)
441
389
self.assertEqual(mit.env, 'foo-env')
442
390
self.assertEqual(mit.new_juju_path, 'bar-path')
443
391
self.assertEqual(mit.stages, [DestroyEnvironmentAttempt,
444
392
BootstrapAttempt])
445
393
self.assertEqual(mit.attempt_count, 5)
446
self.assertEqual(mit.log_parent_dir, 'log-dir')
448
395
def test_make_results(self):
449
mit = MultiIndustrialTest('foo-env', 'bar-path', AttemptSuiteFactory([
450
DestroyEnvironmentAttempt]), 5)
396
mit = MultiIndustrialTest('foo-env', 'bar-path', [
397
DestroyEnvironmentAttempt, BootstrapAttempt], 5)
451
398
results = mit.make_results()
452
399
self.assertEqual(results, {'results': [
453
400
{'attempts': 0, 'old_failures': 0, 'new_failures': 0,
454
'title': 'bootstrap', 'test_id': 'bootstrap', 'report_on': True},
455
{'attempts': 0, 'old_failures': 0, 'new_failures': 0,
456
'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
458
{'attempts': 0, 'old_failures': 0, 'new_failures': 0,
459
401
'title': 'destroy environment', 'test_id': 'destroy-env',
460
402
'report_on': True},
461
403
{'attempts': 0, 'old_failures': 0, 'new_failures': 0,
462
404
'title': 'check substrate clean', 'test_id': 'substrate-clean',
463
405
'report_on': True},
406
{'attempts': 0, 'old_failures': 0, 'new_failures': 0,
407
'title': 'bootstrap', 'test_id': 'bootstrap', 'report_on': True},
466
410
def test_make_results_report_on(self):
531
450
def test_make_industrial_test(self):
532
mit = MultiIndustrialTest('foo-env', 'bar-path', AttemptSuiteFactory([
533
DestroyEnvironmentAttempt]), 'log-dir', 5)
534
with self.patch_client(
535
lambda x, y=None, debug=False: fake_juju_client(
536
JujuData(x, {}, juju_home=''), full_path=y)):
451
mit = MultiIndustrialTest('foo-env', 'bar-path', [
452
DestroyEnvironmentAttempt, BootstrapAttempt], 5)
453
with self.patch_client(lambda x, y=None, debug=False: (x, y)):
537
454
industrial = mit.make_industrial_test()
538
old_client = industrial.old_client
539
self.assertEqual((old_client.env, old_client.full_path), (
540
JujuData('foo-env-old', {'name': 'foo-env-old'}, juju_home=''),
542
new_client = industrial.new_client
543
self.assertEqual((new_client.env, new_client.full_path), (
544
JujuData('foo-env-new', {'name': 'foo-env-new'}, juju_home=''),
546
self.assertEqual(len(industrial.stage_attempts), 1)
547
self.assertEqual([mit.stages], [sa.attempt_list for sa in
548
industrial.stage_attempts])
455
self.assertEqual(industrial.old_client,
456
(SimpleEnvironment('foo-env-old', {}), None))
457
self.assertEqual(industrial.new_client,
458
(SimpleEnvironment('foo-env-new', {}), 'bar-path'))
459
self.assertEqual(len(industrial.stage_attempts), 2)
460
for stage, attempt in zip(mit.stages, industrial.stage_attempts):
461
self.assertIs(type(attempt), stage)
550
463
def test_make_industrial_test_new_agent_url(self):
551
mit = MultiIndustrialTest('foo-env', 'bar-path',
552
AttemptSuiteFactory([]), 'log-dir',
464
mit = MultiIndustrialTest('foo-env', 'bar-path', [],
553
465
new_agent_url='http://example.com')
554
with self.patch_client(
555
lambda x, y=None, debug=False: fake_juju_client(full_path=y)):
466
with self.patch_client(lambda x, y=None, debug=False: (x, y)):
556
467
industrial = mit.make_industrial_test()
557
468
self.assertEqual(
558
(industrial.new_client.env, industrial.new_client.full_path), (
559
JujuData('foo-env-new', {
561
'default-series': 'angsty',
563
'name': 'foo-env-new',
564
'tools-metadata-url': 'http://example.com',
469
industrial.new_client, (
470
SimpleEnvironment('foo-env-new', {
471
'tools-metadata-url': 'http://example.com'}),
569
475
def test_make_industrial_test_debug(self):
570
mit = MultiIndustrialTest('foo-env', 'bar-path',
571
AttemptSuiteFactory([]), 'log-dir',
476
mit = MultiIndustrialTest('foo-env', 'bar-path', [],
572
477
new_agent_url='http://example.com')
574
479
def side_effect(x, y=None, debug=False):
575
return fake_juju_client(env=JujuData(x, {}, juju_home='x'),
576
full_path=y, debug=debug)
578
482
with self.patch_client(side_effect):
579
483
industrial = mit.make_industrial_test()
580
self.assertEqual(industrial.new_client.debug, False)
581
self.assertEqual(industrial.old_client.debug, False)
484
self.assertEqual(industrial.new_client, False)
485
self.assertEqual(industrial.old_client, False)
583
487
with self.patch_client(side_effect):
584
488
industrial = mit.make_industrial_test()
585
self.assertEqual(industrial.new_client.debug, True)
586
self.assertEqual(industrial.old_client.debug, True)
489
self.assertEqual(industrial.new_client, True)
490
self.assertEqual(industrial.old_client, True)
588
492
def test_update_results(self):
589
mit = MultiIndustrialTest('foo-env', 'bar-path',
590
AttemptSuiteFactory([]), 2)
493
mit = MultiIndustrialTest('foo-env', 'bar-path', [
494
DestroyEnvironmentAttempt, BootstrapAttempt], 2)
591
495
results = mit.make_results()
592
mit.update_results([('bootstrap', True, False)], results)
496
mit.update_results([('destroy-env', True, False)], results)
593
497
expected = {'results': [
594
{'title': 'bootstrap', 'test_id': 'bootstrap',
498
{'title': 'destroy environment', 'test_id': 'destroy-env',
595
499
'attempts': 1, 'new_failures': 1, 'old_failures': 0,
596
500
'report_on': True},
597
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
599
'new_failures': 0, 'old_failures': 0, 'report_on': False},
600
{'title': 'destroy environment', 'test_id': 'destroy-env',
501
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
502
'attempts': 0, 'new_failures': 0, 'old_failures': 0,
504
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 0,
602
505
'new_failures': 0, 'old_failures': 0, 'report_on': True},
603
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
604
'attempts': 0, 'new_failures': 0, 'old_failures': 0,
607
507
self.assertEqual(results, expected)
609
('bootstrap', True, True), ('prepare-suite', True, True),
610
('destroy-env', False, True), ('substrate-clean', True, True)
509
[('destroy-env', True, True), ('substrate-clean', True, True),
510
('bootstrap', False, True)],
612
512
self.assertEqual(results, {'results': [
613
{'title': 'bootstrap', 'test_id': 'bootstrap',
513
{'title': 'destroy environment', 'test_id': 'destroy-env',
614
514
'attempts': 2, 'new_failures': 1, 'old_failures': 0,
615
515
'report_on': True},
616
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
617
'attempts': 1, 'new_failures': 0, 'old_failures': 0,
619
{'title': 'destroy environment', 'test_id': 'destroy-env',
620
'attempts': 1, 'new_failures': 0, 'old_failures': 1, 'report_on':
622
516
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
623
517
'attempts': 1, 'new_failures': 0, 'old_failures': 0,
624
518
'report_on': True},
519
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 1,
520
'new_failures': 0, 'old_failures': 1, 'report_on': True},
626
522
mit.update_results(
627
[('bootstrap', False, False), ('prepare-suite', True, True),
628
('destroy-env', False, False), ('substrate-clean', True, True)],
523
[('destroy-env', False, False), ('substrate-clean', True, True),
524
('bootstrap', False, False)],
630
526
expected = {'results': [
631
{'title': 'bootstrap', 'test_id': 'bootstrap',
527
{'title': 'destroy environment', 'test_id': 'destroy-env',
632
528
'attempts': 2, 'new_failures': 1, 'old_failures': 0,
633
529
'report_on': True},
634
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
635
'attempts': 2, 'new_failures': 0, 'old_failures': 0,
637
{'title': 'destroy environment', 'test_id': 'destroy-env',
638
'attempts': 2, 'new_failures': 1, 'old_failures': 2,
640
530
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
641
531
'attempts': 2, 'new_failures': 0, 'old_failures': 0,
642
532
'report_on': True},
533
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 2,
534
'new_failures': 1, 'old_failures': 2, 'report_on': True},
644
536
self.assertEqual(results, expected)
646
538
def test_run_tests(self):
647
log_dir = use_context(self, temp_dir())
648
mit = MultiIndustrialTest('foo-env', 'bar-path', AttemptSuiteFactory([
649
FakeAttemptClass('foo', True, True, new_path='bar-path'),
650
FakeAttemptClass('bar', True, False, new_path='bar-path'),
539
mit = MultiIndustrialTest('foo-env', 'bar-path', [
540
FakeAttemptClass('foo', True, True),
541
FakeAttemptClass('bar', True, False),
653
def side_effect(env, full_path=None, debug=False):
654
return fake_juju_client(None, full_path, debug)
544
def side_effect(x, y=None, debug=False):
545
return StubJujuClient()
656
547
with self.patch_client(side_effect):
657
with patch('industrial_test.BootstrapManager',
658
side_effect=fake_bootstrap_manager):
659
results = mit.run_tests()
548
results = mit.run_tests()
660
549
self.assertEqual(results, {'results': [
661
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 5,
662
'old_failures': 0, 'new_failures': 0, 'report_on': True},
663
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
664
'attempts': 5, 'old_failures': 0, 'new_failures': 0,
666
550
{'title': 'foo', 'test_id': 'foo-id', 'attempts': 5,
667
551
'old_failures': 0, 'new_failures': 0, 'report_on': True},
668
552
{'title': 'bar', 'test_id': 'bar-id', 'attempts': 5,
669
553
'old_failures': 0, 'new_failures': 5, 'report_on': True},
670
{'title': 'destroy environment', 'test_id': 'destroy-env',
671
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
673
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
674
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
678
556
def test_run_tests_max_attempts(self):
679
log_dir = use_context(self, temp_dir())
680
mit = MultiIndustrialTest('foo-env', 'bar-path', AttemptSuiteFactory([
681
FakeAttemptClass('foo', True, False, new_path='bar-path'),
682
FakeAttemptClass('bar', True, False, new_path='bar-path'),
557
mit = MultiIndustrialTest('foo-env', 'bar-path', [
558
FakeAttemptClass('foo', True, False),
559
FakeAttemptClass('bar', True, False),
685
def side_effect(env, full_path=None, debug=False):
686
return fake_juju_client(None, full_path, debug)
562
def side_effect(x, y=None, debug=False):
563
return StubJujuClient()
688
565
with self.patch_client(side_effect):
689
with patch('industrial_test.BootstrapManager',
690
side_effect=fake_bootstrap_manager):
691
results = mit.run_tests()
566
results = mit.run_tests()
692
567
self.assertEqual(results, {'results': [
693
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 5,
694
'old_failures': 0, 'new_failures': 0, 'report_on': True},
695
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
696
'attempts': 5, 'old_failures': 0, 'new_failures': 0,
698
568
{'title': 'foo', 'test_id': 'foo-id', 'attempts': 5,
699
569
'old_failures': 0, 'new_failures': 5, 'report_on': True},
700
570
{'title': 'bar', 'test_id': 'bar-id', 'attempts': 0,
701
571
'old_failures': 0, 'new_failures': 0, 'report_on': True},
702
{'title': 'destroy environment', 'test_id': 'destroy-env',
703
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
705
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
706
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
710
574
def test_run_tests_max_attempts_less_than_attempt_count(self):
711
log_dir = use_context(self, temp_dir())
712
mit = MultiIndustrialTest(
713
'foo-env', 'bar-path', AttemptSuiteFactory([
714
FakeAttemptClass('foo', True, False, new_path='bar-path'),
715
FakeAttemptClass('bar', True, False, new_path='bar-path')],
575
mit = MultiIndustrialTest('foo-env', 'bar-path', [
576
FakeAttemptClass('foo', True, False),
577
FakeAttemptClass('bar', True, False),
719
def side_effect(env, full_path=None, debug=False):
720
return fake_juju_client(None, full_path, debug)
580
def side_effect(x, y=None, debug=False):
581
return StubJujuClient()
722
583
with self.patch_client(side_effect):
723
with patch('industrial_test.BootstrapManager',
724
side_effect=fake_bootstrap_manager):
725
results = mit.run_tests()
727
{'title': 'bootstrap', 'test_id': 'bootstrap', 'attempts': 4,
728
'old_failures': 0, 'new_failures': 0, 'report_on': True},
729
{'title': 'Prepare suite tests', 'test_id': 'prepare-suite',
730
'attempts': 4, 'old_failures': 0, 'new_failures': 0,
584
results = mit.run_tests()
585
self.assertEqual(results, {'results': [
732
586
{'title': 'foo', 'test_id': 'foo-id', 'attempts': 4,
733
587
'old_failures': 0, 'new_failures': 4, 'report_on': True},
734
588
{'title': 'bar', 'test_id': 'bar-id', 'attempts': 0,
735
589
'old_failures': 0, 'new_failures': 0, 'report_on': True},
736
{'title': 'destroy environment', 'test_id': 'destroy-env',
737
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
739
{'title': 'check substrate clean', 'test_id': 'substrate-clean',
740
'attempts': 0, 'old_failures': 0, 'new_failures': 0,
743
self.assertEqual(results, {'results': expected})
746
593
def get_results_1():
848
695
def test_from_args(self):
849
696
def side_effect(x, y=None, debug=False):
850
return fake_juju_client(env=JujuData(x, {}), full_path=y)
851
with patch('industrial_test.client_from_config',
852
side_effect=side_effect):
853
industrial = IndustrialTest.from_args(
854
'foo', 'new-juju-path', [])
698
with patch('jujupy.EnvJujuClient.by_version', side_effect=side_effect):
699
with patch('jujupy.SimpleEnvironment.from_config',
700
side_effect=lambda x: SimpleEnvironment(x, {})):
701
industrial = IndustrialTest.from_args(
702
'foo', 'new-juju-path', [])
855
703
self.assertIsInstance(industrial, IndustrialTest)
856
old_client = industrial.old_client
857
self.assertEqual((old_client.env, old_client.full_path), (
858
JujuData('foo-old', {'name': 'foo-old'}), None))
859
new_client = industrial.new_client
860
self.assertEqual((new_client.env, new_client.full_path), (
861
JujuData('foo-new', {'name': 'foo-new'}),
863
self.assertNotEqual(old_client.env.environment,
864
new_client.env.environment)
704
self.assertEqual(industrial.old_client,
705
(SimpleEnvironment('foo-old', {}), None))
706
self.assertEqual(industrial.new_client,
707
(SimpleEnvironment('foo-new', {}), 'new-juju-path'))
708
self.assertNotEqual(industrial.old_client[0].environment,
709
industrial.new_client[0].environment)
866
711
def test_from_args_debug(self):
867
712
def side_effect(x, y=None, debug=False):
868
return fake_juju_client(full_path=y, debug=debug)
869
with patch('industrial_test.client_from_config',
870
side_effect=side_effect):
714
with patch('jujupy.EnvJujuClient.by_version', side_effect=side_effect):
871
715
with patch('jujupy.SimpleEnvironment.from_config'):
872
716
industrial = IndustrialTest.from_args(
873
717
'foo', 'new-juju-path', [], debug=False)
874
self.assertEqual(industrial.old_client.debug, False)
875
self.assertEqual(industrial.new_client.debug, False)
718
self.assertEqual(industrial.old_client, False)
719
self.assertEqual(industrial.new_client, False)
876
720
industrial = IndustrialTest.from_args(
877
721
'foo', 'new-juju-path', [], debug=True)
878
self.assertEqual(industrial.old_client.debug, True)
879
self.assertEqual(industrial.new_client.debug, True)
722
self.assertEqual(industrial.old_client, True)
723
self.assertEqual(industrial.new_client, True)
881
725
def test_run_stages(self):
882
726
old_client = FakeEnvJujuClient('old')
883
727
new_client = FakeEnvJujuClient('new')
884
728
industrial = IndustrialTest(old_client, new_client, [
885
FakeStepAttempt.from_result(True, True),
886
FakeStepAttempt.from_result(True, True)])
729
FakeAttempt(True, True), FakeAttempt(True, True)])
887
730
with patch('subprocess.call') as cc_mock:
888
731
result = industrial.run_stages()
889
732
self.assertItemsEqual(result, [('foo-id', True, True),
891
734
self.assertEqual(len(cc_mock.mock_calls), 0)
893
736
def test_run_stages_old_fail(self):
894
old_client = fake_juju_client()
895
new_client = fake_juju_client(full_path='bar-path')
737
old_client = FakeEnvJujuClient('old')
738
new_client = FakeEnvJujuClient('new')
896
739
industrial = IndustrialTest(old_client, new_client, [
897
FakeStepAttempt.from_result(False, True),
898
FakeStepAttempt.from_result(True, True)])
899
suite_factory = AttemptSuiteFactory([
900
FakeAttemptClass('foo', False, True, new_path='bar-path'),
901
FakeAttemptClass('bar', True, True, new_path='bar-path')])
902
log_dir = use_context(self, temp_dir())
903
suite = suite_factory.factory([], log_dir, None)
904
industrial = IndustrialTest(old_client, new_client, [suite])
905
with patch('industrial_test.BootstrapManager',
906
fake_bootstrap_manager):
740
FakeAttempt(False, True), FakeAttempt(True, True)])
741
with patch('subprocess.call') as cc_mock:
907
742
result = industrial.run_stages()
908
self.assertItemsEqual(result, [
909
('bootstrap', True, True),
910
('prepare-suite', True, True),
911
('foo-id', False, True)])
912
self.assertEqual('controller-killed',
913
old_client._backend.controller_state.state)
914
self.assertEqual('controller-killed',
915
new_client._backend.controller_state.state)
743
self.assertItemsEqual(result, [('foo-id', False, True)])
744
assert_juju_call(self, cc_mock, old_client, get_timeout_prefix(600) + (
745
'juju', '--show-log', 'destroy-environment', 'old',
747
assert_juju_call(self, cc_mock, new_client, get_timeout_prefix(600) + (
748
'juju', '--show-log', 'destroy-environment', 'new',
917
751
def test_run_stages_new_fail(self):
918
old_client = fake_juju_client()
919
new_client = fake_juju_client(full_path='bar-path')
920
log_dir = use_context(self, temp_dir())
921
suite_factory = AttemptSuiteFactory([
922
FakeAttemptClass('foo', True, False, new_path='bar-path'),
923
FakeAttemptClass('bar', True, True, new_path='bar-path')])
924
suite = suite_factory.factory([], log_dir, None)
925
industrial = IndustrialTest(old_client, new_client, [suite])
926
with patch('industrial_test.BootstrapManager',
927
fake_bootstrap_manager):
752
old_client = FakeEnvJujuClient('old')
753
new_client = FakeEnvJujuClient('new')
754
industrial = IndustrialTest(old_client, new_client, [
755
FakeAttempt(True, False), FakeAttempt(True, True)])
756
with patch('subprocess.call') as cc_mock:
928
757
result = industrial.run_stages()
929
self.assertItemsEqual(result, [
930
('bootstrap', True, True),
931
('prepare-suite', True, True),
932
('foo-id', True, False)])
933
self.assertEqual('controller-killed',
934
old_client._backend.controller_state.state)
935
self.assertEqual('controller-killed',
936
new_client._backend.controller_state.state)
758
self.assertItemsEqual(result, [('foo-id', True, False)])
759
assert_juju_call(self, cc_mock, old_client, get_timeout_prefix(600) + (
760
'juju', '--show-log', 'destroy-environment', 'old',
762
assert_juju_call(self, cc_mock, new_client, get_timeout_prefix(600) + (
763
'juju', '--show-log', 'destroy-environment', 'new',
938
766
def test_run_stages_both_fail(self):
939
old_client = fake_juju_client()
940
new_client = fake_juju_client()
941
log_dir = use_context(self, temp_dir())
942
suite = AttemptSuiteFactory([
943
FakeAttemptClass('foo', False, False),
944
FakeAttemptClass('bar', True, True)]).factory([], log_dir,
946
industrial = IndustrialTest(old_client, new_client, [suite])
947
with patch('industrial_test.BootstrapManager',
948
fake_bootstrap_manager):
767
old_client = FakeEnvJujuClient('old')
768
new_client = FakeEnvJujuClient('new')
769
industrial = IndustrialTest(old_client, new_client, [
770
FakeAttempt(False, False), FakeAttempt(True, True)])
771
with patch('subprocess.call') as cc_mock:
949
772
result = industrial.run_stages()
950
self.assertItemsEqual(result, [
951
('bootstrap', True, True),
952
('prepare-suite', True, True),
953
('foo-id', False, False)])
954
self.assertEqual('controller-killed',
955
old_client._backend.controller_state.state)
956
self.assertEqual('controller-killed',
957
new_client._backend.controller_state.state)
773
self.assertItemsEqual(result, [('foo-id', False, False)])
774
assert_juju_call(self, cc_mock, old_client, get_timeout_prefix(600) + (
775
'juju', '--show-log', 'destroy-environment', 'old',
777
assert_juju_call(self, cc_mock, new_client, get_timeout_prefix(600) + (
778
'juju', '--show-log', 'destroy-environment', 'new',
959
781
def test_run_stages_recover_failure(self):
960
old_client = fake_juju_client()
961
new_client = fake_juju_client()
782
old_client = FakeEnvJujuClient('old')
783
new_client = FakeEnvJujuClient('new')
962
784
fsa = FakeStepAttempt([('foo', True, False), ('bar', True, True)])
963
785
industrial = IndustrialTest(old_client, new_client, [
964
fsa, FakeStepAttempt.from_result(True, True)])
786
fsa, FakeAttempt(True, True)])
965
787
self.assertEqual(list(industrial.run_stages()), [
966
788
('foo', True, False), ('bar', True, True), ('foo-id', True, True)])
1836
1510
'0': {'agent-state': 'started'},
1840
with patch_status(controller_client, final_status) as gs_mock:
1514
with patch_status(client, final_status) as gs_mock:
1841
1515
self.assertEqual(iterator.next(),
1842
1516
{'test_id': 'back-up-restore', 'result': True})
1843
1517
gs_mock.assert_called_once_with()
1846
class TestPrepareUpgradeJujuAttempt(JujuPyTestCase):
1520
class TestUpgradeJujuAttempt(JujuPyTestCase):
1848
1522
def test_factory(self):
1849
uj_attempt = PrepareUpgradeJujuAttempt.factory(
1850
['a', 'b', 'c'], None)
1851
self.assertIs(type(uj_attempt), PrepareUpgradeJujuAttempt)
1523
uj_attempt = UpgradeJujuAttempt.factory(['a', 'b', 'c'])
1524
self.assertIs(type(uj_attempt), UpgradeJujuAttempt)
1852
1525
self.assertEqual(uj_attempt.bootstrap_paths, {'b': 'a', 'c': 'b'})
1854
1527
def test_factory_empty(self):
1855
1528
with self.assertRaisesRegexp(
1856
1529
ValueError, 'Not enough paths for upgrade.'):
1857
PrepareUpgradeJujuAttempt.factory(['a'], None)
1530
UpgradeJujuAttempt.factory(['a'])
1858
1531
with self.assertRaisesRegexp(
1859
1532
ValueError, 'Not enough paths for upgrade.'):
1860
PrepareUpgradeJujuAttempt.factory([], None)
1862
def test_get_bootstrap_client(self):
1863
client = fake_juju_client(full_path='c', debug=True)
1864
puj_attempt = PrepareUpgradeJujuAttempt.factory(['a', 'b', 'c'], None)
1866
def by_version(path):
1867
return fake_juju_client(client.env, path, client.debug)
1869
with patch.object(client, 'clone_path_cls', by_version):
1870
bootstrap_client = puj_attempt.get_bootstrap_client(client)
1872
self.assertIsNot(bootstrap_client, client)
1873
self.assertIs(client.debug, bootstrap_client.debug)
1874
self.assertIs(client.env, bootstrap_client.env)
1875
self.assertEqual('b', bootstrap_client.full_path)
1533
UpgradeJujuAttempt.factory([])
1877
1535
def test_iter_steps(self):
1878
future_client = FakeEnvJujuClient(full_path='/future/juju')
1879
present_client = FakeEnvJujuClient(full_path='/present/juju')
1880
puj_attempt = PrepareUpgradeJujuAttempt(
1536
future_client = FakeEnvJujuClient()
1537
future_client.full_path = '/future/juju'
1538
present_client = FakeEnvJujuClient()
1539
present_client.full_path = '/present/juju'
1540
uj_attempt = UpgradeJujuAttempt(
1881
1541
{future_client.full_path: present_client.full_path})
1882
puj_iterator = iter_steps_validate_info(self, puj_attempt,
1884
with patch('subprocess.check_output', return_value='2.0-alpha3-a-b'):
1885
with patch('industrial_test.client_from_config',
1886
return_value=future_client):
1887
self.assertEqual({'test_id': 'prepare-upgrade-juju'},
1888
puj_iterator.next())
1889
with observable_temp_file() as config_file:
1890
with patch('subprocess.Popen') as po_mock:
1891
self.assertEqual({'test_id': 'prepare-upgrade-juju'},
1892
puj_iterator.next())
1893
assert_juju_call(self, po_mock, future_client, (
1894
'juju', '--show-log', 'bootstrap', '--constraints', 'mem=2G',
1895
'steve', 'fake/regionx', '--config', config_file.name,
1896
'--agent-version', '2.0-alpha3'))
1897
po_mock.return_value.wait.return_value = 0
1898
self.assertEqual(puj_iterator.next(),
1899
{'test_id': 'prepare-upgrade-juju'})
1542
uj_iterator = iter_steps_validate_info(self, uj_attempt, future_client)
1543
with patch('subprocess.check_output', return_value='foo'):
1544
self.assertEqual({'test_id': 'prepare-upgrade-juju'},
1546
with patch('subprocess.Popen') as po_mock:
1547
self.assertEqual({'test_id': 'prepare-upgrade-juju'},
1549
assert_juju_call(self, po_mock, present_client, (
1550
'juju', '--show-log', 'bootstrap', '-e', 'steve', '--constraints',
1552
po_mock.return_value.wait.return_value = 0
1553
self.assertEqual(uj_iterator.next(),
1554
{'test_id': 'prepare-upgrade-juju'})
1901
1556
'machines': {'0': {'agent-state': 'started'}},
1904
1559
with patch_status(None, b_status):
1905
1560
self.assertEqual(
1906
puj_iterator.next(),
1907
1562
{'test_id': 'prepare-upgrade-juju', 'result': True})
1909
def test_iter_steps_no_previous_client(self):
1910
uj_attempt = PrepareUpgradeJujuAttempt({})
1911
client = FakeEnvJujuClient(full_path='/present/juju')
1912
uj_iterator = uj_attempt.iter_steps(client)
1913
with self.assertRaises(CannotUpgradeToClient) as exc_context:
1915
self.assertIs(exc_context.exception.client, client)
1918
class TestUpgradeJujuAttempt(JujuPyTestCase):
1920
def test_iter_steps(self):
1921
future_client = FakeEnvJujuClient(full_path='/future/juju')
1922
uj_attempt = UpgradeJujuAttempt()
1923
uj_iterator = iter_steps_validate_info(self, uj_attempt, future_client)
1924
1563
self.assertEqual(uj_iterator.next(), {'test_id': 'upgrade-juju'})
1925
1564
with patch('subprocess.check_call') as cc_mock:
1926
1565
self.assertEqual({'test_id': 'upgrade-juju'}, uj_iterator.next())
1931
('juju', '--show-log', 'upgrade-juju',
1932
'-m', 'steve:steve', '--version',
1933
future_client.get_matching_agent_version()))
1566
assert_juju_call(self, cc_mock, future_client, (
1567
'juju', '--show-log', 'upgrade-juju', '-e', 'steve', '--version',
1568
future_client.get_matching_agent_version()))
1934
1569
version_status = {
1935
1570
'machines': {'0': {
1936
1571
'agent-version': future_client.get_matching_agent_version()}},
1939
1574
with patch_status(None, version_status):
1940
1575
self.assertEqual({'test_id': 'upgrade-juju', 'result': True},
1941
1576
uj_iterator.next())
1578
def test_iter_steps_no_previous_client(self):
1579
uj_attempt = UpgradeJujuAttempt({})
1580
client = FakeEnvJujuClient()
1581
client.full_path = '/present/juju'
1582
uj_iterator = uj_attempt.iter_steps(client)
1583
with self.assertRaises(CannotUpgradeToClient) as exc_context:
1585
self.assertIs(exc_context.exception.client, client)
1944
1588
class TestUpgradeCharmAttempt(JujuPyTestCase):
2122
1741
{'test_id': 'foo-id', 'result': True})
2123
1742
self.assertEqual(si.as_result(False),
2124
1743
{'test_id': 'foo-id', 'result': False})
2127
class TestAttemptSuiteFactory(TestCase):
2129
def test_factory(self):
2130
fake_bootstrap = FakeAttemptClass('bootstrap')
2131
factory = AttemptSuiteFactory([],
2132
bootstrap_attempt=fake_bootstrap)
2133
attempt_suite = factory.factory(['1', '2'], 'log-1', 'foo-stream')
2134
self.assertEqual(factory, attempt_suite.attempt_list)
2135
self.assertEqual(['1', '2'], attempt_suite.upgrade_sequence)
2136
self.assertEqual('log-1', attempt_suite.log_dir)
2137
self.assertEqual('foo-stream', attempt_suite.agent_stream)
2139
def test_get_test_info(self):
2140
fake_bootstrap = FakeAttemptClass('fake-bootstrap')
2141
fake_1 = FakeAttemptClass('fake-1')
2142
fake_2 = FakeAttemptClass('fake-2')
2143
factory = AttemptSuiteFactory([fake_1, fake_2],
2144
bootstrap_attempt=fake_bootstrap)
2145
self.assertEqual(OrderedDict([
2146
('fake-bootstrap-id', {'title': 'fake-bootstrap'}),
2147
('prepare-suite', {'title': 'Prepare suite tests',
2148
'report_on': False}),
2149
('fake-1-id', {'title': 'fake-1'}),
2150
('fake-2-id', {'title': 'fake-2'}),
2151
('destroy-env', {'title': 'destroy environment',
2152
'report_on': True}),
2153
('substrate-clean', {'title': 'check substrate clean',
2154
'report_on': True}),
2155
]), factory.get_test_info())
2158
class TestAttemptSuite(TestCase):
2160
def test_get_test_info(self):
2161
fake_bootstrap = FakeAttemptClass('fake-bootstrap')
2162
fake_1 = FakeAttemptClass('fake-1')
2163
fake_2 = FakeAttemptClass('fake-2')
2164
factory = AttemptSuiteFactory([fake_1, fake_2],
2165
bootstrap_attempt=fake_bootstrap)
2166
attempt_suite = AttemptSuite(factory, None, None, None)
2167
self.assertEqual(OrderedDict([
2168
('fake-bootstrap-id', {'title': 'fake-bootstrap'}),
2169
('prepare-suite', {'title': 'Prepare suite tests',
2170
'report_on': False}),
2171
('fake-1-id', {'title': 'fake-1'}),
2172
('fake-2-id', {'title': 'fake-2'}),
2173
('destroy-env', {'title': 'destroy environment',
2174
'report_on': True}),
2175
('substrate-clean', {'title': 'check substrate clean',
2176
'report_on': True}),
2177
]), attempt_suite.get_test_info())
2180
def iter_steps_cxt(self, attempt_suite):
2181
with patch('industrial_test.BootstrapManager') as mock_bm:
2182
with patch.object(attempt_suite,
2183
'_iter_bs_manager_steps') as mock_ibms:
2184
with patch('industrial_test.make_log_dir',
2185
return_value='qux-1'):
2186
yield (mock_ibms, mock_bm)
2188
def test_iter_steps(self):
2189
fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
2190
factory = AttemptSuiteFactory([], bootstrap_attempt=fake_bootstrap)
2191
attempt_suite = AttemptSuite(factory, None, 'asdf', None)
2192
with self.iter_steps_cxt(attempt_suite) as (mock_ibms, mock_bm):
2193
client = fake_juju_client()
2194
attempt_suite.iter_steps(client)
2195
mock_bm.assert_called_once_with(
2196
'name', client, client, agent_stream=None, agent_url=None,
2197
bootstrap_host=None, jes_enabled=True, keep_env=True,
2198
log_dir='qux-1', machines=[], permanent=True,
2199
region=None, series=None)
2201
def test_iter_steps_agent_stream(self):
2202
fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
2203
factory = AttemptSuiteFactory([], bootstrap_attempt=fake_bootstrap)
2204
attempt_suite = AttemptSuite(factory, None, 'asdf', 'bar-stream')
2205
with self.iter_steps_cxt(attempt_suite) as (mock_ibms, mock_bm):
2206
client = fake_juju_client()
2207
iterator = attempt_suite.iter_steps(client)
2208
self.assertEqual(iterator, mock_ibms.return_value)
2209
mock_bm.assert_called_once_with(
2210
'name', client, client, agent_stream='bar-stream', agent_url=None,
2211
bootstrap_host=None, jes_enabled=True, keep_env=True,
2212
log_dir='qux-1', machines=[], permanent=True,
2213
region=None, series=None)
2215
def test__iter_bs_manager_steps(self):
2216
fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
2217
fake_1 = FakeAttemptClass('fake-1', '1', '2')
2218
fake_2 = FakeAttemptClass('fake-2', '1', '2')
2219
factory = AttemptSuiteFactory([fake_1, fake_2],
2220
bootstrap_attempt=fake_bootstrap)
2221
attempt_suite = AttemptSuite(factory, None, None, None)
2222
client = fake_juju_client()
2223
bs_manager = FakeBootstrapManager(client)
2224
steps = list(attempt_suite._iter_bs_manager_steps(
2225
bs_manager, client, fake_bootstrap(), True))
2227
{'test_id': 'fake-bootstrap-id'},
2228
{'test_id': 'fake-bootstrap-id', 'result': '1'},
2229
{'test_id': 'prepare-suite'},
2230
{'test_id': 'prepare-suite', 'result': True},
2231
{'test_id': 'fake-1-id'},
2232
{'test_id': 'fake-1-id', 'result': '1'},
2233
{'test_id': 'fake-2-id'},
2234
{'test_id': 'fake-2-id', 'result': '1'},
2235
{'test_id': 'destroy-env'},
2236
{'test_id': 'destroy-env', 'result': True},
2237
{'test_id': 'substrate-clean'},
2238
{'test_id': 'substrate-clean', 'result': True},
2241
def test__iter_bs_manager_steps_teardown_in_runtime(self):
2242
fake_bootstrap = FakeAttemptClass('fake-bootstrap', '1', '2')
2243
fake_1 = FakeAttemptClass('fake-1', Exception('fake exception'), '2')
2244
factory = AttemptSuiteFactory([fake_1],
2245
bootstrap_attempt=fake_bootstrap)
2246
attempt_suite = AttemptSuite(factory, None, None, None)
2247
client = fake_juju_client()
2248
bs_manager = FakeBootstrapManager(client, keep_env=True)
2249
with self.assertRaisesRegexp(Exception, 'fake exception'):
2250
list(attempt_suite._iter_bs_manager_steps(
2251
bs_manager, client, fake_bootstrap(), True))
2252
self.assertIs(True, bs_manager.torn_down)