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

E2E tests related to default vmgroup and non-default vmgroup #1381

Merged
merged 1 commit into from
Jun 27, 2017

Conversation

ashahi1
Copy link
Contributor

@ashahi1 ashahi1 commented Jun 9, 2017

Fixes: #1486 and #1477

This PR fixes following issues:

TestDeleteDefaultVmgroup has already been reviewed.

Fixing test cleanup is the new change in the current commit. Please review it.

=============================

Test: TestDeleteDefaultVmgroup

Steps:
Objective: Verify volume creation fails after deleting _DEFAULT tenant
 1. Create a volume
 2. Verify volume from docker host and esx
 2. Delete default tenant
 3. Verify not able to create volume from docker host - Error: VM does not belong to any vmgroup
 4. Verify docker volume ls does not show any volumes
 5. Verify admin cli shows volume with VMGroup set as N/A
 6. Create _DEFAULT vmgroup with —default-datastore=_VM_DS
 7. Again create new volume - operation should succeed
 8. Verify volume from esx and docker host
2017/06/13 22:20:49 Removing policy [validPolicy] on esx [10.162.4.8]
--- PASS: Test (463.98s)
PASS
OK: 25 passed
ok  	github.com/vmware/docker-volume-vsphere/tests/e2e	463.982s
make: Leaving directory `/go/src/github.com/vmware/docker-volume-vsphere/vmdk_plugin'

@@ -142,3 +144,8 @@ func GetTestConfig() *TestConfig {

return config
}

// GetTenantNameWithTimeStamp prepares unique tenant name by appending current time-stamp value
func GetTenantNameWithTimeStamp(vmgroupName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

you know there is an open issue of avoid using strconv.FormatInt(time.Now().Unix(), 10) approach and use random string instead.

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

if s.config == nil {
c.Skip("Unable to retrieve test config, skipping vmgroupbasic.TestVmgroupLs.")
}
out, err := admincli.ConfigInit(s.config.EsxHost)
Copy link
Contributor

Choose a reason for hiding this comment

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

Its incorrect to init and cleanup the DB for each test. The DB is a part of the system being tested. If a bunch of ops are performed on the DB we need to verify that the DB itself is sane at the end of the test. Customers aren't going to be cleaning up their DB every now and then. ConfigInit must be done either on the ESX host before the test or done once at the start of all tests.


// Removes config init
func (s *vgBasicSuite) TearDownSuite(c *C) {
out, err := admincli.ConfigRemove(s.config.EsxHost)
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect to remove config DB.

}

func (s *vgBasicSuite) TearDownTest(c *C) {
out, err := admincli.DeleteVMgroup(s.config.EsxHost, s.tenantName)
Copy link
Contributor

Choose a reason for hiding this comment

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

If something is done in setup-suite then undo it in teardown-suite. Unless its something to be done after each test. Is that the case here.

func (s *vgBasicSuite) TestVmgroupLs(c *C) {
misc.LogTestStart("", c.TestName())

out, err := admincli.CreateVMgroup(s.config.EsxHost, s.tenantName, s.config.DockerHostNames[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Admin cli doesn't return errors :-( so while these checks are there for asserting nil error, its doing nothing. The CLI command could have failed and we know nothing about it. The CLI shell command itself doesn't exit with a non-zero exit status to check this.

log.Printf("VM[%s]'s current power state is [%s]", s.config.DockerHostNames[0], properties.PoweredOnState)
c.Assert(powerState, Equals, properties.PoweredOnState, Commentf("VM [%s] should be powered on state", s.config.DockerHostNames[0]))

vmProcessID := esxcli.GetVMProcessID(s.config.EsxHost, s.config.DockerHostNames[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

esxcli and govc routines are all doing the same thing - getting/setting data on ESX. May be then create an esx.go module and add functions there to GetVMPowerState(), KillVMByName(name) (will get the process ID and kill the VM), WaitVMPowerState(state), etc. I can add that or you can do this. Let me know. The misc.WaitForExpectedState() should move that esx module.

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 will add it.

// GetVmgroupVMs - lists all the VMs of a particular vmgroup
// [] Empty array is returned if no VMs exist in vmgroup
func GetVmgroupVMs(esxIP, vmGroupName string) []string {
log.Printf("Getting all the VMs belonging to a particular tenant [%s] \n", vmGroupName)
Copy link
Contributor

Choose a reason for hiding this comment

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

"particular vmgroup"

cmd := admincli.ListVmgroupVMs + vmGroupName + " 2>/dev/null | cut -d ' ' -f 3 "
out, _ := ssh.InvokeCommand(esxIP, cmd)
vmNames := strings.Fields(out)
vmList := vmNames[1:len(vmNames)]
Copy link
Contributor

Choose a reason for hiding this comment

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

can specify vmNames[1:] meaning from index 1 till last index.

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

if out == "" {
return false
}
log.Printf("out : \n %s", out)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove if its only debug.

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

return false
}
log.Printf("out : \n %s", out)
return strings.Contains(out, vmgroupName)
Copy link
Contributor

Choose a reason for hiding this comment

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

strings.Contains can handle "" strings. Can just return strings.Contains(out, vmgroupName) at line 185

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

@@ -142,3 +144,8 @@ func GetTestConfig() *TestConfig {

return config
}

// GetTenantNameWithTimeStamp prepares unique tenant name by appending current time-stamp value
func GetTenantNameWithTimeStamp(vmgroupName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

GetVmgroupNameWithTimeStamp

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 Jun 9, 2017

Choose a reason for hiding this comment

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

+1 ... GetVmgroupUniqueName to keep consistent with others.

@ashahi1 ashahi1 changed the title Tenant ls command does not works if vm that was added to tenant is deleted. [Test Automation] Verify vmgroup ls command works even after vmgroup's vm is killed Jun 9, 2017
@ashahi1 ashahi1 changed the title [Test Automation] Verify vmgroup ls command works even after vmgroup's vm is killed [Test Automation] [Do NOT Review]Verify vmgroup ls command works even after vmgroup's vm is killed Jun 9, 2017
@ashahi1 ashahi1 changed the title [Test Automation] [Do NOT Review]Verify vmgroup ls command works even after vmgroup's vm is killed [Test Automation] [Do NOT Review] Verify vmgroup ls command works even after vmgroup's vm is killed Jun 9, 2017
@ashahi1 ashahi1 changed the title [Test Automation] [Do NOT Review] Verify vmgroup ls command works even after vmgroup's vm is killed [Test Automation] [Do Not Review] Verify vmgroup ls command works even after vmgroup's vm is killed Jun 9, 2017
@shuklanirdesh82 shuklanirdesh82 changed the title [Test Automation] [Do Not Review] Verify vmgroup ls command works even after vmgroup's vm is killed [Do Not Review] Verify vmgroup ls command works even after vmgroup's vm is killed Jun 9, 2017
@msterin
Copy link
Contributor

msterin commented Jun 13, 2017

@ashahi1 - can this be closed ? You can reopen it when it's ready to be reviewed and merged

@ashahi1
Copy link
Contributor Author

ashahi1 commented Jun 14, 2017

@msterin I am done with all the changes, will be sending out the code for review later today.

@ashahi1 ashahi1 force-pushed the vmgroupls.ashahi1 branch 2 times, most recently from 1ceec05 to 3d882a0 Compare June 14, 2017 04:29
@ashahi1 ashahi1 changed the title [Do Not Review] Verify vmgroup ls command works even after vmgroup's vm is killed E2E tests related to default vmgroup and non-default vmgroup Jun 14, 2017

// DefaultVMgroup referring name of default vmgroup
DefaultVMgroup = "_DEFAULT "
DefaultVMgroup = "_DEFAULT"
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, such spaces after a const are introduced to properly construct the remote command.
If you remove such spaces, please make sure all existing test pass correctly (i.e . CI passes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

. "gopkg.in/check.v1"
)

const (
ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
Copy link
Contributor

Choose a reason for hiding this comment

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

Which error msg? Please rename this const to be more specific. defintelu not ErrorMsg .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to vgErrorMsg.

ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
NotAvailable = "N/A"
defaultVG = "defaultVG"
Copy link
Contributor

Choose a reason for hiding this comment

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

please rename this to defualtVGTest. it doesn't imply if this is a test var something we need to define for our test to pass.

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

esxIP string
hostName string
config *inputparams.TestConfig
volumeName1 string
Copy link
Contributor

Choose a reason for hiding this comment

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

I can certainly imagine more volumes coming in as a part of this part. do you mind having this a slice instead of volumeName1, volumeName2 etc. it would only create inconvenience later.

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 := admincli.ReplaceVMFromVMgroup(s.esxIP, con.DefaultVMgroup, s.hostName)
out, err := admincli.ReplaceVMFromVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.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.

why not s.config.DockerHostNames[0] ?
Is it due to something due to env dependency? please call out in PR description so that all of us are aware about it.

Copy link
Contributor Author

@ashahi1 ashahi1 Jun 17, 2017

Choose a reason for hiding this comment

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

I didn't get you. You are asking why I am using s.config.DockerHostNames[1]? Nothing specific, trying to replace DockerHostNames[1] and not DockerHostNames[0]

func (s *DefaultVMGroupTestSuite) TestDeleteDefaultVmgroupAndVerify(c *C) {
misc.LogTestStart(c.TestName())
s.volumeName1 = inputparams.GetUniqueVolumeName(defaultVG)
s.volumeName2 = inputparams.GetUniqueVolumeName(defaultVG)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use c.TestName() here instead of defaultVG

Copy link
Contributor Author

@ashahi1 ashahi1 Jun 17, 2017

Choose a reason for hiding this comment

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

volume name becomes extremely long in that case. e.g. TestDeleteDefaultVmgroupAndVerify_volume_<Some 6-7 digit random number>


// Create a volume - operation should fail as default vmgroup no longer exist
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeName2)
c.Assert(err, Not(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 check is good.
Do we also have another string that we can double check as part of out to indicate the scenario that vmgroup no longer exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right before this step, I am already checking if default vmgroup exists or not. I am basically listing all the vmgroup using vmgroup ls cmd and then verifying if default vmgroup exist in there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added additional check to verify the error message as well from vm.

c.Assert(isVmgroupAvailable, Equals, false, Commentf("Falied to delete vmgroup %s .", admincliconst.DefaultVMgroup))

// Create a volume - operation should fail as default vmgroup no longer exist
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeName2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same steps are done for volume1 and then for volume 2.

Do you mind wrapping them in a func.

If there are more incoming test in this suite, it would be good to do this steps to do these steps as part of test setup/or not.

Feel free to make the call.

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

c.Assert(status, Equals, true, Commentf("Volume %s is still attached", s.volumeName))

log.Printf("END: swarm_test.TestDockerSwarm")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming deletion of this file was by mistake. If not; why? //CC @shaominchen

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, added the file back.


const (
//PoweredOffState - vm powered-off
PoweredOffState = "poweredOff"
Copy link
Contributor

Choose a reason for hiding this comment

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

We have moved these 2 constants to a new file, but why the below moving file change shows "File renamed without changes."? Shouldn't we remove these VM related constants from volumeproperties.go?

BTW, the file name "volumeroperties.go" has a typo, please fix 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

// 6. Create _DEFAULT vmgroup with —default-datastore=_VM_DS
// 7. Again create new volume - operation should succedd
// 8. Verify volume from esx and docker host
func (s *DefaultVMGroupTestSuite) TestDeleteDefaultVmgroupAndVerify(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.

The suffix "AndVerify" seems redundant.

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

}

// Create volumes
func (s *DefaultVMGroupTestSuite) createVolume(c *C, hostIp, volumeName string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest avoid passing *C to private functions. A private function should just take care of one specific task (for code reuse or whatever purpose), and return a result (e.g. string, boolean, error, etc.) that can be verified by the main test workflow using c.Assert().

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

@ashahi1 ashahi1 force-pushed the vmgroupls.ashahi1 branch 2 times, most recently from 0b142ef to f2a84f0 Compare June 20, 2017 03:53
VMlist = " --vm-list="

// AddDatastoreToVMgroup adds datastore to vmgroup
AddDatastoreToVMgroup = 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.

AddDatastoreToVMgroup sounds confusing .. I guess idea is to add datastore access to VMgroup. .. it can be simplified with name AddDatastoreAccess or AssignDatastoreAccess

. "gopkg.in/check.v1"
)

const (
ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
vgErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
NotAvailable = "N/A"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this required to be exported constant?

@@ -143,3 +144,12 @@ func GetTestConfig() *TestConfig {

return config
}

// GetRandomNumber returns random number
func GetRandomNumber() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to be exported member .. getRandomNumber is sufficient.

// VerifyVDVSIsRunning - finds out if vDVS is running. This util can be useful
// in scenarios where vm is powered-on and user wants to find out if
// vm is fully up to be able to run docker volume commands.
func VerifyVDVSIsRunning(ip 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.

volumelifecycle.go is not a better home to host this util .. Please move to appropriate file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a separate file named vDVSUtil.go under tests/utils/verification/

func VerifyVDVSIsRunning(ip string) bool {
log.Printf("Verifying if vDVS is running on vm : %s", ip)
maxAttempt := 20
waitTime := 5
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: let's reduce this to 2 or 3

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

}

// DeleteVMgroup method deletes a vmgroup and removes its volumes as well
func DeleteVMgroup(ip, name string) (string, error) {
log.Printf("Deleting a vmgroup [%s] on esx [%s]\n", name, ip)
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name+admincli.RemoveVolumes)
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the reason behind this change?

}

// AddCreateAccessForVMgroup - set allow-create access on the vmgroup
func AddCreateAccessForVMgroup(ip, name, datastore string) (string, error) {
log.Printf("Enabling create access for vmgroup %s, datastore %s on esx [%s] \n", name, datastore, ip)
return ssh.InvokeCommand(ip, admincli.SetAccessForVMgroup + name + " --allow-create True --datastore " + datastore)

// Following two lines are only for debugging purposes - will remove before final merge
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I guess CI is passed and this debug lines should be removed.

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

@@ -84,3 +91,56 @@ func ConfigRemove(ip string) (string, error) {
log.Printf("Removing the SingleNode Config DB on esx [%s] \n", ip)
return ssh.InvokeCommand(ip, admincli.RemoveLocalConfigDb)
}

// CheckVmgroupAvailability - checks for a vmgroup in list of vmgroups
func CheckVmgroupAvailability(esxIP, vmgroupName 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.

CheckVmgroupAvailability should be renamed to IsVMgroupPresent/Exist

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

}

// CheckVolumeExistInVmgroup - verify volume's vmgroup is same as expected
func CheckVolumeExistInVmgroup(esxIP, volName, vmgroupName 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.

minor: CheckVolumeExistInVmgroup => IsVolumeExistInVmgroup

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

log.Printf("Getting vmgroup %s access rights to datastore %s , on esx [%s] \n", name, datastore, ip)
cmd := admincli.GetAccessForVMgroup + name + " 2>/dev/null | awk -v OFS='\t' '{print $1, $2}' | grep " + datastore
out, _ := ssh.InvokeCommand(ip, cmd)
accessRights := strings.Fields(out)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we have to check out is not empty? What happens when datastore access rule is not set for the 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.

Done

cmd := admincli.CreateVMgroup + admincli.DefaultVMgroup + " --default-datastore " + admincli.VMHomeDatastore
_, err := ssh.InvokeCommand(ip, cmd)
if err != nil {
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.

need to add logging statement here like Error occurred while creating _DEFAULT vm group

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

if err != nil {
return false
}
_, err = ssh.InvokeCommand(ip, admincli.AddDatastoreToVMgroup+admincli.DefaultVMgroup+" --datastore=_ALL_DS --allow-create ")
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 ... is err field reliable?

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

}
_, err = ssh.InvokeCommand(ip, admincli.AddDatastoreToVMgroup+admincli.DefaultVMgroup+" --datastore=_ALL_DS --allow-create ")
if err != nil {
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.

minor: need logging statement for better triaging.

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

// 4. Verify docker volume ls does not show any volumes
// 5. Verify admin cli shows volume with VMGroup set as N/A
// 6. Create _DEFAULT vmgroup with —default-datastore=_VM_DS
// 7. Again create new volume - operation should succedd
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: need to fix succedd

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

NoVgErrorMsg := "VolumeDriver.Create: VM " + s.config.DockerHostNames[0] + " does not belong to any vmgroup"

// Create a volume
out, err := dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding a check that only _default vmgroup is 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.

Done

out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[1])
c.Assert(err, IsNil, Commentf(out))

// Check if volume was successfully created
Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 Jun 20, 2017

Choose a reason for hiding this comment

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

need to add one more check here .. after recreation of default vmgroup .. previously created volume (L#136) should be available.

Note: comment is for L#146 in fact immediately after creating _default 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.

Done

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.

This PR is having too many changes and making reviewer's life harder.

By taking this PR as an example, I would suggest to break this down in the future.

c.Assert(isAvailable, Equals, true, Commentf("Volume %s is not available after creation", s.volumeNames[1]))

// Verify if volume exists in default vmgroup
isVolInVmgroup = admincli.CheckVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[1], admincliconst.DefaultVMgroup)
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to check about both volumes are exist and having _DEFAULT under vmgroup column and not N/A

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 (
vmGroupName = "vg_basictest"
NotApplicable = "N/A"
Copy link
Contributor

Choose a reason for hiding this comment

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

seen this again .. it is better to move to admincli const file.

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

// See the License for the specific language governing permissions and
// limitations under the License.

// This test suite tries to verify if vmgroup ls command works fine even after tenant's vm is killed.
Copy link
Contributor

Choose a reason for hiding this comment

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

this information is not sufficient ... current file is holding 4 tests .. it is better to have some general comments.

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.LogTestStart(c.TestName())

// Create a vmgroup and add vm to it
log.Printf("Created a vm with default ds: %s", s.config.Datastores[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Created a vm with default ds? need to fix 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


// Remove the create privilege on the non-default vmgroup for specified datastore
admincli.RemoveCreateAccessForVMgroup(s.config.EsxHost, vmGroupName, s.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.

need to make sure .. access is revoked.

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.

Looks good. Minor comments. Good to merge then


func (s *vgBasicSuite) SetUpTest(c *C) {
// Creating non-default vmgroup only if it does not exists
if !admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

too nested. just return if Vmgroup is present.
If not then execute steps to create it. No need for nesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it.

c.Assert(isVmgroupAvailable, Equals, false, Commentf("Failed to delete the vmgroup [%s] .", vmGroupName))

// Removing the DB at the end of suite
admincli.ConfigRemove(s.config.EsxHost)
Copy link
Contributor

Choose a reason for hiding this comment

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

check if this is successful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new util that gets the current config mode from esx

func DeleteVMgroup(ip, name string) (string, error) {
log.Printf("Deleting a vmgroup [%s] on esx [%s]\n", name, ip)
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need of empty line.

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.

Overall looks good.

misc.LogTestEnd(c.TestName())
}

func (s *DefaultVMGroupTestSuite) isVolumeInVmgroup(esxIP string, volumeNames []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.

We don't really need a receiver here. I'd suggest to remove the receiver so that we can move this private function to common util whenever needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

// See the License for the specific language governing permissions and
// limitations under the License.

// This test suite contains tests to verify behaviors of non-default vmgroup
Copy link
Contributor

@shaominchen shaominchen Jun 21, 2017

Choose a reason for hiding this comment

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

Can we please clarify the difference between vmgroupbasic_test and vmgroup_test? If necessary, we should update the comments in existing vmgroup_test as well to make sure the intentions of these two test groups 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.

As discussed offline, added a statement to existing vmgroup_test and renamed my test file to vmgroupmisc_test

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.

@@ -56,14 +56,17 @@ const (
GetAccessForVMgroup = vmdkopsAdmin + "vmgroup access ls --name "

// ListVMgroups list vm groups
ListVMgroups = vmdkopsAdmin + "vmgroup ls"
ListVMgroups = vmdkopsAdmin + "vmgroup ls "
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: do we really need "vmgroup ls " .. extra spacing.

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.

Please make sure you have addressed all open comments.

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

Choose a reason for hiding this comment

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

nit: need to fix timeout status

// VerifyVDVSIsRunning - finds out if vDVS is running. This util can be useful
// in scenarios where vm is powered-on and user wants to find out if
// vm is fully up to be able to run docker volume commands.
func VerifyVDVSIsRunning(ip 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.

VerifyVDVSIsRunning =>IsVDVSRunning

@@ -242,3 +242,22 @@ func GetVolumeProperties(volumeName, hostName string) (string, error) {
cmd := dockercli.InspectVolume + volumeName + " --format ' {{index .Status.capacity.size}} {{index .Status.diskformat}} {{index .Status \"attached to VM\"}}' | sed -e 's/<no value>/detached/' "
return ssh.InvokeCommand(hostName, cmd)
}

// VerifyVDVSIsRunning - finds out if vDVS is running. This util can be useful
Copy link
Contributor

Choose a reason for hiding this comment

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

this method should be removed ... you may want to fix the diff.

@shuklanirdesh82
Copy link
Contributor

@ashahi1 Can you please add issue# here? Which issue current PR is addressing?

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.

Need to review the remaining functions for the vmgroup tests.

We are now having three vmgroup test files, vmgroup, default and misc - please look at combining at least into two (default and misc)

AddDatastoreAccess = vmdkopsAdmin + "vmgroup access add --name="

// NotApplicable or NotAvailable
NotApplicable = "N/A"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow! :-)) this is really not needed, constants should be for whats really usable across tests in different files. And this is something that simply can be used as "N/A" there's no need for a global for this sort of strings or ",", ".", etc.

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, that's how I had done initially - made it local to test. And then I was asked to put it into separate constant file. Now again bring it back to local test. Gosh!!

@@ -31,4 +31,10 @@ const (

// StartService starts vmdkops service
StartService = vmdkopsd + "start"

// DBNotConfigured - DB mode not configured
DBNotConfigured = "NotConfigured"
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 just use a constant in the relevant test file.

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 will be used by cross-esx tests when we start automating them. I will keep it here.


// Verify if volume exists in default vmgroup
isVolInVmgroup := admincli.IsVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[0], admincliconst.DefaultVMgroup)
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames[0], admincliconst.DefaultVMgroup))
Copy link
Contributor

Choose a reason for hiding this comment

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

If this check and the above one can't be combined then please make a issue to have verification.CheckVolume() which will check against a bunch of volume properties. No need to have multiple checks on the same volume. I remember you wrote code to get a map of volume properties.

Can't that be used to make one check for group membership. Being able to get the volume properties itself shows the volume exits.

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 will create a separate issue for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue #1470


// Check volumes now again belong to default vmgroup
c.Assert(isVolumeInVmgroup(s.config.EsxHost, s.volumeNames), Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames, admincliconst.DefaultVMgroup))

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, the test function is more or less lengthy with repeat checks which is needed but can be a single function call to do these - verification.CheckVolume() which checks all specified properties vs. a call per check. Assertions can be done in CheckVolume() itself.

if !isVolInVmgroup {
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.

Looks like we can move this into verification pkg into verification.CheckVolume() as mentioned above - seems like a common verification other tests can use.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 .. yeah I was thinking on the same note too.


// Verify vm belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, s.config.DockerHostNames[0], vmGroupName)
c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", s.config.DockerHostNames[0], vmGroupName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Or just add the VM always and ignore any error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@govint I think verification is needed here cause if test fails because of vm not being there then we will have hard finding the actual issue. So it's better to have different verifications to save our time during debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pls. see comment above, we may not need this function if none of the tests are going to remove the VM from the vmgroup. If they did then this logic to check for vmgroup present and exit won;t work. If no test is removing the VM from the vmgroup then why this function to check and exit for every test, its unnecessary.


// Verifying DB successfully removed
c.Assert(admincli.GetDBmode(s.config.EsxHost), Equals, admincliconst.DBNotConfigured, Commentf("Failed to remove the DB mode on ESX - .", s.config.EsxHost))

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats my point about setup and teardown test functions, its almost yet another test done for each and every test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we skip these verifications in the setup/teardown functions. Because what you are doing here should be in a vmgroup create, add VM to vmgroup, create/delete config test.

Lets make these tests simpleer code and remove unnecessary verifications. Keep verifications only in the actual test functions. Asserting error here is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, I was asked to verify if DB mode is as expected. Hence I added this check. We just go back and forth and delay the check-in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And how do we decide which is necessary and which ones are unnecessary verifications? Do we really know where tests can fail? What if there was some issue with step 1 but test failed at step 4's verification. We will spend more time debugging because we think Step 4 failed whereas actually the issue was with Step 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest the setup and tear down code (especially the test setup/teardown functions) really don;'t need verifications. Those are items to be done as tests and the setup and tear down can limit to asserting function return values alone. Verification should be just in the test functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@ashahi1 ashahi1 Jun 23, 2017

Choose a reason for hiding this comment

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

We have already ran into an issue because clean-up was not verified. #1448 (comment)


// Verify if volume exists in vmgroup
isVolInVmgroup := admincli.IsVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[0], vmGroupName)
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames[0], vmGroupName))
Copy link
Contributor

Choose a reason for hiding this comment

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

So, one verification.CheckVolume() should reduce code every where.

c.Assert(isVmgroupAvailable, Equals, false, Commentf("Failed to delete the vmgroup [%s] .", vmGroupName))

// Verify vmgroup for volume is N/A
isVolInVmgroup = admincli.IsVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[0], admincliconst.NotApplicable)
Copy link
Contributor

Choose a reason for hiding this comment

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

using "N/A" is fine here or make it a local global string like
NullGroup = "N/A" using NotApplicable doesn't seem correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

General comment - I had made it local only and then I was asked to put in a constant file in separate review. Now I have to again put it back to local. No wonder reviews take longer. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Fully agree, that keeps happening. But as code author I'd suggest you going over review comments and figuring out exactly whats really needed vs. good to have or specific code style. And only then making changes based on your judgement.

In this case a function like IsVolumeExistingInVmgroup() should get a vmgroup name always and hence a special case like NotApplicable doesn't seem correct. When we define an API, the params have a meaning and the values passed should reflect that. So defining a constant for a NullVmgroup as N/A and using that keeps the code understandable. And if no one else needs a NullVmgroup in their tests lets keep it locally. Thats the reasoning behind doing it this way.

c.Assert(isVolInVmgroup, Equals, true, Commentf("Unexpected Behavior: Vmgroup [%s] for volume [%s] is not N/A. ", s.volumeNames[0], vmGroupName))

// Delete the orphaned volume which does not belong to any vmgroup
admincli.DeleteOrphanedVolume(s.config.EsxHost, s.volumeNames[0], vmGroupName, s.config.Datastores[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this function needed? Why pass vmgroup, volume isn't in the group anymore and vmgroup is already deleted. Lets just use DeleteVolume instead?

It should be possible to delete a volume irrespective of where it is. Make a bug issue to have that supported or make --remove-volumes the default behavior whether user specifies --remove-volumes or not. There is no point allowing volumes to get orphaned and then not be able to delete them (if thats the case really, can you confirm).

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, we are not able to delete volumes for which there are no vmgroups - N/A. I will file an issue for it. Wrote this util to not pollute our test setup else we will have left-over volumes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks and this is a good find.

The tests should never create or use any method except whats advertised, documented as the way to handle the scenario. If a method doesn't exist then the test must not create one and instead that should become an issue.

@shuklanirdesh82
Copy link
Contributor

shuklanirdesh82 commented Jun 22, 2017

@ashahi1 Let's sync up offline today to break down your current review and we can merge irrelevant to new test + test util (keep E2E tests related to default vmgroup and non-default vmgroup #1381 related code). It helps to avoid conflict and getting some of the files stale.

admincli.RemoveVMFromVMgroup(s.config.EsxHost, vmGroupName, s.config.DockerHostNames[0])

// Verify vm does not belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, s.config.DockerHostNames[0], vmGroupName)
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 verification isn't needed because setupTest() has placed the VM in the group and the tests aren't removing the VM from the group is that right?

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 am removing the vm from vmgroup so I am just making sure removal was successful.

// Creating non-default vmgroup only if it does not exists
if admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName) {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In which case is this code needed in the setupTest() at all. Say for the first test we add the VM to the VMGroup thereafter do we need to keep checking for every test? If none of the tests are moving the VM out of this VMGroup then there is no need for a setupTest() to keep checking and exiting for every test.


// Verify vm belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, s.config.DockerHostNames[0], vmGroupName)
c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", s.config.DockerHostNames[0], vmGroupName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls. see comment above, we may not need this function if none of the tests are going to remove the VM from the vmgroup. If they did then this logic to check for vmgroup present and exit won;t work. If no test is removing the VM from the vmgroup then why this function to check and exit for every test, its unnecessary.

isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0])
c.Assert(isAvailable, Equals, false, Commentf("Unexpected Behavior: Orphaned volume %s "+
"is visible from host [%s] ", s.volumeNames[0], s.config.DockerHosts[0]))

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest skipping this test till these kind of volumes can be handled correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Will do it.

c.Assert(isStatusChanged, Equals, true, Commentf("Failed to power-on the VM [%s]", s.config.DockerHostNames[0]))

// Verify vDVS successfully started
isVDVSRunning := verification.IsVDVSIsRunning(s.config.DockerHosts[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

it should be like vdvs is available meaning he plugin is able to accept requests vs. running. But not for this PR.

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.

Pls.check tje coments provided and handle those.

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.

LGTM. Let the CI pass.
As you have created separate PR #1478 for some of the tests, please update the description of this PR.

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.

Thanks for keeping patience and addressing all review comments.

@shuklanirdesh82 shuklanirdesh82 merged commit 76ebd29 into vmware-archive:master Jun 27, 2017
shuklanirdesh82 pushed a commit that referenced this pull request Jun 29, 2017
[CI SKIP] Known issue doc.liping (#1475)

* Add known issue in README.md. [SKIP CI]

Adds Microsoft/go-winio vendor package (#1473)

This commit adds the Microsoft/go-winio vendor package, which will be used for implementing the npipe based Docker plugin for Windows.

Creates platform specific config and main modules (#1482)

This commit separates platform specific config and plugin serving code from the generic one. It will aid development of the Windows plugin.

* Extracts unix sock service from main.go into main_linux.go.
* Moves linux specific config from config.go into config_linux.go.
* Renames config_test.go to config_linux_test.go.

Adding a test for delete/recreate default vm group & fix cleanup in vmdk_ops_test.py (#1381)

Log cleanup for VMListener : VM object not found (#1489)

Update CONTRIBUTING.md

Refreshing test setup requirement and bring contributing.md to current.

[SKIP CI] Addressing Sam's comment

revamping contributing.md

Addressing Mark's comment

Update CONTRIBUTING.md
@ashahi1 ashahi1 deleted the vmgroupls.ashahi1 branch August 16, 2017 01:01
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.

[Test Automation] Verify volume creation after deleting _DEFAULT tenant
7 participants