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

Test to delete vm from its vmgroup and few dependent utils #1483

Merged

Conversation

ashahi1
Copy link
Contributor

@ashahi1 ashahi1 commented Jun 26, 2017

This PR covers following things:


Test steps:

  1. Create a vm VM1 using govc
  2. Create a vmgroup and associate VM1 to it.
  3. Execute vmgroup ls command.
  4. Delete the vm that was added to the vmgroup.
  5. Again execute vmgroup ls command to verify command works fine.

Tested it locally. All test test-esx passed

=> Running target test-e2e-runalways
OK: 6 passed
--- PASS: Test (115.64s)
PASS

=> Running target test-e2e-runonce
--- PASS: Test (493.81s)
PASS
OK: 22 passed, 3 skipped

// 4. Again execute vmgroup ls command to verify command works fine.
func (s *vgBasicSuite) TestDeleteVMFromVmgroup(c *C) {
misc.LogTestStart(c.TestName())
vmName := "VM_" + inputparams.GetRandomNumber()
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 you want to create a new vmgroup here? Why not using existing vmgroup "vmGroupName"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lipingxue Because of issue #1484, I am creating a separate tenant else verifications in other tests will start failing. For remaining tests in the same file, I am creating vmgroup once in the SetUpSuite()

vgName := "VG_" + inputparams.GetRandomNumber()

// Create a vm - we need this to add to vmgroup and later on delete this vm
esx.CreateVM(vmName, 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.

Should check the out and err returned by function "esx.CreateVM".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Create a vm - we need this to add to vmgroup and later on delete this vm
esx.CreateVM(vmName, s.config.Datastores[0])

admincli.CreateVMgroup(s.config.EsxHost, vgName, vmName, admincliconst.VMHomeDatastore)
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 assert to make sure no error is returned from "CreateVMgroup".

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

admincli.CreateVMgroup(s.config.EsxHost, vgName, vmName, admincliconst.VMHomeDatastore)
// Verify if vmgroup exists
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vgName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup ls command does not lists the vmgroup %s .", vgName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Change "vmgroup ls command does not lists the vmgroup %s ." to "Vmgroup %s dose not 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

c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", vmName, vgName))

// Destroy the vm
esx.DestroyVM(vmName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the out and error returned from DestroyVM.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 .. atleast validate VM is no more present.


// Destroy the vm
esx.DestroyVM(vmName)
misc.SleepForSec(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the sleep is needed? Please add comments for that.

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


// Check vmgroup ls
isVmgroupAvailable = admincli.IsVmgroupPresent(s.config.EsxHost, vgName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup ls command does not lists the vmgroup %s .", vgName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments 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

// CreateVM creates a vm on the specified ds and esx
func CreateVM(vmName, datastore string) string {
log.Printf("Creating a vm [%s] \n", vmName)
cmd := esx.VMCreate + datastore + " -on=false -link=false -net.adapter=vmxnet3 " + vmName
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 always use "-net.adapter=vmxnet3"?

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 into a parameter to be passed to function.

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.

LGTM!

vgName := "VG_" + inputparams.GetRandomNumber()

// Create a vm - we need this to add to vmgroup and later on delete this vm
esx.CreateVM(vmName, 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.

minor: can we atleast validate vm is created or not? (helps in debugging failure)

c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", vmName, vgName))

// Destroy the vm
esx.DestroyVM(vmName)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 .. atleast validate VM is no more present.

func DestroyVM(vmName string) string {
log.Printf("Deleting a vm - %s \n", vmName)
cmd := esx.VMDestroy + vmName
return ssh.InvokeCommandLocally(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: command can be simply moved here.

// Check vmgroup ls
isVmgroupAvailable = admincli.IsVmgroupPresent(s.config.EsxHost, vgName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup ls command does not lists the vmgroup %s .", vgName))

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 add TODO here saying .. due to product behavior vmgroup deletion is not possible and add the reference of the issue here .. if there is any issue otherwise please raise one and add its reference here.

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.

LGTM! Please address minor comments before merging.

log.Printf("Verifying if vm - %s exists \n", vmName)
listVMs := " /ha-datacenter/vm"
cmd := esx.LsOption + listVMs
vmList := ssh.InvokeCommandLocally(cmd)
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 to combine 94-96.

esx.DestroyVM(vmName)

// Added the sleep before next step as deletion may take time to finish completely.
misc.SleepForSec(3)
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 use polling mechanism here instead 3 seconds ..

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

VMDestroy = govcCmd + "vm.destroy "

// LsOption refers to govc ls
LsOption = govcCmd + "ls "
Copy link
Contributor

Choose a reason for hiding this comment

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

could have created ListVMs as an exported variable.

@ashahi1 ashahi1 force-pushed the vmgrouplsAfterVMdelete.ashahi1 branch from f3bb9c9 to 03791aa Compare June 28, 2017 19:08
Copy link
Contributor

@lipingxue lipingxue left a comment

Choose a reason for hiding this comment

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

One general comment, after you addressed comments, please don't squash before you push. I would like o see only the delta between the current code and my last review.

c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", vmName, vgName))

// Destroy the vm
esx.DestroyVM(vmName)
Copy link
Contributor

Choose a reason for hiding this comment

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

This still not address. You don't check the out and error returned from DestroyVM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

govc does not returns error code. I wrote a util to check if vm exists. That I am using after creating a vm as well as after destroying vm.

@ashahi1 ashahi1 force-pushed the vmgrouplsAfterVMdelete.ashahi1 branch from 03791aa to b64b05c Compare June 29, 2017 23:52
@shuklanirdesh82 shuklanirdesh82 merged commit 4a95c2c into vmware-archive:master Jun 30, 2017
@ashahi1 ashahi1 deleted the vmgrouplsAfterVMdelete.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.

4 participants