Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Automation test for removing user created vmgroup. #1474

Merged
merged 15 commits into from
Jul 6, 2017

Conversation

lipingxue
Copy link
Contributor

@lipingxue lipingxue commented Jun 23, 2017

Fixed #1341

This PR includes

  1. the automation test for removing user created vmgroup with "--remove-volumes" option
  2. code refactoring for function VerifyDetachedStatus to meet the need for automating this test

Test Done:
Only swarm related tests failed since I do not have a swarm setup

=> Running target test-e2e-runalways Tue Jun 27 22:57:46 UTC 2017
GO15VENDOREXPERIMENT=1 go test -v -timeout 30m -tags runalways github.com/vmware/docker-volume-vsphere/tests/e2e

PASS
OK: 6 passed
ok  	github.com/vmware/docker-volume-vsphere/tests/e2e	124.073s


=> Running target test-e2e-runonce Tue Jun 27 22:59:53 UTC 2017

GO15VENDOREXPERIMENT=1 go test -v -timeout 30m -tags runonce github.com/vmware/docker-volume-vsphere/tests/e2e

-- FAIL: Test (481.53s)
FAIL
OOPS: 24 passed, 2 FAILED, 1 MISSED
exit status 1
FAIL	github.com/vmware/docker-volume-vsphere/tests/e2e	481.539s


@@ -49,6 +49,9 @@ const (
// where --name will be name of the vmgroup
ReplaceVMFromVMgroup = vmdkopsAdmin + "vmgroup vm replace --name="

// AddAccessForVMgroup create access perms on vmgroup
AddAccessForVMgroup = vmdkopsAdmin + "vmgroup access add --name "
Copy link
Contributor

Choose a reason for hiding this comment

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

#1381 is also modifying this code pls. check if there is any overlap.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

L#99 is doing the same thing .. Please remove this one.

misc.SleepForSec(2)

// Status should be detached
status = verification.VerifyDetachedStatusOnNonDefaultDS(vg.volName2, vg.config.Datastores[1],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't the same VerifyDetachedStatus() be used here? Why have a separate function for the non-default DS, the DS name is being passed anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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 introduce this because most of the existing tests only need to verify volumes created on default datastore and already call function VerifyDetachedStatus(. By introducing this new function, we can keep those part unchanged. Those two util functions can be used by caller in different cases.


out, err = adminutils.AddVMToVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))
misc.LogTestEnd(c.TestName())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to recreate and add the VMs back? is it for maintaining the test config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Just for maintaining the test config.

// 2. create two volumes for this vmgroup, one is on default datastore, and the other is on non-default datastore
// 3. verify mount/unmount for this volume
// 4. after unmount, verify the volume is detached for both volumes
// 5. remove VMs from this vmgroup, and remove the vmgroup with "--remove-volume" option
Copy link
Contributor

Choose a reason for hiding this comment

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

with or without the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))

Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, please combine them as to me it seems that we are removing VMs from the same vmgroup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we do remove VMs from same vmgroup, and it is what we need to do here.

out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))

log.Printf("Removing test vmgroup %s", vgTestVMgroup1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: We do not really need this statement as DeleteVMgroup method itself has log message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@pshahzeb pshahzeb left a comment

Choose a reason for hiding this comment

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

Test looks good.
I have some refactoring comments tagged as minor. It doesn't affect the test case as such but just to avoid code repetition.
Another comment is about the sleep added in test. I think it is not needed. If yes, please add a comment.

@@ -46,6 +47,7 @@ type VmGroupTest struct {
volName1 string
volName2 string
volName3 string
volName4 string
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't because of your change but this should have been a slice instead. You might wanna handle it if it is trivial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

out, err := adminutils.AddCreateAccessForVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.Datastores[1])
c.Assert(err, IsNil, Commentf(out))

cmd := adminconst.GetAccessForVMgroup + vgTestVMgroup1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a verification step after access has been added. Might wanna wrap it into a util. If we always do this after adding the access, you might wanna add these steps to AddCreateAccessForVMgroup util so that the test steps itself are clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a verification step, remove this.

log.Printf(out)
}

