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

r/virtual_machine: Handle missing environment browser #414

Merged
merged 2 commits into from
Feb 27, 2018

Conversation

vancluever
Copy link
Contributor

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:

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.

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.
@vancluever vancluever requested a review from a team February 27, 2018 19:19
@vancluever vancluever added bug Type: Bug crash Impact: Crash labels Feb 27, 2018
os.Getenv("VSPHERE_DATACENTER"),
os.Getenv("VSPHERE_EMPTY_CLUSTER"),
os.Getenv("VSPHERE_NETWORK_LABEL_PXE"),
os.Getenv("VSPHERE_DATASTORE"),

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.

Copy link
Contributor Author

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.

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)

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 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(),

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?

Copy link
Contributor Author

@vancluever vancluever Feb 27, 2018

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.
Copy link

@paddycarver paddycarver left a 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.

@vancluever
Copy link
Contributor Author

Thanks @paddycarver!

@vancluever vancluever merged commit aba1737 into master Feb 27, 2018
@paddycarver
Copy link

(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.)

@vancluever vancluever deleted the b-missing-environment-browser branch March 31, 2018 17:41
@ghost ghost locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug crash Impact: Crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unexpected EOF when running example template
3 participants