gear: Be sure to run datasource before install

Seems in certain condition the datasource is kicking late and serving the datasource not fast as wanted.

We make sure to pull it before install, so we also give chance to convoluted setups to pull configs.

Also wires up autoinstall tests to CI
This commit is contained in:
Ettore Di Giacinto 2022-07-21 21:38:07 +00:00 committed by Itxaka
parent 6c08ac78a8
commit 09b41735f4
3 changed files with 27 additions and 0 deletions

View File

@ -65,6 +65,13 @@ func Install(dir ...string) error {
}
})
// Try to pull userdata once more. best-effort
if _, err := os.Stat("/oem/userdata"); err != nil {
if err := machine.ExecuteCloudConfig("/system/oem/00_datasource.yaml", "rootfs.before"); err != nil {
fmt.Println("Warning: Failed pulling from datasources")
}
}
// Reads config, and if present and offline is defined,
// runs the installation
cc, err := config.Scan(config.Directories(dir...), config.MergeBootLine)

View File

@ -145,3 +145,13 @@ func SentinelExist(f string) bool {
}
return false
}
func ExecuteInlineCloudConfig(cloudConfig, stage string) error {
_, err := utils.ShellSTDIN(cloudConfig, fmt.Sprintf("elemental run-stage -s %s -", stage))
return err
}
func ExecuteCloudConfig(file, stage string) error {
_, err := utils.SH(fmt.Sprintf("elemental run-stage -s %s %s", stage, file))
return err
}

View File

@ -1,6 +1,7 @@
package utils
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
@ -31,3 +32,12 @@ func Shell() *exec.Cmd {
cmd.Stdin = os.Stdin
return cmd
}
func ShellSTDIN(s, c string) (string, error) {
cmd := exec.Command("/bin/sh", "-c", c)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = bytes.NewBuffer([]byte(s))
o, err := cmd.CombinedOutput()
return string(o), err
}