Ensure cat process is terminated
per bug report we should be terminating that "cat" subprocess at the end of test_KillFilter. switching from kill to terminate/wait, add try/finally to make sure we are ok even if an exception is thrown in between fixes bug #1079629 Change-Id: I8ca767402a2bd992d4b9579615375eda0c75cb6b
This commit is contained in:
@@ -69,29 +69,34 @@ class RootwrapTestCase(test.TestCase):
|
|||||||
p = subprocess.Popen(["cat"], stdin=subprocess.PIPE,
|
p = subprocess.Popen(["cat"], stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
f = filters.KillFilter("root", "/bin/cat", "-9", "-HUP")
|
try:
|
||||||
f2 = filters.KillFilter("root", "/usr/bin/cat", "-9", "-HUP")
|
f = filters.KillFilter("root", "/bin/cat", "-9", "-HUP")
|
||||||
usercmd = ['kill', '-ALRM', p.pid]
|
f2 = filters.KillFilter("root", "/usr/bin/cat", "-9", "-HUP")
|
||||||
# Incorrect signal should fail
|
usercmd = ['kill', '-ALRM', p.pid]
|
||||||
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
# Incorrect signal should fail
|
||||||
usercmd = ['kill', p.pid]
|
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
||||||
# Providing no signal should fail
|
usercmd = ['kill', p.pid]
|
||||||
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
# Providing no signal should fail
|
||||||
# Providing matching signal should be allowed
|
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
||||||
usercmd = ['kill', '-9', p.pid]
|
# Providing matching signal should be allowed
|
||||||
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
|
usercmd = ['kill', '-9', p.pid]
|
||||||
|
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
|
||||||
|
|
||||||
f = filters.KillFilter("root", "/bin/cat")
|
f = filters.KillFilter("root", "/bin/cat")
|
||||||
f2 = filters.KillFilter("root", "/usr/bin/cat")
|
f2 = filters.KillFilter("root", "/usr/bin/cat")
|
||||||
usercmd = ['kill', os.getpid()]
|
usercmd = ['kill', os.getpid()]
|
||||||
# Our own PID does not match /bin/sleep, so it should fail
|
# Our own PID does not match /bin/sleep, so it should fail
|
||||||
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
||||||
usercmd = ['kill', 999999]
|
usercmd = ['kill', 999999]
|
||||||
# Nonexistent PID should fail
|
# Nonexistent PID should fail
|
||||||
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
|
||||||
usercmd = ['kill', p.pid]
|
usercmd = ['kill', p.pid]
|
||||||
# Providing no signal should work
|
# Providing no signal should work
|
||||||
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
|
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
|
||||||
|
finally:
|
||||||
|
# Terminate the "cat" process and wait for it to finish
|
||||||
|
p.terminate()
|
||||||
|
p.wait()
|
||||||
|
|
||||||
def test_KillFilter_no_raise(self):
|
def test_KillFilter_no_raise(self):
|
||||||
"""Makes sure ValueError from bug 926412 is gone"""
|
"""Makes sure ValueError from bug 926412 is gone"""
|
||||||
|
Reference in New Issue
Block a user