Show isogen container logs if debug is enabled
Change-Id: I92c82eecdb35de22cc4da2326632b8af3aadd4cd
This commit is contained in:
parent
6fbcc26323
commit
e57b3ce4c0
@ -225,8 +225,7 @@ func (c *DockerContainer) RunCommand(
|
||||
containerInput io.Reader,
|
||||
volumeMounts []string,
|
||||
envVars []string,
|
||||
// TODO (D. Ukov) add debug logic
|
||||
_ bool,
|
||||
debug bool,
|
||||
) error {
|
||||
realCmd, err := c.getCmd(cmd)
|
||||
if err != nil {
|
||||
@ -264,7 +263,24 @@ func (c *DockerContainer) RunCommand(
|
||||
return err
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.Debug("start reading container logs")
|
||||
var reader io.ReadCloser
|
||||
reader, err = c.dockerClient.ContainerLogs(*c.ctx, c.id, types.ContainerLogsOptions{ShowStdout: true, Follow: true})
|
||||
if err != nil {
|
||||
log.Debugf("failed to read container logs %s", err)
|
||||
reader = ioutil.NopCloser(strings.NewReader(""))
|
||||
}
|
||||
|
||||
_, err = io.Copy(log.Writer(), reader)
|
||||
if err != nil {
|
||||
log.Debugf("failed to write container logs to log output %s", err)
|
||||
}
|
||||
log.Debug("got EOF from container logs")
|
||||
}
|
||||
|
||||
statusCh, errCh := c.dockerClient.ContainerWait(*c.ctx, c.id, container.WaitConditionNotRunning)
|
||||
log.Debugf("waiting until command '%s' is finished...", realCmd)
|
||||
select {
|
||||
case err = <-errCh:
|
||||
if err != nil {
|
||||
|
@ -352,7 +352,7 @@ func TestRunCommand(t *testing.T) {
|
||||
cmd: []string{"testCmd"},
|
||||
containerInput: nil,
|
||||
volumeMounts: nil,
|
||||
debug: false,
|
||||
debug: true,
|
||||
mockDockerClient: mockDockerClient{
|
||||
containerWait: func() (<-chan container.ContainerWaitOKBody, <-chan error) {
|
||||
resC := make(chan container.ContainerWaitOKBody)
|
||||
@ -365,6 +365,26 @@ func TestRunCommand(t *testing.T) {
|
||||
expectedErr: ErrRunContainerCommand{Cmd: "docker logs testID"},
|
||||
assertF: func(t *testing.T) {},
|
||||
},
|
||||
{
|
||||
cmd: []string{"testCmd"},
|
||||
containerInput: nil,
|
||||
volumeMounts: nil,
|
||||
debug: true,
|
||||
mockDockerClient: mockDockerClient{
|
||||
containerWait: func() (<-chan container.ContainerWaitOKBody, <-chan error) {
|
||||
resC := make(chan container.ContainerWaitOKBody)
|
||||
go func() {
|
||||
resC <- container.ContainerWaitOKBody{StatusCode: 1}
|
||||
}()
|
||||
return resC, nil
|
||||
},
|
||||
containerLogs: func() (io.ReadCloser, error) {
|
||||
return nil, fmt.Errorf("Logs error")
|
||||
},
|
||||
},
|
||||
expectedErr: ErrRunContainerCommand{Cmd: "docker logs testID"},
|
||||
assertF: func(t *testing.T) {},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
cnt := getDockerContainerMock(tt.mockDockerClient)
|
||||
|
@ -50,3 +50,8 @@ func Fatal(v ...interface{}) {
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
airshipLog.Fatalf(format, v...)
|
||||
}
|
||||
|
||||
// Writer returns log output writer object
|
||||
func Writer() io.Writer {
|
||||
return airshipLog.Writer()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user