Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import unittest |
| 2 | import os |
| 3 | import fnmatch |
| 4 | from oeqa.oetest import oeRuntimeTest, skipModule |
| 5 | from oeqa.utils.decorators import * |
| 6 | |
| 7 | def setUpModule(): |
| 8 | if not oeRuntimeTest.hasFeature("package-management"): |
| 9 | skipModule("rpm module skipped: target doesn't have package-management in IMAGE_FEATURES") |
| 10 | if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES", True).split()[0]: |
| 11 | skipModule("rpm module skipped: target doesn't have rpm as primary package manager") |
| 12 | |
| 13 | |
| 14 | class RpmBasicTest(oeRuntimeTest): |
| 15 | |
| 16 | @testcase(960) |
| 17 | @skipUnlessPassed('test_ssh') |
| 18 | def test_rpm_help(self): |
| 19 | (status, output) = self.target.run('rpm --help') |
| 20 | self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output)) |
| 21 | |
| 22 | @testcase(191) |
| 23 | @skipUnlessPassed('test_rpm_help') |
| 24 | def test_rpm_query(self): |
| 25 | (status, output) = self.target.run('rpm -q rpm') |
| 26 | self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output)) |
| 27 | |
| 28 | class RpmInstallRemoveTest(oeRuntimeTest): |
| 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(self): |
| 32 | pkgarch = oeRuntimeTest.tc.d.getVar('TUNE_PKGARCH', True).replace("-", "_") |
| 33 | rpmdir = os.path.join(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR', True), "rpm", pkgarch) |
| 34 | # pick rpm-doc as a test file to get installed, because it's small and it will always be built for standard targets |
| 35 | for f in fnmatch.filter(os.listdir(rpmdir), "rpm-doc-*.%s.rpm" % pkgarch): |
| 36 | testrpmfile = f |
| 37 | oeRuntimeTest.tc.target.copy_to(os.path.join(rpmdir,testrpmfile), "/tmp/rpm-doc.rpm") |
| 38 | |
| 39 | @testcase(192) |
| 40 | @skipUnlessPassed('test_rpm_help') |
| 41 | def test_rpm_install(self): |
| 42 | (status, output) = self.target.run('rpm -ivh /tmp/rpm-doc.rpm') |
| 43 | self.assertEqual(status, 0, msg="Failed to install rpm-doc package: %s" % output) |
| 44 | |
| 45 | @testcase(194) |
| 46 | @skipUnlessPassed('test_rpm_install') |
| 47 | def test_rpm_remove(self): |
| 48 | (status,output) = self.target.run('rpm -e rpm-doc') |
| 49 | self.assertEqual(status, 0, msg="Failed to remove rpm-doc package: %s" % output) |
| 50 | |
| 51 | @testcase(1096) |
| 52 | @skipUnlessPassed('test_ssh') |
| 53 | def test_rpm_query_nonroot(self): |
| 54 | (status, output) = self.target.run('useradd test1') |
| 55 | self.assertTrue(status == 0, msg="Failed to create new user") |
| 56 | (status, output) = self.target.run('sudo -u test1 id') |
| 57 | self.assertTrue('(test1)' in output, msg="Failed to execute as new user") |
| 58 | (status, output) = self.target.run('sudo -u test1 rpm -qa') |
| 59 | self.assertEqual(status, 0, msg="status: %s. Cannot run rpm -qa" % status) |
| 60 | |
| 61 | @testcase(195) |
| 62 | @skipUnlessPassed('test_rpm_install') |
| 63 | def test_check_rpm_install_removal_log_file_size(self): |
| 64 | """ |
| 65 | Summary: Check rpm install/removal log file size |
| 66 | Expected: There should be some method to keep rpm log in a small size . |
| 67 | Product: BSPs |
| 68 | Author: Alexandru Georgescu <alexandru.c.georgescu@intel.com> |
| 69 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 70 | """ |
| 71 | db_files_cmd = 'ls /var/lib/rpm/__db.*' |
| 72 | get_log_size_cmd = "du /var/lib/rpm/log/log.* | awk '{print $1}'" |
| 73 | |
| 74 | # Make sure that some database files are under /var/lib/rpm as '__db.xxx' |
| 75 | (status, output) = self.target.run(db_files_cmd) |
| 76 | self.assertEqual(0, status, 'Failed to find database files under /var/lib/rpm/ as __db.xxx') |
| 77 | |
| 78 | # Remove the package just in case |
| 79 | self.target.run('rpm -e rpm-doc') |
| 80 | |
| 81 | # Install/Remove a package 10 times |
| 82 | for i in range(10): |
| 83 | (status, output) = self.target.run('rpm -ivh /tmp/rpm-doc.rpm') |
| 84 | self.assertEqual(0, status, "Failed to install rpm-doc package. Reason: {}".format(output)) |
| 85 | |
| 86 | (status, output) = self.target.run('rpm -e rpm-doc') |
| 87 | self.assertEqual(0, status, "Failed to remove rpm-doc package. Reason: {}".format(output)) |
| 88 | |
| 89 | # Get the size of log file |
| 90 | (status, output) = self.target.run(get_log_size_cmd) |
| 91 | self.assertEqual(0, status, 'Failed to get the final size of the log file.') |
| 92 | |
| 93 | # Compare each log size |
| 94 | for log_file_size in output: |
| 95 | self.assertLessEqual(int(log_file_size), 11264, |
| 96 | 'Log file size is greater that expected (~10MB), found {} bytes'.format(log_file_size)) |
| 97 | |
| 98 | @classmethod |
| 99 | def tearDownClass(self): |
| 100 | oeRuntimeTest.tc.target.run('rm -f /tmp/rpm-doc.rpm') |
| 101 | |