mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-24 10:43:16 +08:00
Combine mock stderr and stdout logs
Mock doesn't normally log anything to stdout - so it's confusing to mention separate logs in the messages. Combine the two output streams together. (This is what koji does as well.)
This commit is contained in:
@@ -356,7 +356,7 @@ class KojiModuleBuilder(GenericBuilder):
|
|||||||
fd.close()
|
fd.close()
|
||||||
log.debug("Building %s.spec" % name)
|
log.debug("Building %s.spec" % name)
|
||||||
|
|
||||||
# We are not interested in the rpmbuild stdout...
|
# We are not interested in the rpmbuild output...
|
||||||
null_fd = open(os.devnull, "w")
|
null_fd = open(os.devnull, "w")
|
||||||
execute_cmd(
|
execute_cmd(
|
||||||
[
|
[
|
||||||
@@ -369,7 +369,7 @@ class KojiModuleBuilder(GenericBuilder):
|
|||||||
"_sourcedir %s" % sources_dir,
|
"_sourcedir %s" % sources_dir,
|
||||||
],
|
],
|
||||||
cwd=td,
|
cwd=td,
|
||||||
stdout=null_fd,
|
output=null_fd,
|
||||||
)
|
)
|
||||||
null_fd.close()
|
null_fd.close()
|
||||||
sdir = os.path.join(td, "SRPMS")
|
sdir = os.path.join(td, "SRPMS")
|
||||||
|
|||||||
@@ -646,11 +646,9 @@ class MockModuleBuilder(GenericBuilder):
|
|||||||
mock_config = os.path.join(
|
mock_config = os.path.join(
|
||||||
self.configdir, "mock-%s.cfg" % str(threading.current_thread().name))
|
self.configdir, "mock-%s.cfg" % str(threading.current_thread().name))
|
||||||
|
|
||||||
# Open the logs to which we will forward mock stdout/stderr.
|
# Open the log to which we will forward mock stdout/stderr.
|
||||||
mock_stdout_log = open(
|
mock_output_log = open(
|
||||||
os.path.join(self.resultsdir, artifact_name + "-mock-stdout.log"), "w")
|
os.path.join(self.resultsdir, artifact_name + "-mock-output.log"), "w")
|
||||||
mock_stderr_log = open(
|
|
||||||
os.path.join(self.resultsdir, artifact_name + "-mock-stderr.log"), "w")
|
|
||||||
|
|
||||||
srpm = artifact_name
|
srpm = artifact_name
|
||||||
resultsdir = builder.resultsdir
|
resultsdir = builder.resultsdir
|
||||||
@@ -658,12 +656,11 @@ class MockModuleBuilder(GenericBuilder):
|
|||||||
# Initialize mock.
|
# Initialize mock.
|
||||||
execute_cmd(
|
execute_cmd(
|
||||||
["mock", "-v", "-r", mock_config, "--init"],
|
["mock", "-v", "-r", mock_config, "--init"],
|
||||||
stdout=mock_stdout_log,
|
output=mock_output_log,
|
||||||
stderr=mock_stderr_log,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start the build and store results to resultsdir
|
# Start the build and store results to resultsdir
|
||||||
builder.build(mock_stdout_log, mock_stderr_log)
|
builder.build(mock_output_log)
|
||||||
srpm = find_srpm(resultsdir)
|
srpm = find_srpm(resultsdir)
|
||||||
|
|
||||||
# Emit messages simulating complete build. These messages
|
# Emit messages simulating complete build. These messages
|
||||||
@@ -687,8 +684,7 @@ class MockModuleBuilder(GenericBuilder):
|
|||||||
with open(os.path.join(resultsdir, "status.log"), "w") as f:
|
with open(os.path.join(resultsdir, "status.log"), "w") as f:
|
||||||
f.write("failed\n")
|
f.write("failed\n")
|
||||||
|
|
||||||
mock_stdout_log.close()
|
mock_output_log.close()
|
||||||
mock_stderr_log.close()
|
|
||||||
|
|
||||||
self._save_log(resultsdir, "state.log", artifact_name)
|
self._save_log(resultsdir, "state.log", artifact_name)
|
||||||
self._save_log(resultsdir, "root.log", artifact_name)
|
self._save_log(resultsdir, "root.log", artifact_name)
|
||||||
@@ -810,8 +806,8 @@ class BaseBuilder(object):
|
|||||||
self.resultsdir = resultsdir
|
self.resultsdir = resultsdir
|
||||||
self.cmd = ["mock", "-v", "-r", config, "--no-clean", "--resultdir=%s" % resultsdir]
|
self.cmd = ["mock", "-v", "-r", config, "--no-clean", "--resultdir=%s" % resultsdir]
|
||||||
|
|
||||||
def build(self, stdout, stderr):
|
def build(self, output):
|
||||||
execute_cmd(self.cmd, stdout=stdout, stderr=stderr)
|
execute_cmd(self.cmd, output=output)
|
||||||
|
|
||||||
|
|
||||||
class SRPMBuilder(BaseBuilder):
|
class SRPMBuilder(BaseBuilder):
|
||||||
|
|||||||
@@ -26,27 +26,24 @@ def find_srpm(cod):
|
|||||||
return os.path.join(cod, f)
|
return os.path.join(cod, f)
|
||||||
|
|
||||||
|
|
||||||
def execute_cmd(args, stdout=None, stderr=None, cwd=None):
|
def execute_cmd(args, output=None, cwd=None):
|
||||||
"""
|
"""
|
||||||
Executes command defined by `args`. If `stdout` or `stderr` is set to
|
Executes command defined by `args`. If `output` is set to
|
||||||
Python file object, the stderr/stdout output is redirecter to that file.
|
Python file object, the stderr and stdout output is redirected to that file.
|
||||||
If `cwd` is set, current working directory is set accordingly for the
|
If `cwd` is set, current working directory is set accordingly for the
|
||||||
executed command.
|
executed command.
|
||||||
|
|
||||||
:param args: list defining the command to execute.
|
:param args: list defining the command to execute.
|
||||||
:param stdout: Python file object to redirect the stdout to.
|
:param output: Python file object to redirect the stderr and stdout to.
|
||||||
:param stderr: Python file object to redirect the stderr to.
|
|
||||||
:param cwd: string defining the current working directory for command.
|
:param cwd: string defining the current working directory for command.
|
||||||
:raises RuntimeError: Raised when command exits with non-zero exit code.
|
:raises RuntimeError: Raised when command exits with non-zero exit code.
|
||||||
"""
|
"""
|
||||||
out_log_msg = ""
|
out_log_msg = ""
|
||||||
if stdout and hasattr(stdout, "name"):
|
if output and hasattr(output, "name"):
|
||||||
out_log_msg += ", stdout log: %s" % stdout.name
|
out_log_msg += ", output log: %s" % output.name
|
||||||
if stderr and hasattr(stderr, "name"):
|
|
||||||
out_log_msg += ", stderr log: %s" % stderr.name
|
|
||||||
|
|
||||||
log.info("Executing the command \"%s\"%s" % (" ".join(args), out_log_msg))
|
log.info("Executing the command \"%s\"%s" % (" ".join(args), out_log_msg))
|
||||||
proc = subprocess.Popen(args, stdout=stdout, stderr=stderr, cwd=cwd)
|
proc = subprocess.Popen(args, stdout=output, stderr=output, cwd=cwd)
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user