Skip to content
Snippets Groups Projects
Commit 41744be8 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

merge develop into branch

parent 21f56a47
Branches
Tags
2 merge requests!116Resolve "Transport Tests",!90Develop
Pipeline #65983 passed with warnings
......@@ -29,7 +29,10 @@ func main() {
if err != nil {
log.Debug(err)
}
pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi)
pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi)
if err != nil {
log.Fatal(err)
}
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
......@@ -46,7 +49,7 @@ func main() {
HeartbeatInterval: uint64(time.Second.Nanoseconds()),
Paths: gnmi.SplitPaths(paths),
Origin: "",
Target: device.Transport.GetOptions().GetAddress(),
Target: "portainer.danet.fbi.h-da.de:6030",
}
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGILL, syscall.SIGTERM)
......
......@@ -45,6 +45,22 @@ func (_m *Transport) Get(ctx context.Context, params ...string) (interface{}, er
return r0, r1
}
// GetOptions provides a mock function with given fields:
func (_m *Transport) GetOptions() interface{} {
ret := _m.Called()
var r0 interface{}
if rf, ok := ret.Get(0).(func() interface{}); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(interface{})
}
}
return r0
}
// ProcessResponse provides a mock function with given fields: resp, root, models
func (_m *Transport) ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error {
ret := _m.Called(resp, root, models)
......
// Code generated by mockery v2.6.0. DO NOT EDIT.
package mocks
import mock "github.com/stretchr/testify/mock"
// TransportOptions is an autogenerated mock type for the TransportOptions type
type TransportOptions struct {
mock.Mock
}
// GetAddress provides a mock function with given fields:
func (_m *TransportOptions) GetAddress() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// GetPassword provides a mock function with given fields:
func (_m *TransportOptions) GetPassword() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// GetUsername provides a mock function with given fields:
func (_m *TransportOptions) GetUsername() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// IsTransportOption provides a mock function with given fields:
func (_m *TransportOptions) IsTransportOption() {
_m.Called()
}
......@@ -181,9 +181,10 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs
}
tmpDevice := pb.Device{
Uuid: uuidDevice.String(),
Address: device.Transport.GetOptions().GetAddress(),
Username: device.Transport.GetOptions().GetUsername(),
Password: device.Transport.GetOptions().GetPassword()}
Address: device.Transport.GetOptions().(TransportOptions).GetAddress(),
Username: device.Transport.GetOptions().(TransportOptions).GetUsername(),
Password: device.Transport.GetOptions().(TransportOptions).GetPassword(),
}
devices = append(devices, &tmpDevice)
}
sbi, err := s.core.sbic.get(pnd.GetSBIs().(*sbiStore).UUIDs()[0])
......
......@@ -24,9 +24,13 @@ type Device struct {
//NewDevice creates a Device
func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*Device, error) {
var transport Transport
var err error
switch ttype {
case "gnmi":
transport = NewGnmiTransport(opts.(*GnmiTransportOptions))
transport, err = NewGnmiTransport(opts.(*GnmiTransportOptions))
if err != nil {
return nil, err
}
case "restconf":
//TODO: implement restconf -> NewRestConfTransport(opts)
default:
......@@ -42,5 +46,5 @@ func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*D
}
func (d *Device) Id() uuid.UUID {
return d.Config.Uuid
return d.Uuid
}
......@@ -23,19 +23,6 @@ func init() {
tapProto = false
}
func NewGnmiTransport(config *gnmi.Config) (*Gnmi, error) {
c, err := gnmi.Dial(config)
if err != nil {
return nil, err
}
return &Gnmi{
SetNode: nil,
RespChan: nil,
config: config,
client: c,
}, nil
}
type Gnmi struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse
......@@ -44,15 +31,19 @@ type Gnmi struct {
client gpb.GNMIClient
}
func NewGnmiTransport(opts *GnmiTransportOptions) *Gnmi {
ngt := &Gnmi{
func NewGnmiTransport(opts *GnmiTransportOptions) (*Gnmi, error) {
config := createConfig(opts)
c, err := gnmi.Dial(config)
if err != nil {
return nil, err
}
return &Gnmi{
SetNode: opts.SetNode,
RespChan: opts.RespChan,
Options: opts,
}
config := ngt.CreateConfig(opts)
ngt.SetConfig(config)
return ngt
config: config,
client: c,
}, nil
}
//SetConfig sets the config of gnmi
......@@ -71,12 +62,12 @@ func (g *Gnmi) SetOptions(to TransportOptions) {
}
//GetConfig returns the gnmi config
func (g *Gnmi) GetOptions() TransportOptions {
func (g *Gnmi) GetOptions() interface{} {
return g.Options
}
//CreateConfig creates a new gnmi config based on the given parameters
func (g *Gnmi) CreateConfig(opts *GnmiTransportOptions) *gnmi.Config {
func createConfig(opts *GnmiTransportOptions) *gnmi.Config {
return &gnmi.Config{
Addr: opts.Addr,
Username: opts.Username,
......
......@@ -36,14 +36,8 @@ func testSetupPnd() {
func mockDevice() Device {
return Device{
GoStruct: nil,
SBI: &OpenConfig{},
Config: DeviceConfig{
Uuid: mdid,
Address: "mock://localhost",
Username: "mock",
Password: "mock",
},
GoStruct: nil,
SBI: &OpenConfig{},
Transport: &mocks.Transport{},
}
}
......@@ -184,9 +178,7 @@ func Test_pndImplementation_AddDevice(t *testing.T) {
{
name: "default",
args: args{device: &Device{
Config: DeviceConfig{
Uuid: did,
},
Uuid: did,
}},
wantErr: false,
},
......@@ -258,15 +250,15 @@ func Test_pndImplementation_ContainsDevice(t *testing.T) {
}{
{name: "default", args: args{
uuid: did,
device: &Device{Config: DeviceConfig{Uuid: did}},
device: &Device{Uuid: did},
}, want: true},
{name: "fails", args: args{
uuid: uuid.New(),
device: &Device{Config: DeviceConfig{Uuid: did}},
device: &Device{Uuid: did},
}, want: false},
{name: "fails empty", args: args{
uuid: uuid.New(),
device: &Device{Config: DeviceConfig{Uuid: did}},
device: &Device{Uuid: did},
}, want: false},
}
for _, tt := range tests {
......@@ -383,14 +375,8 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
pnd := newPnd()
d := &Device{
GoStruct: &openconfig.Device{},
SBI: nil,
Config: DeviceConfig{
Uuid: tt.args.uuid,
Address: "localhost",
Username: "test",
Password: "test",
},
GoStruct: &openconfig.Device{},
SBI: nil,
Transport: nil,
}
if err := pnd.addDevice(d); err != nil {
......@@ -428,7 +414,7 @@ func Test_pndImplementation_RemoveDevice(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
pnd := newPnd()
if tt.name != "fails empty" {
d := &Device{Config: DeviceConfig{Uuid: did}}
d := &Device{Uuid: did}
if err := pnd.addDevice(d); err != nil {
t.Error(err)
}
......
......@@ -276,9 +276,7 @@ func Test_sbiStore_get(t *testing.T) {
fields: fields{
store: store{
did: &Device{
Config: DeviceConfig{
Uuid: did,
},
Uuid: did,
},
},
},
......@@ -351,9 +349,7 @@ func Test_pndStore_get(t *testing.T) {
fields: fields{
store: store{
did: &Device{
Config: DeviceConfig{
Uuid: did,
},
Uuid: did,
},
},
},
......@@ -396,12 +392,10 @@ func Test_deviceStore_get(t *testing.T) {
name: "exists",
fields: fields{
store: store{
defaultPndId: &Device{Config: DeviceConfig{Uuid: did}}}},
defaultPndId: &Device{Uuid: did}}},
args: args{id: defaultPndId},
want: &Device{
Config: DeviceConfig{
Uuid: did,
},
Uuid: did,
},
wantErr: false,
},
......@@ -409,7 +403,7 @@ func Test_deviceStore_get(t *testing.T) {
name: "fails",
fields: fields{
store: store{
defaultPndId: &Device{Config: DeviceConfig{Uuid: did}}}},
defaultPndId: &Device{Uuid: did}}},
args: args{id: iid},
wantErr: true,
},
......
......@@ -15,7 +15,7 @@ type Transport interface {
Set(ctx context.Context, params ...string) (interface{}, error)
Subscribe(ctx context.Context, params ...string) error
Type() string
GetOptions() TransportOptions
GetOptions() interface{}
ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment