Newer
Older
mnepb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/networkelement"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
"code.fbi.h-da.de/danet/gosdn/controller/mocks"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus"
"code.fbi.h-da.de/danet/gosdn/models/generated/openconfig"
Malte Bauch
committed
"github.com/openconfig/gnmi/proto/gnmi"
// TODO(PND): this whole file needs to be reworked!
func getTestPndServer(t *testing.T) *PndServer {
var err error
pndUUID, err = uuid.Parse(pndID)
if err != nil {
sbiUUID, err = uuid.Parse(sbiID)
if err != nil {
pendingChangeUUID, err = uuid.Parse(pendingChangeID)
if err != nil {
}
committedChangeUUID, err = uuid.Parse(committedChangeID)
if err != nil {
mneUUID, err = uuid.Parse(mneID)
mockNetworkElement = &nucleus.CommonNetworkElement{
System: &openconfig.OpenconfigSystem_System{
Config: &openconfig.OpenconfigSystem_System_Config{
Malte Bauch
committed
Hostname: &hostname,
DomainName: &domainname,
UUID: mneUUID,
sbi, err := nucleus.NewSBI(spb.Type_TYPE_OPENCONFIG, sbiUUID)
mockNetworkElement.(*nucleus.CommonNetworkElement).SetSBI(sbi)
mockNetworkElement.(*nucleus.CommonNetworkElement).SetTransport(&mocks.Transport{})
mockNetworkElement.(*nucleus.CommonNetworkElement).SetName(hostname)
Fabian Seidl
committed
sbiStore = nucleus.NewSbiStore()
if err := sbiStore.Add(mockNetworkElement.SBI()); err != nil {
mockChange := &mocks.Change{}
mockChange.On("Age").Return(time.Hour)
mockChange.On("State").Return(mnepb.ChangeState_CHANGE_STATE_INCONSISTENT)
mockPnd.On("ID").Return(pndUUID)
mockPnd.On("GetName").Return("test")
mockPnd.On("GetDescription").Return("test")
mockPnd.On("GetSBIs").Return(sbiStore)
mockPnd.On("GetSBI", mock.Anything).Return(mockNetworkElement.SBI(), nil)
mockPnd.On("NetworkElements").Return([]uuid.UUID{mneUUID})
mockPnd.On("PendingChanges").Return([]uuid.UUID{pendingChangeUUID})
mockPnd.On("CommittedChanges").Return([]uuid.UUID{committedChangeUUID})
mockPnd.On("GetChange", mock.Anything).Return(mockChange, nil)
mockPnd.On("AddNetworkElement", mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockPnd.On("GetNetworkElement", mock.Anything).Return(mockNetworkElement, nil)
mockPnd.On("Commit", mock.Anything).Return(nil)
mockPnd.On("Confirm", mock.Anything).Return(nil)
mockPnd.On("ChangeMNE", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uuid.Nil, nil)
mockPnd.On("Request", mock.Anything, mock.Anything).Return(&gnmi.GetResponse{}, nil)
pndStore := nucleus.NewMemoryPndStore()
if err := pndStore.Add(mockPnd); err != nil {
t.Fatal(err)
pndService := nucleus.NewPndService(pndStore)
eventService := eventservice.NewMockEventService()
sbiService := nucleus.NewSbiService(sbiStore, eventService)
c := NewPndServer(pndService, sbiService)
// TODO: This test case does not make sense; needs to be adjusted.
Malte Bauch
committed
func Test_pnd_GetPath(t *testing.T) {
initUUIDs(t)
//opts := cmp.Options{
// cmpopts.SortSlices(
// func(x, y *gnmi.Update) bool {
// return x.GetVal().String() < y.GetVal().String()
// },
// ),
// cmp.Comparer(proto.Equal),
//}
Malte Bauch
committed
Malte Bauch
committed
type args struct {
ctx context.Context
request *mnepb.GetPathRequest
Malte Bauch
committed
}
tests := []struct {
name string
args args
want []*gnmi.Notification
wantErr bool
}{
{
name: "get path: system/config/hostname",
args: args{
ctx: context.Background(),
request: &mnepb.GetPathRequest{
Malte Bauch
committed
Timestamp: time.Now().UnixNano(),
Mneid: mneUUID.String(),
Malte Bauch
committed
Path: "system/config/hostname",
Pid: pndUUID.String(),
Malte Bauch
committed
},
},
want: []*gnmi.Notification{
{
Update: []*gnmi.Update{
{
Malte Bauch
committed
Path: &gnmi.Path{
Elem: []*gnmi.PathElem{
{
Name: "system",
},
{
Name: "config",
},
{
Name: "hostname",
},
},
},
Malte Bauch
committed
Val: &gnmi.TypedValue{
Value: &gnmi.TypedValue_StringVal{
StringVal: "manfred",
},
},
},
}},
},
wantErr: false,
},
{
name: "get path: system",
args: args{
ctx: context.Background(),
request: &mnepb.GetPathRequest{
Malte Bauch
committed
Timestamp: time.Now().UnixNano(),
Mneid: mneUUID.String(),
Malte Bauch
committed
Path: "system",
Pid: pndUUID.String(),
Malte Bauch
committed
},
},
want: []*gnmi.Notification{
{
Update: []*gnmi.Update{
{
Malte Bauch
committed
Path: &gnmi.Path{
Elem: []*gnmi.PathElem{
{
Name: "system",
},
Malte Bauch
committed
},
},
Val: &gnmi.TypedValue{
Malte Bauch
committed
Value: &gnmi.TypedValue_JsonIetfVal{
JsonIetfVal: []byte("{\n \"openconfig-system:config\": {\n \"domain-name\": \"uwe\",\n \"hostname\": \"manfred\"\n }\n}"),
Malte Bauch
committed
},
},
},
}},
},
wantErr: false,
},
//{
// name: "get path: this/path/is/not/valid",
// args: args{
// ctx: context.Background(),
// request: &ppb.GetPathRequest{
// Timestamp: time.Now().UnixNano(),
// Mneid: mneUUID.String(),
// Path: "this/path/is/not/valid",
// Pid: pndUUID.String(),
// },
// },
// want: []*gnmi.Notification{},
// wantErr: true,
//},
Malte Bauch
committed
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// s := getTestPndServer(t)
// _, err := s.GetPath(tt.args.ctx, tt.args.request)
// if (err != nil) != tt.wantErr {
// t.Errorf("GetPath() error = %v, wantErr %v", err, tt.wantErr)
// return
// }
Malte Bauch
committed
Malte Bauch
committed
//for i, n := range got {
// if diff := cmp.Diff(n.GetUpdate(), tt.want[i].GetUpdate(), opts...); diff != "" {
// t.Errorf("GetPath() diff in the received notification %d: \n%s", i+1, diff)
// }
//}
Malte Bauch
committed
})
}
}
// type args struct {
// ctx context.Context
// request *ppb.SetRequest
// }
// tests := []struct {
// name string
// args args
// want ppb.SetResponseStatus
// wantErr bool
// }{
// {
// name: "set mne",
// args: args{
// ctx: context.Background(),
// request: &ppb.SetRequest{
// Mne: []*ppb.SetMne{
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// {
// Sbi: &spb.SouthboundInterface{
// Id: sbiID,
// Type: spb.Type_TYPE_OPENCONFIG,
// },
// DeviceName: hostname,
// TransportOption: &transport.TransportOption{
// Address: "test",
// Username: "test",
// Password: "test",
// TransportOption: &transport.TransportOption_GnmiTransportOption{
// GnmiTransportOption: &transport.GnmiTransportOption{},
// },
// },
// },
// },
// Pid: pndID,
// },
// },
// want: ppb.SetResponse_OK,
// },
// // {
// // name: "set change",
// // args: args{
// // ctx: context.Background(),
// // request: &ppb.SetRequest{
// // Pid: pndID,
// // Change: []*ppb.SetChange{
// // {
// // Cuid: pendingChangeID,
// // Op: ppb.SetChange_COMMIT,
// // },
// // {
// // Cuid: committedChangeID,
// // Op: ppb.SetChange_CONFIRM,
// // },
// // },
// // },
// // },
// // want: ppb.SetResponse_OK,
// // },
// // {
// // name: "change request",
// // args: args{
// // ctx: context.Background(),
// // request: &ppb.SetRequest{
// // Pid: pndID,
// // ChangeRequest: []*ppb.ChangeRequest{
// // {
// // Id: mneID,
// // Path: "/system/config/hostname",
// // Value: "herbert",
// // ApiOp: ppb.ApiOperation_UPDATE,
// // },
// // {
// // Id: mneID,
// // Path: "/system/config/hostname",
// // Value: "fridolin",
// // ApiOp: ppb.ApiOperation_REPLACE,
// // },
// // {
// // Id: mneID,
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// // Path: "/system/config/hostname",
// // ApiOp: ppb.ApiOperation_DELETE,
// // },
// // },
// // },
// // },
// // want: ppb.SetResponse_OK,
// // },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// p := pndServer{
// UnimplementedPndServiceServer: ppb.UnimplementedPndServiceServer{},
// }
// resp, err := p.Set(tt.args.ctx, tt.args.request)
// if (err != nil) != tt.wantErr {
// t.Errorf("Set() error = %v, wantErr %v", err, tt.wantErr)
// return
// }
// got := resp.Status
// if !reflect.DeepEqual(got, tt.want) {
// t.Errorf("Set() got = %v, want %v", got, tt.want)
// }
// for _, r := range resp.Responses {
// got = r.Status
// if !reflect.DeepEqual(got, tt.want) {
// t.Errorf("Set() got = %v, want %v", got, tt.want)
// }
// }
// })
// }