Skip to content
Snippets Groups Projects
Commit a929f576 authored by Florent Gluck's avatar Florent Gluck
Browse files

client: validate script handles errors correctly now; added new test scenarios

parent a0a8f79b
Branches
No related tags found
No related merge requests found
Showing
with 102 additions and 35 deletions
......@@ -71,6 +71,11 @@ func printFilteredTemplates(c cmd.Command, args []string, route string) int {
return 1
}
if len(templates) == 0 {
u.PrintlnErr("Error: template(s) not found.")
return 1
}
if foundLongOutputFlag >= 0 {
for _, template := range templates {
str, err := template.String()
......
......@@ -103,6 +103,11 @@ func printFilteredUsers(c cmd.Command, args []string, route string) int {
}
}
if len(userList) == 0 {
u.PrintlnErr("Error: user(s) not found.")
return 1
}
if foundLongOutputFlag >= 0 {
for _, user := range userList {
u.Println(user.String())
......
......@@ -127,7 +127,7 @@ func (cmd *AddAccess)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -44,7 +44,7 @@ func (cmd *AttachAsync)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -45,7 +45,7 @@ func (cmd *AttachSync)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -52,7 +52,7 @@ func (cmd *Creds2csv)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -50,7 +50,7 @@ func (cmd *Creds2pdf)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -41,7 +41,7 @@ func (cmd *Del)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -111,7 +111,7 @@ func (cmd *DelAccess)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -79,7 +79,7 @@ func (cmd *Edit)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -56,7 +56,7 @@ func (cmd *ExportDir)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -55,7 +55,7 @@ func (cmd *ImportDir)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -41,7 +41,7 @@ func (cmd *Reboot)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -41,7 +41,7 @@ func (cmd *Shutdown)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -41,7 +41,7 @@ func (cmd *Start)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -41,7 +41,7 @@ func (cmd *Stop)Run(args []string) int {
}
if len(vms) == 0 {
u.PrintlnErr("No match.")
u.PrintlnErr("Error: VM(s) not found.")
return 1
}
......
......@@ -6,6 +6,9 @@ validate_help: help
@echo " make validate EMAIL=jane.doe@nexus.org"
validate: prepare_dev validate/validate
ifndef EMAIL
$(error Please define the EMAIL variable)
endif
go build .
cd validate && ./validate $(EMAIL)
......
......@@ -19,10 +19,11 @@ cleanup () {
sleep 3
$nexus_cli vmdel "$partial_name"
$nexus_cli tpldel "$partial_name"
echo "calling del_gen_files..."
del_gen_files
}
checkLastCmd () {
checkLastCmdSucceeded () {
if [ $? -ne 0 ]; then
echo "[FATAL] $1 failed."
cleanup
......@@ -30,11 +31,24 @@ checkLastCmd () {
fi
}
checkLastCmdFailed () {
if [ $? -eq 0 ]; then
echo "[FATAL] $1 succeeded."
cleanup
exit 1
fi
}
OK () {
echo -e "[OK]\n"
}
checkValidUUID () {
if [ $# -lt 1 ]; then
echo "[FATAL] UUID missing!"
exit 1
fi
type=`uuidparse $1 | tail -n1 | awk '{print $3}'`
test $type = "random"
if [ $? -ne 0 ]; then
......@@ -61,85 +75,125 @@ fi
OK
# Look for the first template containing "Xubuntu 22.04" in its name
tpl="Xubuntu 22.04"
echo "List templates..."
baseTemplateID=`$nexus_cli tpllist . | grep "Xubuntu 22.04" | awk -F"|" '{print $2}'|head -n1`
checkLastCmd "tpllist"
baseTemplateID=`$nexus_cli tpllist "$tpl"`
checkLastCmdSucceeded "tpllist"
baseTemplateID=`echo $baseTemplateID | awk -F"|" '{print $2}' | head -n1`
checkValidUUID $baseTemplateID
OK
# TODO
# - Add vmcreate with invalid arguments and check it doesn't work (e.g. 64MB of RAM)
# - Update script to handle errors properly when using pipes
echo "Attempt to create an invalid VM (invalid CPU)..."
vmID=`$nexus_cli vmcreate "$partial_name" 0 1024 none none $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid CPU)..."
vmID=`$nexus_cli vmcreate "$partial_name" 17 1024 none none $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid RAM)..."
vmID=`$nexus_cli vmcreate "$partial_name" 1 500 user 067b:2303 $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid RAM)..."
vmID=`$nexus_cli vmcreate "$partial_name" 1 33000 user none $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid NIC)..."
vmID=`$nexus_cli vmcreate "$partial_name" 1 1024 pipo none $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid USB)..."
vmID=`$nexus_cli vmcreate "$partial_name" 1 1024 none pipo $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Attempt to create an invalid VM (invalid USB)..."
vmID=`$nexus_cli vmcreate "$partial_name" 1 1024 none 067b:23x3 $baseTemplateID`
checkLastCmdFailed "vmcreate"
OK
echo "Create base VM..."
vmID=`$nexus_cli vmcreate "$partial_name" 2 1500 user 067b:2303 $baseTemplateID | awk -F"|" '{print $2}'`
checkLastCmd "vmcreate"
#vmID=`$nexus_cli vmcreate "$partial_name" 2 1500 user 067b:2303 $baseTemplateID | awk -F"|" '{print $2}
vmID=`$nexus_cli vmcreate "$partial_name" 2 1500 user 067b:2303 $baseTemplateID`
checkLastCmdSucceeded "vmcreate"
vmID=`echo $vmID | awk -F"|" '{print $2}'`
checkValidUUID $vmID
OK
echo "Import files into VM..."
$nexus_cli vmimportdir "$partial_name" validation_data/exam /home
checkLastCmd "vmimportdir"
$nexus_cli vmimportdir "$partial_name" data/exam /home
checkLastCmdSucceeded "vmimportdir"
OK
echo "Create template from VM (can take a few minutes)..."
templateID=`$nexus_cli tplcreate "$partial_name" private $vmID | grep \"id\" | awk -F'"' '{print $4}'`
checkLastCmd "tplcreate"
#templateID=`$nexus_cli tplcreate "$partial_name" private $vmID | grep \"id\" | awk -F'"' '{print $4}'`
templateID=`$nexus_cli tplcreate "$partial_name" private $vmID`
checkLastCmdSucceeded "tplcreate"
templateID=`echo $templateID | grep \"id\" | awk -F'"' '{print $4}'`
checkValidUUID $templateID
OK
echo "Create students VMs..."
$nexus_cli vmcreate "$full_name" 2 1500 none 1fc9:0132,03eb:6124 $templateID validation_data/students.csv
checkLastCmd "vmcreate VMs"
$nexus_cli vmcreate "$full_name" 2 1500 none 1fc9:0132,03eb:6124 $templateID data/students.csv
checkLastCmdSucceeded "vmcreate VMs"
OK
echo "Start students VMs..."
$nexus_cli vmstart "$full_name"
checkLastCmd "vmstart VMs"
checkLastCmdSucceeded "vmstart VMs"
sleep 3
OK
echo "Generate credentials to PDF..."
$nexus_cli vmcreds2pdf "$full_name" $creds_pdf_file
checkLastCmd "vmcreds2pdf"
checkLastCmdSucceeded "vmcreds2pdf"
OK
echo "Generate credentials to CSV..."
$nexus_cli vmcreds2csv "$full_name" $creds_csv_file
checkLastCmd "vmcreds2csv"
checkLastCmdSucceeded "vmcreds2csv"
OK
echo "Kill students VMs..."
$nexus_cli vmkill "$full_name"
sleep 3
checkLastCmd "vmkill VMs"
checkLastCmdSucceeded "vmkill VMs"
OK
echo "Export files from VMs..."
$nexus_cli vmexportdir "$full_name" /home
checkLastCmd "vmexportdir"
checkLastCmdSucceeded "vmexportdir"
OK
echo "Re-start students VMs with previous credentials..."
$nexus_cli vmstartwithcreds $creds_csv_file
checkLastCmd "vmstartwithcreds VMs"
checkLastCmdSucceeded "vmstartwithcreds VMs"
sleep 10
OK
echo "Kill students VMs..."
$nexus_cli vmkill "$full_name"
sleep 3
checkLastCmd "vmkill VMs"
checkLastCmdSucceeded "vmkill VMs"
OK
echo "Delete students VMs..."
$nexus_cli vmdel "$partial_name"
checkLastCmd "vmdel VMs"
checkLastCmdSucceeded "vmdel VMs"
OK
echo "Delete template..."
$nexus_cli tpldel "$templateID"
checkLastCmd "tpldel"
checkLastCmdSucceeded "tpldel"
OK
del_gen_files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment