From 4f54ea987106e028e2fa8d2370b613f73f2fa3ba Mon Sep 17 00:00:00 2001 From: Manuel Kieweg <mail@manuelkieweg.de> Date: Thu, 4 Mar 2021 18:45:24 +0000 Subject: [PATCH] first boilerplate integration tests. only error checking for now --- build/ci/.terraform-ci.yml | 1 - cmd/gnmi-telemetry/telemetry.go | 8 +- cmd/gnmi/gnmi.go | 4 +- nucleus/integration_test.go | 105 ++++++++++++++++++++++++- nucleus/principalNetworkDomain_test.go | 9 --- 5 files changed, 108 insertions(+), 19 deletions(-) diff --git a/build/ci/.terraform-ci.yml b/build/ci/.terraform-ci.yml index 6c6a08cb1..c2dc2bda1 100644 --- a/build/ci/.terraform-ci.yml +++ b/build/ci/.terraform-ci.yml @@ -71,5 +71,4 @@ destroy: stage: .post script: - gitlab-terraform destroy - needs: ["apply"] <<: *tf \ No newline at end of file diff --git a/cmd/gnmi-telemetry/telemetry.go b/cmd/gnmi-telemetry/telemetry.go index c083c4a9b..4abcced5f 100644 --- a/cmd/gnmi-telemetry/telemetry.go +++ b/cmd/gnmi-telemetry/telemetry.go @@ -33,17 +33,13 @@ func main() { log.Fatal(err) } - transport := &nucleus.Gnmi{ - SetNode: sbi.SetNode(), - RespChan: make(chan *gpb.SubscribeResponse), - } cfg := &gnmi.Config{ - Addr: "portainer.danet.fbi.h-da.de:6030", + Addr: "[2003:e6:1722:fed0:0:242:ac11:5]:6030", Username: "admin", Password: "arista", Encoding: gpb.Encoding_JSON_IETF, } - transport.SetConfig(cfg) + transport,_ := nucleus.NewGnmiTransport(cfg) device.Transport = transport diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index f6f4eb984..65b5ecb51 100644 --- a/cmd/gnmi/gnmi.go +++ b/cmd/gnmi/gnmi.go @@ -32,7 +32,7 @@ func main() { } cfg := &gnmi.Config{ - Addr: "[fdfd::ce05]:6030", + Addr: "[2003:e6:1722:fed0:0:242:ac11:5]:6030", Username: "admin", Password: "arista", Encoding: gpb.Encoding_JSON_IETF, @@ -45,7 +45,7 @@ func main() { device.Transport = transport - p := []string{"/interfaces/interface"} + p := []string{"/interfaces/interface/name"} errors := 0 for _, path := range p { err := pnd.RequestAll(path) diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go index 003a1802b..def64439c 100644 --- a/nucleus/integration_test.go +++ b/nucleus/integration_test.go @@ -1,39 +1,142 @@ package nucleus -import "testing" +import ( + "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" + "context" + gpb "github.com/openconfig/gnmi/proto/gnmi" + "testing" + "time" +) + +var address = "141.100.70.171:6030" func TestGnmi_SetIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Run("Test GNMI Set", func(t *testing.T){ + cfg := &gnmi.Config{ + Addr: address, + Username: "admin", + Password: "arista", + Encoding: gpb.Encoding_JSON_IETF, + } + transport,err := NewGnmiTransport(cfg) + if err != nil { + t.Error(err) + } + p := []string{"/interfaces/interface"} + resp, err := transport.Set(context.Background(), p...) + if err != nil { + t.Error(err) + } + if resp == nil { + t.Error("resp is nil") + } + }) } func TestGnmi_GetIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Run("Test GNMI Get", func(t *testing.T){ + cfg := &gnmi.Config{ + Addr: address, + Username: "admin", + Password: "arista", + Encoding: gpb.Encoding_JSON_IETF, + } + transport,err := NewGnmiTransport(cfg) + if err != nil { + t.Error(err) + } + p := []string{"/interfaces/interface"} + resp, err := transport.Get(context.Background(), p...) + if err != nil { + t.Error(err) + } + if resp == nil { + t.Error("resp is nil") + } + }) } func TestGnmi_SubscribeIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Run("Test GNMI Subscribe", func(t *testing.T){ + cfg := &gnmi.Config{ + Addr: address, + Username: "admin", + Password: "arista", + Encoding: gpb.Encoding_JSON_IETF, + } + transport,_ := NewGnmiTransport(cfg) + + paths := []string{"/interfaces/interface/name"} + + opts := &gnmi.SubscribeOptions{ + UpdatesOnly: false, + Prefix: "", + Mode: "stream", + StreamMode: "sample", + SampleInterval: uint64(10 * time.Second.Nanoseconds()), + SuppressRedundant: false, + HeartbeatInterval: uint64(time.Second.Nanoseconds()), + Paths: gnmi.SplitPaths(paths), + Origin: "", + Target: address, + } + ctx := context.WithValue(context.Background(), "opts", opts) + d := time.Now().Add(60 * time.Second) + ctx, cancel := context.WithDeadline(ctx, d) + defer cancel() + go func() { + if err := transport.Subscribe(ctx); err != nil { + t.Error(err) + } + }() + time.Sleep(time.Second * 50) + }) } func TestGnmi_CapabilitiesIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Run("Test GNMI Capabilities", func(t *testing.T){ + cfg := &gnmi.Config{ + Addr: address, + Username: "admin", + Password: "arista", + Encoding: gpb.Encoding_JSON_IETF, + } + transport,err := NewGnmiTransport(cfg) + if err != nil { + t.Error(err) + } + resp, err := transport.Capabilities(context.Background()) + if err != nil { + t.Error(err) + } + if resp == nil { + t.Error("resp is nil") + } + }) } func TestPndImplementation_RequestAllIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Fail() } func TestPndImplementation_RequestIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } + t.Fail() } \ No newline at end of file diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 1ef15fa9c..3f8e7f002 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -49,15 +49,6 @@ func mockDevice() Device { } func newPnd() pndImplementation { - return pndImplementation{ - name: "default", - description: "default test pnd", - sbic: sbiStore{store{}}, - devices: deviceStore{store{}}, - } -} - -func newPndWithId() pndImplementation { return pndImplementation{ name: "default", description: "default test pnd", -- GitLab