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