summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime_cases/rpm.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/runtime_cases/rpm.py')
-rw-r--r--meta/lib/oeqa/runtime_cases/rpm.py120
1 files changed, 120 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..f1c4763fc0
--- /dev/null
+++ b/meta/lib/oeqa/runtime_cases/rpm.py
@@ -0,0 +1,120 @@
1import unittest
2import os
3import fnmatch
4from oeqa.oetest import oeRuntimeTest, skipModule
5from oeqa.utils.decorators import *
6
7def setUpModule():
8 if not oeRuntimeTest.hasFeature("package-management"):
9 skipModule("rpm module skipped: target doesn't have package-management in IMAGE_FEATURES")
10 if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES").split()[0]:
11 skipModule("rpm module skipped: target doesn't have rpm as primary package manager")
12
13
14class RpmBasicTest(oeRuntimeTest):
15
16 @testcase(960)
17 @skipUnlessPassed('test_ssh')
18 def test_rpm_help(self):
19 (status, output) = self.target.run('rpm --help')
20 self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output))
21
22 @testcase(191)
23 @skipUnlessPassed('test_rpm_help')
24 def test_rpm_query(self):
25 (status, output) = self.target.run('rpm -q rpm')
26 self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output))
27
28class RpmInstallRemoveTest(oeRuntimeTest):
29
30 @classmethod
31 def setUpClass(self):
32 pkgarch = oeRuntimeTest.tc.d.getVar('TUNE_PKGARCH').replace("-", "_")
33 rpmdir = os.path.join(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR'), "rpm", pkgarch)
34 # pick rpm-doc as a test file to get installed, because it's small and it will always be built for standard targets
35 for f in fnmatch.filter(os.listdir(rpmdir), "rpm-doc-*.%s.rpm" % pkgarch):
36 testrpmfile = f
37 oeRuntimeTest.tc.target.copy_to(os.path.join(rpmdir,testrpmfile), "/tmp/rpm-doc.rpm")
38
39 @testcase(192)
40 @skipUnlessPassed('test_rpm_help')
41 def test_rpm_install(self):
42 (status, output) = self.target.run('rpm -ivh /tmp/rpm-doc.rpm')
43 self.assertEqual(status, 0, msg="Failed to install rpm-doc package: %s" % output)
44
45 @testcase(194)
46 @skipUnlessPassed('test_rpm_install')
47 def test_rpm_remove(self):
48 (status,output) = self.target.run('rpm -e rpm-doc')
49 self.assertEqual(status, 0, msg="Failed to remove rpm-doc package: %s" % output)
50
51 @testcase(1096)
52 @skipUnlessPassed('test_ssh')
53 def test_rpm_query_nonroot(self):
54
55 def set_up_test_user(u):
56 (status, output) = self.target.run("id -u %s" % u)
57 if status == 0:
58 pass
59 else:
60 (status, output) = self.target.run("useradd %s" % u)
61 self.assertTrue(status == 0, msg="Failed to create new user: " + output)
62
63 def exec_as_test_user(u):
64 (status, output) = self.target.run("su -c id %s" % u)
65 self.assertTrue("({0})".format(u) in output, msg="Failed to execute as new user")
66 (status, output) = self.target.run("su -c \"rpm -qa\" %s " % u)
67 self.assertEqual(status, 0, msg="status: %s. Cannot run rpm -qa: %s" % (status, output))
68
69 def unset_up_test_user(u):
70 (status, output) = self.target.run("userdel -r %s" % u)
71 self.assertTrue(status == 0, msg="Failed to erase user: %s" % output)
72
73 tuser = 'test1'
74
75 try:
76 set_up_test_user(tuser)
77 exec_as_test_user(tuser)
78 finally:
79 unset_up_test_user(tuser)
80
81 @testcase(195)
82 @skipUnlessPassed('test_rpm_install')
83 def test_check_rpm_install_removal_log_file_size(self):
84 """
85 Summary: Check rpm install/removal log file size
86 Expected: There should be some method to keep rpm log in a small size .
87 Product: BSPs
88 Author: Alexandru Georgescu <alexandru.c.georgescu@intel.com>
89 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
90 """
91 db_files_cmd = 'ls /var/lib/rpm/__db.*'
92 get_log_size_cmd = "du /var/lib/rpm/log/log.* | awk '{print $1}'"
93
94 # Make sure that some database files are under /var/lib/rpm as '__db.xxx'
95 (status, output) = self.target.run(db_files_cmd)
96 self.assertEqual(0, status, 'Failed to find database files under /var/lib/rpm/ as __db.xxx')
97
98 # Remove the package just in case
99 self.target.run('rpm -e rpm-doc')
100
101 # Install/Remove a package 10 times
102 for i in range(10):
103 (status, output) = self.target.run('rpm -ivh /tmp/rpm-doc.rpm')
104 self.assertEqual(0, status, "Failed to install rpm-doc package. Reason: {}".format(output))
105
106 (status, output) = self.target.run('rpm -e rpm-doc')
107 self.assertEqual(0, status, "Failed to remove rpm-doc package. Reason: {}".format(output))
108
109 # Get the size of log file
110 (status, output) = self.target.run(get_log_size_cmd)
111 self.assertEqual(0, status, 'Failed to get the final size of the log file.')
112
113 # Compare each log size
114 for log_file_size in output:
115 self.assertLessEqual(int(log_file_size), 11264,
116 'Log file size is greater that expected (~10MB), found {} bytes'.format(log_file_size))
117
118 @classmethod
119 def tearDownClass(self):
120 oeRuntimeTest.tc.target.run('rm -f /tmp/rpm-doc.rpm')