@@ -187,8 +187,7 @@ def oslogin_instance(ssh_firewall, oslogin_service_account):
187
187
188
188
yield client .get (project = PROJECT , zone = ZONE , instance = instance .name )
189
189
190
- # The deletion of the instance has been moved to the test itself.
191
- # client.delete(project=PROJECT, zone=ZONE, instance=instance.name).result()
190
+ client .delete (project = PROJECT , zone = ZONE , instance = instance .name ).result ()
192
191
193
192
194
193
def test_oslogin_ssh (oslogin_instance , oslogin_service_account , capsys ):
@@ -201,17 +200,17 @@ def test_oslogin_ssh(oslogin_instance, oslogin_service_account, capsys):
201
200
hostname = oslogin_instance .network_interfaces [0 ].access_configs [0 ].nat_i_p ,
202
201
oslogin = oslogin_client )
203
202
204
- delete_instance = True
205
-
206
203
out , _ = capsys .readouterr ()
207
204
assert_value = 'Linux {test_id}' .format (test_id = TEST_ID )
208
205
try :
209
206
assert assert_value in out
210
- except AssertionError :
211
- delete_instance = False
212
- finally :
213
- # If the assert passed, we can safely delete the instance. If it failed, we want to keep it around for
214
- # manual inspection.
215
- if delete_instance :
216
- compute_client = compute_v1 .InstancesClient ()
217
- compute_client .delete (project = PROJECT , zone = ZONE , instance = oslogin_instance .name )
207
+ except AssertionError as err :
208
+ fw_client = compute_v1 .FirewallsClient ()
209
+ try :
210
+ fw_client .get (project = PROJECT , firewall = TEST_ID )
211
+ except NotFound :
212
+ # The test probably failed due to the firewall rule being removed too soon.
213
+ pytest .skip ("The test was interrupted by removal of SSH firewall rule." )
214
+ else :
215
+ # The test failed due to some other reason.
216
+ raise err
0 commit comments