diff --git a/cli/capabilities.go b/cli/capabilities.go index f1c2d6be0c7b58bb3f77f6ab6474318c3d4c1d3c..9e3518f82b48d0361754e27d2e6d7a9ed879423b 100644 --- a/cli/capabilities.go +++ b/cli/capabilities.go @@ -1,12 +1,13 @@ package cli import ( - spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" - tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "context" "fmt" "strings" + 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/nucleus" gpb "github.com/openconfig/gnmi/proto/gnmi" ) @@ -15,9 +16,9 @@ import ( // and prints the supported models to stdout func Capabilities(a, u, p string) error { opts := &tpb.TransportOption{ - Address: a, - Username: u, - Password: p, + Address: a, + Username: u, + Password: p, } transport, err := nucleus.NewGnmiTransport(opts, nucleus.NewSBI(spb.Type_OPENCONFIG)) if err != nil { diff --git a/cli/grpc.go b/cli/grpc.go index e60cdf25ddd258a57b39025504569ae8fe34d91c..bac5efa61752eef7bbbdda52a5454a9ef1297ae4 100644 --- a/cli/grpc.go +++ b/cli/grpc.go @@ -1,14 +1,15 @@ package cli import ( + "context" + "time" + ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" nbi "code.fbi.h-da.de/cocsn/gosdn/northbound/client" - "context" log "github.com/sirupsen/logrus" "github.com/spf13/viper" - "time" pb "code.fbi.h-da.de/cocsn/api/go/gosdn/core" "google.golang.org/grpc" @@ -36,7 +37,7 @@ func Init(addr string) error { return nil } -func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain,error) { +func GetIds(addr string) ([]*ppb.PrincipalNetworkDomain, error) { ctx := context.Background() resp, err := getAllCore(ctx, addr) if err != nil { @@ -65,7 +66,7 @@ func AddPnd(addr, name, description, sbi string) error { ctx := context.Background() req := &pb.SetRequest{ Timestamp: time.Now().UnixNano(), - Pnd: []*pb.SetPnd{ + Pnd: []*pb.SetPnd{ { Name: name, Description: description, @@ -85,7 +86,7 @@ func AddPnd(addr, name, description, sbi string) error { func GetPnd(addr string, args ...string) (*pb.GetResponse, error) { coreClient, err := nbi.CoreClient(addr, grpcWithInsecure) if err != nil { - return nil,err + return nil, err } ctx := context.Background() req := &pb.GetRequest{ @@ -114,7 +115,7 @@ func GetChanges(addr, pnd string) (*ppb.GetResponse, error) { return client.Get(ctx, req) } -func Commit(addr, pnd string, cuids ...string) (*ppb.SetResponse,error) { +func Commit(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { changes := make([]*ppb.SetChange, len(cuids)) for i, arg := range cuids { changes[i] = &ppb.SetChange{ @@ -125,7 +126,7 @@ func Commit(addr, pnd string, cuids ...string) (*ppb.SetResponse,error) { return commitConfirm(addr, pnd, changes) } -func Confirm(addr, pnd string, cuids ...string) (*ppb.SetResponse,error) { +func Confirm(addr, pnd string, cuids ...string) (*ppb.SetResponse, error) { changes := make([]*ppb.SetChange, len(cuids)) for i, arg := range cuids { changes[i] = &ppb.SetChange{ @@ -136,7 +137,7 @@ func Confirm(addr, pnd string, cuids ...string) (*ppb.SetResponse,error) { return commitConfirm(addr, pnd, changes) } -func commitConfirm(addr, pnd string, changes []*ppb.SetChange) (*ppb.SetResponse,error) { +func commitConfirm(addr, pnd string, changes []*ppb.SetChange) (*ppb.SetResponse, error) { ctx := context.Background() client, err := nbi.PndClient(addr, grpcWithInsecure) if err != nil { @@ -164,11 +165,11 @@ func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName str Sbi: &spb.SouthboundInterface{ Type: spb.Type_OPENCONFIG, }, - DeviceName: deviceName, + DeviceName: deviceName, TransportOption: &tpb.TransportOption{ - Address: addr, - Username: username, - Password: password, + Address: addr, + Username: username, + Password: password, }, }, }, @@ -183,7 +184,7 @@ func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName str return nil } -func GetDevice(addr, pid, path string, did ...string) (*ppb.GetResponse,error) { +func GetDevice(addr, pid, path string, did ...string) (*ppb.GetResponse, error) { pndClient, err := nbi.PndClient(addr, grpcWithInsecure) if err != nil { return nil, err @@ -249,4 +250,4 @@ func sendChangeRequest(addr, pid string, req *ppb.ChangeRequest) (*ppb.SetRespon Pid: pid, } return pndClient.Set(ctx, r) - } +} diff --git a/cli/grpc_test.go b/cli/grpc_test.go index 8a4a76a4ce36695bafe3c191de9e1beebeac7c6a..3e959df945772c2817bdd1009522a075d1c17142 100644 --- a/cli/grpc_test.go +++ b/cli/grpc_test.go @@ -1,19 +1,20 @@ package cli import ( + "context" + "net" + "reflect" + "strconv" + "testing" + "time" + pb "code.fbi.h-da.de/cocsn/api/go/gosdn/core" ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" nbi "code.fbi.h-da.de/cocsn/gosdn/northbound/server" "code.fbi.h-da.de/cocsn/gosdn/nucleus" - "context" log "github.com/sirupsen/logrus" "google.golang.org/grpc" "k8s.io/apimachinery/pkg/util/rand" - "net" - "reflect" - "strconv" - "testing" - "time" ) const unreachable = "203.0.113.10:6030" diff --git a/cmd/getPnd.go b/cmd/getPnd.go index 0c1f0e0f3775c9791a6e19228f896ae5b1711759..e426d051678a51eb31183361c26716f0f8079726 100644 --- a/cmd/getPnd.go +++ b/cmd/getPnd.go @@ -41,7 +41,7 @@ import ( var getCmd = &cobra.Command{ Use: "get", Short: "get one or multiple pnds by uuid or name and print them to stdout", - Long: ``, + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { resp, err := cli.GetPnd(apiEndpoint, args...) if err != nil { diff --git a/cmd/list.go b/cmd/list.go index b650c07afcfb5d0267c70847feaa84c89bcf07a4..ea0a8c13f4e1c1959ba024e486ae22866e83d0c5 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -49,8 +49,8 @@ var listCmd = &cobra.Command{ } for _, change := range resp.Change { log.WithFields(log.Fields{ - "uuid": change.Id, - "age": change.Age, + "uuid": change.Id, + "age": change.Age, "state": change.State, }).Infof("") } diff --git a/controller.go b/controller.go index e057aaf0b02bb5643816aaf5f1e3a337217c5a85..0f5b4085ff4c49fdad703419cdcb262e57ad227b 100644 --- a/controller.go +++ b/controller.go @@ -1,7 +1,6 @@ package gosdn import ( - spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" "context" "net" "net/http" @@ -10,6 +9,8 @@ import ( "sync" "time" + spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" + "github.com/spf13/viper" "google.golang.org/grpc" diff --git a/northbound/server/pnd.go b/northbound/server/pnd.go index c5674f2a5f1f8c512cdcf798ef20913e7e714cfd..00bd6e0b44817f827fb76aa3d4a24ff50acd58ef 100644 --- a/northbound/server/pnd.go +++ b/northbound/server/pnd.go @@ -236,7 +236,6 @@ func (p pnd) Set(ctx context.Context, request *ppb.SetRequest) (*ppb.SetResponse return nil, err } - ondResp, err := handleSetOnd(pnd, request.Ond) if err != nil { return nil, err @@ -289,7 +288,7 @@ func handleSetSbi(pnd nucleus.PrincipalNetworkDomain, req []*ppb.SetSbi) (*ppb.S } func handleSetChange(pnd nucleus.PrincipalNetworkDomain, req []*ppb.SetChange) (*ppb.SetResponse, error) { - for _,r := range req { + for _, r := range req { cuid, err := uuid.Parse(r.Cuid) if err != nil { return nil, err @@ -317,7 +316,7 @@ func handleSetChange(pnd nucleus.PrincipalNetworkDomain, req []*ppb.SetChange) ( } func handleChangeRequest(pnd nucleus.PrincipalNetworkDomain, req []*ppb.ChangeRequest) (*ppb.SetResponse, error) { - for _,r := range req { + for _, r := range req { did, err := uuid.Parse(r.Id) if err != nil { return nil, err diff --git a/nucleus/change.go b/nucleus/change.go index 1e36a8bcfa83ac98dd1e484dc7a29bbb8a6e09f7..231f217046e7a46253287c4e66729c0682b69313 100644 --- a/nucleus/change.go +++ b/nucleus/change.go @@ -1,12 +1,13 @@ package nucleus import ( - ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" "errors" "os" "sync" "time" + ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" + "github.com/google/uuid" "github.com/openconfig/ygot/ygot" log "github.com/sirupsen/logrus" diff --git a/nucleus/device_test.go b/nucleus/device_test.go index 6e3cb98f389f248c6a53e61ef12d0b56a4386b36..ef04e4631ddce19a6c0f9e282d629db040145656 100644 --- a/nucleus/device_test.go +++ b/nucleus/device_test.go @@ -1,10 +1,11 @@ package nucleus import ( - tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "reflect" "testing" + tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" + "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "github.com/google/uuid" "github.com/openconfig/ygot/ygot" @@ -91,7 +92,7 @@ func TestNewDevice(t *testing.T) { Password: "test", }, }, - want: nil, + want: nil, wantErr: true, }, } diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index ec229e8b83556ab410d05916c81c05e6a8c1833b..12d04505ea3da57f25bfb3c518376fe3430a028d 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -1,11 +1,12 @@ package nucleus import ( - ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" "context" - "google.golang.org/grpc" "reflect" + ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" + "google.golang.org/grpc" + "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/nucleus/errors" "code.fbi.h-da.de/cocsn/gosdn/nucleus/types" diff --git a/nucleus/gnmi_transport_test.go b/nucleus/gnmi_transport_test.go index aed87d2496a28495afdf7412cc85f07536ab3060..c32a269c65061a9dfdfc4ccefa329e4fe52d4623 100644 --- a/nucleus/gnmi_transport_test.go +++ b/nucleus/gnmi_transport_test.go @@ -1,13 +1,14 @@ package nucleus import ( - spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" - tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "context" "errors" "reflect" "testing" + 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/mocks" "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" diff --git a/nucleus/initialise_test.go b/nucleus/initialise_test.go index bbfe6cc01c489e9681ecba915aec503618dc7cfe..d62e06d498f3e25fb6f25ca2943825f0f472e46f 100644 --- a/nucleus/initialise_test.go +++ b/nucleus/initialise_test.go @@ -1,11 +1,12 @@ package nucleus import ( - tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "context" "os" "testing" + 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/mocks" "code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto" @@ -84,15 +85,15 @@ func mockTransport() Gnmi { RespChan: make(chan *gpb.SubscribeResponse), Options: newGnmiTransportOptions(), client: &mocks.GNMIClient{}, - config: gnmiConfig, + config: gnmiConfig, } } func newGnmiTransportOptions() *tpb.TransportOption { return &tpb.TransportOption{ - Address: "localhost:13371", - Username: "test", - Password: "test", + Address: "localhost:13371", + Username: "test", + Password: "test", TransportOption: &tpb.TransportOption_GnmiTransportOption{ GnmiTransportOption: &tpb.GnmiTransportOption{}, }, diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index dee39d5289d6da7fd12d1ed0469996dfe217d08f..216be2b78d8241e642cc1e6f7750da0dc711be1d 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -1,11 +1,12 @@ package nucleus import ( + "context" + "reflect" + ppb "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/errors" - "context" - "reflect" "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "github.com/openconfig/ygot/ygot" diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 398679443379709179094a332c562939c568bbb8..8ab5b389d63b58fef06ae37264c6ce9e633b95f7 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -1,13 +1,14 @@ package nucleus import ( - ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" - spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" - tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "errors" "reflect" "testing" + ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" + 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/mocks" "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "github.com/google/uuid" @@ -556,7 +557,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr bool }{ { - name: "update", + name: "update", args: args{ uuid: mdid, operation: ppb.ApiOperation_UPDATE, @@ -566,7 +567,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: false, }, { - name: "replace", + name: "replace", args: args{ uuid: mdid, operation: ppb.ApiOperation_REPLACE, @@ -576,7 +577,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: false, }, { - name: "delete", + name: "delete", args: args{ uuid: mdid, operation: ppb.ApiOperation_DELETE, @@ -585,7 +586,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: false, }, { - name: "delete w/args", + name: "delete w/args", args: args{ uuid: mdid, operation: ppb.ApiOperation_DELETE, @@ -597,7 +598,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { // Negative test cases { - name: "invalid operation", + name: "invalid operation", args: args{ uuid: mdid, operation: 54, @@ -605,7 +606,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: true, }, { - name: "invalid arg count", + name: "invalid arg count", args: args{ uuid: mdid, operation: ppb.ApiOperation_UPDATE, @@ -615,7 +616,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: true, }, { - name: "invalid arg count - update, no args", + name: "invalid arg count - update, no args", args: args{ uuid: mdid, operation: ppb.ApiOperation_UPDATE, @@ -624,7 +625,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: true, }, { - name: "invalid arg count - replace, no args", + name: "invalid arg count - replace, no args", args: args{ uuid: mdid, operation: ppb.ApiOperation_UPDATE, @@ -633,7 +634,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { wantErr: true, }, { - name: "device not found", + name: "device not found", args: args{ uuid: did, operation: ppb.ApiOperation_UPDATE, diff --git a/nucleus/transport.go b/nucleus/transport.go index c0527b31694c07ed4df3fa85a655970c0079e51b..dded3c4b299dcf9e9046b52e9c18c5f52dfe737e 100644 --- a/nucleus/transport.go +++ b/nucleus/transport.go @@ -1,9 +1,10 @@ package nucleus import ( + "context" + tpb "code.fbi.h-da.de/cocsn/api/go/gosdn/transport" "code.fbi.h-da.de/cocsn/gosdn/nucleus/errors" - "context" "github.com/openconfig/ygot/ytypes" )