Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Handle errors on Get() call from server. #699

Merged
merged 1 commit into from
Nov 9, 2016
Merged

Handle errors on Get() call from server. #699

merged 1 commit into from
Nov 9, 2016

Conversation

govint
Copy link
Contributor

@govint govint commented Nov 4, 2016

The Get() returns volume status thats optional in the docker plugin API. So, don't treat errors on status fetch as fatal. This test below had to artifically create an empty KV file because thats the only way it can be made empty or corrupted.

Tests:

$ docker volume create -d vmdk --name ca-vol-7
ca-vol-7

$ docker volume inspect ca-vol-7
[
    {
        "Name": "ca-vol-7",
        "Driver": "vmdk",
        "Mountpoint": "/mnt/vmdk/ca-vol-7",
        "Status": {
            "access": "read-write",
            "attach-as": "independent_persistent",
            "capacity": {
                "allocated": "13MB",
                "size": "100MB"
            },
            "created": "Fri Nov  4 11:38:53 2016",
            "created by VM": "2",
            "datastore": "bigone",
            "diskformat": "thin",
            "fstype": "ext4",
            "status": "detached"
        },
        "Labels": {},
        "Scope": "global"
    }
]

<trash the KV file - empty it>

$ docker volume inspect ca-vol-7
[
    {
        "Name": "ca-vol-7",
        "Driver": "vmdk",
        "Mountpoint": "/mnt/vmdk/ca-vol-7",
        "Labels": {},
        "Scope": "global"
    }
]

$ docker run --rm -it -w /data -v ca-vol-7:/data busybox
/data #

@@ -352,22 +352,32 @@ func (d *vmdkDriver) Mount(r volume.MountRequest) volume.Response {

// This is the first time we are asked to mount the volume, so comply
status, err := d.ops.Get(r.Name)

fstype := "ext4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a constant for the default fstype fs.FstypeDefault

msg := fmt.Sprintf("Got invalid filesystem type for %s, assuming type as ext2.", r.Name)
log.WithFields(log.Fields{"name": r.Name, "error": msg}).Error("")
// Fail back to a default version that we can try with.
value = "ext4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@brunotm
Copy link
Contributor

brunotm commented Nov 4, 2016

If we cannot rely in the metadata in those cases, maybe we could have a fallback method for mounting with exec.Command and mount -t auto instead of passing the default fstype that may not be the user specified FS ?

@govint
Copy link
Contributor Author

govint commented Nov 4, 2016

Yes, that sounds good but may be a separate change from this one.

On Fri, Nov 4, 2016 at 6:00 PM, Bruno Moura notifications@github.com
wrote:

If we cannot rely in the metadata in those cases, maybe we could have a
fallback method for mounting with exec.Command and mount -t auto instead of
passing the default fstype that may not be the user specified FS ?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#699 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/APHsePFPy_0YRzeRvisZWgNJO2jp9ajkks5q6yVLgaJpZM4Kpc-c
.

Copy link
Contributor

@msterin msterin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good , a few comments inline (the main one is that we need to print offending strings, and use warning instead of debug() is we fail to parse json.

@@ -105,7 +105,7 @@ func (v VmdkOps) Get(name string) (map[string]interface{}, error) {

err = json.Unmarshal(str, &statusMap)
if err != nil {
return nil, err
log.Debugf("vmdkOps.Get failed decoding volume status for name=%s", name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be warning , not debug. Admin cant do much about it but at least needs to know about it since it is why default would be applied.

@@ -421,7 +421,7 @@ def getVMDK(vmdk_path, vol_name, datastore):
except Exception as ex:
msg = "Failed to get disk details for %s (%s)" % (vmdk_path, ex)
logging.error(msg)
result = err(msg)
result = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this fix msg is not needed and the code could be simply be as follows:

  except Exception as ex:
      logging.error("Failed to get disk details for %s (%s)" % (vmdk_path, ex))
  return None

if !exists {
msg := fmt.Sprintf("Got invalid access type for %s, assuming read-write access.", r.Name)
log.WithFields(log.Fields{"name": r.Name, "error": msg}).Error("")
isReadOnly = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to actually print the offending string

// Check access type.
value, exists := status["access"].(string)
if !exists {
msg := fmt.Sprintf("Got invalid access type for %s, assuming read-write access.", r.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Got" is not needed, the msg can simply say "Invalid access type..."

// Check file system type.
value, exists = status["fstype"].(string)
if !exists {
msg := fmt.Sprintf("Got invalid filesystem type for %s, assuming type as ext2.", r.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Got" is not needed, the msg can simply say "Invalid access type..."

value, exists = status["fstype"].(string)
if !exists {
msg := fmt.Sprintf("Got invalid filesystem type for %s, assuming type as ext2.", r.Name)
log.WithFields(log.Fields{"name": r.Name, "error": msg}).Error("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to print the offending string as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@govint

Yes, that sounds good but may be a separate change from this one.

if you agree with the suggestions but want to put it in a different change, please open an issue and refer to it

@msterin
Copy link
Contributor

msterin commented Nov 7, 2016

LGTM when CI passes

Copy link
Contributor

@pdhamdhere pdhamdhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed as well rebased to merge but never clicked merge. Please merge away.

@kerneltime
Copy link
Contributor

Fixes #662

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants