Make SolarTransportResult output contain both outs

SolarTransportResult contains both stdout and stderr when error is
encountered.

Change-Id: I0f3c8e617a816230239c7c44634c15d49b73c61b
Closes-bug: 1544537
This commit is contained in:
Maciej Kwiek 2016-03-02 11:58:41 +01:00
parent 7c8e19e0d7
commit 52919b04f0
3 changed files with 37 additions and 9 deletions

View File

@ -49,11 +49,7 @@ class BaseHandler(object):
if not result.success:
message = 'CMD %r failed RC %s ERR %s' % (cmd, rc, err)
log.error(message)
# TODO: https://bugs.launchpad.net/solar/+bug/1544537
e_cnt = "stdout:\n{}\n{}\nstderr:\n{}".format(result.stdout,
'=' * 80,
result.stderr)
raise errors.SolarError(e_cnt)
raise errors.SolarError(result.output)
def __enter__(self):
return self

View File

@ -81,10 +81,9 @@ class SolarTransportResult(object):
def output(self):
if self.success:
return self.stdout
msg = self.stderr
if not msg:
msg = self.stdout
return msg
return "stdout:\n{}\n{}\nstderr:\n{}".format(self.stdout, '=' * 80,
self.stderr)
@classmethod
def from_tuple(cls, return_code, stdout, stderr):

View File

@ -0,0 +1,33 @@
# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pytest
from solar.core.handlers.base import BaseHandler
from solar.core.transports.base import SolarTransportResult
from solar.errors import SolarError
def test_verify_run_raises_stdout_and_stderr():
handler = BaseHandler(None)
result = SolarTransportResult()
result.stdout = 'stdout'
result.stderr = 'stderr'
result.return_code = 1
with pytest.raises(SolarError) as excinfo:
handler.verify_run_result('', result)
assert result.stdout in excinfo.value.message
assert result.stderr in excinfo.value.message