diff --git a/packaging/resource_suite_s3_nocache.py b/packaging/resource_suite_s3_nocache.py index 873c960..81205d2 100644 --- a/packaging/resource_suite_s3_nocache.py +++ b/packaging/resource_suite_s3_nocache.py @@ -2903,3 +2903,121 @@ def test_decoupled_redirect_issue_2146(self): self.admin.assert_icommand("iadmin rmresc %s" % resource_name) s3plugin_lib.remove_if_exists(file1) s3plugin_lib.remove_if_exists(retrieved_file) + + # This verifies that once the file is written to the DB, whatever mode was used remains in effect as the DB always wins. + def test_resource_updated_from_consistent_to_decoupled_issue_2161(self): + + file1 = "f1" + file1_size = 2*1024 + file2 = "f2" + file2_size = 3*1024 + retrieved_file = 'f.get' + hostname = lib.get_hostname() + resource_name = "s3_resc" + + s3_context_consistent = self.s3_context.replace('ARCHIVE_NAMING_POLICY=decoupled', 'ARCHIVE_NAMING_POLICY=consistent') + s3_context_decoupled = self.s3_context + + # create the S3 resource + self.admin.assert_icommand(f'iadmin mkresc {resource_name} s3 {hostname}:/{self.s3bucketname}/{resource_name} {s3_context_consistent}', 'STDOUT_SINGLELINE', 's3') + + try: + # create file1 and file2 + lib.make_arbitrary_file(file1, file1_size) + lib.make_arbitrary_file(file2, file2_size) + + # put file1 + self.user1.assert_icommand(f'iput -R {resource_name} {file1}') + + # get and verify the file contents + self.user1.assert_icommand(f'iget {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file1, retrieved_file)) # confirm retrieved is correct + + # verify in the physical path that consistent mode was used + print(self.user1.run_icommand(['ils', '-l', file1])[0]) # just debug + self.user1.assert_icommand(f'ils -L {file1}', 'STDOUT_SINGLELINE', f'/{self.s3bucketname}/{resource_name}/home/.+/{file1}', use_regex=True) + + # update the resource to decoupled mode + self.admin.run_icommand(f'iadmin modresc {resource_name} context {s3_context_decoupled}') + + # get and verify the file contents + self.user1.assert_icommand(f'iget -f {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file1, retrieved_file)) # confirm retrieved is correct with file1 + + # overwrite file1 with file2 + self.user1.assert_icommand(f'iput -f -R {resource_name} {file2} {file1}') + + # verify the path remains in consistent mode (DB rules) + print(self.user1.run_icommand(['ils', '-l', file1])[0]) # just debug + self.user1.assert_icommand(f'ils -L {file1}', 'STDOUT_SINGLELINE', f'/{self.s3bucketname}/{resource_name}/home/.+/{file1}', use_regex=True) + + # get and verify the file contents + self.user1.assert_icommand(f'iget -f {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file2, retrieved_file)) # confirm retrieved is correct with file2 + + finally: + # cleanup + self.user1.assert_icommand("irm -f %s" % file1) # irm + self.admin.assert_icommand("iadmin rmresc %s" % resource_name) + s3plugin_lib.remove_if_exists(file1) + s3plugin_lib.remove_if_exists(file2) + s3plugin_lib.remove_if_exists(retrieved_file) + + # This verifies that once the file is written to the DB, whatever mode was used remains in effect as the DB always wins. + def test_resource_updated_from_decoupled_to_consistent_issue_2161(self): + + file1 = "f1" + file1_size = 2*1024 + file2 = "f2" + file2_size = 3*1024 + retrieved_file = 'f.get' + hostname = lib.get_hostname() + resource_name = "s3_resc" + + s3_context_consistent = self.s3_context.replace('ARCHIVE_NAMING_POLICY=decoupled', 'ARCHIVE_NAMING_POLICY=consistent') + s3_context_decoupled = self.s3_context + + # create the S3 resource + self.admin.assert_icommand(f'iadmin mkresc {resource_name} s3 {hostname}:/{self.s3bucketname}/{resource_name} {s3_context_decoupled}', 'STDOUT_SINGLELINE', 's3') + + try: + # create file1 and file2 + lib.make_arbitrary_file(file1, file1_size) + lib.make_arbitrary_file(file2, file2_size) + + # put file1 + self.user1.assert_icommand(f'iput -R {resource_name} {file1}') + + # get and verify the file contents + self.user1.assert_icommand(f'iget {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file1, retrieved_file)) # confirm retrieved is correct + + # verify in the physical path that decoupled mode was used + print(self.user1.run_icommand(['ils', '-l', file1])[0]) # just debug + self.user1.assert_icommand(f'ils -L {file1}', 'STDOUT_SINGLELINE', f'/{self.s3bucketname}/[0-9]+/{file1}', use_regex=True) + + # update the resource to consistent mode + self.admin.run_icommand(f'iadmin modresc {resource_name} context {s3_context_consistent}') + + # get and verify the file contents + self.user1.assert_icommand(f'iget -f {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file1, retrieved_file)) # confirm retrieved is correct with file1 + + # overwrite file1 with file2 + self.user1.assert_icommand(f'iput -f -R {resource_name} {file2} {file1}') + + # verify the path remains in decoupled mode (DB rules) + print(self.user1.run_icommand(['ils', '-l', file1])[0]) # just debug + self.user1.assert_icommand(f'ils -L {file1}', 'STDOUT_SINGLELINE', f'/{self.s3bucketname}/[0-9]+/{file1}', use_regex=True) + + # get and verify the file contents + self.user1.assert_icommand(f'iget -f {file1} {retrieved_file}') + self.assertTrue(filecmp.cmp(file2, retrieved_file)) # confirm retrieved is correct with file2 + + finally: + # cleanup + self.user1.assert_icommand("irm -f %s" % file1) # irm + self.admin.assert_icommand("iadmin rmresc %s" % resource_name) + s3plugin_lib.remove_if_exists(file1) + s3plugin_lib.remove_if_exists(file2) + s3plugin_lib.remove_if_exists(retrieved_file)