From b39c61f2d442c79d03b73e8ffd104996fcb2177e Mon Sep 17 00:00:00 2001 From: Mariano Lopez Date: Tue, 1 Nov 2016 07:48:16 +0000 Subject: oeqa/runtime/cases: Migrate runtime tests. This migrates current runtime test suite to be used with the new framework. [YOCTO #10234] Signed-off-by: Mariano Lopez --- meta/lib/oeqa/runtime/cases/rpm.py | 141 +++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 meta/lib/oeqa/runtime/cases/rpm.py (limited to 'meta/lib/oeqa/runtime/cases/rpm.py') diff --git a/meta/lib/oeqa/runtime/cases/rpm.py b/meta/lib/oeqa/runtime/cases/rpm.py new file mode 100644 index 0000000000..532fbf82eb --- /dev/null +++ b/meta/lib/oeqa/runtime/cases/rpm.py @@ -0,0 +1,141 @@ +import os +import fnmatch + +from oeqa.runtime.case import OERuntimeTestCase +from oeqa.core.decorator.depends import OETestDepends +from oeqa.core.decorator.oeid import OETestID +from oeqa.core.decorator.data import skipIfDataVar +from oeqa.runtime.decorator.package import OEHasPackage +from oeqa.core.utils.path import findFile + +class RpmBasicTest(OERuntimeTestCase): + + @classmethod + def setUpClass(cls): + if cls.tc.td['PACKAGE_CLASSES'].split()[0] != 'package_rpm': + cls.skipTest('Tests require image to be build from rpm') + + @OETestID(960) + @OETestDepends(['ssh.SSHTest.test_ssh']) + def test_rpm_help(self): + status, output = self.target.run('rpm --help') + msg = 'status and output: %s and %s' % (status, output) + self.assertEqual(status, 0, msg=msg) + + @OETestID(191) + @OETestDepends(['rpm.RpmBasicTest.test_rpm_help']) + def test_rpm_query(self): + status, output = self.target.run('rpm -q rpm') + msg = 'status and output: %s and %s' % (status, output) + self.assertEqual(status, 0, msg=msg) + +class RpmInstallRemoveTest(OERuntimeTestCase): + + @classmethod + def setUpClass(cls): + if cls.tc.td['PACKAGE_CLASSES'].split()[0] != 'package_rpm': + cls.skipTest('Tests require image to be build from rpm') + + pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_') + rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch) + # Pick rpm-doc as a test file to get installed, because it's small + # and it will always be built for standard targets + rpm_doc = 'rpm-doc-*.%s.rpm' % pkgarch + for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc): + test_file = os.path.join(rpmdir, f) + dst = '/tmp/rpm-doc.rpm' + cls.tc.target.copyTo(test_file, dst) + + @classmethod + def tearDownClass(cls): + dst = '/tmp/rpm-doc.rpm' + cls.tc.target.run('rm -f %s' % dst) + + @OETestID(192) + @OETestDepends(['rpm.RpmBasicTest.test_rpm_help']) + def test_rpm_install(self): + status, output = self.target.run('rpm -ivh /tmp/rpm-doc.rpm') + msg = 'Failed to install rpm-doc package: %s' % output + self.assertEqual(status, 0, msg=msg) + + @OETestID(194) + @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_install']) + def test_rpm_remove(self): + status,output = self.target.run('rpm -e rpm-doc') + msg = 'Failed to remove rpm-doc package: %s' % output + self.assertEqual(status, 0, msg=msg) + + @OETestID(1096) + @OETestDepends(['rpm.RpmBasicTest.test_rpm_query']) + def test_rpm_query_nonroot(self): + + def set_up_test_user(u): + status, output = self.target.run('id -u %s' % u) + if status: + status, output = self.target.run('useradd %s' % u) + msg = 'Failed to create new user: %s' % output + self.assertTrue(status == 0, msg=msg) + + def exec_as_test_user(u): + status, output = self.target.run('su -c id %s' % u) + msg = 'Failed to execute as new user' + self.assertTrue("({0})".format(u) in output, msg=msg) + + status, output = self.target.run('su -c "rpm -qa" %s ' % u) + msg = 'status: %s. Cannot run rpm -qa: %s' % (status, output) + self.assertEqual(status, 0, msg=msg) + + def unset_up_test_user(u): + status, output = self.target.run('userdel -r %s' % u) + msg = 'Failed to erase user: %s' % output + self.assertTrue(status == 0, msg=msg) + + tuser = 'test1' + + try: + set_up_test_user(tuser) + exec_as_test_user(tuser) + finally: + unset_up_test_user(tuser) + + @OETestID(195) + @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_remove']) + def test_check_rpm_install_removal_log_file_size(self): + """ + Summary: Check rpm install/removal log file size + Expected: There should be some method to keep rpm log in a small size . + Product: BSPs + Author: Alexandru Georgescu + AutomatedBy: Daniel Istrate + """ + db_files_cmd = 'ls /var/lib/rpm/__db.*' + get_log_size_cmd = "du /var/lib/rpm/log/log.* | awk '{print $1}'" + + # Make sure that some database files are under /var/lib/rpm as '__db.xxx' + status, output = self.target.run(db_files_cmd) + msg = 'Failed to find database files under /var/lib/rpm/ as __db.xxx' + self.assertEqual(0, status, msg=msg) + + # Remove the package just in case + self.target.run('rpm -e rpm-doc') + + # Install/Remove a package 10 times + for i in range(10): + status, output = self.target.run('rpm -ivh /tmp/rpm-doc.rpm') + msg = 'Failed to install rpm-doc package. Reason: {}'.format(output) + self.assertEqual(0, status, msg=msg) + + status, output = self.target.run('rpm -e rpm-doc') + msg = 'Failed to remove rpm-doc package. Reason: {}'.format(output) + self.assertEqual(0, status, msg=msg) + + # Get the size of log file + status, output = self.target.run(get_log_size_cmd) + msg = 'Failed to get the final size of the log file.' + self.assertEqual(0, status, msg=msg) + + # Compare each log size + for log_file_size in output: + msg = ('Log file size is greater that expected (~10MB), ' + 'found {} bytes'.format(log_file_size)) + self.assertLessEqual(int(log_file_size), 11264, msg=msg) -- cgit 1.2.3-korg