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 GetVirtualHardwareSection fuction #200

Merged
merged 20 commits into from
Aug 28, 2019
Merged

Conversation

frenchtoasters
Copy link
Contributor

IMPORTANT

To help us process your pull request efficiently, please follow the
guidelines shown below.

A Pull Request should be associated with an Issue

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.

We accept PRs without associated issues provided the change is sufficiently evident
from the commit message. If you have typos or simple bug fixes go for it.

Description

Related issue: #199

Add GetVirtualHardwareSection fuction

This function is near identical to GetNetworkConnectionSection() in /govcd/vm.go and does essentially the same thing. It gathers the /vApp/{id}/virtualHardwareSection endpoint of a VM from the restapi and then returns that the *types.VirtualHardwareSection pointer which already has the corresponding structs written, here. It also references a new mime type types.MimeVirtualHardwareSection which was derived from here.

frenchtoasters and others added 5 commits June 10, 2019 23:45
Returning the Vdc.Status as a string breaks the usage of the `types.VDCStatuses[]` map as the value returned is of `type string` and not `type int` as the map is defined here https://github.com/vmware/go-vcloud-director/blob/master/types/v56/types.go#37. Currently something like this is required to use the `types.VDCStatues[]` map:

```
i, err := strconv.Atoi(vdc.Vdc.Status)
if err != nil {
	return err
}
log.Info(types.VDCStatuses[i])    // Returns the mapped value       
```

This change would give `Vdc.Status` the same behavior as `Vapp.Status` when using either of their corresponding maps and allow for this to work:

```
log.Info(types.VDCStatuses[vdc.Vdc.Status])
```
@Didainius Didainius requested review from lvirbalas, vbauzys and dataclouder and removed request for vbauzys June 12, 2019 08:37
@Didainius
Copy link
Collaborator

Hi, @frenchtoasters. Thanks for the PR.
Would you be able to pull in a test for the new function?

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

Thank you for your PR - just small improvements needed. And also unit test will be big help.

@frenchtoasters
Copy link
Contributor Author

Hi, @frenchtoasters. Thanks for the PR.
Would you be able to pull in a test for the new function?

Ya sure I didnt see one for the GetNetworkConnectionSection but I can mock one up tonight for this.

@lvirbalas
Copy link
Collaborator

lvirbalas commented Jun 18, 2019

@frenchtoasters as a preparation for merge, please provide a commit message following the guidelines https://chris.beams.io/posts/git-commit/ as referenced in CONTRIBUTING.md

govcd/vm_test.go Outdated
},
}

vm, err := vcd.client.Client.FindVMByHREF(newVM.HREF)
Copy link
Contributor

@dataclouder dataclouder Jun 18, 2019

Choose a reason for hiding this comment

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

This call cannot work.
You are calling a function that finds a VM by HREF, but the HREF is empty, as it is only available for entities that have been created or fetched from vCD.

The test should use an already existing VM (preferred), or create a new one, and then get its contents.

@lvirbalas
Copy link
Collaborator

@frenchtoasters Are you planning to complete this one?

@frenchtoasters
Copy link
Contributor Author

@frenchtoasters Are you planning to complete this one?

Yes I do just have not been able to budget out the time to correct the unit test. Though I believe the fix is fairly simple, in that I should just be using the findFirstVapp and findFirstVm functions instead of creating my own vm.

Though I am wondering @dataclouder would it be acceptable to set the VirtualHardwareSection for the VM that was found myself and then validate those values are returned correctly from the GetVirtualHardwareSection or should I use a SetVirtualHardwareSection function to create them as well?

@dataclouder
Copy link
Contributor

Though I am wondering @dataclouder would it be acceptable to set the VirtualHardwareSection for the VM that was found myself and then validate those values are returned correctly from the GetVirtualHardwareSection or should I use a SetVirtualHardwareSection function to create them as well?

Both approaches work, though I am not sure the first one could get predictable results.
I would accept both, provided that:
a) the tests are done with real VMs, not mocks.
b) the results are independently verifiable (meaning that creating vApps/VMs with our own OVAs, we get the same results as you do)
c) the testing code has sufficient comments to explain what is the test intention and what's the expected result.

Looking forward to evaluating your improvements!

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

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

Hi @frenchtoasters,
Sorry for leaving you in limbo for this long. We had the release on tight schedule.

I have ran your test and it failed on my side.

go test -tags functional -check.vv -check.f "Test_GetVirtualHardwareSection" -timeout=15m .

START: vm_test.go:815: TestVCD.Test_GetVirtualHardwareSection
Running: TestGetVirtualHardwareSection
vm_test.go:851:
    check.Assert(item.Address, Equals, vm.VM.VirtualHardwareSection.Item[0].Address)
... obtained string = "00:50:56:29:01:fd"
... expected string = "1.1.1.1"

FAIL: vm_test.go:815: TestVCD.Test_GetVirtualHardwareSection

I have left some ideas inline on how to make this working.

frenchtoasters and others added 2 commits August 24, 2019 11:51
Co-Authored-By: Dainius <Didainius@users.noreply.github.com>
@Didainius
Copy link
Collaborator

The tests seems to be passing for me. Could you merge latest master branch as it has conflicts now.

@Didainius
Copy link
Collaborator

Be sure to make fmt and see that TravisCI is green.

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

LGTM

Co-Authored-By: Dainius <Didainius@users.noreply.github.com>
@Didainius
Copy link
Collaborator

Thanks!
The test passes, looks fine. I'll let other team members look around and approve before we merge it.

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

Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!

@Didainius Didainius merged commit 7f5c3df into vmware:master Aug 28, 2019
@Didainius
Copy link
Collaborator

It is now merged. Thank you @frenchtoasters !

Didainius added a commit to Didainius/go-vcloud-director that referenced this pull request Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants