Skip to content

Commit

Permalink
Merge pull request rook#9675 from subhamkrai/clean
Browse files Browse the repository at this point in the history
core: remove obsolete ceph-volume executor code
  • Loading branch information
satoru-takeuchi committed Jan 31, 2022
2 parents 096dabf + 6bdd5b2 commit 2f867c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 96 deletions.
10 changes: 3 additions & 7 deletions pkg/daemon/ceph/osd/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func GetCephVolumeLVMOSDs(context *clusterd.Context, clusterInfo *client.Cluster

var lvPath string
args := []string{cvMode, "list", lv, "--format", "json"}
result, err := callCephVolume(context, false, args...)
result, err := callCephVolume(context, args...)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve ceph-volume %s list results", cvMode)
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster
args = []string{cvMode, "list", "--format", "json"}
}

result, err := callCephVolume(context, false, args...)
result, err := callCephVolume(context, args...)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve ceph-volume %s list results", cvMode)
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster
return osds, nil
}

func callCephVolume(context *clusterd.Context, requiresCombinedOutput bool, args ...string) (string, error) {
func callCephVolume(context *clusterd.Context, args ...string) (string, error) {
// Use stdbuf to capture the python output buffer such that we can write to the pod log as the
// logging happens instead of using the default buffering that will log everything after
// ceph-volume exits
Expand All @@ -1162,10 +1162,6 @@ func callCephVolume(context *clusterd.Context, requiresCombinedOutput bool, args

// Do not use combined output for "list" calls, otherwise we will get stderr is the output and this will break the json unmarshall
f := context.Executor.ExecuteCommandWithOutput
if requiresCombinedOutput {
// If the action is preparing we need the combined output
f = context.Executor.ExecuteCommandWithCombinedOutput
}
co, err := f(baseCommand, append(baseArgs, args...)...)
if err != nil {
// Print c-v log before exiting with failure
Expand Down
89 changes: 0 additions & 89 deletions pkg/util/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package exec
import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
Expand Down Expand Up @@ -142,93 +140,6 @@ func (*CommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...
return runCommandWithOutput(cmd, true)
}

// ExecuteCommandWithOutputFileTimeout Same as ExecuteCommandWithOutputFile but with a timeout limit.
// #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close
func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duration,
command, outfileArg string, arg ...string) (string, error) {

outFile, err := ioutil.TempFile("", "")
if err != nil {
return "", errors.Wrap(err, "failed to open output file")
}
defer outFile.Close()
defer os.Remove(outFile.Name())

arg = append(arg, outfileArg, outFile.Name())
logCommand(command, arg...)

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

// #nosec G204 Rook controls the input to the exec arguments
cmd := exec.CommandContext(ctx, command, arg...)
cmdOut, err := cmd.CombinedOutput()
if err != nil {
cmdOut = []byte(fmt.Sprintf("%s. %s", string(cmdOut), assertErrorType(err)))
}

// if there was anything that went to stdout/stderr then log it, even before
// we return an error
if string(cmdOut) != "" {
if !strings.Contains(err.Error(), "error calling conf_read_file") {
logger.Debug(string(cmdOut))
}
}

if ctx.Err() == context.DeadlineExceeded {
return string(cmdOut), ctx.Err()
}

if err != nil {
return string(cmdOut), &CephCLIError{err: err, output: string(cmdOut)}
}

fileOut, err := ioutil.ReadAll(outFile)
if err := outFile.Close(); err != nil {
return "", err
}
return string(fileOut), err
}

// ExecuteCommandWithOutputFile executes a command with output on a file
// #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close
func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, arg ...string) (string, error) {

// create a temporary file to serve as the output file for the command to be run and ensure
// it is cleaned up after this function is done
outFile, err := ioutil.TempFile("", "")
if err != nil {
return "", errors.Wrap(err, "failed to open output file")
}
defer outFile.Close()
defer os.Remove(outFile.Name())

// append the output file argument to the list or args
arg = append(arg, outfileArg, outFile.Name())

logCommand(command, arg...)
// #nosec G204 Rook controls the input to the exec arguments
cmd := exec.Command(command, arg...)
cmdOut, err := cmd.CombinedOutput()
if err != nil {
cmdOut = []byte(fmt.Sprintf("%s. %s", string(cmdOut), assertErrorType(err)))
}
// if there was anything that went to stdout/stderr then log it, even before we return an error
if string(cmdOut) != "" {
logger.Debug(string(cmdOut))
}
if err != nil {
return string(cmdOut), &CephCLIError{err: err, output: string(cmdOut)}
}

// read the entire output file and return that to the caller
fileOut, err := ioutil.ReadAll(outFile)
if err := outFile.Close(); err != nil {
return "", err
}
return string(fileOut), err
}

func startCommand(env []string, command string, arg ...string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) {
logCommand(command, arg...)

Expand Down

0 comments on commit 2f867c0

Please sign in to comment.