util: make ExecComand return stdout and stderr as string

Most consumers of util.ExecCommand() need to convert the returned []byte
format of stdout and/or stderr to string. By having util.ExecCommand()
return strings instead, the code gets a little simpler.

A few commands return JSON that needs to be parsed. These commands will
be replaced by go-ceph implementations later on. For now, convert the
strings back to []byte when needed.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2020-07-22 14:53:22 +02:00
committed by mergify[bot]
parent ddac66d76b
commit 36469b87e2
6 changed files with 31 additions and 28 deletions

View File

@ -67,16 +67,15 @@ func getVolumeRootPathCeph(ctx context.Context, volOptions *volumeOptions, cr *u
"--keyfile="+cr.KeyFile)
if err != nil {
stdErrString := string(stderr)
klog.Errorf(util.Log(ctx, "failed to get the rootpath for the vol %s(%s) stdError %s"), string(volID), err, stdErrString)
klog.Errorf(util.Log(ctx, "failed to get the rootpath for the vol %s(%s) stdError %s"), string(volID), err, stderr)
if strings.HasPrefix(stdErrString, errNotFoundString) {
if strings.HasPrefix(stderr, errNotFoundString) {
return "", util.JoinErrors(ErrVolumeNotFound, err)
}
return "", err
}
return strings.TrimSuffix(string(stdout), "\n"), nil
return strings.TrimSuffix(stdout, "\n"), nil
}
type localClusterState struct {