1
# Copyright 2004-2005 Canonical Ltd. All rights reserved.
12
from canonical.config import config
14
class SoyuzUploadError(Exception):
15
"""Used in the soyuz-upload test."""
18
"""Provides a setup and teardown mechanism for a poppy subprocess instance.
20
Use this like you would LibrarianTestSetup or similar.
23
def __init__(self, fsroot,
25
cmd='echo @distro@; ls @fsroot@',
34
"""Start the poppy instance."""
35
script = os.path.join(config.root, "daemons/poppy-upload.py")
36
self.process = subprocess.Popen([sys.executable, script,
37
"--allow-user", self.user,
39
self.fsroot, self.port],
40
stdout=subprocess.PIPE)
43
def setNonBlocking(self):
44
"""Ensure that Poppy's stdout is nonblocking."""
45
flags = fcntl.fcntl(self.process.stdout.fileno(), fcntl.F_GETFL, 0)
46
flags |= os.O_NONBLOCK
47
fcntl.fcntl(self.process.stdout.fileno(), fcntl.F_SETFL, flags)
50
"""Kill the poppy instance dead."""
53
os.kill(self.process.pid, signal.SIGTERM)
54
# Give poppy a chance to die
56
# Look to see if it has died yet
57
ret = self.process.poll()
59
# Poppy had not died, so send it SIGKILL
60
os.kill(self.process.pid, signal.SIGKILL)
61
# Finally return the result.
63
return self.process.wait()
67
"""Whether or not the poppy instance is still alive."""
70
return self.process.poll() is None
74
"""Read some bytes from Poppy's stdout."""
75
return self.process.stdout.read()
78
def verify_output(self, expected):
79
"""Verify that poppy writes the expected output."""
83
while time.time() - now < timeout:
85
raise SoyuzUploadError("Poppy died unexpectedly")
88
now = time.time() # Reset the timout
90
lines = buffer.splitlines()
94
if line not in expected:
95
raise SoyuzUploadError("Unexpected line found in "
96
"poppy output: %r" % line)
103
raise SoyuzUploadError("FTP server timed out. The following "
104
"was expected but not yet received: %r"