Skip to content

Commit

Permalink
evetestkit : Add functions to reboot eve node
Browse files Browse the repository at this point in the history
Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
  • Loading branch information
shjala committed Sep 11, 2024
1 parent 286717c commit 369b7f2
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions pkg/evetestkit/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 369b7f2

Please sign in to comment.