diff --git a/cli/grpc.go b/cli/grpc.go index 7962269f749d5bd1f64cda1378e00b0a7b3a267b..efe7c20d3c54c5f5e8dedec2b068a496a80ec2cd 100644 --- a/cli/grpc.go +++ b/cli/grpc.go @@ -168,7 +168,7 @@ func commitConfirm(addr, pnd string, changes []*ppb.SetChange) (*ppb.SetResponse // AddDevice adds a new device to the controller. The device name is optional. // If no name is provided a name will be generated upon device creation. -func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName string) error { +func AddDevice(addr, username, password, pnd, deviceAddress, deviceName string, sbi spb.Type) error { pndClient, err := nbi.PndClient(addr, grpcWithInsecure) if err != nil { return err @@ -180,7 +180,7 @@ func AddDevice(addr, username, password, sbi, pnd, deviceAddress, deviceName str { Address: deviceAddress, Sbi: &spb.SouthboundInterface{ - Type: spb.Type_OPENCONFIG, + Type: sbi, }, DeviceName: deviceName, TransportOption: &tpb.TransportOption{ diff --git a/cli/grpc_test.go b/cli/grpc_test.go index 3e959df945772c2817bdd1009522a075d1c17142..2faf56cb4f023d027dba02e6ed9db6b11bbf63ad 100644 --- a/cli/grpc_test.go +++ b/cli/grpc_test.go @@ -10,8 +10,10 @@ import ( pb "code.fbi.h-da.de/cocsn/api/go/gosdn/core" ppb "code.fbi.h-da.de/cocsn/api/go/gosdn/pnd" + spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" nbi "code.fbi.h-da.de/cocsn/gosdn/northbound/server" "code.fbi.h-da.de/cocsn/gosdn/nucleus" + "github.com/google/uuid" log "github.com/sirupsen/logrus" "google.golang.org/grpc" "k8s.io/apimachinery/pkg/util/rand" @@ -29,6 +31,17 @@ func startGrpcServer() (*grpc.Server, string, error) { port := rand.IntnRange(1025, 65536) sock := "localhost:" + strconv.Itoa(port) pndc := nucleus.NewPndStore() + pid, err := uuid.Parse(testPid) + if err != nil { + return nil, "", err + } + pnd, err := nucleus.NewPND("testpnd", "test pnd", pid, nil) + if err != nil { + return nil, "", err + } + if err := pndc.Add(pnd); err != nil { + return nil, "", err + } lis, err := net.Listen("tcp", sock) if err != nil { return nil, "", err @@ -47,10 +60,10 @@ func TestAddDevice(t *testing.T) { type args struct { username string password string - sbi string pnd string deviceName string deviceAddress string + sbi spb.Type } tests := []struct { name string @@ -60,11 +73,11 @@ func TestAddDevice(t *testing.T) { { name: "default", args: args{ - username: testUser, - password: testPassword, - sbi: "openconfig", - pnd: testPid, - deviceAddress: "", + username: testUser, + password: testPassword, + pnd: testPid, + deviceName: "testDevice", + sbi: spb.Type_OPENCONFIG, }, wantErr: false, }, @@ -86,10 +99,10 @@ func TestAddDevice(t *testing.T) { sock, tt.args.username, tt.args.password, - tt.args.sbi, tt.args.pnd, tt.args.deviceName, tt.args.deviceAddress, + tt.args.sbi, ); (err != nil) != tt.wantErr { t.Errorf("AddDevice() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/cmd/addDevice.go b/cmd/addDevice.go index 8b905f44a950e9209b574ae435f1eb6354e3f555..b35a2654a958f0edef80ba5eee7b48c63e49c8e0 100644 --- a/cmd/addDevice.go +++ b/cmd/addDevice.go @@ -32,6 +32,8 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( + spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound" + "code.fbi.h-da.de/cocsn/gosdn/cli" "github.com/spf13/cobra" ) @@ -50,9 +52,9 @@ if they diverge from the default credentials.`, username, password, cliPnd, - cliSbi, address, deviceName, + spb.Type_OPENCONFIG, ) }, } diff --git a/nucleus/gnmi_transport_test.go b/nucleus/gnmi_transport_test.go index e7fa677b5aae2a04ec83c399e778df1936c9cdb7..d4d89bd10b886ca4481c02dc75256dca1ab01a35 100644 --- a/nucleus/gnmi_transport_test.go +++ b/nucleus/gnmi_transport_test.go @@ -102,7 +102,6 @@ func TestGnmi_Close(t *testing.T) { type fields struct { SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error RespChan chan *gpb.SubscribeResponse - config *gnmi.Config } tests := []struct { name string @@ -273,8 +272,7 @@ func TestGnmi_Set(t *testing.T) { transport *Gnmi } type args struct { - params []interface{} - runEndpoint bool + params []interface{} } tests := []struct { name string @@ -306,7 +304,6 @@ func TestGnmi_Subscribe(t *testing.T) { type fields struct { SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error RespChan chan *gpb.SubscribeResponse - config *gnmi.Config } type args struct { ctx context.Context @@ -334,7 +331,6 @@ func TestGnmi_Type(t *testing.T) { type fields struct { SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error RespChan chan *gpb.SubscribeResponse - config *gnmi.Config } tests := []struct { name string diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 242ce6fad41ca4c84cf21ad1e599d4ad785a2a52..d4ad28e5a6c3a853971397e28cac736175a5fce6 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -546,7 +546,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { }, } type args struct { - uuid uuid.UUID operation ppb.ApiOperation path string value []string @@ -559,7 +558,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "update", args: args{ - uuid: mdid, operation: ppb.ApiOperation_UPDATE, path: "/system/config/hostname", value: []string{"ceos3000"}, @@ -569,7 +567,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "replace", args: args{ - uuid: mdid, operation: ppb.ApiOperation_REPLACE, path: "/system/config/hostname", value: []string{"ceos3000"}, @@ -579,7 +576,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "delete", args: args{ - uuid: mdid, operation: ppb.ApiOperation_DELETE, path: "/system/config/hostname", }, @@ -588,7 +584,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "delete w/args", args: args{ - uuid: mdid, operation: ppb.ApiOperation_DELETE, path: "/system/config/hostname", value: []string{"ceos3000"}, @@ -600,7 +595,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "invalid operation", args: args{ - uuid: mdid, operation: 54, }, wantErr: true, @@ -608,7 +602,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "invalid arg count", args: args{ - uuid: mdid, operation: ppb.ApiOperation_UPDATE, path: "/system/config/hostname", value: []string{"ceos3000", "ceos3001"}, @@ -618,7 +611,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "invalid arg count - update, no args", args: args{ - uuid: mdid, operation: ppb.ApiOperation_UPDATE, path: "/system/config/hostname", }, @@ -627,7 +619,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "invalid arg count - replace, no args", args: args{ - uuid: mdid, operation: ppb.ApiOperation_UPDATE, path: "/system/config/hostname", }, @@ -636,7 +627,6 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { { name: "device not found", args: args{ - uuid: did, operation: ppb.ApiOperation_UPDATE, }, wantErr: true, @@ -648,11 +638,19 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { if err := pnd.addSbi(&OpenConfig{id: defaultSbiID}); err != nil { t.Error(err) } - if err := pnd.AddDevice("", opts, defaultSbiID); err != nil { + if err := pnd.AddDevice("testdevice", opts, defaultSbiID); err != nil { t.Error(err) return } - if err := pnd.ChangeOND(tt.args.uuid, tt.args.operation, tt.args.path, tt.args.value...); (err != nil) != tt.wantErr { + + did, ok := pnd.devices.deviceNameToUUIDLookup["testdevice"] + if !ok { + err := errors.New("error fetching device") + t.Error(err) + return + } + + if err := pnd.ChangeOND(did, tt.args.operation, tt.args.path, tt.args.value...); (err != nil) != tt.wantErr { t.Errorf("ChangeOND() error = %v, wantErr %v", err, tt.wantErr) return }