]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
oeqa: runtime: logrotate: Remove setup and tear down methods
authorMathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Thu, 9 Oct 2025 13:15:57 +0000 (15:15 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 27 Oct 2025 16:58:15 +0000 (16:58 +0000)
Setup and tear down methods are executed even when the tests are disabled.
This lead to SSH being used to run commands on the target, and as it
might fail when no SSH server is present, we had to use
ignore_ssh_fails=True here.

Instead, run cleanup tasks in tests themselves and remove the tear down
method.

Also, the wtmp configuration file is not modified since the test was
modified a few years ago: there is no need to backup and restore it.

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
meta/lib/oeqa/runtime/cases/logrotate.py

index 0d4b9ac60baaf1c5bc88e1c75551b284d7c37467..9fe1170226c816a915822cb83b21ff98337f380c 100644 (file)
@@ -12,17 +12,6 @@ from oeqa.core.decorator.depends import OETestDepends
 from oeqa.runtime.decorator.package import OEHasPackage
 
 class LogrotateTest(OERuntimeTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        cls.tc.target.run('cp /etc/logrotate.d/wtmp $HOME/wtmp.oeqabak',
-                          ignore_ssh_fails=True)
-
-    @classmethod
-    def tearDownClass(cls):
-        cls.tc.target.run('mv -f $HOME/wtmp.oeqabak /etc/logrotate.d/wtmp && rm -rf /var/log/logrotate_dir', ignore_ssh_fails=True)
-        cls.tc.target.run('rm -rf /var/log/logrotate_testfile && rm -rf /etc/logrotate.d/logrotate_testfile', ignore_ssh_fails=True)
-
     @OETestDepends(['ssh.SSHTest.test_ssh'])
     @OEHasPackage(['logrotate'])
     def test_logrotate_wtmp(self):
@@ -33,6 +22,7 @@ class LogrotateTest(OERuntimeTestCase):
 
         # Create a folder to store rotated file and add the corresponding
         # configuration option
+        self.addCleanup(self.target.run, 'rm -rf /var/log/logrotate_dir')
         status, output = self.target.run('mkdir /var/log/logrotate_dir')
         msg = ('Could not create logrotate_dir. Output: %s' % output)
         self.assertEqual(status, 0, msg = msg)
@@ -55,10 +45,17 @@ class LogrotateTest(OERuntimeTestCase):
         self.assertEqual(status, 0, msg = msg)
 
         # Create a new configuration file dedicated to a /var/log/logrotate_testfile
+        self.addCleanup(self.target.run, 'rm -f /var/log/logrotate_testfile')
         status, output = self.target.run('echo "/var/log/logrotate_testfile {\n missingok \n monthly \n rotate 1}" > /etc/logrotate.d/logrotate_testfile')
         msg = ('Could not write to /etc/logrotate.d/logrotate_testfile')
         self.assertEqual(status, 0, msg = msg)
 
+        self.addCleanup(self.target.run, 'rm -rf /var/log/logrotate_dir')
+        status, output = self.target.run('mkdir /var/log/logrotate_dir')
+        msg = ('Could not create logrotate_dir. Output: %s' % output)
+        self.assertEqual(status, 0, msg = msg)
+
+        self.addCleanup(self.target.run, 'rm -f /etc/logrotate.d/logrotate_testfile')
         status, output = self.target.run('echo "create \n olddir /var/log/logrotate_dir \n include /etc/logrotate.d/logrotate_testfile" > /tmp/logrotate-test2.conf')
         msg = ('Could not write to /tmp/logrotate_test2.conf')
         self.assertEqual(status, 0, msg = msg)