Assertion error in RootwrapTestCase.test_KillFilter within py39 / rhel9 OSP 18 job

Bug #2037383 reported by Herve Beraud
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.rootwrap
Fix Released
Undecided
Unassigned

Bug Description

we observe a failure in RPM job executed as part of Component CI for OSP 18

```
oslo_rootwrap.tests.test_rootwrap.RootwrapTestCase.test_KillFilter
------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/home/zuul/src/code.engineering.redhat.com/oslo.rootwrap/oslo_rootwrap/tests/test_rootwrap.py", line 211, in test_KillFilter
    self.assertTrue(f.match(usercmd) or f2.match(usercmd))

      File "/usr/lib64/python3.9/unittest/case.py", line 688, in assertTrue
    raise self.failureException(msg)

    AssertionError: False is not true
```

In the broken unit test described here, for the needs of the unit test, we launch the `cat` command in a python subprocess [1]. This subprocess allow us to retrieve the pid related to the `cat` command [2].
The match function of the KillFilter class is designed to see if the passed argument match the command to kill [3].

This test is based on the command related to the pid, however [4], in this case, the returned command for the pid of `cat` is `/usr/bin/coreutils`, rather than `/bin/cat` or `/usr/bin/cat` this is why the match function return false and then the test fails.

I think this is due to the way the rhel 9 containers are builts. As the call of the python os.readlink function [5] against `/proc/<pid-of-cat>/exe` return the path of the symbolic link points of the given pid, in this case it correspond to `coreutils`. This is why the string doesn't match and the test fails.

From an oslo POV the code of oslo.rootwrap looks correct, and until now it never caused us issues.

I'll check if we can extend the test case to see if I can append coreutils at the list of tested values, but I wonder why this have suddently changed.

[1] https://opendev.org/openstack/oslo.rootwrap/src/branch/master/oslo_rootwrap/tests/test_rootwrap.py#L197
[2] https://opendev.org/openstack/oslo.rootwrap/src/branch/master/oslo_rootwrap/tests/test_rootwrap.py#L209
[3] https://opendev.org/openstack/oslo.rootwrap/src/branch/master/oslo_rootwrap/filters.py#L272
[4] https://opendev.org/openstack/oslo.rootwrap/src/branch/master/oslo_rootwrap/filters.py#L211
[5] https://docs.python.org/3.9/library/os.html#os.readlink

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.rootwrap (master)
Changed in oslo.rootwrap:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.rootwrap (master)

Reviewed: https://review.opendev.org/c/openstack/oslo.rootwrap/+/896492
Committed: https://opendev.org/openstack/oslo.rootwrap/commit/43ab5ad7a7e6ad8aa17e7abe5957bfe15cc043ac
Submitter: "Zuul (22348)"
Branch: master

commit 43ab5ad7a7e6ad8aa17e7abe5957bfe15cc043ac
Author: Hervé Beraud <email address hidden>
Date: Tue Sep 26 10:18:31 2023 +0200

    Add coreutils as valid value to fix KillFilter test

    In containerized RHEL 9 environment the KillFilter test started to fail
    because `os.readlink("/proc/<pid-of-cat/exe>")` return /usr/bin/coreutils.

    Indeed cat is part of the coreutils package and the symlink of
    this file point toward coreutils. Fixing this bug by adding
    coreutils as a possible returned value for our tests.

    Closes-Bug: #2037383
    Change-Id: I141eb15efa30c7df3ca5419b594097f4b683663c

Changed in oslo.rootwrap:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.rootwrap (stable/2023.2)

Fix proposed to branch: stable/2023.2
Review: https://review.opendev.org/c/openstack/oslo.rootwrap/+/898943

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.rootwrap (stable/2023.2)

Reviewed: https://review.opendev.org/c/openstack/oslo.rootwrap/+/898943
Committed: https://opendev.org/openstack/oslo.rootwrap/commit/206151c7326cb7e1537b0e7f376bfec24845b88d
Submitter: "Zuul (22348)"
Branch: stable/2023.2

commit 206151c7326cb7e1537b0e7f376bfec24845b88d
Author: Hervé Beraud <email address hidden>
Date: Tue Sep 26 10:18:31 2023 +0200

    Add coreutils as valid value to fix KillFilter test

    In containerized RHEL 9 environment the KillFilter test started to fail
    because `os.readlink("/proc/<pid-of-cat/exe>")` return /usr/bin/coreutils.

    Indeed cat is part of the coreutils package and the symlink of
    this file point toward coreutils. Fixing this bug by adding
    coreutils as a possible returned value for our tests.

    Closes-Bug: #2037383
    Change-Id: I141eb15efa30c7df3ca5419b594097f4b683663c
    (cherry picked from commit 43ab5ad7a7e6ad8aa17e7abe5957bfe15cc043ac)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.rootwrap (stable/2023.1)

Fix proposed to branch: stable/2023.1
Review: https://review.opendev.org/c/openstack/oslo.rootwrap/+/899327

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.rootwrap (stable/2023.1)

Reviewed: https://review.opendev.org/c/openstack/oslo.rootwrap/+/899327
Committed: https://opendev.org/openstack/oslo.rootwrap/commit/b187d6b1859f00d9412ab68df1e7d642f31b3f7d
Submitter: "Zuul (22348)"
Branch: stable/2023.1

commit b187d6b1859f00d9412ab68df1e7d642f31b3f7d
Author: Hervé Beraud <email address hidden>
Date: Tue Sep 26 10:18:31 2023 +0200

    Add coreutils as valid value to fix KillFilter test

    In containerized RHEL 9 environment the KillFilter test started to fail
    because `os.readlink("/proc/<pid-of-cat/exe>")` return /usr/bin/coreutils.

    Indeed cat is part of the coreutils package and the symlink of
    this file point toward coreutils. Fixing this bug by adding
    coreutils as a possible returned value for our tests.

    Closes-Bug: #2037383
    Change-Id: I141eb15efa30c7df3ca5419b594097f4b683663c
    (cherry picked from commit 43ab5ad7a7e6ad8aa17e7abe5957bfe15cc043ac)
    (cherry picked from commit 206151c7326cb7e1537b0e7f376bfec24845b88d)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/oslo.rootwrap 7.2.0

This issue was fixed in the openstack/oslo.rootwrap 7.2.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.