diff --git a/src/client/cmdTemplate/helper.go b/src/client/cmdTemplate/helper.go index 5adf5cd7be34a789faef6826b5e4346f3ea82d56..d1b756c61a3e59a15557c0e241b27c907a8ad0b3 100644 --- a/src/client/cmdTemplate/helper.go +++ b/src/client/cmdTemplate/helper.go @@ -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() diff --git a/src/client/cmdUser/helper.go b/src/client/cmdUser/helper.go index c0f3f40f80ec1af34be3dea3046f8d7988fc6c7e..1bae8f1ba8d3c02a3155782b063be5f145730313 100644 --- a/src/client/cmdUser/helper.go +++ b/src/client/cmdUser/helper.go @@ -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()) diff --git a/src/client/cmdVM/vmAddAccess.go b/src/client/cmdVM/vmAddAccess.go index 7dfefe79aa16d7666a22fcfbebf276f78d7a86a3..fdda5e691bc385d6f2016656f724aaae72baefd2 100644 --- a/src/client/cmdVM/vmAddAccess.go +++ b/src/client/cmdVM/vmAddAccess.go @@ -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 } diff --git a/src/client/cmdVM/vmAttachAsync.go b/src/client/cmdVM/vmAttachAsync.go index b95aa60a50c32e0bd2a0019f6da98c50193cf02b..bc90520bb8dbc1cf627fdf0a7335d8b9df7aaba2 100644 --- a/src/client/cmdVM/vmAttachAsync.go +++ b/src/client/cmdVM/vmAttachAsync.go @@ -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 } diff --git a/src/client/cmdVM/vmAttachSync.go b/src/client/cmdVM/vmAttachSync.go index c7ab96c4188ed7c1e6b5629f78e9aa8e730deef0..a21f1e80e645b93f56e79a20efc54057059f62f1 100644 --- a/src/client/cmdVM/vmAttachSync.go +++ b/src/client/cmdVM/vmAttachSync.go @@ -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 } diff --git a/src/client/cmdVM/vmCreds2csv.go b/src/client/cmdVM/vmCreds2csv.go index 794cbdfcc0385ff261b99998bf6e8663c73f07a9..89e91c4e8ae67512ab77fbc8382bd60447934c31 100644 --- a/src/client/cmdVM/vmCreds2csv.go +++ b/src/client/cmdVM/vmCreds2csv.go @@ -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 } diff --git a/src/client/cmdVM/vmCreds2pdf.go b/src/client/cmdVM/vmCreds2pdf.go index daa10a069121d491b9124664ee15147c7b3cae10..51a1439dba982e33147039dc0c6ed83223651eb2 100644 --- a/src/client/cmdVM/vmCreds2pdf.go +++ b/src/client/cmdVM/vmCreds2pdf.go @@ -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 } diff --git a/src/client/cmdVM/vmDel.go b/src/client/cmdVM/vmDel.go index 0480b1b41968bd217788877b1d836f1cdee4a6fd..6852b66406033ca3156a07802420c81b80210c9a 100644 --- a/src/client/cmdVM/vmDel.go +++ b/src/client/cmdVM/vmDel.go @@ -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 } diff --git a/src/client/cmdVM/vmDelAccess.go b/src/client/cmdVM/vmDelAccess.go index 51919ff2fb9066d65f58597c7f4276eed0394fa1..d21cedaf062c5ebb6667b25c8bbbb951cf9a138c 100644 --- a/src/client/cmdVM/vmDelAccess.go +++ b/src/client/cmdVM/vmDelAccess.go @@ -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 } diff --git a/src/client/cmdVM/vmEdit.go b/src/client/cmdVM/vmEdit.go index 759a3b7d98a2c45bdaab9a01ab46ca974dbf63b1..3ee59b5725704ffc7a33511f9e74d6034cf94620 100644 --- a/src/client/cmdVM/vmEdit.go +++ b/src/client/cmdVM/vmEdit.go @@ -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 } diff --git a/src/client/cmdVM/vmExportDir.go b/src/client/cmdVM/vmExportDir.go index 5ac187f11a20ad3a45a1093ec2663c704d638d1b..21545c1d2d0955b24eb79d413ad3860ddc53189f 100644 --- a/src/client/cmdVM/vmExportDir.go +++ b/src/client/cmdVM/vmExportDir.go @@ -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 } diff --git a/src/client/cmdVM/vmImportDir.go b/src/client/cmdVM/vmImportDir.go index 21e8104a778acc75e934c928c08c7560eae2019c..cc5be51271009d3c977d989a2365d2cd9f428d3e 100644 --- a/src/client/cmdVM/vmImportDir.go +++ b/src/client/cmdVM/vmImportDir.go @@ -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 } diff --git a/src/client/cmdVM/vmReboot.go b/src/client/cmdVM/vmReboot.go index 70ef2045ba99efec37929a397f51b58156df570f..7bfd13741eed41d7355dbe23b6836352d6996b40 100644 --- a/src/client/cmdVM/vmReboot.go +++ b/src/client/cmdVM/vmReboot.go @@ -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 } diff --git a/src/client/cmdVM/vmShutdown.go b/src/client/cmdVM/vmShutdown.go index 2f71b446d11c56377fb6f4d240db2bef6debfe50..7ba11308896ce6e75eb401c107f9f3ba869273e3 100644 --- a/src/client/cmdVM/vmShutdown.go +++ b/src/client/cmdVM/vmShutdown.go @@ -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 } diff --git a/src/client/cmdVM/vmStart.go b/src/client/cmdVM/vmStart.go index 519ac4829e7e61fe88352316c4b9734a5deb9f68..2656261431be5219617e328bf86aa96fce18a862 100644 --- a/src/client/cmdVM/vmStart.go +++ b/src/client/cmdVM/vmStart.go @@ -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 } diff --git a/src/client/cmdVM/vmStop.go b/src/client/cmdVM/vmStop.go index 3655cfa4d6d122523ed9b30590dcf2e4bc5f2988..f3d4651a69f968318f90be322ffdb82c98d98ae7 100644 --- a/src/client/cmdVM/vmStop.go +++ b/src/client/cmdVM/vmStop.go @@ -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 } diff --git a/src/client/nexus-cli/Makefile b/src/client/nexus-cli/Makefile index 35a880d0c5c7cc02a656dfa1f1399971278c5016..d5f5163eec675fd02dbacf409733bfc567580b1f 100644 --- a/src/client/nexus-cli/Makefile +++ b/src/client/nexus-cli/Makefile @@ -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) diff --git a/src/client/nexus-cli/validate/validate b/src/client/nexus-cli/validate/validate index 0440328bc5d697ba388b57546769b893e8519efd..c3ec1c8279ce2b0975a22f26ad6a3963fd87f13d 100755 --- a/src/client/nexus-cli/validate/validate +++ b/src/client/nexus-cli/validate/validate @@ -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