This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
[E2E] Validation after admincli vmgroup and config ops #1568
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
return out, nil | ||
} | ||
|
||
msg := "Could not verify removal of vmgroup " + name + " on esx " + ip | ||
return msg, fmt.Errorf(msg) | ||
} | ||
|
||
// AddVMToVMgroup - Adds vm to vmgroup | ||
|
@@ -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 "DB init successful on esx " + ip, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we return original command output in this case? return out, nil Basically the point is: we don't want to change the original command output if the extra verification passes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
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 "DB remove successful on esx " + ip, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
|
||
msg := "Could not remove DB on esx " + ip | ||
return msg, fmt.Errorf(msg) | ||
} | ||
|
||
// IsVmgroupPresent - checks for a vmgroup in list of vmgroups | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, make sense.