Skip to contentSkip to conversation

oeqa: Remove linux user utilized for rpm test.

PATCH Superseded Edwin Plauchu 2 participants 3 messages Sep 8, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oeqa: Remove linux user utilized for rpm test.

From: Edwin Plauchu <[email protected]>

When trying to re-test smart rpm tests. A fail arises due to a linux user previously created upon the image. W've added a few lines to delete such user and his home dir when finishing test.

[YOCTO #9204]

---
 meta/lib/oeqa/runtime/rpm.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
meta/lib/oeqa/runtime/rpm.py +6 -3
index 4d03ecb..285f39b 100644
@@ -51,12 +51,15 @@ class RpmInstallRemoveTest(oeRuntimeTest):
     @testcase(1096)
     @skipUnlessPassed('test_ssh')
     def test_rpm_query_nonroot(self):
-        (status, output) = self.target.run('useradd test1')
+        test_user = 'test1'
+        (status, output) = self.target.run("useradd %s" % test_user)
         self.assertTrue(status == 0, msg="Failed to create new user: " + output)
-        (status, output) = self.target.run('su -c id test1')
+        (status, output) = self.target.run("su -c id %s" % test_user)
         self.assertTrue('(test1)' in output, msg="Failed to execute as new user")
-        (status, output) = self.target.run('su -c "rpm -qa" test1 ')
+        (status, output) = self.target.run("su -c \"rpm -qa\" %s " % test_user)
         self.assertEqual(status, 0, msg="status: %s. Cannot run rpm -qa: %s" % (status, output))
+        (status, output) = self.target.run("userdel -r %s" % test_user)
+        self.assertTrue(status == 0, msg="Failed to erase user: %s" % output)
 
     @testcase(195)
     @skipUnlessPassed('test_rpm_install')
Signature · 1 line
2.9.3
#1 lore raw
Quoted 17 lines · Edwin Plauchu

def test_rpm_query_nonroot(self):

meta/lib/oeqa/runtime/rpm.py +2 -1
-        (status, output) = self.target.run('useradd test1')
+        test_user = 'test1'
+        (status, output) = self.target.run("useradd %s" % test_user)
         self.assertTrue(status == 0, msg="Failed to create new user: " +

output)

meta/lib/oeqa/runtime/rpm.py +1 -1
-        (status, output) = self.target.run('su -c id test1')
+        (status, output) = self.target.run("su -c id %s" % test_user)
         self.assertTrue('(test1)' in output, msg="Failed to execute as

new user")

(quoted diff) +1 -1
-        (status, output) = self.target.run('su -c "rpm -qa" test1 ')
+        (status, output) = self.target.run("su -c \"rpm -qa\" %s " %

test_user)
self.assertEqual(status, 0, msg="status: %s. Cannot run rpm -qa:
%s" % (status, output))

(quoted diff) +2 -0
+        (status, output) = self.target.run("userdel -r %s" % test_user)
+        self.assertTrue(status == 0, msg="Failed to erase user: %s" %
Quoted 2 lines

output)

The user removal should be in a try/finally block around the test so that it always executes even if the test fails.

Ross

#2 lore raw
In reply to Edwin Plauchu
Quoted 5 lines · Edwin Plauchu

When trying to re-test smart rpm tests. A fail arises due to a linux user previously created upon the image. W've added a few lines to delete such user and his home dir when finishing test.

Also as part of a belt-and-brances approach the test should not create a new user if it already exists.

Ross