-
Notifications
You must be signed in to change notification settings - Fork 454
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
r/virtual_machine: Handle missing environment browser #414
Conversation
The virtual machine resource relies on the cluster or standalone host it's deployed on for information regarding a default hardware set or guest OS family information. This is obtained via the EnvironmentBrowser MO referenced by the respective cluster or host's ComputeResource MO. There are certain situations where this attribute will be missing, two of which have been identified so far via bug reports: * A cluster without hosts will not contain an environment browser. * vSphere licensing issues may cause a missing environment browser (#409 reported an expired vCenter). This update wraps our fetching of the environment browser by the two current compute resource helpers that utilize it in a helper that validates that we actually have an environment browser before proceeding to load it up, issuing an error alluding to the above if it is missing. Fixes #411. May also correct #409.
os.Getenv("VSPHERE_DATACENTER"), | ||
os.Getenv("VSPHERE_EMPTY_CLUSTER"), | ||
os.Getenv("VSPHERE_NETWORK_LABEL_PXE"), | ||
os.Getenv("VSPHERE_DATASTORE"), |
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.
nit: these functions feel like they'd be more reusable if the environment variables are passed in as arguments, but I don't have the context to know if that's a valid design consideration or not.
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 applicable, configuration generators do have parameterization, but again, only when it's necessary in a test (ie: a multi-step test where the configuration is the same but a variable is changing). Otherwise, these configurations should be considered static and doubling up the parameterization would only serve to make things more redundant.
Some future work I'm considering doing is possibly adding to the test suite so that we can load external configuration (ie: out of a test-fixtures
directory), and allowing the use of actual variables. If that indeed comes to fruition, this is probably when I would come back to this and refactor things so that the parameterization is in the individual test cases themselves.
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.
on that note - tbh there's an argument for making these values a Struct that's parsed out once, rather than in each test function (this is the case in all providers)
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 be fine with this if there was a way to wrap it in a way that retains the same "static generation" look and feel. I actually am not a fan of having variables declared in every test function.
I think that something along the lines of this would work even:
Config: resource.GenerateConfig(testAccResourceVSphereConfigHere),
Where resource.GenerateConfig
is a generator that takes a text/template
with a lightweight, Packer-ish way of accessing environment variables.
testAccSomeConfig = `
variable "foo" {
default = "{{env TEST_PROVDER_ENV_VAR}}"
}
`
In any case, such things are kind of out of scope here 😛
}, | ||
{ | ||
Config: testAccResourceVSphereEmpty, | ||
Check: resource.ComposeTestCheckFunc(), |
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.
Is this really supposed to execute the config and not check anything?
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 necessary for steps with PlanOnly
to ensure that the destroy step does not attempt to plan/refresh off of the broken configuration and run into the same issue. I think this might be a bug in the test framework but I'm not 100% sure, as the destroy step is only supposed to run if a state exists as referenced here, and it's odd to me as to why a bad plan would have a state versus a bad apply. In any case, the second step just runs with a completely blank config to clear out the state so any subsequent destroy steps have nothing to do.
An example of what happens when that step does not run:
--- FAIL: TestAccResourceVSphereVirtualMachine/clone_into_empty_cluster,_no_environment_browser_(fails_on_plan) (5.54s)
testing.go:573: Error destroying resource! WARNING: Dangling resources
may exist. The full state and error is shown below.
Error: Error refreshing: 1 error(s) occurred:
* vsphere_virtual_machine.vm: 1 error(s) occurred:
* vsphere_virtual_machine.vm: cannot find OS family for guest ID "ubuntu64Guest": compute resource "ComputeResource:domain-c178 @ /hashi-dc/host/hashi-cluster2" is missing an Environment Browser. Check host, cluster, and vSphere license health of all associated resources and try again
State: <nil>
I've removed it from the apply test (creation from scratch) and will push.
This test does not need it as the issue where the acceptance test framework seems to attempt a destroy when it doesn't have a state only seems to happen on PlanOnly tests.
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.
My questions have been adequately answered to satisfy me that they're design decisions and not oversights.
I don't have the context or experience here to gauge those design decisions, but the code seems ok to me.
Thanks @paddycarver! |
(This approval was meant to convey "looks good to me within the limits of my ability to determine whether something is good or not", but I've been awful at communicating today, so apologies if it came off as something else.) |
The virtual machine resource relies on the cluster or standalone host
it's deployed on for information regarding a default hardware set or
guest OS family information. This is obtained via the
EnvironmentBrowser
MO referenced by the respective cluster or host's
ComputeResource
MO.There are certain situations where this attribute will be missing, two
of which have been identified so far via bug reports:
reported an expired vCenter).
This update wraps our fetching of the environment browser by the two
current compute resource helpers that utilize it in a helper that
validates that we actually have an environment browser before proceeding
to load it up, issuing an error alluding to the above if it is missing.
Fixes #411.
May also correct #409.