Skip to content

[tests] Add permissions tests#4302

Open
tiredPotato wants to merge 2 commits into
sosreport:mainfrom
tiredPotato:permissions_tests
Open

[tests] Add permissions tests#4302
tiredPotato wants to merge 2 commits into
sosreport:mainfrom
tiredPotato:permissions_tests

Conversation

@tiredPotato

Copy link
Copy Markdown
Contributor

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

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname email@example.com?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?
  • Are all passwords or private data gathered by this PR obfuscated?

@packit-as-a-service

Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/sosreport-sos-4302
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@jcastill jcastill added the Kind/Testing Related to Testing label Apr 20, 2026
Comment thread tests/report_tests/permissions_tests/permissions.py Outdated
@tiredPotato tiredPotato requested a review from pmoravec May 13, 2026 09:14
@pmoravec

Copy link
Copy Markdown
Contributor

Originally I thought an easier approach would be having the files like /etc/no_perms_file.conf directly in sos/tests, like sos/tests/unittests/path/to/leaf, and dont bother by creating and chmod-ing them in the code.

But since we need to test file permissions and can't rely on umask or manual changes done on the system where avocado is run, the current approach is safer.

Let me review the particular code..

Comment on lines +42 to +43
test_file1 = '/etc/no_perms_file.conf'
test_file2 = '/var/log/some_perms_file.log'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +54 to +70
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)}"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Comment on lines +91 to +94
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

@pmoravec pmoravec May 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth using test_root as well (ditto 'touch {test_file1}' above)?

Same applies to further filepaths.

@tiredPotato tiredPotato force-pushed the permissions_tests branch 2 times, most recently from b8e8bb4 to 93b51e4 Compare June 11, 2026 10:30
@jcastill

Copy link
Copy Markdown
Member

@tiredPotato make sure you sync your branch to get the latest commits.
I'm checking the four test errors in cs10:

 (060/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:FilePermissionsPreserved.test_archive_created:  ERROR: stat: path should be string, bytes, os.PathLike or integer, not NoneType (0.02 s)

 (062/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_nested_dir_permissions_preserved:  ERROR: expected str, bytes or os.PathLike object, not NoneType (0.04 s)

 (063/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_deep_nested_dir_permissions_preserved:  ERROR: expected str, bytes or os.PathLike object, not NoneType (0.04 s)

 (064/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_archive_created:  ERROR: stat: path should be string, bytes, os.PathLike or integer, not NoneType (0.02 s)

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.

@tiredPotato

tiredPotato commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@tiredPotato make sure you sync your branch to get the latest commits. I'm checking the four test errors in cs10:

 (060/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:FilePermissionsPreserved.test_archive_created:  ERROR: stat: path should be string, bytes, os.PathLike or integer, not NoneType (0.02 s)

 (062/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_nested_dir_permissions_preserved:  ERROR: expected str, bytes or os.PathLike object, not NoneType (0.04 s)

 (063/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_deep_nested_dir_permissions_preserved:  ERROR: expected str, bytes or os.PathLike object, not NoneType (0.04 s)

 (064/132) /__w/sos/sos/sos/tests/report_tests/permissions_tests/permissions_test.py:DirectoryPermissionsPreserved.test_archive_created:  ERROR: stat: path should be string, bytes, os.PathLike or integer, not NoneType (0.02 s)

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.

@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>
@tiredPotato

Copy link
Copy Markdown
Contributor Author

I found this in logs:
stderr: b'tar (child): xz: Cannot exec: No such file or directory\ntar (child): Error is not recoverable: exiting now\ntar: Child returned status 2\ntar: Error is not recoverable: exiting now\n'
so it seems xz is just not installed on the CI runner. I've pushed a workaround which uses the python libraries instead.

@tiredPotato tiredPotato requested review from jcastill and pmoravec June 12, 2026 12:54
@pmoravec

Copy link
Copy Markdown
Contributor

I found this in logs: stderr: b'tar (child): xz: Cannot exec: No such file or directory\ntar (child): Error is not recoverable: exiting now\ntar: Child returned status 2\ntar: Error is not recoverable: exiting now\n' so it seems xz is just not installed on the CI runner. I've pushed a workaround which uses the python libraries instead.

Good catch! Does it make sense to add xz installed by default, e.g. inside the @arif-ali's changes in #4345 ?

(pros: we wont fall into this trap the next time. negs: in 99% cases, xz will be installed redundantly. I am bit inclined to to decline my own idea..)

Comment on lines +19 to +21
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@pmoravec pmoravec added Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer Status/Needs Review This issue still needs a review from project members labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kind/Testing Related to Testing Reviewed/Needs 2nd Ack Require a 2nd ack from a maintainer Status/Needs Review This issue still needs a review from project members

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants