diff --git a/build/ci/.build-container.yml b/build/ci/.build-container.yml index 771db4345f68c12be3b43c12c0a9ea18913ef685..3d1d3576d46f53cc9e1ff6d1dc2a4b1754b19374 100644 --- a/build/ci/.build-container.yml +++ b/build/ci/.build-container.yml @@ -43,16 +43,26 @@ deploy:latest: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH <<: *deploy +.deploy:mr: &deploy-mr + stage: deploy + needs: ["build:docker"] + tags: + - baremetal + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker tag $DOCKER_IMAGE_SHA $TAG + - docker push $TAG + deploy:merge-request:master: variables: TAG: $CI_REGISTRY_IMAGE:mr-master rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - <<: *deploy + <<: *deploy-mr deploy:merge-mr:develop: variables: TAG: $CI_REGISTRY_IMAGE:mr-develop rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop' - <<: *deploy + <<: *deploy-mr diff --git a/build/ci/.test.yml b/build/ci/.test.yml index f6114fcf3ecfa37a8c54e199fdc35a9629369de5..587bc1d392f53e238b2d5135a40c400d773bbe46 100644 --- a/build/ci/.test.yml +++ b/build/ci/.test.yml @@ -1,4 +1,4 @@ -unit-test-master: +integration-test: image: golang:1.14 stage: test rules: @@ -18,6 +18,6 @@ unit-test: - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH script: - - go test -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out + - go test -short -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out after_script: - go tool cover -func=coverage.out \ No newline at end of file diff --git a/cmd/gnmi-telemetry/telemetry.go b/cmd/gnmi-telemetry/telemetry.go index 98650bd09d0fda8e12855b17387e2c346f392e43..c083c4a9bc2a9cfa91659b5955a405d05935f772 100644 --- a/cmd/gnmi-telemetry/telemetry.go +++ b/cmd/gnmi-telemetry/telemetry.go @@ -25,7 +25,10 @@ func main() { Uuid: uuid.New(), }, } - pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi) + pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", uuid.New(), sbi) + if err != nil { + log.Fatal(err) + } if err := pnd.AddDevice(&device); err != nil { log.Fatal(err) } diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index 62ca0d32e53af0255ed5c09960dee80a2d494ec0..f6f4eb9846a1b5b3e04dd6cdf9cec7afc67c331b 100644 --- a/cmd/gnmi/gnmi.go +++ b/cmd/gnmi/gnmi.go @@ -23,7 +23,7 @@ func main() { Uuid: uuid.New(), }, } - pnd, err := nucleus.NewPND("openconfig", "test description", sbi) + pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi) if err != nil { log.Fatal(err) } diff --git a/cmd/gosdn/main.go b/cmd/gosdn/main.go index f6f6c8ee20bae517da4daedf2888bdffeafb0efd..4356fbc6a18839313c531ceade42c064a8ac5f07 100644 --- a/cmd/gosdn/main.go +++ b/cmd/gosdn/main.go @@ -8,7 +8,6 @@ import ( func main() { _, debug := os.LookupEnv("GOSDN_DEBUG") - _, integrationTest := os.LookupEnv("GOSDN_TEST") if debug { log.SetLevel(log.DebugLevel) } @@ -17,9 +16,5 @@ func main() { IsRunningChannel := make(chan bool) // hand off to cmd for further processing - if !integrationTest { nucleus.StartAndRun(IsRunningChannel) - } else { - nucleus.IntegrationTests() - } } diff --git a/nucleus/integration.go b/nucleus/integration.go deleted file mode 100644 index 90763e683122e92a38144e30f75e2bfd902bff4e..0000000000000000000000000000000000000000 --- a/nucleus/integration.go +++ /dev/null @@ -1,59 +0,0 @@ -package nucleus - -import ( - "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" - "context" - "github.com/google/uuid" - gpb "github.com/openconfig/gnmi/proto/gnmi" - log "github.com/sirupsen/logrus" - "time" -) - -func IntegrationTests() { - sbi := &OpenConfig{} - device := &Device{ - GoStruct: sbi.Schema().Root, - SBI: sbi, - Config: DeviceConfig{ - Uuid: uuid.New(), - }, - } - pnd, err := NewPND("openconfig", "test description", sbi) - if err != nil { - log.Fatal(err) - } - if err := pnd.AddDevice(device); err != nil { - log.Fatal(err) - } - - cfg := &gnmi.Config{ - Addr: "172.100.100.20:6030", - Username: "admin", - Password: "admin", - Encoding: gpb.Encoding_JSON_IETF, - } - transport, err := NewGnmiTransport(cfg) - if err != nil { - log.Fatal(err) - } - transport.SetNode = sbi.SetNode() - - device.Transport = transport - - var resp interface{} - for i := 0; i < 10; i++ { - deadline := time.Now().Add(10 * time.Second) - ctx, cancel := context.WithDeadline(context.Background(), deadline) - resp, err = transport.Capabilities(ctx) - cancel() - if err != nil { - if i < 9 { - log.Error(err) - log.Infof("retrying. %v of 10", i+1) - } else { - log.Fatal(err) - } - } - } - log.Fatal(resp) -} diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go new file mode 100644 index 0000000000000000000000000000000000000000..003a1802b51e619a538c9df03cd2b72d275cb35f --- /dev/null +++ b/nucleus/integration_test.go @@ -0,0 +1,39 @@ +package nucleus + +import "testing" + +func TestGnmi_SetIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} + +func TestGnmi_GetIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} + +func TestGnmi_SubscribeIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} + +func TestGnmi_CapabilitiesIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} + +func TestPndImplementation_RequestAllIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} + +func TestPndImplementation_RequestIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } +} \ No newline at end of file diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 7b26ada3e9e07f3426efbf8159c15a269e543359..ec7a80f2b15e343341164529ebcc2dc3ff9dff32 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -34,20 +34,7 @@ type pndImplementation struct { } // NewPND creates a Principle Network Domain -func NewPND(name, description string, sbi SouthboundInterface) (PrincipalNetworkDomain, error) { - pnd := &pndImplementation{ - name: name, - description: description, - sbic: sbiStore{store{}}, - devices: deviceStore{store{}}, - } - if err := pnd.sbic.add(sbi); err != nil { - return nil, &ErrAlreadyExists{item: sbi} - } - return pnd, nil -} - -func NewPNDwithId(name, description string, id uuid.UUID, sbi SouthboundInterface) (PrincipalNetworkDomain, error) { +func NewPND(name, description string, id uuid.UUID, sbi SouthboundInterface) (PrincipalNetworkDomain, error) { pnd := &pndImplementation{ name: name, description: description, diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 5d77a64dd956a94b2ebcd7e92bb5598aca52428c..1ef15fa9cfc931e00b3c5a06bc71a3f618fdd7d2 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -81,6 +81,7 @@ func TestNewPND(t *testing.T) { name string description string sbi SouthboundInterface + pid uuid.UUID } tests := []struct { name string @@ -94,6 +95,7 @@ func TestNewPND(t *testing.T) { name: "default", description: "default test pnd", sbi: &OpenConfig{id: defaultSbiId}, + pid: defaultPndId, }, want: &pnd, wantErr: false, @@ -101,7 +103,7 @@ func TestNewPND(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := NewPND(tt.args.name, tt.args.description, tt.args.sbi) + got, err := NewPND(tt.args.name, tt.args.description, tt.args.pid, tt.args.sbi) if (err != nil) != tt.wantErr { t.Errorf("NewPND() error = %v, wantErr %v", err, tt.wantErr) return @@ -113,49 +115,6 @@ func TestNewPND(t *testing.T) { } } -func TestNewPNDwithId(t *testing.T) { - pnd := newPndWithId() - if err := pnd.addSbi(&OpenConfig{id: defaultSbiId}); err != nil { - t.Error(err) - } - type args struct { - name string - description string - id uuid.UUID - sbi SouthboundInterface - } - tests := []struct { - name string - args args - want PrincipalNetworkDomain - wantErr bool - }{ - { - name: "default", - args: args{ - name: "default", - description: "default test pnd", - id: defaultPndId, - sbi: &OpenConfig{id: defaultSbiId}, - }, - want: &pnd, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewPNDwithId(tt.args.name, tt.args.description, tt.args.id, tt.args.sbi) - if (err != nil) != tt.wantErr { - t.Errorf("NewPNDwithId() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("NewPNDwithId() got = %v, want %v", got, tt.want) - } - }) - } -} - func Test_destroy(t *testing.T) { tests := []struct { name string