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

linter pleasing

parent 7de2cf06
No related branches found
No related tags found
1 merge request!173Process response overhaul
Pipeline #77034 passed with warnings
......@@ -110,6 +110,7 @@ func (d *CommonDevice) ProcessResponse(resp proto.Message) error {
return d.transport.ProcessResponse(resp, d.GoStruct, d.sbi.Schema())
}
// CsbiDevice is used for the cSBI functionality.
type CsbiDevice struct {
CommonDevice
}
......@@ -119,22 +120,28 @@ func (d *CsbiDevice) ID() uuid.UUID {
return d.UUID
}
// Model returns the ygot representation of the Device
func (d *CsbiDevice) Model() ygot.GoStruct {
return d.GoStruct
}
// Transport returns the Transport of the device
func (d *CsbiDevice) Transport() transport.Transport {
return d.transport
}
// Name returns the name of the device
func (d *CsbiDevice) Name() string {
return d.name
}
// SBI returns the sbi of the Device
func (d *CsbiDevice) SBI() southbound.SouthboundInterface {
return d.sbi
}
// ProcessResponse processes a response for the Device
func (d *CsbiDevice) ProcessResponse(resp proto.Message) error {
// TODO: callback to send response to caller
return d.transport.ProcessResponse(resp, d.GoStruct, d.sbi.Schema())
}
......@@ -66,12 +66,12 @@ func newGnmiTransport(opts *tpb.TransportOption, sbi southbound.SouthboundInterf
"tls": opts.Tls,
}).Info("building new gNMI transport")
return &Gnmi{
SetNode: sbi.SetNode(),
RespChan: make(chan *gpb.SubscribeResponse),
Unmarshal: sbi.Unmarshal(),
Options: opts,
client: c,
config: gnmiConfig,
SetNode: sbi.SetNode,
RespChan: make(chan *gpb.SubscribeResponse),
Unmarshal: sbi.Unmarshal,
Options: opts,
client: c,
config: gnmiConfig,
}, nil
}
......@@ -227,7 +227,7 @@ func (g *Gnmi) Type() string {
// ProcessResponse takes a gNMI response and serializes the contents to the root struct.
func (g *Gnmi) ProcessResponse(resp interface{}, root interface{}, s *ytypes.Schema) error {
models := s.SchemaTree
d, ok := root.(ygot.ValidatedGoStruct)
d, ok := root.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
}
......
......@@ -257,8 +257,8 @@ func TestGnmi_ProcessResponse(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &Gnmi{
SetNode: tt.fields.Sbi.SetNode(),
Unmarshal: tt.fields.Sbi.(*OpenConfig).Unmarshal(),
SetNode: tt.fields.Sbi.SetNode,
Unmarshal: tt.fields.Sbi.(*OpenConfig).Unmarshal,
}
s := tt.fields.Sbi.Schema()
resp := gnmiMessages[tt.args.path]
......
......@@ -414,6 +414,7 @@ func (pnd *pndImplementation) handleCsbiEnrolment(name string, opt *tpb.Transpor
return nil
}
// DeviceDetails contains details of a device used by the cSBI mechanism
type DeviceDetails struct {
ID string
Address string
......
......@@ -62,21 +62,19 @@ func (oc *OpenConfig) Schema() *ytypes.Schema {
// SetNode injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return ytypes.SetNode(schema, root.(*openconfig.Device), path, val, opts...)
}
func (oc *OpenConfig) SetNode(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return ytypes.SetNode(schema, root.(*openconfig.Device), path, val, opts...)
}
// Unmarshal injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
func (oc *OpenConfig) Unmarshal() func([]byte, []string, ygot.ValidatedGoStruct, ...ytypes.UnmarshalOpt) error {
return oc.unmarshal
func (oc *OpenConfig) Unmarshal(bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
return unmarshal(oc.Schema(), bytes, fields, goStruct, opt...)
}
// unmarshal parses gNMI response to a go struct. If it's a root level response
// it uses
func (oc *OpenConfig) unmarshal(bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
func unmarshal(schema *ytypes.Schema, bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
defer func() {
if r := recover(); r != nil {
log.Error(r.(error))
......@@ -88,7 +86,7 @@ func (oc *OpenConfig) unmarshal(bytes []byte, fields []string, goStruct ygot.Val
var c ygot.ValidatedGoStruct
// Load SBI definition
root, err := ygot.DeepCopy(oc.Schema().Root)
root, err := ygot.DeepCopy(schema.Root)
if err != nil {
return err
}
......@@ -106,10 +104,7 @@ func (oc *OpenConfig) unmarshal(bytes []byte, fields []string, goStruct ygot.Val
return err
}
ygot.PruneEmptyBranches(d)
if err := ygot.MergeStructInto(goStruct, d); err != nil {
return err
}
return nil
return ygot.MergeStructInto(goStruct, d)
}
// getField traverses the GoStruct and returns the field that represents the
......@@ -145,26 +140,30 @@ func (oc *OpenConfig) ID() uuid.UUID {
// Type returns the Southbound's type
func (oc *OpenConfig) Type() spb.Type { return spb.Type_OPENCONFIG }
// Csbi is a stub for the containerised SBI functionality.
// It holds the standard goSDN OPENCONFIG schema for minimum
// compatibility
type Csbi struct {
schema *ytypes.Schema
id uuid.UUID
}
// SbiIdentifier returns the identifier as a
func (csbi *Csbi) SbiIdentifier() string {
return "csbi"
}
func (csbi *Csbi) SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return ytypes.SetNode(schema, root.(*openconfig.Device), path, val, opts...)
}
// SetNode injects schema specific model representation to the transport.
// Needed for type assertion.
func (csbi *Csbi) SetNode(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return ytypes.SetNode(schema, root.(*openconfig.Device), path, val, opts...)
}
// Unmarshal injects OpenConfig specific model representation to the transport.
// Unmarshal injects schema specific model representation to the transport.
// Needed for type assertion.
func (csbi *Csbi) Unmarshal() func([]byte, []string, ygot.ValidatedGoStruct, ...ytypes.UnmarshalOpt) error {
func (csbi *Csbi) Unmarshal(bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
oc := OpenConfig{}
return oc.unmarshal
return unmarshal(oc.Schema(), bytes, fields, goStruct, opt...)
}
// Schema is holding the default OpenConfig schema for minimal compatibility
......@@ -178,10 +177,12 @@ func (csbi *Csbi) Schema() *ytypes.Schema {
return schema
}
// ID returns the Southbound's UUID
func (csbi *Csbi) ID() uuid.UUID {
return csbi.id
}
// Type returns the Southbound's type
func (csbi *Csbi) Type() spb.Type {
return spb.Type_CONTAINERISED
}
......@@ -170,9 +170,8 @@ func Test_unmarshal(t *testing.T) {
}
fields := path.ToStrings(resp.Notification[0].Update[0].Path)
bytes := resp.Notification[0].Update[0].Val.GetJsonIetfVal()
sbi := NewSBI(spb.Type_OPENCONFIG)
oc := sbi.(*OpenConfig)
if err := oc.unmarshal(bytes, fields, tt.args.goStruct, tt.args.opt...); err != nil {
oc := NewSBI(spb.Type_OPENCONFIG)
if err := unmarshal(oc.Schema(), bytes, fields, tt.args.goStruct, tt.args.opt...); err != nil {
if !tt.wantErr {
t.Errorf("unmarshal() error = %v, wantErr %v", err, tt.wantErr)
}
......
......@@ -165,6 +165,8 @@ func (s PndStore) GetPND(id uuid.UUID) (networkdomain.NetworkDomain, error) {
return pnd, nil
}
// PendingChannels holds channels used communicate with pending
// cSBI deployments
func (s PndStore) PendingChannels(id uuid.UUID, parseErrors ...error) (chan DeviceDetails, error) {
ch, ok := s.pendingChannels[id]
if !ok {
......@@ -173,10 +175,12 @@ func (s PndStore) PendingChannels(id uuid.UUID, parseErrors ...error) (chan Devi
return ch, nil
}
// AddPendingChannel adds a pending channel to the map
func (s PndStore) AddPendingChannel(id uuid.UUID, ch chan DeviceDetails) {
s.pendingChannels[id] = ch
}
// RemovePendingChannel removes a pending channel from the map
func (s PndStore) RemovePendingChannel(id uuid.UUID) {
delete(s.pendingChannels, id)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment