Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first golang-only test #1037

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ runs:
else
./eden config set default --key=eve.accel --value=false
fi
./dist/bin/eden+ports.sh 2223:2223 2224:2224 5912:5902 5911:5901 8027:8027 8028:8028 8029:8029 8030:8030 8031:8031
./eden config set default --key=eve.tpm --value=${{ inputs.tpm_enabled }}
./eden config set default --key=eve.cpu --value=2
shell: bash
Expand Down Expand Up @@ -105,3 +106,10 @@ runs:
./eden setup -v debug --grub-options='set_global dom0_extra_args "$dom0_extra_args eve_install_zfs_with_raid_level "'
shell: bash
working-directory: "./eden"

- name: Start and Onboard
run: |
./eden start -v debug
./eden eve onboard -v debug
shell: bash
working-directory: "./eden"
2 changes: 1 addition & 1 deletion cmd/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func newCertsCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
Short: "manage certs",
Long: `Managed certificates for Adam and EVE.`,
Run: func(cmd *cobra.Command, args []string) {
if err := eden.GenerateEveCerts(cfg.Eden.CertsDir, cfg.Adam.CertsDomain, cfg.Adam.CertsIP, cfg.Adam.CertsEVEIP, cfg.Eve.CertsUUID, cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Password, grubOptions, cfg.Adam.APIv1); err != nil {
if err := eden.GenerateEveCerts(cfg.Eden.CertsDir, cfg.Adam.CertsDomain, cfg.Adam.CertsIP, cfg.Adam.CertsEVEIP, cfg.Eve.CertsUUID, cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Arch, cfg.Eve.Password, grubOptions, cfg.Adam.APIv1); err != nil {
log.Errorf("cannot GenerateEveCerts: %s", err)
} else {
log.Info("GenerateEveCerts done")
Expand Down
17 changes: 11 additions & 6 deletions cmd/edenConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/lf-edge/eden/pkg/defaults"
"github.com/lf-edge/eden/pkg/openevec"
Expand All @@ -10,7 +11,11 @@ import (
)

func newConfigCmd(configName, verbosity *string) *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will all these functions be removed anyway once NeoEden tests are done?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure about it,
talking about it on high-level: openevec is your Code As Infrastructure (think terraform) which allows you to describe your environment to deploy EVE, then you have your evetestkit which allows you to access certain states of EVE, Adam and then you have a test, which utilizes openevec and evetestkit to setup certain environment, run certain commands via controller and check EVE state. Openevec can also be used to setup a certain environment via CLI.
So broadly speaking, I can see scenarios, where I'd like to keep configurations persistent and therefore want to keep it on disk. Talking about it practically, we can't remove it, because changers are dependent on default folder structure and files, in theory we could remove it, propogating configuration there, but that'd be another big refactoring patch, as of now I'd pursue this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in more broader terms: can we remove the eden commands?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but your overview is very nice, thank you ❤️

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, that's an interesting take... Do we want Eden commands at all? I'd say yes. Imagine this: you run tests and then it gets stuck or fails, then in order to investigate you just set it up to a certain condition and then you can use eden commands to play around, ssh into thing, change certificates, etc. etc. so you don't waste time writing one openevec command and then rerunning the whole thing, rather do it interactively

cfg := &openevec.EdenSetupArgs{}
currentPath, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
cfg := openevec.GetDefaultConfig(currentPath)
var configCmd = &cobra.Command{
Use: "config",
Short: "work with config",
Expand Down Expand Up @@ -73,13 +78,13 @@ func newConfigAddCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
configAddCmd.Flags().StringVarP(&cfg.Eve.QemuFileToSave, "qemu-config", "", defaults.DefaultQemuFileToSave, "file to save config")
configAddCmd.Flags().IntVarP(&cfg.Eve.QemuCpus, "cpus", "", defaults.DefaultCpus, "cpus")
configAddCmd.Flags().IntVarP(&cfg.Eve.QemuMemory, "memory", "", defaults.DefaultMemory, "memory (MB)")
configAddCmd.Flags().StringSliceVarP(&cfg.Eve.QemuFirmware, "eve-firmware", "", nil, "firmware path")
configAddCmd.Flags().StringVarP(&cfg.Eve.QemuConfigPath, "config-part", "", "", "path for config drive")
configAddCmd.Flags().StringVarP(&cfg.Eve.QemuDTBPath, "dtb-part", "", "", "path for device tree drive (for arm)")
configAddCmd.Flags().StringSliceVarP(&cfg.Eve.QemuFirmware, "eve-firmware", "", cfg.Eve.QemuFirmware, "firmware path")
configAddCmd.Flags().StringVarP(&cfg.Eve.QemuConfigPath, "config-part", "", cfg.Eve.QemuConfigPath, "path for config drive")
configAddCmd.Flags().StringVarP(&cfg.Eve.QemuDTBPath, "dtb-part", "", cfg.Eve.QemuDTBPath, "path for device tree drive (for arm)")
configAddCmd.Flags().StringToStringVarP(&cfg.Eve.HostFwd, "eve-hostfwd", "", defaults.DefaultQemuHostFwd, "port forward map")
configAddCmd.Flags().StringVar(&cfg.Eve.Ssid, "ssid", "", "set ssid of wifi for rpi")
configAddCmd.Flags().StringVar(&cfg.Eve.Arch, "arch", "", "arch of EVE (amd64 or arm64)")
configAddCmd.Flags().StringVar(&cfg.Eve.ModelFile, "devmodel-file", "", "File to use for overwrite of model defaults")
configAddCmd.Flags().StringVar(&cfg.Eve.Arch, "arch", cfg.Eve.Arch, "arch of EVE (amd64 or arm64)")
configAddCmd.Flags().StringVar(&cfg.Eve.ModelFile, "devmodel-file", cfg.Eve.ModelFile, "File to use for overwrite of model defaults")
configAddCmd.Flags().BoolVarP(&force, "force", "", false, "force overwrite config file")

return configAddCmd
Expand Down
6 changes: 3 additions & 3 deletions cmd/edenSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func newSetupCmd(configName, verbosity *string) *cobra.Command {
Long: `Setup harness.`,
PersistentPreRunE: preRunViperLoadFunction(cfg, configName, verbosity),
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.ConfigCheck(*configName); err != nil {
log.Fatalf("Config check failed %s", err)
}
// if err := openevec.ConfigCheck(*configName); err != nil {
// log.Fatalf("Config check failed %s", err)
// }
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then ConfigCheck also becomes obsolete

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

if err := openEVEC.SetupEden(*configName, configDir, softSerial, zedControlURL, ipxeOverride, grubOptions, netboot, installer); err != nil {

log.Fatalf("Setup eden failed: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/edenStop.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newStopCmd(configName, verbosity *string) *cobra.Command {
registryRm, eServerRm,
cfg.Eve.Remote, cfg.Eve.Pid,
swtpmPidFile(cfg), cfg.Sdn.PidFile,
cfg.Eve.DevModel, vmName,
cfg.Eve.DevModel, vmName, cfg.Sdn.Disable,
)
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/edenTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/lf-edge/eden/pkg/defaults"
"github.com/lf-edge/eden/pkg/openevec"
"github.com/lf-edge/eden/pkg/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ test <test_dir> -r <regexp> [-t <timewait>] [-v <level>]
}
}

vars, err := utils.InitVars()
vars, err := openevec.InitVarsFromConfig(cfg)

if err != nil {
return fmt.Errorf("error reading config: %s\n", err)
Expand Down
153 changes: 151 additions & 2 deletions pkg/defaults/templates.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package defaults

//DefaultEdenTemplate is configuration template for Eden
// DefaultEdenTemplate is configuration template for Eden
const DefaultEdenTemplate = `#config is generated by eden
adam:
#tag on adam container to pull
Expand Down Expand Up @@ -317,7 +317,7 @@
network-model: '{{parse "sdn.network-model"}}'
`

//DefaultQemuTemplate is configuration template for qemu
// DefaultQemuTemplate is configuration template for qemu
const DefaultQemuTemplate = `#qemu config file generated by eden
{{- if .Firmware }}
{{ $firmwareLength := len .Firmware }}{{ if eq $firmwareLength 1 }}
Expand Down Expand Up @@ -428,3 +428,152 @@
</Shot>
</Snapshots>
</Parallels_disk_image>`

// DefaultEdenTemplate is configuration template for Eden

Check failure on line 432 in pkg/defaults/templates.go

View workflow job for this annotation

GitHub Actions / yetus

revive: comment on exported const DefaultActivateShTemplate should be of the form "DefaultActivateShTemplate ..." https://revive.run/r#exported
const DefaultActivateShTemplate = `# This file must be used with "source bin/activate" *from bash*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to remove activate.sh.tmpl and activate.csh.tmpl?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, we should remove the files, they're not needed anymore, thx!

# you cannot run it directly

if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi

eden_deactivate () {
# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_EDEN_PATH:+_}" ] ; then
PATH="$_OLD_EDEN_PATH"
export PATH
unset _OLD_EDEN_PATH
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi

if ! [ -z "${_OLD_EDEN_PS1+_}" ] ; then
PS1="$_OLD_EDEN_PS1"
export PS1
unset _OLD_EDEN_PS1
fi

unset EDEN_HOME
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
unset -f eden_deactivate
unset -f eden_config
unset -f eden-config
unset -f eden+config
fi
}

eden_config () {
if [ $# -eq 0 ]
then
echo Usage: eden_config config
return
fi

eden config set $1
PS1="EDEN-$(eden config get)_${_OLD_EDEN_PS1-}"
}

eden+config () {
if [ $# -eq 0 ]
then
echo Usage: eden+config config
return
fi

cd $(eden config get --key eden.root)/..
eden config add $1
cd -
}

eden-config () {
if [ $# -eq 0 ]
then
echo Usage: eden-config config
return
fi

eden config delete $1
eden_config default
}

# unset irrelevant variables
eden_deactivate nondestructive

EDEN_HOME={{.Eden.Root}}
EDEN_BIN={{.Eden.BinDir}}
export EDEN_HOME

_OLD_EDEN_PATH="$PATH"
PATH="$EDEN_BIN:$PATH"
export PATH

if [ -z "${EDEN_HOME_DISABLE_PROMPT-}" ] ; then
_OLD_EDEN_PS1="${PS1-}"
PS1="EDEN-$(eden config get)_${PS1-}"
export PS1
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi
`

const DefaultActivateCshTemplate = `# This file must be used with "source bin/activate.csh" *from csh*.

Check failure on line 532 in pkg/defaults/templates.go

View workflow job for this annotation

GitHub Actions / yetus

revive: exported const DefaultActivateCshTemplate should have comment or be unexported https://revive.run/r#exported
# You cannot run it directly.

set newline='\
'

alias eden_deactivate 'test $?_OLD_EDEN_PATH != 0 && setenv PATH "$_OLD_EDEN_PATH:q" && unset _OLD_EDEN_PATH; rehash; test $?_OLD_EDEN_PROMPT != 0 && set prompt="$_OLD_EDEN_PROMPT:q" && unset _OLD_EDEN_PROMPT; unsetenv EDEN_HOME; test "\!:*" != "nondestructive" && unalias eden_deactivate && unalias eden_config && unalias eden+config && unalias eden-config'

alias eden_config 'eden config set \!:1 && set prompt="EDEN-$(eden config get)_$_OLD_EDEN_PROMPT:q"'

alias eden+config 'cd $(eden config get --key eden.root)/..; eden config add \!:1; cd -'
alias eden-config 'eden config delete \!:1; eden_config default'

# Unset irrelevant variables.
eden_deactivate nondestructive

setenv EDEN_HOME "{{.Eden.Root}}"

set _OLD_EDEN_PATH="$PATH:q"
setenv PATH "{{.Eden.BinDir}}:$PATH:q"

if ( $?EDEN_DISABLE_PROMPT ) then
if ( $EDEN_DISABLE_PROMPT == "" ) then
set do_prompt = "1"
else
set do_prompt = "0"
endif
else
set do_prompt = "1"
endif

if ( $do_prompt == "1" ) then
# Could be in a non-interactive environment,
# in which case, $prompt is undefined and we wouldn't
# care about the prompt anyway.
if ( $?prompt ) then
set _OLD_EDEN_PROMPT="$prompt:q"
if ( "$prompt:q" =~ *"$newline:q"* ) then
:
else
set prompt = "eden-$(eden config get)_$prompt:q"
endif
endif
endif

unset do_prompt

rehash`
28 changes: 14 additions & 14 deletions pkg/eden/eden.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func StatusEServer() (status string, err error) {
}

// GenerateEveCerts function generates certs for EVE
func GenerateEveCerts(certsDir, domain, ip, eveIP, uuid, devModel, ssid, password string, grubOptions []string, apiV1 bool) (err error) {
func GenerateEveCerts(certsDir, domain, ip, eveIP, uuid, devModel, ssid, arch, password string, grubOptions []string, apiV1 bool) (err error) {
model, err := models.GetDevModelByName(devModel)
if err != nil {
return fmt.Errorf("GenerateEveCerts: %s", err)
Expand Down Expand Up @@ -495,7 +495,7 @@ func GenerateEveCerts(certsDir, domain, ip, eveIP, uuid, devModel, ssid, passwor
}
}
}
if model.DevModelType() == defaults.DefaultQemuModel && viper.GetString("eve.arch") == "arm64" {
if model.DevModelType() == defaults.DefaultQemuModel && arch == "arm64" {
// we need to properly set console for qemu arm64
grubOptions = append(grubOptions, "set_global dom0_console \"console=ttyAMA0,115200 $dom0_console\"")
}
Expand Down Expand Up @@ -523,7 +523,7 @@ func GenerateEveCerts(certsDir, domain, ip, eveIP, uuid, devModel, ssid, passwor
}

// PutEveCerts function put certs for zedcontrol
func PutEveCerts(certsDir, devModel, ssid, password string) (err error) {
func PutEveCerts(certsDir, devModel, ssid, arch, password string) (err error) {
model, err := models.GetDevModelByName(devModel)
if err != nil {
return fmt.Errorf("GenerateEveCerts: %s", err)
Expand Down Expand Up @@ -591,7 +591,7 @@ func PutEveCerts(certsDir, devModel, ssid, password string) (err error) {
}
}
}
if model.DevModelType() == defaults.DefaultQemuModel && viper.GetString("eve.arch") == "arm64" {
if model.DevModelType() == defaults.DefaultQemuModel && arch == "arm64" {
// we need to properly set console for qemu arm64
if err := os.WriteFile(filepath.Join(certsDir, "grub.cfg"), []byte("set_global dom0_console \"console=ttyAMA0,115200 $dom0_console\""), 0666); err != nil {
return fmt.Errorf("GenerateEveCerts: %s", err)
Expand Down Expand Up @@ -754,7 +754,7 @@ func MakeEveInRepo(desc utils.EVEDescription, dist string) (image, additional st
}

// CleanContext cleanup only context data
func CleanContext(eveDist, certsDist, imagesDist, evePID, eveUUID, sdnPID, vmName string, configSaved string, remote bool) (err error) {
func CleanContext(eveDist, certsDist, imagesDist, evePID, eveUUID, sdnPID, vmName string, configSaved string, remote, sdnDisable bool) (err error) {
edenDir, err := utils.DefaultEdenDir()
if err != nil {
return fmt.Errorf("CleanContext: %s", err)
Expand Down Expand Up @@ -828,7 +828,7 @@ func CleanContext(eveDist, certsDist, imagesDist, evePID, eveUUID, sdnPID, vmNam
log.Infof("swtpm is stopping")
}
}
StopSDN(devModel, sdnPID)
StopSDN(devModel, sdnPID, sdnDisable)
}
if _, err = os.Stat(eveDist); !os.IsNotExist(err) {
if err = os.RemoveAll(eveDist); err != nil {
Expand All @@ -855,7 +855,7 @@ func CleanContext(eveDist, certsDist, imagesDist, evePID, eveUUID, sdnPID, vmNam

// StopEden teardown Eden
func StopEden(adamRm, redisRm, registryRm, eserverRm, eveRemote bool,
evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName string) {
evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName string, sdnDisable bool) {
if err := StopAdam(adamRm); err != nil {
log.Infof("cannot stop adam: %s", err)
} else {
Expand All @@ -877,12 +877,12 @@ func StopEden(adamRm, redisRm, registryRm, eserverRm, eveRemote bool,
log.Infof("eserver stopped")
}
if !eveRemote {
StopEve(evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName)
StopEve(evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName, sdnDisable)
}
}

// StopEve stops EVE, vTPM and SDN.
func StopEve(evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName string) {
func StopEve(evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName string, sdnDisable bool) {
if devModel == defaults.DefaultVBoxModel {
if err := StopEVEVBox(vmName); err != nil {
log.Infof("cannot stop EVE: %s", err)
Expand Down Expand Up @@ -910,11 +910,11 @@ func StopEve(evePidFile, swtpmPidFile, sdnPidFile, devModel, vmName string) {
}
}
}
StopSDN(devModel, sdnPidFile)
StopSDN(devModel, sdnPidFile, sdnDisable)
}

func StopSDN(devModel, sdnPidFile string) {
if devModel != defaults.DefaultQemuModel || viper.GetBool("sdn.disable") {
func StopSDN(devModel, sdnPidFile string, sdnDisable bool) {
if devModel != defaults.DefaultQemuModel || sdnDisable {
// SDN is not running, nothing to do
return
}
Expand All @@ -937,11 +937,11 @@ func StopSDN(devModel, sdnPidFile string) {
// CleanEden teardown Eden and cleanup
func CleanEden(eveDist, adamDist, certsDist, imagesDist, eserverDist, redisDist,
registryDist, configDist, evePID, sdnPID, configSaved string, remote bool,
devModel, vmName string) (err error) {
devModel, vmName string, sdnDisable bool) (err error) {
command := "swtpm"
swtpmPidFile := filepath.Join(imagesDist, fmt.Sprintf("%s.pid", command))
StopEden(true, true, true, true, remote,
evePID, swtpmPidFile, sdnPID, devModel, vmName)
evePID, swtpmPidFile, sdnPID, devModel, vmName, sdnDisable)
if _, err = os.Stat(eveDist); !os.IsNotExist(err) {
if err = os.RemoveAll(eveDist); err != nil {
return fmt.Errorf("1 CleanEden: error in %s delete: %s", eveDist, err)
Expand Down
Loading
Loading