Skip to content
Snippets Groups Projects
Commit b1d2bf80 authored by Malte Bauch's avatar Malte Bauch
Browse files

Merge branch 'develop' into...

Merge branch 'develop' into 148-specific-paths-cant-be-requested-because-the-underlying-device-gostruct-can-t-be-filled-gnmic
parents 2e0e3919 e36a276c
No related branches found
No related tags found
1 merge request!213Resolve "Specific paths cant be requested, because the underlying device goStruct can't be filled."
Pipeline #89671 passed
......@@ -63,6 +63,7 @@ func Test_core_Get(t *testing.T) {
name string
args args
want []string
length int
wantErr bool
}{
{
......@@ -70,15 +71,28 @@ func Test_core_Get(t *testing.T) {
args: args{
ctx: context.Background(),
request: &pb.GetRequest{
All: true,
Pid: []string{
pndID,
},
},
},
length: 1,
want: []string{
pndID,
"test",
"test",
},
},
{
name: "getAll",
args: args{
ctx: context.Background(),
request: &pb.GetRequest{
All: true,
},
},
length: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
......@@ -91,13 +105,19 @@ func Test_core_Get(t *testing.T) {
return
}
got := []string{
resp.Pnd[0].Id,
resp.Pnd[0].Name,
resp.Pnd[0].Description,
if tt.name == "default" {
got := []string{
resp.Pnd[0].Id,
resp.Pnd[0].Name,
resp.Pnd[0].Description,
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("core.Get() = %v, want %v", got, tt.want)
}
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("core.Get() = %v, want %v", got, tt.want)
length := len(resp.Pnd)
if tt.length != length {
t.Errorf("core.Get() = %v, want %v", length, tt.length)
}
})
}
......
......@@ -15,48 +15,15 @@ import (
)
// NewDevice creates a Device
func NewDevice(name string, opt *tpb.TransportOption, sbi southbound.SouthboundInterface) (device.Device, error) {
func NewDevice(name string, uuidInput uuid.UUID, opt *tpb.TransportOption, sbi southbound.SouthboundInterface) (device.Device, error) {
t, err := NewTransport(opt, sbi)
if err != nil {
return nil, err
}
if name == "" {
name = namesgenerator.GetRandomName(0)
}
root, err := ygot.DeepCopy(sbi.Schema().Root)
if err != nil {
return nil, err
}
if opt.Type == spb.Type_CONTAINERISED {
return &CsbiDevice{
CommonDevice: CommonDevice{
UUID: uuid.New(),
GoStruct: root,
sbi: sbi,
transport: t,
name: name,
transportOptions: opt,
},
}, nil
}
return &CommonDevice{
UUID: uuid.New(),
GoStruct: root,
sbi: sbi,
transport: t,
name: name,
transportOptions: opt,
}, nil
}
// NewDeviceWithUUID creates a Device with a provided UUID
func NewDeviceWithUUID(name string, uuid uuid.UUID, opt *tpb.TransportOption, sbi southbound.SouthboundInterface) (device.Device, error) {
t, err := NewTransport(opt, sbi)
if err != nil {
return nil, err
// TODO: this needs to check the case that the uuidInput is set, as the same uuid may be already stored.
if uuidInput == uuid.Nil {
uuidInput = uuid.New()
}
if name == "" {
......@@ -70,7 +37,7 @@ func NewDeviceWithUUID(name string, uuid uuid.UUID, opt *tpb.TransportOption, sb
if opt.Type == spb.Type_CONTAINERISED {
return &CsbiDevice{
CommonDevice: CommonDevice{
UUID: uuid,
UUID: uuidInput,
GoStruct: root,
sbi: sbi,
transport: t,
......@@ -81,7 +48,7 @@ func NewDeviceWithUUID(name string, uuid uuid.UUID, opt *tpb.TransportOption, sb
}
return &CommonDevice{
UUID: uuid,
UUID: uuidInput,
GoStruct: root,
sbi: sbi,
transport: t,
......
......@@ -99,7 +99,7 @@ func TestNewDevice(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp, err := NewDevice(tt.args.name, tt.args.opts, tt.args.sbi)
resp, err := NewDevice(tt.args.name, uuid.Nil, tt.args.opts, tt.args.sbi)
if (err != nil) != tt.wantErr {
t.Errorf("NewDevice() error = %v, wantErr %v", err, tt.wantErr)
return
......
......@@ -173,7 +173,7 @@ func (pnd *pndImplementation) AddDevice(name string, opt *tpb.TransportOption, s
}
}
d, err := NewDevice(name, opt, sbi)
d, err := NewDevice(name, uuid.Nil, opt, sbi)
if err != nil {
return err
}
......@@ -191,7 +191,7 @@ func (pnd *pndImplementation) AddDeviceFromStore(name string, deviceUUID uuid.UU
return err
}
d, err := NewDeviceWithUUID(name, deviceUUID, opt, sbi)
d, err := NewDevice(name, deviceUUID, opt, sbi)
if err != nil {
return err
}
......@@ -444,7 +444,7 @@ func (pnd *pndImplementation) createCsbiDevice(ctx context.Context, name string,
TransportOption: opt.TransportOption,
}
log.WithField("transport option", csbiTransportOptions).Debug("gosdn gnmi transport options")
d, err := NewDevice(name, csbiTransportOptions, csbi)
d, err := NewDevice(name, uuid.Nil, csbiTransportOptions, csbi)
if err != nil {
panic(err)
}
......
......@@ -676,7 +676,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) {
func Test_pndImplementation_GetDevice(t *testing.T) {
pnd := newPnd()
sbi := NewSBI(spb.Type_OPENCONFIG)
d, err := NewDevice("", newGnmiTransportOptions(), sbi)
d, err := NewDevice("", uuid.Nil, newGnmiTransportOptions(), sbi)
if err != nil {
t.Error(err)
return
......@@ -726,7 +726,7 @@ func Test_pndImplementation_GetDevice(t *testing.T) {
func Test_pndImplementation_GetDeviceByName(t *testing.T) {
p := newPnd()
sbi := NewSBI(spb.Type_OPENCONFIG)
d, err := NewDevice("my-device", newGnmiTransportOptions(), sbi)
d, err := NewDevice("my-device", uuid.Nil, newGnmiTransportOptions(), sbi)
if err != nil {
t.Error(err)
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment