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

Misc features in vcsim #855

Merged
merged 3 commits into from
Oct 5, 2017
Merged

Misc features in vcsim #855

merged 3 commits into from
Oct 5, 2017

Conversation

anfernee
Copy link
Contributor

@anfernee anfernee commented Oct 2, 2017

  • Snapshot support
  • UpdateNetworkConfig support
  • UserDirectory support

Fixes #819 #821 (I assume it will fix those, not exactly sure because of lack of context)

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

Great stuff. A few minor comments/suggestions.

}
}

func (v VirtualMachineSnapshot) RevertToSnapshotTask(req *types.RevertToSnapshot_Task) soap.HasFault {
Copy link
Member

Choose a reason for hiding this comment

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

Make that a pointer receiver *VirtualMachineSnapshot

body := &methods.RetrieveUserGroupsBody{}
var res []types.BaseUserSearchResult

var compare func(a, b string) bool
Copy link
Member

Choose a reason for hiding this comment

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

Looks like it should also be case insensitive when ExactMatch is false. Maybe:

func equal(name string, search string) bool {
    return name == search
}

func match(name string, search string) bool {
    return strings.Contains(strings.ToLower(name), search)
} 

Then:

compare := equal
search := req.SearchStr
if !req.ExactMatch {
    compare = match
    search = strings.ToLower(search)
}


func NewUserDirectory(c *vim25.Client) *UserDirectory {
return &UserDirectory{
Common: NewCommon(c, *c.ServiceContent.UserDirectory),
Copy link
Member

Choose a reason for hiding this comment

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

UserDirectory is also a property of HostConfigManager, so we don't want to hardwire ServiceContent.UserDirectory

}

func GetUserDirectory(c *vim25.Client) (*UserDirectory, error) {
if c.ServiceContent.UserDirectory == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a case where it would be nil? We only have a few of these Get methods for ServiceContent to cover the cases where ESX is not supported, such as GetExtensionManager and GetCustomFieldsManager.

}
}

func (u UserDirectory) RetrieveUserGroups(
Copy link
Member

Choose a reason for hiding this comment

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

I think we should just skip the object package wrapper for UserDirectory. As we discussed, there's too much in object/ already, we can just use the types+methods packages directly for calling RetrieveUserGroups.

mo.VirtualMachineSnapshot
}

func NewVirtualMachineSnapshot(
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we need this func, the other simulator.New* funcs are called from more than one place or outside of a soap service method, such as NewServiceInstance(). Here you can just inline the 2 lines within CreateSnapshot.

@@ -552,6 +552,71 @@ load test_helper
assert_success
}

@test "vm.snapshot vcsim" {
Copy link
Member

Choose a reason for hiding this comment

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

Great to have tests against both real ESX and vcsim. But if they are the same, could you move the code to a function and call it from both?

test_snapshot() {
   ...
}

@test "vm.snapshot" {
  esx_env
  test_snapshot
}

@test "vm.snapshot vcsim" {
  vcsim_env
  test_snapshot

return snapshot
}

func (v *VirtualMachineSnapshot) AddChild(child types.ManagedObjectReference) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's not export this method. Or maybe this could just be inlined instead of having the extra method?

result = append(result, ss.Snapshot)
result = append(result, allSnapshotsInTree(ss.ChildSnapshotList)...)
}
return result
Copy link
Member

Choose a reason for hiding this comment

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

style: add an empty line between the statements (there's a few of these in the PR), we do that in most cases for return too:
git grep -A1 -B2 'return ' -- simulator

t.Fatal(err)
}

vm := vms[0]
Copy link
Member

Choose a reason for hiding this comment

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

Note that for the test cases where you can use any instead of a type, you can avoid the Finder hassle with the Map.Any function:

vm := object.NewVirtualMachine(c, Map.Any("VirtualMachine").Reference())

@Akasurde
Copy link
Contributor

Akasurde commented Oct 4, 2017

@anfernee @dougm I look forward for these changes and will test with Ansible. Thanks.

@anfernee anfernee force-pushed the vcsim branch 2 times, most recently from 7477320 to 941963a Compare October 4, 2017 23:14
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

Looking good, mainly don't want to leave the test against esx disabled.


load test_helper

test_vm_snapshot() {
Copy link
Member

Choose a reason for hiding this comment

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

ok to call the file and the func/test names just "snapshot" without the "vm" prefix, since the command doesn't have it either.


vm=$(new_ttylinux_vm)

# test_vm_snapshot $vm
Copy link
Member

Choose a reason for hiding this comment

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

Is this test not working against ESX or was just taking too long to run? You can use this to run a single test: sstephenson/bats#117

(even nicer with bats.el :)

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 forgot to re-enable that..

vm=$(new_empty_vm)

test_vm_snapshot $vm

Copy link
Member

Choose a reason for hiding this comment

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

whoops, don't want a blank line there


for _, ug := range u.userGroup {
if req.FindUsers && !ug.Group || req.FindGroups && ug.Group {
compare := compareFunc(req.SearchStr, req.ExactMatch)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you could move this outside of the for loop, so it only needs to be called once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

return body
}

func compareFunc(compared string, exactly bool) func(string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

nice use of closures!

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

lgtm

@dougm dougm merged commit 539c497 into vmware:master Oct 5, 2017
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.

Unable to add portgroup
4 participants