From 369b7f2bda3160c4b588b3084cf9d66c97e8f778 Mon Sep 17 00:00:00 2001 From: Shahriyar Jalayeri Date: Wed, 11 Sep 2024 14:12:36 +0300 Subject: [PATCH] evetestkit : Add functions to reboot eve node Signed-off-by: Shahriyar Jalayeri --- pkg/evetestkit/utils.go | 42 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/pkg/evetestkit/utils.go b/pkg/evetestkit/utils.go index 0c3f8aa31..d6b797bf8 100644 --- a/pkg/evetestkit/utils.go +++ b/pkg/evetestkit/utils.go @@ -332,6 +332,44 @@ func WithSSH(user, pass, port string) AppOption { } } +// EveRebootNode reboots the EVE node. +func (node *EveNode) EveRebootNode() error { + return node.controller.EdgeNodeReboot("") +} + +// EveRebootAndWait reboots the EVE node and waits for it to come back. +func (node *EveNode) EveRebootAndWait(timeoutSeconds uint) error { + out, err := node.EveRunCommand("uptime -s") + if err != nil { + return err + } + uptimeOne := strings.TrimSpace(string(out)) + + if err := node.EveRebootNode(); err != nil { + return err + } + + start := time.Now() + for { + if time.Since(start) > time.Duration(timeoutSeconds)*time.Second { + return fmt.Errorf("timeout waiting for the node to reboot and come back") + } + + out, err := node.EveRunCommand("uptime -s") + if err != nil { + continue + } + + if uptimeOne != strings.TrimSpace(string(out)) { + break + } + + time.Sleep(5 * time.Second) + } + + return nil +} + // EveDeployApp deploys a VM/App on the EVE node func (node *EveNode) EveDeployApp(appLink string, pc openevec.PodConfig, options ...AppOption) error { node.apps = append(node.apps, appInstanceConfig{name: pc.Name}) @@ -372,7 +410,7 @@ func GetDefaultVMConfig(appName, cloudConfig string, portPub []string) openevec. var pc openevec.PodConfig pc.Name = appName - pc.AppMemory = humanize.Bytes(defaults.DefaultAppMem * 1024) + pc.AppMemory = "4GB" //humanize.Bytes(defaults.DefaultAppMem * 1024 * 4) pc.DiskSize = "4GB" pc.VolumeType = "QCOW2" pc.Metadata = cloudConfig @@ -382,7 +420,7 @@ func GetDefaultVMConfig(appName, cloudConfig string, portPub []string) openevec. pc.VolumeSize = humanize.IBytes(defaults.DefaultVolumeSize) pc.PortPublish = portPub pc.VncDisplay = 0 - pc.AppCpus = defaults.DefaultAppCPU + pc.AppCpus = defaults.DefaultAppCPU * 4 pc.AppAdapters = nil pc.Networks = nil pc.ACLOnlyHost = false