Skip to content
Snippets Groups Projects

pnd adapter skeleton

Merged Ghost User requested to merge api-adapter into develop
Files
14
+ 23
83
package api
import (
"os"
"testing"
"code.fbi.h-da.de/cocsn/api/go/gosdn/pnd"
tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"github.com/google/uuid"
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"
)
const unreachable = "203.0.113.10:6030"
const testPath = "/system/config/hostname"
var testAddress = "141.100.70.170:6030"
var testAPIEndpoint = "gosdn-latest.apps.ocp.fbi.h-da.de"
var testUsername = "admin"
var testPassword = "arista"
var opt *tpb.TransportOption
var gnmiMessages map[string]pb.Message
func TestMain(m *testing.M) {
testSetupIntegration()
os.Exit(m.Run())
}
func testSetupIntegration() {
if os.Getenv("GOSDN_LOG") == "nolog" {
log.SetLevel(log.PanicLevel)
}
addr := os.Getenv("GOSDN_TEST_ENDPOINT")
if addr != "" {
testAddress = addr
log.Infof("GOSDN_TEST_ENDPOINT set to %v", testAddress)
}
api := os.Getenv("GOSDN_TEST_API_ENDPOINT")
if api != "" {
testAPIEndpoint = api
log.Infof("GOSDN_TEST_API_ENDPOINT set to %v", testAPIEndpoint)
}
u := os.Getenv("GOSDN_TEST_USER")
if u != "" {
testUsername = u
log.Infof("GOSDN_TEST_USER set to %v", testUsername)
}
p := os.Getenv("GOSDN_TEST_PASSWORD")
if p != "" {
testPassword = p
log.Infof("GOSDN_TEST_PASSWORD set to %v", testPassword)
}
gnmiMessages = map[string]pb.Message{
"../test/proto/cap-resp-arista-ceos": &gpb.CapabilityResponse{},
"../test/proto/req-full-node": &gpb.GetRequest{},
"../test/proto/req-full-node-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-interface-arista-ceos": &gpb.GetRequest{},
"../test/proto/req-interfaces-wildcard": &gpb.GetRequest{},
"../test/proto/resp-full-node": &gpb.GetResponse{},
"../test/proto/resp-full-node-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-interface-arista-ceos": &gpb.GetResponse{},
"../test/proto/resp-interfaces-wildcard": &gpb.GetResponse{},
"../test/proto/resp-set-system-config-hostname": &gpb.SetResponse{},
}
for k, v := range gnmiMessages {
if err := proto.Read(k, v); err != nil {
log.Fatalf("error parsing %v: %v", k, err)
}
}
opt = &tpb.TransportOption{
Address: testAddress,
Username: testUsername,
Password: testPassword,
}
}
func TestApiIntegration(t *testing.T) {
// TDOO: Remove once openshift grpc support is available
t.Skip("skipped due to openshift limitations")
@@ -110,21 +39,31 @@ func TestApiIntegration(t *testing.T) {
cliPnd := viper.GetString("CLI_PND")
cliSbi := viper.GetString("CLI_SBI")
if _, err := AddDevice(
cliPndUUID, err := uuid.Parse(cliPnd)
clisbiUUID, err := uuid.Parse(cliSbi)
opt := &tpb.TransportOption{
Address: testAddress,
Username: testUsername,
Password: testPassword,
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
}
if _, err := addDevice(
testAPIEndpoint,
testUsername,
testPassword,
cliSbi,
cliPnd,
testAddress,
"test-device",
opt,
clisbiUUID,
cliPndUUID,
); (err != nil) != tt.wantErr {
t.Errorf("gosdn cli add-device error = %v, wantErr %v", err, tt.wantErr)
return
}
did := viper.GetString("LAST_DEVICE_UUID")
_, err := GetDevice(
_, err = getDevice(
testAPIEndpoint,
cliPnd,
testPath,
@@ -135,7 +74,7 @@ func TestApiIntegration(t *testing.T) {
return
}
_, err = GetDevice(
_, err = getDevice(
testAPIEndpoint,
cliPnd,
"",
@@ -147,19 +86,20 @@ func TestApiIntegration(t *testing.T) {
}
hostname := guuid.New().String()
_, err = Update(
_, err = changeRequest(
testAPIEndpoint,
did,
cliPnd,
testPath,
hostname,
pnd.ApiOperation_UPDATE,
)
if (err != nil) != tt.wantErr {
t.Errorf("gosdn cli set error = %v, wantErr %v", err, tt.wantErr)
return
}
resp, err := GetDevice(testAddress, testUsername, testPassword, testPath)
resp, err := getDevice(testAddress, testUsername, testPassword, testPath)
if err != nil {
if !tt.wantErr {
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
Loading