-
Notifications
You must be signed in to change notification settings - Fork 175
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
Conversation
break | ||
} | ||
} | ||
var newps []string |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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"} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Register/Unregister: #3068
2308708
to
b1e845d
Compare
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
lgtm |
This method will overrid govmomi method, to workaround invalid state vm issue
Update fixVM condition as well
lgtm |
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: