diff --git a/.gitignore b/.gitignore index 65899b422cb10044f735e8bc1c7ca91e520a8241..3783bfbc18f1e6558ae25c45a9693f807a27e56f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # tooling -build-tools/ +**/build-tools/ artifacts/ # containerlab @@ -9,6 +9,9 @@ clab-gosdn_csbi_arista_base/ # non vimmers .vscode/ +# MacOS +.DS_Store + # test artifacts coverage.out report.xml @@ -18,10 +21,22 @@ controller/gosdn cli/gosdnc csbi/resources/csbi -# testing and configs +# controller controller/configs/testing-gosdn.toml controller/configs/development-gosdn.toml controller/configs/containerlab-gosdn.toml -**/stores_testing - -config/.gosdnc.toml +controller/config/*_test.toml +controller/configs/ci-testing-gosdn.toml +controller/stores_testing +controller/stores/** +controller/plugins +controller/config/.gosdnc.toml +controller/debug.test +controller/api/api_test.toml +controller/report.xml +controller/test/plugin/**/*.so +controller/nucleus/util/proto/*_test +controller/api/stores_testing/** +controller/northbound/server/stores_testing/** +controller/nucleus/stores_testing/** +controller/nucleus/**/gostructs.go diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/controller/.gitignore b/controller/.gitignore deleted file mode 100644 index 2546ae5dad63a9a9a7da66152f0c66cd942e1347..0000000000000000000000000000000000000000 --- a/controller/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -.vscode/ -.vscode/launch.json -.DS_Store -documentation/design-documentation/ -documentation/design/*.pdf -*.aux -*.bbl -*.blg -*.lof -*.log -*.out -.idea/gosdn.iml -.idea/modules.xml -.idea/vcs.xml -.idea/workspace.xml -restconf/bin/bin -test/.terraform.local/ -configs/gosdn.toml -api/api_test.toml -debug.test - -# developer tools -build-tools/ - -# test files -report.xml -test/plugin/**/*.so -nucleus/util/proto/*_test - -# persistent data -**/stores/** -plugins -documentation/figures/~$goSDN-Net-Environment.drawio.dtmp diff --git a/controller/Makefile b/controller/Makefile index 6574425ce2da4d062dac9abf01f14682bbb236b6..f5b2a70e8469bb596779b57adb2c21fd281f9dca 100644 --- a/controller/Makefile +++ b/controller/Makefile @@ -41,7 +41,7 @@ controller-test: install-tools ENVIRONMENT=testing ./$(TOOLS_DIR)/gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun ci-unit-test: ci-install-tools - ENVIRONMENT=testing 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 -timeout 30m ci-controller-test: ci-install-tools ENVIRONMENT=testing gotestsum --junitfile report.xml --format testname -- -race -v -run TestRun -coverprofile=coverage.out diff --git a/controller/config/config_test.toml b/controller/config/config_test.toml deleted file mode 100644 index fa96c74902f538afe7d054291d1d68b2574a8657..0000000000000000000000000000000000000000 --- a/controller/config/config_test.toml +++ /dev/null @@ -1,5 +0,0 @@ -basepnduuid = "bf8160d4-4659-4a1b-98fd-f409a04111ec" -basesouthboundtype = 1 -basesouthbounduuid = "bf8160d4-4659-4a1b-98fd-f409a04111eb" -databaseconnection = "test@test:test" -gosdn_change_timeout = "10m" diff --git a/controller/configs/ci-testing-gosdn.toml b/controller/configs/ci-testing-gosdn.toml deleted file mode 100644 index d9f5427487fab4c3005bcc1b598ca919d09a9f73..0000000000000000000000000000000000000000 --- a/controller/configs/ci-testing-gosdn.toml +++ /dev/null @@ -1,3 +0,0 @@ -basepnduuid = "e3a04432-a5de-4c6a-9d06-cacc0a349b77" -basesouthboundtype = 1 -basesouthbounduuid = "94f48ae8-6028-4da0-b495-4c554f886366" diff --git a/controller/controller_test.go b/controller/controller_test.go index ce8794bb66d21fc21714ecdfaccf9276e0729def..5c68530f9831695733f78d9ba8272f875daf3da2 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "code.fbi.h-da.de/danet/gosdn/controller/config" "github.com/spf13/viper" ) @@ -16,7 +17,21 @@ const ( configType string = "toml" ) +func TestInit(t *testing.T) { + viper.SetConfigFile("./configs/ci-testing-gosdn.toml") + viper.Set("basePNDUUID", "3e58372e-b53d-41d8-a06e-4131810c8e70") + viper.Set("baseSouthBoundType", 1) + viper.Set("baseSouthBoundUUID", "73b30205-7ad9-48fb-8251-0dbef649ce01") +} + func TestRun(t *testing.T) { + TestInit(t) + err := config.InitializeConfig() + if err != nil { + t.Error(err) + return + } + type args struct { request string } diff --git a/controller/nucleus/deviceFilesystemStore.go b/controller/nucleus/deviceFilesystemStore.go index 47d90d55ada59e9f5b7b568fb93efdc3495d7382..3f1bf140fe4f2ae807d72c4aa7a9e10ca788c8e7 100644 --- a/controller/nucleus/deviceFilesystemStore.go +++ b/controller/nucleus/deviceFilesystemStore.go @@ -125,7 +125,7 @@ func (s *FilesystemDeviceStore) Update(deviceToUpdate device.Device) error { s.fileMutex.Lock() defer s.fileMutex.Unlock() - var loadedDevice device.LoadedDevice + loadedDeviceToUpdate, err := store.TransformObjectToLoadedObject[device.Device, device.LoadedDevice](deviceToUpdate) devices, err := s.readAllDevicesFromFile() if err != nil { @@ -134,11 +134,12 @@ func (s *FilesystemDeviceStore) Update(deviceToUpdate device.Device) error { for i, device := range devices { if device.ID == deviceToUpdate.ID().String() { - devices[i] = loadedDevice + devices[i] = loadedDeviceToUpdate err = s.writeAllDevicesToFile(devices) if err != nil { return err } + return nil } } diff --git a/controller/nucleus/deviceFilesystemStore_test.go b/controller/nucleus/deviceFilesystemStore_test.go index 6534627b1d47b1460b1e9efa7bc53656f5058034..e3179ad319e491b1911c4fe9035e73cdf36dc542 100644 --- a/controller/nucleus/deviceFilesystemStore_test.go +++ b/controller/nucleus/deviceFilesystemStore_test.go @@ -54,11 +54,12 @@ func TestAddDevice(t *testing.T) { pndID, _ := uuid.Parse("b4016412-eec5-45a1-aa29-f59915357bad") deviceID, _ := uuid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") sbiID1, _ := uuid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") + trop := returnBasicTransportOption() sbi1, _ := NewSBI(spb.Type_TYPE_OPENCONFIG, sbiID1) deviceStore := NewDeviceStore(pndID) - device, _ := NewDevice("testdevice", deviceID, nil, sbi1) + device, _ := NewDevice("testdevice", deviceID, &trop, sbi1) err := deviceStore.Add(device) if err != nil { @@ -160,10 +161,52 @@ func TestGetDevice(t *testing.T) { } if returnDevice.ID != inputDevices[1].ID().String() { - t.Errorf("GetAll() = %v, want %v", returnDevice.ID, inputDevices[1].ID().String()) + t.Errorf("Get() = %v, want %v", returnDevice.ID, inputDevices[1].ID().String()) } if returnDevice.Name != inputDevices[1].Name() { - t.Errorf("GetAll() = %v, want %v", returnDevice.Name, inputDevices[1].Name()) + t.Errorf("Get() = %v, want %v", returnDevice.Name, inputDevices[1].Name()) + } +} + +func TestUpdateDevice(t *testing.T) { + ensureDeviceFilesForTestAreRemoved() + defer ensureDeviceFilesForTestAreRemoved() + + pndID, _ := uuid.Parse("b4016412-eec5-45a1-aa29-f59915357bad") + deviceID, _ := uuid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") + sbiID1, _ := uuid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") + + trop := returnBasicTransportOption() + + updatedDeviceName := "testdevice2" + + sbi1, _ := NewSBI(spb.Type_TYPE_OPENCONFIG, sbiID1) + + deviceStore := NewDeviceStore(pndID) + device, _ := NewDevice("testdevice", deviceID, &trop, sbi1) + + err := deviceStore.Add(device) + if err != nil { + t.Error(err) + } + + device, _ = NewDevice(updatedDeviceName, deviceID, &trop, sbi1) + + err = deviceStore.Update(device) + if err != nil { + t.Error(err) + } + + returnDevice, err := deviceStore.Get(store.Query{ID: deviceID, Name: updatedDeviceName}) + if err != nil { + t.Error(err) + } + + if returnDevice.ID != deviceID.String() { + t.Errorf("Get() = %v, want %v", returnDevice.ID, deviceID.String()) + } + if returnDevice.Name != updatedDeviceName { + t.Errorf("Get() = %v, want %v", returnDevice.Name, updatedDeviceName) } }