@@ -327,30 +327,29 @@ def wait_for_network(container, timeout=30):
327327 # and pylxd's container.execute seems to be broken and fails and/or
328328 # hangs trying to properly check if the service is up.
329329 time .sleep (5 )
330-
330+ spec = 'ssh:{}@{}:{}' .format (
331+ test_user ,
332+ host ['address' ],
333+ private_key_path ,
334+ )
335+ err = None
331336 for attempt in range (1 , 4 ):
332337 try :
333338 # add a new manual machine
334- machine1 = await model .add_machine (spec = 'ssh:{}@{}:{}' .format (
335- test_user ,
336- host ['address' ],
337- private_key_path ,
338- ))
339- except paramiko .ssh_exception .NoValidConnectionsError :
339+ machine1 = await model .add_machine (spec = spec )
340+ except (paramiko .ssh_exception .NoValidConnectionsError , paramiko .ssh_exception .AuthenticationException ) as e :
340341 # retry the ssh connection a few times if it fails
342+ err = e
341343 time .sleep (attempt * 5 )
342344 else :
345+ # try part finished without exception, breaking
343346 break
344- else :
345- # this else will only run when for finishes without a
346- # break (meaning it kept erroring)
347- raise Exception ('Unable to add_machine' )
348347
349- assert len (model .machines ) == 1
348+ assert len (model .machines ) == 1 , 'Unable to add_machine in %s attempts with spec : %s -- exception was %s' % ( attempt , spec , err )
350349
351350 res = await machine1 .destroy (force = True )
352351
353- assert res is None
352+ assert res is None , 'Bad teardown, res is : %s' % res
354353 assert len (model .machines ) == 0
355354
356355 container .stop (wait = True )
@@ -445,31 +444,29 @@ def wait_for_network(container, timeout=30):
445444 # and pylxd's container.execute seems to be broken and fails and/or
446445 # hangs trying to properly check if the service is up.
447446 time .sleep (5 )
448-
447+ spec = 'ssh:{}@{}:{}' .format (
448+ "root" ,
449+ host ['address' ],
450+ private_key_path ,
451+ )
452+ err = None
449453 for attempt in range (1 , 4 ):
450454 try :
451455 # add a new manual machine
452- machine1 = await model .add_machine (spec = 'ssh:{}@{}:{}' .format (
453- "root" ,
454- host ['address' ],
455- private_key_path ,
456- ))
457- except (paramiko .ssh_exception .NoValidConnectionsError , paramiko .ssh_exception .AuthenticationException ):
456+ machine1 = await model .add_machine (spec = spec )
457+ except (paramiko .ssh_exception .NoValidConnectionsError , paramiko .ssh_exception .AuthenticationException ) as e :
458458 # if we get an exception, try again
459+ err = e
459460 time .sleep (attempt * 5 )
460461 else :
461462 # try part finished without exception
462463 break
463- else :
464- # this else will only run when for finishes without a
465- # break (meaning it kept erroring)
466- raise Exception ('Unable to add_machine' )
467464
468- assert len (model .machines ) == 1
465+ assert len (model .machines ) == 1 , 'Unable to add_machine in %s attempts with spec : %s -- exception was %s' % ( attempt , spec , err )
469466
470467 res = await machine1 .destroy (force = True )
471468
472- assert res is None
469+ assert res is None , 'Bad teardown, res is : %s' % res
473470 assert len (model .machines ) == 0
474471
475472 container .stop (wait = True )
0 commit comments