@@ -286,21 +286,33 @@ class CopyEBSSnapshotToS3E2ETest(unittest.TestCase):
286286 guidelines in https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html # pylint: disable=line-too-long
287287 """
288288
289- @classmethod
289+ expected_filenames = ['image.bin' , 'log.txt' , 'hlog.txt' , 'mlog.txt' ,
290+ 'instance_copy_stdout.txt' , 'instance_copy_stderr.txt' ]
291+
290292 @typing .no_type_check
291293 @IgnoreWarnings
292- def setUpClass ( cls ):
294+ def setUp ( self ):
293295 try :
294296 project_info = utils .ReadProjectInfo (
295297 ['s3_destination' , 'zone' , 'snapshot_id' ])
296298 except (OSError , RuntimeError , ValueError ) as exception :
297299 raise unittest .SkipTest (str (exception ))
298- cls .zone = project_info ['zone' ]
299- cls .aws = account .AWSAccount (cls .zone )
300- cls .subnet_id = project_info .get ('subnet_id' , None )
301- cls .security_group_id = project_info .get ('security_group_id' , None )
302- cls .s3_destination = project_info .get ('s3_destination' , None )
303- cls .snapshot_id = project_info .get ('snapshot_id' , None )
300+ self .zone = project_info ['zone' ]
301+ self .aws_account : account .AWSAccount = account .AWSAccount (self .zone )
302+ self .subnet_id = project_info .get ('subnet_id' , None )
303+ self .security_group_id = project_info .get ('security_group_id' , None )
304+ self .s3_destination = project_info .get ('s3_destination' , None )
305+ self .snapshot_id = project_info .get ('snapshot_id' , None )
306+
307+ if not self .s3_destination .startswith ('s3://' ):
308+ self .s3_destination = 's3://' + self .s3_destination
309+ path_components = SplitStoragePath (self .s3_destination )
310+ self .bucket : str = path_components [0 ]
311+ self .object_path : str = path_components [1 ]
312+ self .directory : str = '{0:s}/{1:s}/' .format (
313+ self .object_path , self .snapshot_id )
314+
315+ super ().setUp ()
304316
305317 @typing .no_type_check
306318 @IgnoreWarnings
@@ -309,13 +321,6 @@ def testCopyEBSSnapshotToS3(self):
309321
310322 Test copying an EBS snapshot into S3.
311323 """
312-
313- if not self .s3_destination .startswith ('s3://' ):
314- self .s3_destination = 's3://' + self .s3_destination
315- path_components = SplitStoragePath (self .s3_destination )
316- bucket = path_components [0 ]
317- object_path = path_components [1 ]
318-
319324 forensics .CopyEBSSnapshotToS3 (
320325 self .s3_destination ,
321326 self .snapshot_id ,
@@ -325,22 +330,19 @@ def testCopyEBSSnapshotToS3(self):
325330 security_group_id = self .security_group_id ,
326331 cleanup_iam = True )
327332
328- aws_account = account .AWSAccount (self .zone )
329- directory = '{0:s}/{1:s}/' .format (object_path , self .snapshot_id )
330- self .assertEqual (
331- aws_account .s3 .CheckForObject (bucket , directory + 'image.bin' ), True )
332- self .assertEqual (
333- aws_account .s3 .CheckForObject (bucket , directory + 'log.txt' ), True )
334- self .assertEqual (
335- aws_account .s3 .CheckForObject (bucket , directory + 'hlog.txt' ), True )
336- self .assertEqual (
337- aws_account .s3 .CheckForObject (bucket , directory + 'mlog.txt' ), True )
338-
339- # Cleanup
340- aws_account .s3 .RmObject (bucket , directory + 'image.bin' )
341- aws_account .s3 .RmObject (bucket , directory + 'log.txt' )
342- aws_account .s3 .RmObject (bucket , directory + 'hlog.txt' )
343- aws_account .s3 .RmObject (bucket , directory + 'mlog.txt' )
333+ for file in self .expected_filenames :
334+ self .assertTrue (self .aws_account .s3 .CheckForObject (
335+ self .bucket , self .directory + file ))
336+
337+ def tearDown (self ) -> None :
338+ """Remove the created resources."""
339+ for file in self .expected_filenames :
340+ try :
341+ self .aws_account .s3 .RmObject (
342+ self .bucket , self .directory + file )
343+ except Exception as error : # pylint: disable=broad-exception-caught
344+ logger .exception (
345+ 'Error cleaning up %s: {%s}' , file , str (error ), exc_info = True )
344346
345347
346348class S3EndToEndTest (unittest .TestCase ):
0 commit comments