Skip to content

Commit

Permalink
[2161] Test updates when switching ARCHIVE_NAMING_POLICY after put
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinKyleJames committed Jan 10, 2024
1 parent b265c7e commit e897d3d
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions packaging/resource_suite_s3_nocache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e897d3d

Please sign in to comment.