diff --git a/.gitignore b/.gitignore index 3af7552b28464e9859a2f29787f0eb924e57a728..bcba6b719c8682be8a7ab4be9a77be0cb5afd3ec 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,9 @@ clab-gosdn_csbi_arista_base/ coverage.out report.xml +# artifacts +controller/gosdn +cli/gosdnc + +# testing +controller/configs/testing-gosdn.toml diff --git a/controller/Makefile b/controller/Makefile index fd5cb193652e01e55ab6b6e51af5b5d482e5c6c0..f0fc33811e36bc15f6f317da203bf8190e7c9a7e 100644 --- a/controller/Makefile +++ b/controller/Makefile @@ -29,16 +29,16 @@ clean: rm -f $(BINARY_NAME) start: clean build - ./$(BINARY_NAME) -l debug + ENVIRONMENT=development ./$(BINARY_NAME) -l debug start-insecure: clean build - ./$(BINARY_NAME) -l debug -s insecure + ENVIRONMENT=development ./$(BINARY_NAME) -l debug -s insecure unit-test: install-tools - ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out + ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out controller-test: install-tools - ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun + ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun lint: install-tools ./$(TOOLS_DIR)/golangci-lint run --config .gitlab/ci/.golangci-config/.golangci.yml @@ -50,12 +50,13 @@ ci-lint: golangci-lint run --config ../.gitlab/ci/.golangci-config/.golangci.yml --out-format code-climate | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' ci-unit-test: ci-install-tools - gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out + ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -short -race $$( go list ./... | grep -v /forks/ | grep -v /mocks ) -v -coverprofile=coverage.out ci-controller-test: ci-install-tools - gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun + ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun integration-test-nucleus: + ENVIRONMENT=testing &&\ cd ./test/integration &&\ go test -race -v -run TestGnmi_SetIntegration &&\ go test -race -v -run TestGnmi_GetIntegration &&\ @@ -63,5 +64,6 @@ integration-test-nucleus: go test -race -v -run TestGnmi_CapabilitiesIntegration integration-test-api: + ENVIRONMENT=testing &&\ cd ./api &&\ go test -race -v -run TestApiIntegration diff --git a/controller/cmd/root.go b/controller/cmd/root.go index b4479da028257787aeda9d03e8b08bbd966c4491..d56e963cfc96c6082743c777a5dc0f646b7e5d07 100644 --- a/controller/cmd/root.go +++ b/controller/cmd/root.go @@ -33,10 +33,12 @@ package cmd import ( "context" + "fmt" "os" "path/filepath" "code.fbi.h-da.de/danet/gosdn/controller" + "code.fbi.h-da.de/danet/gosdn/controller/config" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -96,10 +98,14 @@ func initConfig() { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { + env := config.DetermineConfigEnvironment() + + log.Infof("environment is %s\n", env) + viper.AddConfigPath(configHome) viper.AddConfigPath("/usr/local/etc/gosdn/") viper.SetConfigType(configType) - viper.SetConfigName(configName) + viper.SetConfigName(fmt.Sprintf("%s-%s", env, configName)) } viper.AutomaticEnv() // read in environment variables that match diff --git a/controller/config/environment.go b/controller/config/environment.go new file mode 100644 index 0000000000000000000000000000000000000000..9e916e7c1c6d1f6c6e69b5590d31555b13b6fdb4 --- /dev/null +++ b/controller/config/environment.go @@ -0,0 +1,47 @@ +package config + +import ( + "os" + "strings" +) + +// Environment is used to determine the environment the controller is running in. +type Environment int64 + +const ( + // Development is used for local development + Development Environment = iota + // Production is used for production deployments + Production + // Testing is used for tests + Testing +) + +func (e Environment) String() string { + switch e { + case Development: + return "development" + case Production: + return "production" + case Testing: + return "testing" + } + + return "development" +} + +// DetermineConfigEnvironment returns the environment mode the controller should use. +func DetermineConfigEnvironment() Environment { + env := os.Getenv("ENVIRONMENT") + + switch strings.ToLower(env) { + case "development": + return Development + case "production": + return Production + case "testing": + return Testing + default: + return Development + } +} diff --git a/controller/configs/ci-testing-gosdn.toml b/controller/configs/ci-testing-gosdn.toml new file mode 100644 index 0000000000000000000000000000000000000000..7c78182ab21fbc4cc3f6797b1b3ccb84765d138c --- /dev/null +++ b/controller/configs/ci-testing-gosdn.toml @@ -0,0 +1,3 @@ +basepnduuid = "d4dd9fcb-7fe3-4657-aa33-f9071b2ae257" +basesouthboundtype = 1 +basesouthbounduuid = "a325693a-aa16-45fc-965d-08c986c476c1" diff --git a/controller/configs/development-gosdn.toml.example b/controller/configs/development-gosdn.toml.example new file mode 100644 index 0000000000000000000000000000000000000000..a5905297427eb70e3799ce15acfb27f095f649ec --- /dev/null +++ b/controller/configs/development-gosdn.toml.example @@ -0,0 +1,14 @@ +basepnduuid = "5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d" +basesouthboundtype = 1 +basesouthbounduuid = "ca29311a-3b17-4385-96f8-515b602a97ac" +cli_pnd = "0455b241-5863-4660-ad15-dfde7617738e" +cli_sbi = "a249f2d2-f7da-481d-8a99-b7f11471e0af" +config = "" +csbi-orchestrator = "localhost:55056" +grpc-port = "" +help = false +log-level = "debug" +pnduuid = "bf8160d4-4659-4a1b-98fd-f409a04111ec" +socket = ":55055" +databaseConnection = "mongodb://root:example@localhost:27017" + diff --git a/controller/controller_test.go b/controller/controller_test.go index f825e95d60c0cbd898403dcee7e9630f341602f2..ce8794bb66d21fc21714ecdfaccf9276e0729def 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -12,7 +12,7 @@ import ( const ( configHome string = "./configs" - configName string = "gosdn" + configName string = "ci-testing-gosdn" configType string = "toml" )