Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix NPE in vic-machine caused by vm invalid state error #2992

Merged
merged 5 commits into from
Nov 12, 2016

Conversation

emlin
Copy link
Contributor

@emlin emlin commented Nov 3, 2016

Fixes #2818
For another kind of invalid state vm, vsphere might return empty vm.Config property, so govmomi will panic for NPE. This is fixed in #2977
This PR did following changes to fix this kind of failure:

  • Override govmomi vm.Properties method in vm.go, and fix the vm if that's in invalid state, cause this function is not enclosed by waitForResult method.
  • Fix waitForResult method, to handle non invalid state error, if vm is already in invalid state. This might include RPC send error.
  • Update urfave/cli vendor code, cause it does not hide all error stack in latest version.

@emlin emlin changed the title fix NPE in vic-machine caused by vm invalid state error [full ci]fix NPE in vic-machine caused by vm invalid state error Nov 3, 2016
break
}
}
var newps []string
Copy link
Contributor

@hmahmood hmahmood Nov 3, 2016

Choose a reason for hiding this comment

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

You can just do (no need for newps)

if !contains {
  ps = append(ps, connectionStatus)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because I need to double check properties, and the next time, I don't need to add new properties. So I kept the old variable.

Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need to check? What happens if we append "summary.runtime.connectionState" every time, irrespective of whether it's present already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't matter to query duplicated properties, but as we're trying to make minimum properties query each time, it will help to reduce the array length.
And I think this array length is really short based on our current coding practice, I assume it doesn't hurt to loop that array.

}
var newps []string
if !contains {
newps = append(ps, connectionStatus)
Copy link
Contributor

@hmahmood hmahmood Nov 3, 2016

Choose a reason for hiding this comment

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

You are checking for summary above, but then appending on connectionStatus here? What about if connectionStatus is present in ps.

Also, the constant names are less intuitive than the actual strings; makes the code a little less readable imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any suggestion on the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would not use the constants.

@@ -888,6 +888,14 @@
"branch": "v1"
},
{
"importpath": "gopkg.in/urfave/cli.v1",
"repository": "https://gopkg.in/urfave/cli.v1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are we using this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. I just use gvt to fetch urfave/cli latest commit, but it includes this one dynamically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I searched the urfave/cli code, itself has this dependency, so I assume I cannot remove this directory simply.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like we should be using "gopkg.in/urfave/cli.v1" as the import path in our own code to avoid the duplicate vendoring of this package. If the NPE fix doesn't depend on updating this dependency, maybe the vendor update + import path change could be done in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not directly related, just to improve the capability to print out NPE. I can separate it.

@emlin emlin changed the title [full ci]fix NPE in vic-machine caused by vm invalid state error fix NPE in vic-machine caused by vm invalid state error Nov 3, 2016
log.Debugf("Fix invalid state VM: %s", vm.Reference())
folders, err := vm.Session.Datacenter.Folders(ctx)
if err != nil {
log.Errorf("Unable to get vm folder: %s", err)
return err
}

properties := []string{"config.files", "summary.config", "summary.runtime", "resourcePool", "parentVApp"}
properties := []string{"summary.config", "summary.runtime", "resourcePool", "parentVApp"}
Copy link
Member

Choose a reason for hiding this comment

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

While you're in there, looks like we only use Runtime.Host here, maybe limit that to "summary.runtime.host".

@@ -190,6 +191,13 @@ func TestVM(t *testing.T) {
t.Errorf("Failed to find fixed vm: %s", err)
}
assert.Equal(t, vm.Reference(), newVM.Reference())

// VM properties
var ovm mo.VirtualMachine
Copy link
Member

Choose a reason for hiding this comment

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

This is exactly the sort of test where we should be using vcsim to return InvalidState - @dougm is there an easy way to do this fault injection?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we are doing fault injection in this test for example: https://github.com/vmware/vic/blob/master/pkg/vsphere/tasks/waiter_test.go#L376

The test also implements methods that are not implemented by the simulator (MarkAsTemplate), similar might be needed here since Register/Unregister aren't currently implemented by the simulator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dougm the registervm methods are folder method or vApp method, how to inject the folder or vApp in simulator?

Copy link
Member

Choose a reason for hiding this comment

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

Added Register/Unregister: #3068

@emlin emlin force-pushed the 2818 branch 3 times, most recently from 2308708 to b1e845d Compare November 9, 2016 16:09
@emlin emlin changed the title fix NPE in vic-machine caused by vm invalid state error [full ci]fix NPE in vic-machine caused by vm invalid state error Nov 9, 2016
@emlin
Copy link
Contributor Author

emlin commented Nov 9, 2016

Changed fixed vm condition in WaitForResult for #2958


// // Inject invalid connection state to vm
ref := simulator.Map.Get(vmo.Reference()).(*simulator.VirtualMachine)
ref.Summary.Config.VmPathName = "[LocalDS_0] ha-host_VM0/ha-host_VM0.vmx"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we need to set that field in vcsim. You can also use this for now, rather than the hardcoded string:
ref.Config.Files.VmPathName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good

@dougm
Copy link
Member

dougm commented Nov 9, 2016

lgtm

@emlin emlin changed the title [full ci]fix NPE in vic-machine caused by vm invalid state error fix NPE in vic-machine caused by vm invalid state error Nov 9, 2016
  This method will overrid govmomi method, to workaround invalid
  state vm issue
  Update fixVM condition as well
@emlin
Copy link
Contributor Author

emlin commented Nov 12, 2016

lgtm

@emlin emlin merged commit 6719689 into vmware:master Nov 12, 2016
@emlin emlin deleted the 2818 branch November 14, 2016 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC error in docker stop, and eventually, vic-machine delete constantly fail with invalid memory address
5 participants