Skip to content

Commit

Permalink
Multi-EVE network test
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Sadov <[email protected]>
  • Loading branch information
sadov committed Jan 25, 2021
1 parent 3f995f0 commit 8361cdf
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 56 deletions.
6 changes: 3 additions & 3 deletions cmd/edenConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var configAddCmd = &cobra.Command{
if len(args) > 0 {
context.Current = args[0]
} else {
context.Current = "default"
context.Current = defaults.DefaultContext
}
configFile = context.GetCurrentConfig()
if contextFile != "" {
Expand All @@ -130,7 +130,7 @@ var configAddCmd = &cobra.Command{
for k, v := range model.Config() {
viper.Set(k, v)
}
if err = utils.GenerateConfigFileFromViper(); err != nil {
if err = utils.GenerateConfigFileFromViper(configFile); err != nil {
log.Fatalf("error writing config: %s", err)
}
context.SetContext(currentContextName)
Expand Down Expand Up @@ -197,7 +197,7 @@ var configSetCmd = &cobra.Command{
log.Fatalf("error reading config: %s", err.Error())
}
viper.Set(contextKeySet, contextValueSet)
if err = utils.GenerateConfigFileFromViper(); err != nil {
if err = utils.GenerateConfigFileFromViper(configFile); err != nil {
log.Fatalf("error writing config: %s", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/edenExportImport.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var importCmd = &cobra.Command{
if viperLoaded {
if edenRoot != viper.GetString("eden.root") {
viper.Set("eve.root", edenRoot)
if err = utils.GenerateConfigFileFromViper(); err != nil {
if err = utils.GenerateConfigFileFromViper(configFile); err != nil {
log.Fatalf("error writing config: %s", err)
}
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ var configName string
var configFile string

var rootCmd = &cobra.Command{Use: "eden", PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
configNameEnv := os.Getenv(defaults.DefaultConfigEnv)
if configNameEnv != "" {
configName = configNameEnv
if configName == "" {
configNameEnv := os.Getenv(defaults.DefaultConfigEnv)
if configNameEnv != "" {
configName = configNameEnv
} else {
configName = defaults.DefaultContext
}
}

configFile = utils.GetConfig(configName)
if verbosity == "debug" {
fmt.Println("configName: ", configName)
Expand Down Expand Up @@ -99,7 +104,7 @@ func init() {

// Execute primary function for cobra
func Execute() {
rootCmd.PersistentFlags().StringVar(&configName, "config", defaults.DefaultContext, "Name of config")
rootCmd.PersistentFlags().StringVar(&configName, "config", "", "Name of config ('default' by default)")
rootCmd.PersistentFlags().StringVarP(&verbosity, "verbosity", "v", log.InfoLevel.String(), "Log level (debug, info, warn, error, fatal, panic")
_ = rootCmd.Execute()
}
13 changes: 8 additions & 5 deletions pkg/projects/testContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ type TestContext struct {
}

//NewTestContext creates new TestContext
func NewTestContext() *TestContext {
func NewTestContext(config string) *TestContext {
var err error
viperLoaded := false
if edenConfigEnv := os.Getenv(defaults.DefaultConfigEnv); edenConfigEnv != "" {
if config != "" {
viperLoaded, err = utils.LoadConfigFile(utils.GetConfig(config))
//fmt.Printf("NewTestContext config=%s viperLoaded=%v err=%v\n", config, viperLoaded, err)
} else if edenConfigEnv := os.Getenv(defaults.DefaultConfigEnv); edenConfigEnv != "" {
viperLoaded, err = utils.LoadConfigFile(utils.GetConfig(edenConfigEnv))
} else {
viperLoaded, err = utils.LoadConfigFile("")
Expand Down Expand Up @@ -109,10 +112,10 @@ func (tc *TestContext) GetNodeDescriptions() (nodes []*EdgeNodeDescription) {
} else {
log.Debug("NodeDescriptions not found. Will use default one.")
nodes = append(nodes, &EdgeNodeDescription{
Name: viper.GetString("eve.name"),
Key: utils.ResolveAbsPath(viper.GetString("eve.cert")),
Name: viper.GetString("eve.name"),
Key: utils.ResolveAbsPath(viper.GetString("eve.cert")),
Serial: viper.GetString("eve.serial"),
Model: viper.GetString("eve.devModel"),
Model: viper.GetString("eve.devModel"),
})
}
return
Expand Down
11 changes: 7 additions & 4 deletions pkg/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,13 @@ func generateConfigFileFromViperTemplate(filePath string, templateString string)
}

//GenerateConfigFileFromViper is a function to generate yml from viper config
func GenerateConfigFileFromViper() error {
configFile, err := DefaultConfigPath()
if err != nil {
log.Fatalf("fail in DefaultConfigPath: %s", err)
func GenerateConfigFileFromViper(configFile string) error {
if configFile == "" {
cfg, err := DefaultConfigPath()
if err != nil {
log.Fatalf("fail in DefaultConfigPath: %s", err)
}
configFile = cfg
}
return generateConfigFileFromViperTemplate(configFile, defaults.DefaultEdenTemplate)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func (ctx *Context) GetCurrentConfig() string {

//SetContext set current contexts
func (ctx *Context) SetContext(context string) {
//fmt.Println("SetContext:", context)
ctx.Current = context
ctx.Save()
//ctx.Save()
}

//ListContexts show available contexts
Expand Down
4 changes: 3 additions & 1 deletion tests/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// This test wait for the app's state with a timewait.
var (
timewait = flag.Duration("timewait", 10*time.Minute, "Timewait for items waiting")
config = flag.String("config", "default", "EDEN config")
tc *projects.TestContext
states map[string][]string
eveState *eve.State
Expand All @@ -33,7 +34,8 @@ func TestMain(m *testing.M) {

tests.TestArgsParse()

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestAppState", time.Now())

Expand Down
13 changes: 8 additions & 5 deletions tests/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ var (
cpus = flag.Uint("cpus", 1, "Cpu number for app")
memory = flag.String("memory", "1G", "Memory for app")
nohyper = flag.Bool("nohyper", false, "Do not use a hypervisor")
tc *projects.TestContext
externalIP string
portPublish []string
appName string
cfg = flag.String("config", "default", "EDEN config")

tc *projects.TestContext
externalIP string
portPublish []string
appName string
)

// TestMain is used to provide setup and teardown for the rest of the
Expand All @@ -45,7 +47,8 @@ var (
func TestMain(m *testing.M) {
fmt.Println("Docker app deployment Test")

tc = projects.NewTestContext()
fmt.Println("Test config: ", *cfg)
tc = projects.NewTestContext(*cfg)

projectName := fmt.Sprintf("%s_%s", "TestDockerDeploy", time.Now())

Expand Down
3 changes: 1 addition & 2 deletions tests/eclient/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ test:
build: setup

setup: $(BINDIR) $(DATADIR)
cp -a *.sh *.yml $(TESTSCN) testdata $(DATADIR)
cp -a *.txt *.sh *.yml $(TESTSCN) testdata $(DATADIR)
ln -sf ../$(TESTDIR)/eden+ports.sh $(BINDIR)/
ln -sf ../$(TESTDIR)/eden-ports.sh $(BINDIR)/
ln -sf ../$(TESTDIR)/qemu+usb.sh $(BINDIR)/
chmod 700 image/cert/
chmod 600 image/cert/id_rsa*
mkdir -p $(DATADIR)/image/cert/
Expand Down
13 changes: 8 additions & 5 deletions tests/eclient/eden+ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ then
exit
fi

test -n "$EDEN_CONFIG" || EDEN_CONFIG=default

EDEN=eden
DIR=$(dirname "$0")
PATH=$DIR:$DIR/../../bin:$PATH

if [ -z "$EDEN_CONFIG" ]
then
EDEN_CONFIG=default
fi

OLD=$($EDEN config get "$EDEN_CONFIG" --key eve.hostfwd)
NEW=$OLD

Expand All @@ -33,9 +36,9 @@ then
$EDEN config set "$EDEN_CONFIG" --key eve.hostfwd --value "$NEW"
echo $EDEN config get "$EDEN_CONFIG" --key eve.hostfwd
$EDEN config get "$EDEN_CONFIG" --key eve.hostfwd
cat <<END
To activate the changes in the config, you need to restart EVE:
echo $EDEN eve stop
$EDEN eve stop
sleep 5
echo $EDEN eve start
$EDEN eve start
END
fi
13 changes: 8 additions & 5 deletions tests/eclient/eden-ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ then
exit
fi

test -n "$EDEN_CONFIG" || EDEN_CONFIG=default

EDEN=eden
DIR=$(dirname "$0")
PATH=$DIR:$DIR/../../bin:$PATH

if [ -z "$EDEN_CONFIG" ]
then
EDEN_CONFIG=default
fi

OLD=$($EDEN config get "$EDEN_CONFIG" --key eve.hostfwd)
NEW=$OLD

Expand All @@ -33,9 +36,9 @@ then
$EDEN config set "$EDEN_CONFIG" --key eve.hostfwd --value "$NEW"
echo $EDEN config get "$EDEN_CONFIG" --key eve.hostfwd
$EDEN config get "$EDEN_CONFIG" --key eve.hostfwd
cat <<END
To activate the changes in the config, you need to restart EVE:
echo $EDEN eve stop
$EDEN eve stop
sleep 5
echo $EDEN eve start
$EDEN eve start
END
fi
3 changes: 2 additions & 1 deletion tests/escript/go-internal/testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ func (ts *TestScript) setup() string {
)
} else {
env.Vars = append(env.Vars,
homeEnvName()+"=/no-home",
homeEnvName()+"="+os.Getenv("HOME"),
//homeEnvName()+"=/no-home",
)
}
// Must preserve SYSTEMROOT on Windows: https://github.com/golang/go/issues/25513 et al
Expand Down
4 changes: 3 additions & 1 deletion tests/lim/lim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
number = flag.Int("number", 1, "The number of items (0=unlimited) you need to get")
timewait = flag.Duration("timewait", 10*time.Minute, "Timewait for items waiting")
out = flag.String("out", "", "Parameters for out separated by ':'")
config = flag.String("config", "default", "EDEN config")

// This context holds all the configuration items in the same
// way that Eden context works: the commands line options override
Expand Down Expand Up @@ -80,7 +81,8 @@ func TestMain(m *testing.M) {

tests.TestArgsParse()

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestLogInfoMetric", time.Now())

Expand Down
4 changes: 3 additions & 1 deletion tests/network/nw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// This test wait for the network's state with a timewait.
var (
timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting")
config = flag.String("config", "default", "EDEN config")
tc *projects.TestContext
states map[string][]string
eveState *eve.State
Expand All @@ -28,7 +29,8 @@ var (
func TestMain(m *testing.M) {
fmt.Println("Network's state test")

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestNetState", time.Now())

Expand Down
4 changes: 3 additions & 1 deletion tests/reboot/reboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
timewait = flag.Duration("timewait", time.Minute, "Timewait for waiting")
reboot = flag.Bool("reboot", true, "Reboot or not reboot...")
count = flag.Int("count", 1, "Number of reboots")
config = flag.String("config", "default", "EDEN config")

tc *projects.TestContext

Expand Down Expand Up @@ -63,7 +64,8 @@ func TestMain(m *testing.M) {

tests.TestArgsParse()

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestReboot", time.Now())

Expand Down
4 changes: 3 additions & 1 deletion tests/vnc/vnc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

var (
timewait = flag.Duration("timewait", 20*time.Minute, "Timewait for items waiting")
config = flag.String("config", "default", "EDEN config")

expand = flag.Duration("expand", 10*time.Minute, "Expand timewait on success of step")
name = flag.String("name", "", "Name of app, random if empty")
Expand All @@ -55,7 +56,8 @@ var (
func TestMain(m *testing.M) {
fmt.Println("VNC access to app Test")

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestVNCAccess", time.Now())

Expand Down
4 changes: 3 additions & 1 deletion tests/volume/vol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// This test wait for the volume's state with a timewait.
var (
timewait = flag.Duration("timewait", time.Minute, "Timewait for items waiting")
config = flag.String("config", "default", "EDEN config")
tc *projects.TestContext
states map[string][]string
eveState *eve.State
Expand All @@ -28,7 +29,8 @@ var (
func TestMain(m *testing.M) {
fmt.Println("Docker volume's state test")

tc = projects.NewTestContext()
fmt.Println("Test config: ", *config)
tc = projects.NewTestContext(*config)

projectName := fmt.Sprintf("%s_%s", "TestVolState", time.Now())

Expand Down
Loading

0 comments on commit 8361cdf

Please sign in to comment.