Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | import os |
| 2 | import fnmatch |
| 3 | |
| 4 | from oeqa.runtime.case import OERuntimeTestCase |
| 5 | from oeqa.core.decorator.depends import OETestDepends |
| 6 | from oeqa.core.decorator.oeid import OETestID |
| 7 | from oeqa.core.decorator.data import skipIfDataVar |
| 8 | from oeqa.runtime.decorator.package import OEHasPackage |
| 9 | from oeqa.core.utils.path import findFile |
| 10 | |
| 11 | class RpmBasicTest(OERuntimeTestCase): |
| 12 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | @OETestID(960) |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 14 | @OEHasPackage(['rpm']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 16 | def test_rpm_help(self): |
| 17 | status, output = self.target.run('rpm --help') |
| 18 | msg = 'status and output: %s and %s' % (status, output) |
| 19 | self.assertEqual(status, 0, msg=msg) |
| 20 | |
| 21 | @OETestID(191) |
| 22 | @OETestDepends(['rpm.RpmBasicTest.test_rpm_help']) |
| 23 | def test_rpm_query(self): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 24 | status, output = self.target.run('ls /var/lib/rpm/') |
| 25 | if status != 0: |
| 26 | self.skipTest('No /var/lib/rpm on target') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | status, output = self.target.run('rpm -q rpm') |
| 28 | msg = 'status and output: %s and %s' % (status, output) |
| 29 | self.assertEqual(status, 0, msg=msg) |
| 30 | |
| 31 | class RpmInstallRemoveTest(OERuntimeTestCase): |
| 32 | |
| 33 | @classmethod |
| 34 | def setUpClass(cls): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_') |
| 36 | rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 37 | # Pick base-passwd-doc as a test file to get installed, because it's small |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | # and it will always be built for standard targets |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 39 | rpm_doc = 'base-passwd-doc-*.%s.rpm' % pkgarch |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 40 | if not os.path.exists(rpmdir): |
| 41 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 43 | cls.test_file = os.path.join(rpmdir, f) |
| 44 | cls.dst = '/tmp/base-passwd-doc.rpm' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | |
| 46 | @OETestID(192) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 47 | @OETestDepends(['rpm.RpmBasicTest.test_rpm_query']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | def test_rpm_install(self): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 49 | self.tc.target.copyTo(self.test_file, self.dst) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 50 | status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm') |
| 51 | msg = 'Failed to install base-passwd-doc package: %s' % output |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | self.assertEqual(status, 0, msg=msg) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 53 | self.tc.target.run('rm -f %s' % self.dst) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | |
| 55 | @OETestID(194) |
| 56 | @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_install']) |
| 57 | def test_rpm_remove(self): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 58 | status,output = self.target.run('rpm -e base-passwd-doc') |
| 59 | msg = 'Failed to remove base-passwd-doc package: %s' % output |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | self.assertEqual(status, 0, msg=msg) |
| 61 | |
| 62 | @OETestID(1096) |
| 63 | @OETestDepends(['rpm.RpmBasicTest.test_rpm_query']) |
| 64 | def test_rpm_query_nonroot(self): |
| 65 | |
| 66 | def set_up_test_user(u): |
| 67 | status, output = self.target.run('id -u %s' % u) |
| 68 | if status: |
| 69 | status, output = self.target.run('useradd %s' % u) |
| 70 | msg = 'Failed to create new user: %s' % output |
| 71 | self.assertTrue(status == 0, msg=msg) |
| 72 | |
| 73 | def exec_as_test_user(u): |
| 74 | status, output = self.target.run('su -c id %s' % u) |
| 75 | msg = 'Failed to execute as new user' |
| 76 | self.assertTrue("({0})".format(u) in output, msg=msg) |
| 77 | |
| 78 | status, output = self.target.run('su -c "rpm -qa" %s ' % u) |
| 79 | msg = 'status: %s. Cannot run rpm -qa: %s' % (status, output) |
| 80 | self.assertEqual(status, 0, msg=msg) |
| 81 | |
| 82 | def unset_up_test_user(u): |
| 83 | status, output = self.target.run('userdel -r %s' % u) |
| 84 | msg = 'Failed to erase user: %s' % output |
| 85 | self.assertTrue(status == 0, msg=msg) |
| 86 | |
| 87 | tuser = 'test1' |
| 88 | |
| 89 | try: |
| 90 | set_up_test_user(tuser) |
| 91 | exec_as_test_user(tuser) |
| 92 | finally: |
| 93 | unset_up_test_user(tuser) |
| 94 | |
| 95 | @OETestID(195) |
| 96 | @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_remove']) |
| 97 | def test_check_rpm_install_removal_log_file_size(self): |
| 98 | """ |
| 99 | Summary: Check that rpm writes into /var/log/messages |
| 100 | Expected: There should be some RPM prefixed entries in the above file. |
| 101 | Product: BSPs |
| 102 | Author: Alexandru Georgescu <alexandru.c.georgescu@intel.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | Author: Alexander Kanavin <alex.kanavin@gmail.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 104 | AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com> |
| 105 | """ |
| 106 | db_files_cmd = 'ls /var/lib/rpm/__db.*' |
| 107 | check_log_cmd = "grep RPM /var/log/messages | wc -l" |
| 108 | |
| 109 | # Make sure that some database files are under /var/lib/rpm as '__db.xxx' |
| 110 | status, output = self.target.run(db_files_cmd) |
| 111 | msg = 'Failed to find database files under /var/lib/rpm/ as __db.xxx' |
| 112 | self.assertEqual(0, status, msg=msg) |
| 113 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 114 | self.tc.target.copyTo(self.test_file, self.dst) |
| 115 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | # Remove the package just in case |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 117 | self.target.run('rpm -e base-passwd-doc') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | |
| 119 | # Install/Remove a package 10 times |
| 120 | for i in range(10): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm') |
| 122 | msg = 'Failed to install base-passwd-doc package. Reason: {}'.format(output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 123 | self.assertEqual(0, status, msg=msg) |
| 124 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 125 | status, output = self.target.run('rpm -e base-passwd-doc') |
| 126 | msg = 'Failed to remove base-passwd-doc package. Reason: {}'.format(output) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 127 | self.assertEqual(0, status, msg=msg) |
| 128 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 129 | self.tc.target.run('rm -f %s' % self.dst) |
| 130 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 131 | # if using systemd this should ensure all entries are flushed to /var |
| 132 | status, output = self.target.run("journalctl --sync") |
| 133 | # Get the amount of entries in the log file |
| 134 | status, output = self.target.run(check_log_cmd) |
| 135 | msg = 'Failed to get the final size of the log file.' |
| 136 | self.assertEqual(0, status, msg=msg) |
| 137 | |
| 138 | # Check that there's enough of them |
| 139 | self.assertGreaterEqual(int(output), 80, |
| 140 | 'Cound not find sufficient amount of rpm entries in /var/log/messages, found {} entries'.format(output)) |