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