Skip to content
Snippets Groups Projects
Commit e83082b1 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

Northbound Interface

parent 50722ba9
Branches
Tags
9 merge requests!246Develop,!245Develop into Master,!244Master into develop2 into master,!219Draft: Testing,!214Test pipelines,!195DO NOT MERGE 2,!194DO NOT MERGE! just for testing,!155Northbound Interface,!138Develop
package integration
import (
"os"
"testing"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/cli"
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
guuid "github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
pb "google.golang.org/protobuf/proto"
"os"
"testing"
)
const unreachable = "203.0.113.10:6030"
const testPath = "/system/config/hostname"
var testAddress = "141.100.70.171:6030"
var testAPIEndpoint = "http://gosdn-latest.apps.ocp.fbi.h-da.de/api"
var testUsername = "admin"
var testPassword = "arista"
var defaultPath = []string{"/system/config/hostname"}
var opt *nucleus.GnmiTransportOptions
var opt *tpb.TransportOption
func TestMain(m *testing.M) {
testSetupIntegration()
......@@ -74,14 +75,10 @@ func testSetupIntegration() {
}
}
opt = &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: testAddress,
Username: testUsername,
Password: testPassword,
Encoding: gpb.Encoding_JSON_IETF,
},
RespChan: make(chan *gpb.SubscribeResponse),
opt = &tpb.TransportOption{
Address: testAddress,
Username: testUsername,
Password: testPassword,
}
}
......@@ -101,7 +98,7 @@ func TestCmdIntegration(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer viper.Reset()
if err := cli.HTTPGet(testAPIEndpoint, "init"); (err != nil) != tt.wantErr {
if err := cli.Init(testAPIEndpoint); (err != nil) != tt.wantErr {
switch err.(type) {
case viper.ConfigFileNotFoundError:
default:
......@@ -112,65 +109,68 @@ func TestCmdIntegration(t *testing.T) {
cliPnd := viper.GetString("CLI_PND")
cliSbi := viper.GetString("CLI_SBI")
if err := cli.HTTPGet(
if _, err := cli.AddDevice(
testAPIEndpoint,
"addDevice",
"address="+testAddress,
"password="+testPassword,
"username="+testUsername,
"sbi="+cliSbi,
"pnd="+cliPnd,
testUsername,
testPassword,
cliSbi,
cliPnd,
testAddress,
"test-device",
); (err != nil) != tt.wantErr {
t.Errorf("gosdn cli add-device error = %v, wantErr %v", err, tt.wantErr)
return
}
did := viper.GetString("LAST_DEVICE_UUID")
if err := cli.HTTPGet(
_, err := cli.GetDevice(
testAPIEndpoint,
"request",
"uuid="+did,
"sbi="+cliSbi,
"pnd="+cliPnd,
"path=/system/config/hostname",
); (err != nil) != tt.wantErr {
cliPnd,
testPath,
did,
)
if (err != nil) != tt.wantErr {
t.Errorf("gosdn cli request error = %v, wantErr %v", err, tt.wantErr)
return
}
if err := cli.HTTPGet(
_, err = cli.GetDevice(
testAPIEndpoint,
"getDevice",
"address="+testAddress,
"uuid="+did,
"sbi="+cliSbi,
"pnd="+cliPnd,
); (err != nil) != tt.wantErr {
cliPnd,
"",
did,
)
if (err != nil) != tt.wantErr {
t.Errorf("gosdn cli get-device error = %v, wantErr %v", err, tt.wantErr)
return
}
hostname := guuid.New().String()
if err := cli.HTTPGet(
_, err = cli.Update(
testAPIEndpoint,
"update",
"address="+testAddress,
"uuid="+did,
"sbi="+cliSbi,
"pnd="+cliPnd,
"path=/system/config/hostname",
"value="+hostname,
); (err != nil) != tt.wantErr {
did,
cliPnd,
testPath,
hostname,
)
if (err != nil) != tt.wantErr {
t.Errorf("gosdn cli set error = %v, wantErr %v", err, tt.wantErr)
return
}
resp, err := cli.Get(testAddress, testUsername, testPassword, "/system/config/hostname")
if (err != nil) != tt.wantErr {
t.Errorf("cli.Get() error = %v, wantErr %v", err, tt.wantErr)
resp, err := cli.GetDevice(testAddress, testUsername, testPassword, testPath)
if err != nil {
if !tt.wantErr {
t.Errorf("cli.Get() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
got := resp.Notification[0].Update[0].Val.GetStringVal()
var got string
if resp != nil {
got = resp.Ond[0].Name
} else {
t.Errorf("integration test failed got cannot be nil")
}
if got != hostname {
t.Errorf("integration test failed = got: %v, want: %v", got, hostname)
}
......
package integration
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/types"
"context"
gpb "github.com/openconfig/gnmi/proto/gnmi"
pb "google.golang.org/protobuf/proto"
"reflect"
"sort"
"testing"
"time"
spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/types"
gpb "github.com/openconfig/gnmi/proto/gnmi"
pb "google.golang.org/protobuf/proto"
)
var gnmiMessages map[string]pb.Message
......@@ -20,7 +24,7 @@ func TestGnmi_SetIntegration(t *testing.T) {
t.Skip("skipping integration test")
}
type fields struct {
opt *nucleus.GnmiTransportOptions
opt *tpb.TransportOption
}
type args struct {
ctx context.Context
......@@ -34,12 +38,11 @@ func TestGnmi_SetIntegration(t *testing.T) {
}{
{
name: "destination unreachable",
fields: fields{opt: &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
fields: fields{
opt: &tpb.TransportOption{
Address: "203.0.113.10:6030",
},
},
},
args: args{
ctx: context.Background(),
params: []string{"/system/config/hostname", "ceos3000"},
......@@ -67,7 +70,7 @@ func TestGnmi_SetIntegration(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := nucleus.NewGnmiTransport(tt.fields.opt)
g, err := nucleus.NewGnmiTransport(tt.fields.opt, nucleus.NewSBI(spb.Type_OPENCONFIG))
if err != nil {
t.Errorf("NewGnmiTransport() error = %v, wantErr %v", err, tt.wantErr)
return
......@@ -91,7 +94,7 @@ func TestGnmi_GetIntegration(t *testing.T) {
"system/config/hostname",
}
type fields struct {
opt *nucleus.GnmiTransportOptions
opt *tpb.TransportOption
}
type args struct {
ctx context.Context
......@@ -116,12 +119,11 @@ func TestGnmi_GetIntegration(t *testing.T) {
},
{
name: "destination unreachable",
fields: fields{opt: &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
fields: fields{
opt: &tpb.TransportOption{
Address: "203.0.113.10:6030",
},
},
},
args: args{
ctx: context.Background(),
params: paths,
......@@ -132,7 +134,7 @@ func TestGnmi_GetIntegration(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := nucleus.NewGnmiTransport(tt.fields.opt)
g, err := nucleus.NewGnmiTransport(tt.fields.opt, nucleus.NewSBI(spb.Type_OPENCONFIG))
if err != nil {
t.Error(err)
return
......@@ -154,7 +156,7 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
}
type fields struct {
opt *nucleus.GnmiTransportOptions
opt *tpb.TransportOption
}
type args struct {
ctx context.Context
......@@ -169,9 +171,19 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
{
name: "default",
fields: fields{
opt: &nucleus.GnmiTransportOptions{
Config: opt.Config,
RespChan: make(chan *gpb.SubscribeResponse),
opt: &tpb.TransportOption{
Address: "",
Username: "",
Password: "",
Tls: false,
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{
Compression: "",
GrpcDialOptions: nil,
Token: "",
Encoding: 0,
},
},
},
},
args: args{
......@@ -193,10 +205,7 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
{
name: "wrong path",
fields: fields{
opt: &nucleus.GnmiTransportOptions{
Config: opt.Config,
RespChan: make(chan *gpb.SubscribeResponse),
},
opt: &tpb.TransportOption{},
},
args: args{
opts: &gnmi.SubscribeOptions{
......@@ -216,11 +225,8 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
{
name: "destination unreachable",
fields: fields{
opt: &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
},
RespChan: make(chan *gpb.SubscribeResponse),
opt: &tpb.TransportOption{
Address: "203.0.113.10:6030",
},
},
args: args{
......@@ -232,7 +238,7 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var wantErr = tt.wantErr
g, err := nucleus.NewGnmiTransport(tt.fields.opt)
g, err := nucleus.NewGnmiTransport(tt.fields.opt, nucleus.NewSBI(spb.Type_OPENCONFIG))
if err != nil {
t.Error(err)
return
......@@ -261,7 +267,7 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
t.Skip("skipping integration test")
}
type fields struct {
opt *nucleus.GnmiTransportOptions
opt *tpb.TransportOption
}
type args struct {
ctx context.Context
......@@ -296,10 +302,8 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
},
{
name: "destination unreachable",
fields: fields{opt: &nucleus.GnmiTransportOptions{
Config: gnmi.Config{
Addr: "203.0.113.10:6030",
},
fields: fields{opt: &tpb.TransportOption{
Address: "203.0.113.10:6030",
},
},
args: args{ctx: context.Background()},
......@@ -309,7 +313,7 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g, err := nucleus.NewGnmiTransport(tt.fields.opt)
g, err := nucleus.NewGnmiTransport(tt.fields.opt, nucleus.NewSBI(spb.Type_OPENCONFIG))
if err != nil {
t.Error(err)
return
......
package test
import (
"net"
"reflect"
"code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi"
oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
pb "github.com/openconfig/gnmi/proto/gnmi"
......@@ -10,8 +13,6 @@ import (
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"net"
"reflect"
)
type server struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment