diff mbox series

[7/8] oeqa/runtime/rpm: fail tests if test rpm file cannot be found

Message ID 20240126133455.2609378-7-alex@linutronix.de
State Accepted, archived
Commit 5d7a6ede105ea1efc9c324c7029f9d08dadf7255
Headers show
Series [1/8] sysroot user management postinsts: run with /bin/sh -e to report errors when they happen | expand

Commit Message

Alexander Kanavin Jan. 26, 2024, 1:34 p.m. UTC
Discovery of the test file was happening in a class initializer.
That block of code cannot fail (it's not a test), and so it
falls through to completion even if the needed file could not be found.

Then the tests themselves fail later due to class variables not
being set, but all information as to why is already lost at that point.

This converts the discovery to a helper function called from
the tests, so that the function can fail the tests precisely when the
problems occur.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 meta/lib/oeqa/runtime/cases/rpm.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Comments

Richard Purdie Jan. 26, 2024, 2:11 p.m. UTC | #1
On Fri, 2024-01-26 at 14:34 +0100, Alexander Kanavin wrote:
> Discovery of the test file was happening in a class initializer.
> That block of code cannot fail (it's not a test), and so it
> falls through to completion even if the needed file could not be found.

Is that true? I thought a failure in the setup function just caused all
the tests in that class not to run?

I've no issue with the patch itself, I just was surprised to read that.

Cheers,

Richard
Alexander Kanavin Jan. 26, 2024, 2:21 p.m. UTC | #2
On Fri, 26 Jan 2024 at 15:11, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> On Fri, 2024-01-26 at 14:34 +0100, Alexander Kanavin wrote:
> > Discovery of the test file was happening in a class initializer.
> > That block of code cannot fail (it's not a test), and so it
> > falls through to completion even if the needed file could not be found.
>
> Is that true? I thought a failure in the setup function just caused all
> the tests in that class not to run?

I think I didn't formulate it well enough. The rpm test initalizer was
written in a way that it would never fail, even if the needed rpm file
actually could not be discovered and the variable for it (used by test
cases) would remain None.

The reason for it being that way is that the initializer runs even
when the build is not-rpm based (e.g. ipk/deb only), and there's no
way at that point to detect absence of rpm and skip the whole class
(various decorators can be attached to test cases only).

Alex
diff mbox series

Patch

diff --git a/meta/lib/oeqa/runtime/cases/rpm.py b/meta/lib/oeqa/runtime/cases/rpm.py
index a4ba4e67698..ea5619ffea4 100644
--- a/meta/lib/oeqa/runtime/cases/rpm.py
+++ b/meta/lib/oeqa/runtime/cases/rpm.py
@@ -80,21 +80,24 @@  class RpmBasicTest(OERuntimeTestCase):
 
 class RpmInstallRemoveTest(OERuntimeTestCase):
 
-    @classmethod
-    def setUpClass(cls):
-        pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_')
-        rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch)
+    def _find_test_file(self):
+        pkgarch = self.td['TUNE_PKGARCH'].replace('-', '_')
+        rpmdir = os.path.join(self.tc.td['DEPLOY_DIR'], 'rpm', pkgarch)
         # Pick base-passwd-doc as a test file to get installed, because it's small
         # and it will always be built for standard targets
         rpm_doc = 'base-passwd-doc-*.%s.rpm' % pkgarch
         if not os.path.exists(rpmdir):
-            return
+            self.fail("Rpm directory {} does not exist".format(rpmdir))
         for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc):
-            cls.test_file = os.path.join(rpmdir, f)
-        cls.dst = '/tmp/base-passwd-doc.rpm'
+            self.test_file = os.path.join(rpmdir, f)
+            break
+        else:
+            self.fail("Couldn't find the test rpm file {} in {}".format(rpm_doc, rpmdir))
+        self.dst = '/tmp/base-passwd-doc.rpm'
 
     @OETestDepends(['rpm.RpmBasicTest.test_rpm_query'])
     def test_rpm_install(self):
+        self._find_test_file()
         self.tc.target.copyTo(self.test_file, self.dst)
         status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm')
         msg = 'Failed to install base-passwd-doc package: %s' % output
@@ -117,6 +120,7 @@  class RpmInstallRemoveTest(OERuntimeTestCase):
         Author:      Alexander Kanavin <alex.kanavin@gmail.com>
         AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
         """
+        self._find_test_file()
         db_files_cmd = 'ls /var/lib/rpm/rpmdb.sqlite*'
         check_log_cmd = "grep RPM /var/log/messages | wc -l"