Output from fabric.api.run for remote command

The fabric.api.run command returns the string with combined stderr and
stdout. Raw output of the fabric process contains additional line
prefixes to indicate executed command and stdout/stderr stream. Using
raw output to fetch file name of temp file created by 'mktemp' command
is incorrect and causes DB dump to fail.

Add CommandOut.output property and use it to store the output string
produced by fabric.api.run. Use this property to set the name of
temp file in Postgres driver.

Change-Id: I9678a408f5532db1acb8fc36dd4eef4a95b61bfe
Closes-bug: 1526081
This commit is contained in:
Oleg Gelbukh 2015-12-15 14:29:03 +00:00
parent a0bd065080
commit d5dc87599c
1 changed files with 5 additions and 2 deletions

View File

@ -35,12 +35,14 @@ class CommandOut(object):
stdout = None
return_code = None
stderr = None
output = None
def __eq__(self, other):
return (
str(self.stdout) == str(other.stdout) and
str(self.stderr) == str(other.stderr) and
str(self.return_code) == str(other.return_code)
str(self.return_code) == str(other.return_code) and
str(self.output) == str(other.output)
)
@ -109,6 +111,7 @@ class Driver(object):
# NOTE(prmtl): because of pty=True (default) and
# combine_stderr=True (default) stderr is combined
# with stdout
out.output = output
out.stdout = raw_stdout.getvalue()
out.return_code = output.return_code
else:
@ -218,7 +221,7 @@ class Postgres(Driver):
fo.seek(0, 2)
fo.write("{0}\n".format(authline))
os.chmod(pgpass, stat.S_IRUSR + stat.S_IWUSR)
temp = self.command("mktemp").stdout.strip()
temp = self.command("mktemp").output.strip()
self.command("pg_dump -h {dbhost} -U {username} -w "
"-f {file} {dbname}".format(
dbhost=self.dbhost, username=self.username,