diff --git a/cmd/edenConfig.go b/cmd/edenConfig.go index 1a17719d3..9b6ba1724 100644 --- a/cmd/edenConfig.go +++ b/cmd/edenConfig.go @@ -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 != "" { @@ -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) @@ -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) } } diff --git a/cmd/edenExportImport.go b/cmd/edenExportImport.go index 316ecd318..154a28b2d 100644 --- a/cmd/edenExportImport.go +++ b/cmd/edenExportImport.go @@ -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) } } diff --git a/cmd/root.go b/cmd/root.go index df167ee8f..cd3fce006 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) @@ -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() } diff --git a/pkg/projects/testContext.go b/pkg/projects/testContext.go index 87c785dae..85bc30f27 100644 --- a/pkg/projects/testContext.go +++ b/pkg/projects/testContext.go @@ -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("") @@ -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 diff --git a/pkg/utils/config.go b/pkg/utils/config.go index 3d11fffba..7362a0347 100644 --- a/pkg/utils/config.go +++ b/pkg/utils/config.go @@ -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) } diff --git a/pkg/utils/context.go b/pkg/utils/context.go index 469976371..4f1d2d8eb 100644 --- a/pkg/utils/context.go +++ b/pkg/utils/context.go @@ -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 diff --git a/tests/app/app_test.go b/tests/app/app_test.go index b0d4c7b01..53c439c19 100644 --- a/tests/app/app_test.go +++ b/tests/app/app_test.go @@ -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 @@ -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()) diff --git a/tests/docker/docker_test.go b/tests/docker/docker_test.go index 260c5582f..5e70c0c47 100644 --- a/tests/docker/docker_test.go +++ b/tests/docker/docker_test.go @@ -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 @@ -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()) diff --git a/tests/eclient/Makefile b/tests/eclient/Makefile index 816516182..7f7c0b912 100644 --- a/tests/eclient/Makefile +++ b/tests/eclient/Makefile @@ -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/ diff --git a/tests/eclient/eden+ports.sh b/tests/eclient/eden+ports.sh index 67e85e196..4ee2f1192 100755 --- a/tests/eclient/eden+ports.sh +++ b/tests/eclient/eden+ports.sh @@ -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 @@ -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 <