summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/cases/rpm.py
diff options
context:
space:
mode:
authorMariano Lopez <mariano.lopez@linux.intel.com>2016-11-01 07:48:16 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:20 +0000
commitb569aa0e0056a97b29577f5bda611ef3dd539db3 (patch)
tree64f4d7856959435abfc7c49258688f64861f6d7c /meta/lib/oeqa/runtime/cases/rpm.py
parent3857e5c91da678d7bdc07712a1df9daa14354986 (diff)
downloadpoky-b569aa0e0056a97b29577f5bda611ef3dd539db3.tar.gz
oeqa/runtime/cases: Migrate runtime tests.
This migrates current runtime test suite to be used with the new framework. [YOCTO #10234] (From OE-Core rev: b39c61f2d442c79d03b73e8ffd104996fcb2177e) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/rpm.py')
-rw-r--r--meta/lib/oeqa/runtime/cases/rpm.py141
1 files changed, 141 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/rpm.py b/meta/lib/oeqa/runtime/cases/rpm.py
new file mode 100644
index 0000000000..532fbf82eb
--- /dev/null
+++ b/meta/lib/oeqa/runtime/cases/rpm.py
@@ -0,0 +1,141 @@
1import 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 rpm install/removal log file size
106 Expected: There should be some method to keep rpm log in a small size .
107 Product: BSPs
108 Author: Alexandru Georgescu <alexandru.c.georgescu@intel.com>
109 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
110 """
111 db_files_cmd = 'ls /var/lib/rpm/__db.*'
112 get_log_size_cmd = "du /var/lib/rpm/log/log.* | awk '{print $1}'"
113
114 # Make sure that some database files are under /var/lib/rpm as '__db.xxx'
115 status, output = self.target.run(db_files_cmd)
116 msg = 'Failed to find database files under /var/lib/rpm/ as __db.xxx'
117 self.assertEqual(0, status, msg=msg)
118
119 # Remove the package just in case
120 self.target.run('rpm -e rpm-doc')
121
122 # Install/Remove a package 10 times
123 for i in range(10):
124 status, output = self.target.run('rpm -ivh /tmp/rpm-doc.rpm')
125 msg = 'Failed to install rpm-doc package. Reason: {}'.format(output)
126 self.assertEqual(0, status, msg=msg)
127
128 status, output = self.target.run('rpm -e rpm-doc')
129 msg = 'Failed to remove rpm-doc package. Reason: {}'.format(output)
130 self.assertEqual(0, status, msg=msg)
131
132 # Get the size of log file
133 status, output = self.target.run(get_log_size_cmd)
134 msg = 'Failed to get the final size of the log file.'
135 self.assertEqual(0, status, msg=msg)
136
137 # Compare each log size
138 for log_file_size in output:
139 msg = ('Log file size is greater that expected (~10MB), '
140 'found {} bytes'.format(log_file_size))
141 self.assertLessEqual(int(log_file_size), 11264, msg=msg)