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

Add networkupdate support for VM, introduce forced guest customization function #229

Merged
merged 20 commits into from
Aug 22, 2019

Conversation

Didainius
Copy link
Collaborator

Ref https://github.com/terraform-providers/terraform-provider-vcd/issues/299, https://github.com/terraform-providers/terraform-provider-vcd/issues/300

This PR introduces a few things:

  • Add function for network updates (vm.UpdateNetworkConnectionSection())
  • Add forced guest customization related functions

A few general lint fixes:

  • Get rid of staticcheck lint error SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here
  • Use http client with timeout in lb_test.go

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

First pass, while we wait for tests

govcd/vm.go Outdated
// Runs synchronously, VM is ready for another operation after this function returns.
func (vm *VM) UpdateNetworkConnectionSection(networks *types.NetworkConnectionSection) error {
if vm.VM.HREF == "" {
return fmt.Errorf("cannot refresh, Object is empty")
Copy link
Contributor

Choose a reason for hiding this comment

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

"refresh"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wow. That was way off. Fixed.

@@ -263,12 +263,14 @@ func checkLb(queryUrl string, expectedResponses []string, maxRetryTimeout int) e
iterations = maxRetryTimeout / 5
}

httpClient := &http.Client{Timeout: 5 * time.Second}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment explaining how this timeout affects the expected duration of the test?

I am talking about the estimate given with Waiting for the virtual server to accept responses (%s interval x %d iterations)"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. This simple loop was actually quite unstable in guessing timing. I put in a time.Ticker so that it does not lie and actually work as the time was set.

govcd/vm.go Outdated
// PowerOnAndForceCustomization is a synchronous function which is equivalent to the functionality
// one has in UI. It triggers customization which may be useful in some cases (like altering NICs)
//
// The VM _must_ be Undeployed for this action to actually work.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we detect the state of the VM to make sure this prerequisite is met?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO/ Yes, we should. VM should have status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can add a check, but the problem is that it doesn't actually fail to power on and god knows if it can be useful in any scenario. As far as I've investigated it simply never exits "GC_PENDING" if it wasn't un-deployed before using PowerOnAndForceCustomization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I lost between explanation and doc: "The VM must be Undeployed for this action to actually work." ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. On a second read that may not be too clear. Power on works anyway, but the VM never exits GC_PENDING state if it was not undeployed.

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't vm.status == undeployed isn't sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may be. The problem is that if I enforce vm.status == undeployed, I'm not 100% sure it is the only case it would be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. If we can check the status, we can simply abort when the wanted status is not set.
What am I missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added.

govcd/vm_test.go Outdated

networkBefore, err := vm.GetNetworkConnectionSection()
check.Assert(err, IsNil)
//check.Assert(network, IsNil)
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover comment: can it be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

govcd/vm.go Outdated
// PowerOnAndForceCustomization is a synchronous function which is equivalent to the functionality
// one has in UI. It triggers customization which may be useful in some cases (like altering NICs)
//
// The VM _must_ be Undeployed for this action to actually work.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO/ Yes, we should. VM should have status.

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

discussion needed

govcd/vm.go Outdated
// PowerOnAndForceCustomization is a synchronous function which is equivalent to the functionality
// one has in UI. It triggers customization which may be useful in some cases (like altering NICs)
//
// The VM _must_ be Undeployed for this action to actually work.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. If we can check the status, we can simply abort when the wanted status is not set.
What am I missing?

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

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

LGTM

@Didainius Didainius merged commit 1d19449 into vmware:master Aug 22, 2019
@Didainius Didainius deleted the vm-network-update branch August 22, 2019 09:40
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.

5 participants