blob: de92157c52c4ae5ef7b45552bd73ddbe7d5f7a4f [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001import os
2import fnmatch
3
4from oeqa.runtime.case import OERuntimeTestCase
5from oeqa.core.decorator.depends import OETestDepends
6from oeqa.core.decorator.oeid import OETestID
7from oeqa.core.decorator.data import skipIfDataVar
8from oeqa.runtime.decorator.package import OEHasPackage
9from oeqa.core.utils.path import findFile
10
11class RpmBasicTest(OERuntimeTestCase):
12
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013 @OETestID(960)
Brad Bishopd5ae7d92018-06-14 09:52:03 -070014 @OEHasPackage(['rpm'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 @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 Bishop977dc1a2019-02-06 16:01:43 -050024 status, output = self.target.run('ls /var/lib/rpm/')
25 if status != 0:
26 self.skipTest('No /var/lib/rpm on target')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 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
31class RpmInstallRemoveTest(OERuntimeTestCase):
32
33 @classmethod
34 def setUpClass(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 pkgarch = cls.td['TUNE_PKGARCH'].replace('-', '_')
36 rpmdir = os.path.join(cls.tc.td['DEPLOY_DIR'], 'rpm', pkgarch)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037 # Pick base-passwd-doc as a test file to get installed, because it's small
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 # and it will always be built for standard targets
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039 rpm_doc = 'base-passwd-doc-*.%s.rpm' % pkgarch
Brad Bishop977dc1a2019-02-06 16:01:43 -050040 if not os.path.exists(rpmdir):
41 return
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 for f in fnmatch.filter(os.listdir(rpmdir), rpm_doc):
Brad Bishop977dc1a2019-02-06 16:01:43 -050043 cls.test_file = os.path.join(rpmdir, f)
44 cls.dst = '/tmp/base-passwd-doc.rpm'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045
46 @OETestID(192)
Brad Bishop977dc1a2019-02-06 16:01:43 -050047 @OETestDepends(['rpm.RpmBasicTest.test_rpm_query'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 def test_rpm_install(self):
Brad Bishop977dc1a2019-02-06 16:01:43 -050049 self.tc.target.copyTo(self.test_file, self.dst)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 status, output = self.target.run('rpm -ivh /tmp/base-passwd-doc.rpm')
51 msg = 'Failed to install base-passwd-doc package: %s' % output
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 self.assertEqual(status, 0, msg=msg)
Brad Bishop977dc1a2019-02-06 16:01:43 -050053 self.tc.target.run('rm -f %s' % self.dst)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054
55 @OETestID(194)
56 @OETestDepends(['rpm.RpmInstallRemoveTest.test_rpm_install'])
57 def test_rpm_remove(self):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058 status,output = self.target.run('rpm -e base-passwd-doc')
59 msg = 'Failed to remove base-passwd-doc package: %s' % output
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800103 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 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 Bishop977dc1a2019-02-06 16:01:43 -0500114 self.tc.target.copyTo(self.test_file, self.dst)
115
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500116 # Remove the package just in case
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800117 self.target.run('rpm -e base-passwd-doc')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118
119 # Install/Remove a package 10 times
120 for i in range(10):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800121 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 Bishop6e60e8b2018-02-01 10:27:11 -0500123 self.assertEqual(0, status, msg=msg)
124
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800125 status, output = self.target.run('rpm -e base-passwd-doc')
126 msg = 'Failed to remove base-passwd-doc package. Reason: {}'.format(output)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 self.assertEqual(0, status, msg=msg)
128
Brad Bishop977dc1a2019-02-06 16:01:43 -0500129 self.tc.target.run('rm -f %s' % self.dst)
130
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500131 # 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))