misc.SleepForSec(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this sleep? Does it take time for access to be added? if so please comment.

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 copied from existing code, and verified that this is not needed. So I remove the sleep.

c.Assert(err, IsNil, Commentf(out))

// Docker may not have completed the detach yet with the host.
misc.SleepForSec(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

ExecContainer fires a container with --rm flag. So this detach should happen instantly. I am not sure if a sleep is needed here. Are we hitting a race without this sleep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

misc.SleepForSec(2)

// Status should be detached
status = verification.VerifyDetachedStatusOnNonDefaultDS(vg.volName2, vg.config.Datastores[1],
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[0])
c.Assert(err, IsNil, Commentf(out))

out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: wrap this removal and assert in a loop.


out, err = verification.GetVMGroupForVolume(vg.config.EsxHost, vg.volName2)
log.Println("GetVMGroupForVolume return out[%s] err[%s] for volume %s", out, err, vg.volName2)
c.Assert(err.Error(), Equals, "exit status 1", Commentf("volume %s should be removed", vg.volName2))
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: these 3 repeating lines can be wrapped after you the volume name as slice.

out, err = adminutils.AddVMToVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[0])
c.Assert(err, IsNil, Commentf(out))

out, err = adminutils.AddVMToVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be wrapped in a loop

@@ -152,6 +155,29 @@ func VerifyDetachedStatus(name, hostName, esxName string) bool {
return false
}

// VerifyDetachedStatusOnNonDefaultDS - For volume on non-default DS,
// check if the status gets detached within the timeout
func VerifyDetachedStatusOnNonDefaultDS(name, datastore, hostName, esxName string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this since we already have a util to verify detached status?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, the existing function should be used.

@lipingxue
Copy link
Contributor Author

@govint @ashahi1 @pshahzeb I have addressed your comments, please take a look.

const maxAttempt = 60
for attempt := 0; attempt < maxAttempt; attempt++ {
misc.SleepForSec(2)
status := getVolumeStatusHost(name+"@"+datastore, hostName)
Copy link
Contributor

Choose a reason for hiding this comment

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

The only difference between this util and VerifyDetachedStatus is the datastore arg which is used to construct a fully qualified name to get volume status from docker host.
If it is worth, please put the common part of these utils into a func which can be called from these utils.

I still think we can use VerifyDetachedStatus, unless we are worried about same volume names on different datastores.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @pshahzeb. I think we can do the same thing as what we are doing in VerifyAttachedStatus - please refer to issue #1506 and the fix: 54ea0f1

@@ -152,6 +155,29 @@ func VerifyDetachedStatus(name, hostName, esxName string) bool {
return false
}

// VerifyDetachedStatusOnNonDefaultDS - For volume on non-default DS,
// check if the status gets detached within the timeout
func VerifyDetachedStatusOnNonDefaultDS(name, datastore, hostName, esxName string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, the existing function should be used.

log.Println("GetVMGroupForVolume return out[%s] err[%s] for volume %s", out, err, volume)
c.Assert(out, Equals, "N/A", Commentf("volume %s should not belong to any vmgroup", volume))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Should clean up the volumes created for the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those volumes are no orphan volumes, and user have no way to access/cleanup those orphan volumes. So we cannot cleanup them through adminCLI or dockerCLI.
As we dicussed in #1469, we should NOT allow user to remove a vmgroup if volumes still in the vmgroup. So testing the scenario that "remove vmgroup without removing volumes" is not needed if we decided to not support remove vmgroup without removing volumes.

I plan to remove this test from the PR.

c.Assert(err, IsNil, Commentf(out))

// Status should be detached
status = verification.VerifyDetachedStatusOnNonDefaultDS(vg.volName2, vg.config.Datastores[1],
Copy link
Contributor

Choose a reason for hiding this comment

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

Same function as above can be used for the verification. Verification is best done by exec'ing a container on another docker host VM, which will be successful only when the volume is really detached from the VM.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch from 31c1ae9 to 239e8c0 Compare June 26, 2017 21:35
@lipingxue
Copy link
Contributor Author

@govint @pshahzeb I have addressed your comments and disable the test that removing vmgroup without "--remove-volumes" option.

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

@lipingxue

PR description is missing out following information.

  1. What fixes this PR is targeting. (title says about the automating test infact there are some refactoring work and improvement to existing code)
  2. Testing Done section is missing.


//TODO: Need to implement generic polling logic for better reuse
const maxAttempt = 60
for attempt := 0; attempt < maxAttempt; attempt++ {
misc.SleepForSec(2)
status := getVolumeStatusHost(name, hostName)
status := getVolumeStatusHost(name+"@"+datastore, hostName)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please shade some information why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function getVolumeStatusHost calls dockercli to get the volume status. It actually run docker volume inspect command, so for volume which is not created on the default_datastore, we need to pass in full name of the volume.

// VerifyDetachedStatus - check if the status gets detached within the timeout
func VerifyDetachedStatus(name, hostName, esxName string) bool {
log.Printf("Confirming detached status for volume [%s]\n", name)
// // VerifyDetachedStatus - check if the status gets detached within the timeout
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is dead code and can be cleaned up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// need to use full name for volume name
vg.createVolumes(c, vg.volName2+"@"+vg.config.Datastores[1])

// Verify volume can be mounted and unmounted for the first volume
Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 Jun 27, 2017

Choose a reason for hiding this comment

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

As per the inline comment, please add verification step when volume was attached otherwise inline comment needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the comments.

status := verification.VerifyDetachedStatus(vg.volName1, vg.config.Datastores[0], vg.config.DockerHosts[0], vg.config.EsxHost)
c.Assert(status, Equals, true, Commentf("Volume %s is not detached", vg.volName1))

// Verify volume can be mounted and unmounted for the second volume
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// remove VM1 and VM2 from vgTestVMgroup1 and then remove the vmgroup
vmList := []string{vg.config.DockerHostNames[0], vg.config.DockerHostNames[1]}
for _, vm := range vmList {
out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vm)
Copy link
Contributor

Choose a reason for hiding this comment

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

only one call is sufficient to remove both vms .. admin_cli vmgroup vm remove --name --vm-list .. am I missing anything here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// vmgroup has been removed and all volumes belong to it have been removed
// "err.Error()" will be filled with "exit status 1"
volumeList := []string{vg.volName1, vg.volName2}
for _, volume := range volumeList {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be replaced with one remote call invocation ..admin_cli volume ls > verifies volumes created as part of this test method should not be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should use util function instead of call "admin_cli volume ls" directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed, #1496 is filed to track this.

c.Assert(err.Error(), Equals, "exit status 1", Commentf("volume %s should be removed", volume))
}

// Recreate the test VM group1 and add VM1, VM2 back to the vmgroup
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry we should avoid this approach .. this leads to confusion any of the step fails (L494-502) instead test should create its own vmgroup and deletes it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? I checked the existing tests in "vmgroups_test.go", and I followed the approach as other tests. Why it will lead to confusion? Comments already say what is the purpose of the code from L494-502.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed, #1497 is filed to track this.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch 2 times, most recently from 9839eb5 to 6feda38 Compare June 28, 2017 05:24
// VerifyDetachedStatus - check if the status gets detached within the timeout
func VerifyDetachedStatus(name, hostName, esxName string) bool {
log.Printf("Confirming detached status for volume [%s]\n", name)
// VerifyDetachedStatus- check if the status gets detached within the timeout
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: golint is complaining about this method document ..

Reference: https://ci.vmware.run/vmware/docker-volume-vsphere/763

../tests/utils/verification/volumeproperties.go:136:1: comment on exported function VerifyDetachedStatus should be of the form "VerifyDetachedStatus ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@govint govint left a comment

Choose a reason for hiding this comment

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

Approving the change as we already have issues raised for some comments here.


// Recreate the test VM group1 and add VM1, VM2 back to the vmgroup
// cmd := adminconst.CreateVMgroup + vgTestVMgroup1 + " --default-datastore " + vg.config.Datastores[0]
// log.Printf("Creating test vmgroup %s", vgTestVMgroup1)
Copy link
Contributor

Choose a reason for hiding this comment

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

The vmgroup can be created and the two VMs can be added in this command itself via a "--vm-list"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Move the restore logic to function RestoreVmgroup

// }
// log.Printf("Timed out to poll status\n")
// return false
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete this function instead?


// remove VM1 and VM2 from vgTestVMgroup1 and then remove the vmgroup
vmList := vg.config.DockerHostNames[0] + "," + vg.config.DockerHostNames[1]
out, err = adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vmList)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion, can instead pass the vg.config.DockerHostNames to RemoveVMFromVMgroup() and let it do the creation of the vmlist to pass to the admin cli command. Basically, the test functions are simple and shouldn't have to create special args for the util functions.

c.Assert(err, IsNil, Commentf(out))

out, err = adminutils.AddVMToVMgroup(vg.config.EsxHost, vgTestVMgroup1, vmList)
c.Assert(err, IsNil, Commentf(out))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok, just place it in a separate function RestoreVmgroups() so this test function doesn't look like its cluttered with this restoration code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// for _, vm := range vmList {
// out, err = adminutils.AddVMToVMgroup(vg.config.EsxHost, vgTestVMgroup1, vm)
// c.Assert(err, IsNil, Commentf(out))
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to have a separate function to keep this code to restore the configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Same as above.

}
if len(volProps) != 2 {
log.Printf("Admin cli output is expected to consist of two elements only - "+
"volume name and vmgrop. Actual output %s ", op)
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if the same volume name is on two separate datastores, then we will get two lines (I had this scenario and verification/volumeproperties.go:GetVMAttachedToVolUsingAdminCli() failed).

I'll raise an issue for docker volume inspect to return the vmgroup for a volume so we can use it directly.

I've added a function to return a map of volume properties in PR #1500 and that can be modified to return the vmgroup for a volume.

The above approach is prone to errors in different scenarios and have a lot of this code, as much as possible should be using docker to get properties filtered out for our use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The volume name used in test is unique since it use random generator. So it is not very possible that we hit the scenario that we have same volume name with two different datastores.

For a orphan volume, docker volume inspect may not able to get the vmgroup associated with the volume.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch 2 times, most recently from 3854de9 to 0e7d4db Compare June 29, 2017 17:54
@lipingxue
Copy link
Contributor Author

I think more and decide that we should add function "VerifyDetachedStatusNonDefaultDS" back.
This function is used to check whether volume is detached if the volume is created on the non default datastore. Original function "VerifyDetachedStatus" should be used to check whether volume created on the default datastore is detached or not.

We should not try to combine function "VerifyDetachedStatusNonDefaultDS" and "VerifyDetachedStatus" into one.

Here are the reasons:

  1. From user point of view, for volume created on the default datastore, user should use short name instead of full vol name. Full vol should be used if the volume is not in the default datastore. So it is make sense to have separate functions to handle these two different scenarios. If the language support function overloading, we should have overload function for these two scenarios. Since go does not support function overloading, we should have two functions with different names here.

  2. For automation tests which need to check whether a volume is detached or not, most of the existing tests create the volume on the default datastore and the default_datastore is vm_datastore for most cases. It does not make sense to find out the vm_datastore and then pass in to function "VerifyDetachedStatus" . In order to do that, we must write another util function to get the vm_store for a VM, which is not needed. And then most existing tests need to be refactored. I don't see much value to do this.

@shuklanirdesh82 @govint
I decide to add function "VerifyDetachedStatusNonDefaultDS" back, and please review it.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch 2 times, most recently from 0b3d0a9 to 022e8c4 Compare June 30, 2017 04:16
Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

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

overall LGTM!

Please address supplied comments with this review before merging.

func DeleteVMgroup(ip, name string, delete_vol bool) (string, error) {
log.Printf("Deleting a vmgroup [%s] on esx [%s] with delete_vol[%d]\n", name, ip, delete_vol)
if delete_vol {
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name+admincli.RemoveVolumes)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: actually command should have been prepared in if ...else .. block that improve readability and ssh.InvokeCommand( would be placed at once out of if block.

@@ -49,6 +49,9 @@ const (
// where --name will be name of the vmgroup
ReplaceVMFromVMgroup = vmdkopsAdmin + "vmgroup vm replace --name="

// AddAccessForVMgroup create access perms on vmgroup
AddAccessForVMgroup = vmdkopsAdmin + "vmgroup access add --name "
Copy link
Contributor

Choose a reason for hiding this comment

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

L#99 is doing the same thing .. Please remove this one.

//TODO: Need to implement generic polling logic for better reuse
const maxAttempt = 60
for attempt := 0; attempt < maxAttempt; attempt++ {
misc.SleepForSec(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be removed; it may hide if there is any race condition.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch from 022e8c4 to bd35daf Compare June 30, 2017 06:36
@govint
Copy link
Contributor

govint commented Jun 30, 2017

@lipingxue, no the VerifyDetachedState() function is sufficient for any scenario - whether default or non-default datastore. The user has the choice to specify the datastore whether its a default or not. The function is only figuring out whether a volume is in detached or attached state. Why should that depend on the datastore?

In fact, the restart tests explicitly test for use case where user can attach a volume via short and long name on the default and non-default datastores.

@lipingxue
Copy link
Contributor Author

lipingxue commented Jun 30, 2017

@govint I don't get your point what do you mean "user has the choice to specify the datastore whether its a default or not". Which parameter that the function need to take so that "user has the choice to specify the datastore whether its a default or not"? The function calls both dockerCLI and adminCLI to figure out the volume is detached or not. For dockerCLI, short name can only be used if the volume is created in the default datastore. Otherwise, user need to specify the full vol name.

@shuklanirdesh82
Copy link
Contributor

shuklanirdesh82 commented Jun 30, 2017

@lipingxue Let's continue the investigation in the next sprint. So not merging this PR.

CI is failing: https://ci.vmware.run/vmware/docker-volume-vsphere/842

2017/06/30 15:40:00 START: vgBasicSuite.TestDSAccessPrivilegeForUserVG
2017/06/30 15:40:00 Creating create access for vmgroup vg_basictest, datastore vsanDatastore on esx [192.168.31.62] 
2017/06/30 15:40:03 Getting vmgroup's [vg_basictest] access rights to datastore vsanDatastore ,  on esx [192.168.31.62] 
2017/06/30 15:40:05 Access rights to datastore vsanDatastore for vmgroup - vg_basictest are: [vsanDatastore True] . 

----------------------------------------------------------------------
FAIL: vmgroupmisc_test.go:157: vgBasicSuite.TestDSAccessPrivilegeForUserVG

vmgroupmisc_test.go:165:
    c.Assert(isDatastoreAccessible, Equals, false, Commentf("Unexpected Behavior: Datastore %s is accessible for vmgroup %s .", s.config.Datastores[1], vmGroupName))
... obtained bool = true
... expected bool = false
... Unexpected Behavior: Datastore vsanDatastore is accessible for vmgroup vg_basictest .

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

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

Sorry for the late comments. Change looks good overall.

@@ -35,6 +35,7 @@ import (

type SwarmTestSuite struct {
esxName string
dataStores []string
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover during refactoring? Let's remove this unused field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -431,3 +432,138 @@ func (vg *VmGroupTest) TestVmGroupVolumeClone(c *C) {

misc.LogTestEnd(c.TestName())
}

// Restore VMgroup
func (vg *VmGroupTest) RestoreVmgroup(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This function should start with small letter since we don't really want to export it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const maxAttempt = 60
for attempt := 0; attempt < maxAttempt; attempt++ {
misc.SleepForSec(2)
status := getVolumeStatusHost(name+"@"+datastore, hostName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @pshahzeb. I think we can do the same thing as what we are doing in VerifyAttachedStatus - please refer to issue #1506 and the fix: 54ea0f1

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch from bd35daf to 545b76c Compare July 3, 2017 22:31
@lipingxue
Copy link
Contributor Author

@shaominchen I have addressed your comments, please take a look. Thanks!

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

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

LGTM.

@lipingxue lipingxue force-pushed the vmgroup_rm_test.liping branch from 760c2bc to 40eaf58 Compare July 5, 2017 22:22
@lipingxue lipingxue merged commit 92868b1 into master Jul 6, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the vmgroup_rm_test.liping branch November 10, 2017 05:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants