[tests] Add permissions tests#4302
Conversation
|
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
3869bdb to
25e6439
Compare
|
Originally I thought an easier approach would be having the files like But since we need to test file permissions and can't rely on Let me review the particular code.. |
| test_file1 = '/etc/no_perms_file.conf' | ||
| test_file2 = '/var/log/some_perms_file.log' |
There was a problem hiding this comment.
Worth using more relevant names like noperms_file or someperms_file (or no_perms_file and some_perms_file)?
| test_file2 = '/var/log/some_perms_file.log' | ||
|
|
||
| def pre_sos_setup(self): | ||
| process.run('touch /etc/no_perms_file.conf') |
There was a problem hiding this comment.
Worth using the variable here, i.e. process.run(f'touch {test_file1}') (depends on variable renaming). If you change the filename, no need to replace the code on multiple places.
This applies to other filenames as well.
| extracted_permissions = stat.S_IMODE( | ||
| os.lstat(extracted_file).st_mode) | ||
| self.assertEqual( | ||
| extracted_permissions, 0o000, | ||
| f"Permissions not preserved: expected 0o000, " | ||
| f"got {oct(extracted_permissions)}" | ||
| ) | ||
|
|
||
| self.assertFileCollected(self.test_file2) | ||
| extracted_file = self.get_name_in_archive(self.test_file2) | ||
| extracted_permissions = stat.S_IMODE( | ||
| os.lstat(extracted_file).st_mode) | ||
| self.assertEqual( | ||
| extracted_permissions, 0o666, | ||
| f"Permissions not preserved: expected 0o666, " | ||
| f"got {oct(extracted_permissions)}" | ||
| ) |
There was a problem hiding this comment.
Rather than copy&pasting the code, isnt it better to have:
for fname, mode in [(self.test_file1, 0o000), (self.test_file2, 0o666)]:
assert file collected
extract file
assert permissions
? Iterating over just 2 tuples is a border case, you make the code shorter and prone to copy&paste error, but add some complexity as well..
| os.mkdir(self.test_root) | ||
| os.mkdir(f'{self.test_root}/d1') | ||
| os.mkdir(f'{self.test_root}/d1/d2') | ||
| os.mkdir(f'{self.test_root}/d1/d2/d3') |
There was a problem hiding this comment.
os.makedirs(f'{self.test_root}/d1/d2/d3', exist_ok=True) is elegant one-liner for the same ;-)
|
|
||
| def test_top_dir_permissions_preserved(self): | ||
| extracted_file = self.get_name_in_archive( | ||
| '/var/tmp/permissions-test/d1') |
There was a problem hiding this comment.
Worth using test_root as well (ditto 'touch {test_file1}' above)?
Same applies to further filepaths.
b8e8bb4 to
93b51e4
Compare
|
@tiredPotato make sure you sync your branch to get the latest commits. So far I haven't been able to reproduce locally, but I'm wondering it the failure is a result of a race condition with the tar xf command. |
93b51e4 to
638bb0d
Compare
@jcastill No change. I couldn't reproduce it either. |
Signed-off-by: Adriana Jurkechova <ajurkech@redhat.com>
Signed-off-by: Adriana Jurkechova <ajurkech@redhat.com>
638bb0d to
165617e
Compare
|
I found this in logs: |
Good catch! Does it make sense to add (pros: we wont fall into this trap the next time. negs: in 99% cases, |
| self.add_copy_spec('/etc/no_perms_file.conf') | ||
| self.add_copy_spec('/var/log/some_perms_file.log') | ||
| self.add_copy_spec('/var/tmp/permissions-test') |
There was a problem hiding this comment.
Very nitpick: You can have one call:
self.add_copy_spec([
'/etc/no_perms_file.conf',
'/var/log/some_perms_file.log',
'/var/tmp/permissions-test'
])
(if this is the only feedback, let ignore it)
Adding tests for preserving file and directory permissions. And renaming symlinks_tests for consistency.
Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines