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

[E2E] Validation after admincli vmgroup and config ops #1568

Merged
merged 3 commits into from
Jul 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 58 additions & 6 deletions tests/utils/admincli/vmgroupmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,55 @@
package admincli

import (
"fmt"
"log"
"strings"
"fmt"

"github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/ssh"
)

// CreateVMgroup method is going to create a vmgroup and adds vm to it.
func CreateVMgroup(ip, name, vmName, dsName string) (string, error) {
log.Printf("Creating a vmgroup [%s] on esx [%s]\n", name, ip)
return ssh.InvokeCommand(ip, admincli.CreateVMgroup+name+" --default-datastore="+dsName+admincli.VMlist+vmName)
out, err := ssh.InvokeCommand(ip, admincli.CreateVMgroup+name+" --default-datastore="+dsName+admincli.VMlist+vmName)

if err != nil {
return out, err
}

// Verify the vmgroup creation
if IsVmgroupPresent(ip, name) {
return out, nil
}

msg := "Could not verify presence of vmgroup " + name + " on esx " + ip
return msg, fmt.Errorf(msg)

}

// DeleteVMgroup method deletes a vmgroup and removes its volumes as well if "delete_vol" is set
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)
var out string
var err error
if delete_vol {
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name+admincli.RemoveVolumes)
out, err = ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name+admincli.RemoveVolumes)
} else {
return ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name)
out, err = ssh.InvokeCommand(ip, admincli.RemoveVMgroup+name)
}

if err != nil {
return out, err
}

// Verify the vmgroup removal
if IsVmgroupPresent(ip, name) != true {
Copy link
Contributor

Choose a reason for hiding this comment

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

When "delete_vol" is set to true, should also check volume that associated with that vmgroup have been 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.

Currently this util doesn't have knowledge about which volumes fall into the given VMgroup. So directly we cannot verify.
What we can do is retrieve the list of volumes from admin cli and in verification make sure those volumes are deleted. But I would prefer doing it out of this PR depending on the need of such verification.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, make sense.

return out, nil
}

msg := "Could not verify removal of vmgroup " + name + " on esx " + ip
return msg, fmt.Errorf(msg)
}

// AddVMToVMgroup - Adds vm to vmgroup
Expand Down Expand Up @@ -93,13 +121,37 @@ func ConfigInit(ip string) (string, error) {
}

log.Printf("Initializing the SingleNode Config DB on esx [%s] \n", ip)
return ssh.InvokeCommand(ip, admincli.InitLocalConfigDb)
out, err := ssh.InvokeCommand(ip, admincli.InitLocalConfigDb)

if err != nil {
return out, err
}

// verify the DB init
if GetDBmode(ip) == admincli.DBSingleNode {
return out, nil
}

msg := "Could not init DB to SingleNode on esx " + ip
return msg, fmt.Errorf(msg)
}

// ConfigRemove - Remove the (local) Single Node Config DB
func ConfigRemove(ip string) (string, error) {
log.Printf("Removing the SingleNode Config DB on esx [%s] \n", ip)
return ssh.InvokeCommand(ip, admincli.RemoveLocalConfigDb)
out, err := ssh.InvokeCommand(ip, admincli.RemoveLocalConfigDb)

if err != nil {
return out, err
}

// verify the DB removal
if GetDBmode(ip) == admincli.DBNotConfigured {
return out, nil
}

msg := "Could not remove DB on esx " + ip
return msg, fmt.Errorf(msg)
}

// IsVmgroupPresent - checks for a vmgroup in list of vmgroups
Expand Down