Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
add detail error msg to volume plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan Peng authored and Denise committed Feb 12, 2018
1 parent b7c32bb commit b740cdf
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions core/storage/plugin_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/docker/go-connections/sockets"
"github.com/pkg/errors"
"github.com/rancher/agent/model"
"strings"
)

func CallRancherStorageVolumePlugin(volume model.Volume, action string, payload interface{}) (Response, error) {
Expand All @@ -31,31 +32,29 @@ func CallRancherStorageVolumePlugin(volume model.Volume, action string, payload
driver := volume.Data.Fields.Driver
resp, err := client.Post(url, "application/json", bytes.NewReader(bs))
if err != nil {
logrus.Errorf("Failed to call /VolumeDriver.%v '%s' (driver '%s'): %s", action, volume.Name, driver, err)
return Response{}, err
return Response{}, errors.Errorf("Failed to call /VolumeDriver.%v '%s' (driver '%s'): %s", action, volume.Name, driver, err)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return Response{}, err
}
defer resp.Body.Close()

response := Response{}
if err := json.Unmarshal(data, &response); err != nil {
return Response{}, err
}
if response.Err != "" {
return Response{}, errors.Errorf("Failed to %s volume %s. Driver: %s. Status code: %v. Status: %s. Error Message: %s", strings.ToLower(action), volume.Name, driver, resp.StatusCode, strings.ToLower(resp.Status), response.Err)
}
switch {
case resp.StatusCode >= 200 && resp.StatusCode < 300:
logrus.Infof("Success: /VolumeDriver.%v '%s' (driver '%s')", action, volume.Name, driver)
response := Response{}
err := json.Unmarshal(data, &response)
if err != nil {
return Response{}, err
}
if response.Err != "" {
return Response{}, errors.New(response.Err)
}
return response, nil
case resp.StatusCode >= 400 && resp.StatusCode < 500:
logrus.Infof("/VolumeDriver.%v '%s' is not supported by driver '%s'", action, volume.Name, driver)
default:
return Response{}, errors.Errorf("/VolumeDriver.Attach '%s' (driver '%s') returned status %v: %s", volume.Name, driver, resp.StatusCode, resp.Status)
return Response{}, errors.Errorf("Failed to %s volume %s. Driver: %s. Status code: %v. Status: %s", strings.ToLower(action), volume.Name, driver, resp.StatusCode, strings.ToLower(resp.Status))
}

return Response{}, nil
Expand Down

0 comments on commit b740cdf

Please sign in to comment.