Skip to content

Commit

Permalink
NeoEden: Golang test only
Browse files Browse the repository at this point in the history
Just go to tests/sec and run go test

Signed-off-by: Pavel Abramov <[email protected]>
  • Loading branch information
uncleDecart committed Oct 23, 2024
1 parent 0479cde commit 9ab7f50
Show file tree
Hide file tree
Showing 29 changed files with 908 additions and 267 deletions.
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 {
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)
// }
if err := openEVEC.SetupEden(*configName, configDir, softSerial, zedControlURL, ipxeOverride, grubOptions, netboot, installer); err != nil {

log.Fatalf("Setup eden failed: %s", 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 @@ sdn:
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 @@ const ParallelsDiskTemplate = `<?xml version='1.0' encoding='UTF-8'?>
</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*
# 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`
8 changes: 4 additions & 4 deletions pkg/eve/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/lf-edge/eden/pkg/controller/einfo"
"github.com/lf-edge/eden/pkg/controller/emetric"
"github.com/lf-edge/eden/pkg/device"
"github.com/lf-edge/eden/pkg/projects"
"github.com/lf-edge/eden/pkg/testcontext"
"github.com/lf-edge/eve-api/go/info"
"github.com/lf-edge/eve-api/go/metrics"
log "github.com/sirupsen/logrus"
Expand All @@ -22,13 +22,13 @@ type State struct {
applications map[string]*AppInstState
networks map[string]*NetInstState
volumes map[string]*VolInstState
infoAndMetrics *projects.State
infoAndMetrics *testcontext.State
device *device.Ctx
}

// Init State object with controller and device
func Init(ctrl controller.Cloud, dev *device.Ctx) (ctx *State) {
ctx = &State{device: dev, infoAndMetrics: projects.InitState(dev)}
ctx = &State{device: dev, infoAndMetrics: testcontext.InitState(dev)}
ctx.applications = make(map[string]*AppInstState)
ctx.networks = make(map[string]*NetInstState)
if err := ctx.initApplications(ctrl, dev); err != nil {
Expand All @@ -44,7 +44,7 @@ func Init(ctrl controller.Cloud, dev *device.Ctx) (ctx *State) {
}

// InfoAndMetrics returns last info and metric objects
func (ctx *State) InfoAndMetrics() *projects.State {
func (ctx *State) InfoAndMetrics() *testcontext.State {
return ctx.infoAndMetrics
}

Expand Down
Loading

0 comments on commit 9ab7f50

Please sign in to comment.