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

fix tests and linter pleasing

parent 64cce224
No related branches found
No related tags found
1 merge request!174remove sub modules
...@@ -36,6 +36,7 @@ const sbiID = "f6fd4b35-f039-4111-9156-5e4501bb8a5a" ...@@ -36,6 +36,7 @@ const sbiID = "f6fd4b35-f039-4111-9156-5e4501bb8a5a"
const ondID = "7e0ed8cc-ebf5-46fa-9794-741494914883" const ondID = "7e0ed8cc-ebf5-46fa-9794-741494914883"
var pndStore *nucleus.PndStore var pndStore *nucleus.PndStore
var sbiStore *nucleus.SbiStore
var lis *bufconn.Listener var lis *bufconn.Listener
var pndUUID uuid.UUID var pndUUID uuid.UUID
var sbiUUID uuid.UUID var sbiUUID uuid.UUID
...@@ -48,6 +49,7 @@ func bootstrapUnitTest() { ...@@ -48,6 +49,7 @@ func bootstrapUnitTest() {
lis = bufconn.Listen(bufSize) lis = bufconn.Listen(bufSize)
s := grpc.NewServer() s := grpc.NewServer()
pndStore = nucleus.NewPndStore() pndStore = nucleus.NewPndStore()
sbiStore = nucleus.NewSbiStore()
changeUUID, err := uuid.Parse(changeID) changeUUID, err := uuid.Parse(changeID)
if err != nil { if err != nil {
...@@ -83,6 +85,8 @@ func bootstrapUnitTest() { ...@@ -83,6 +85,8 @@ func bootstrapUnitTest() {
}, nil) }, nil)
mockPnd.On("Commit", mock.Anything).Return(nil) mockPnd.On("Commit", mock.Anything).Return(nil)
mockPnd.On("Confirm", mock.Anything).Return(nil) mockPnd.On("Confirm", mock.Anything).Return(nil)
mockPnd.On("Devices").Return([]uuid.UUID{deviceUUID})
mockPnd.On("GetSBIs").Return(sbiStore)
mockPnd.On("ChangeOND", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) mockPnd.On("ChangeOND", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
if err := pndStore.Add(&mockPnd); err != nil { if err := pndStore.Add(&mockPnd); err != nil {
......
...@@ -13,11 +13,15 @@ import ( ...@@ -13,11 +13,15 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// PrincipalNetworkDomainAdapter is an API adapter to reflect the NetworkDomain
// interface
type PrincipalNetworkDomainAdapter struct { type PrincipalNetworkDomainAdapter struct {
id uuid.UUID id uuid.UUID
endpoint string endpoint string
} }
// NewAdapter creates a PND Adapter. It requires a valid PND UUID and a reachable
// goSDN endpoint.
func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) { func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) {
pid, err := uuid.Parse(id) pid, err := uuid.Parse(id)
if err != nil { if err != nil {
...@@ -29,14 +33,17 @@ func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) { ...@@ -29,14 +33,17 @@ func NewAdapter(id, endpoint string) (networkdomain.NetworkDomain, error) {
}, nil }, nil
} }
// Destroy destroys the PND Adapter. Currently not implemented
func (p *PrincipalNetworkDomainAdapter) Destroy() error { func (p *PrincipalNetworkDomainAdapter) Destroy() error {
return &errors.ErrNotYetImplemented{} return &errors.ErrNotYetImplemented{}
} }
// AddSbi adds an SBI to the PND Adapter. Currently not implemented
func (p *PrincipalNetworkDomainAdapter) AddSbi(s southbound.SouthboundInterface) error { func (p *PrincipalNetworkDomainAdapter) AddSbi(s southbound.SouthboundInterface) error {
return &errors.ErrNotYetImplemented{} return &errors.ErrNotYetImplemented{}
} }
// RemoveSbi removes an SBI from the PND Adapter. Currently not implemented
func (p *PrincipalNetworkDomainAdapter) RemoveSbi(uuid.UUID) error { func (p *PrincipalNetworkDomainAdapter) RemoveSbi(uuid.UUID) error {
return &errors.ErrNotYetImplemented{} return &errors.ErrNotYetImplemented{}
} }
...@@ -65,6 +72,7 @@ func (p *PrincipalNetworkDomainAdapter) GetDevice(identifier string) (device.Dev ...@@ -65,6 +72,7 @@ func (p *PrincipalNetworkDomainAdapter) GetDevice(identifier string) (device.Dev
return nil, nil return nil, nil
} }
// RemoveDevice removes a device from the PND Adapter
func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error { func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error {
resp, err := deleteDevice(p.endpoint, p.id.String(), did.String()) resp, err := deleteDevice(p.endpoint, p.id.String(), did.String())
if err != nil { if err != nil {
...@@ -74,10 +82,15 @@ func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error { ...@@ -74,10 +82,15 @@ func (p *PrincipalNetworkDomainAdapter) RemoveDevice(did uuid.UUID) error {
return nil return nil
} }
// Devices sends an API call to the controller requesting the UUIDs of all
// registered devices. Returns nil.
func (p *PrincipalNetworkDomainAdapter) Devices() []uuid.UUID { func (p *PrincipalNetworkDomainAdapter) Devices() []uuid.UUID {
return nil return nil
} }
// ChangeOND sends an API call to the controller requesting the creation of
// a change from the provided Operation, path and value. The Change is marked
// as Pending and times out after the specified timeout period
func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error { func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error {
var v string var v string
if len(value) != 0 { if len(value) != 0 {
...@@ -91,6 +104,8 @@ func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb. ...@@ -91,6 +104,8 @@ func (p *PrincipalNetworkDomainAdapter) ChangeOND(uuid uuid.UUID, operation ppb.
return err return err
} }
// Request sends an API call to the controller requesting the specified path
// for the specified device
func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) error { func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) error {
resp, err := getPath(p.endpoint, p.id.String(), did.String(), path) resp, err := getPath(p.endpoint, p.id.String(), did.String(), path)
if err != nil { if err != nil {
...@@ -100,34 +115,47 @@ func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) erro ...@@ -100,34 +115,47 @@ func (p *PrincipalNetworkDomainAdapter) Request(did uuid.UUID, path string) erro
return nil return nil
} }
// RequestAll sends an API call to the controller requesting the specified path
// for all registered devices. Not yet implemented.
func (p *PrincipalNetworkDomainAdapter) RequestAll(string) error { func (p *PrincipalNetworkDomainAdapter) RequestAll(string) error {
return &errors.ErrNotYetImplemented{} return &errors.ErrNotYetImplemented{}
} }
// GetName returns the PND Adapter's name
func (p *PrincipalNetworkDomainAdapter) GetName() string { func (p *PrincipalNetworkDomainAdapter) GetName() string {
return "" return "PND Adapter"
} }
// GetDescription returns the PND Adapter's description
func (p *PrincipalNetworkDomainAdapter) GetDescription() string { func (p *PrincipalNetworkDomainAdapter) GetDescription() string {
return "" return "PND Adapter"
} }
// MarshalDevice sends an API call to the controller requesting the specified
// device as JSON representation. Not yet implemented
func (p *PrincipalNetworkDomainAdapter) MarshalDevice(string) (string, error) { func (p *PrincipalNetworkDomainAdapter) MarshalDevice(string) (string, error) {
return "", &errors.ErrNotYetImplemented{} return "", &errors.ErrNotYetImplemented{}
} }
// ContainsDevice sends an API call to the controller checking if a device
// with the given UUID is present. Not implemented, always returns false
func (p *PrincipalNetworkDomainAdapter) ContainsDevice(uuid.UUID) bool { func (p *PrincipalNetworkDomainAdapter) ContainsDevice(uuid.UUID) bool {
return false return false
} }
// GetSBIs sends an API call to the controller requesting the
// registered SBIs. Not implemented, always returns nil
func (p *PrincipalNetworkDomainAdapter) GetSBIs() store.Store { func (p *PrincipalNetworkDomainAdapter) GetSBIs() store.Store {
return nil return nil
} }
// ID returns the PND Adapter's UUID
func (p *PrincipalNetworkDomainAdapter) ID() uuid.UUID { func (p *PrincipalNetworkDomainAdapter) ID() uuid.UUID {
return p.id return p.id
} }
// PendingChanges sends an API call to the controller requesting
// the UUIDs of all pending changes
func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID { func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID {
resp, err := getChanges(p.endpoint, p.id.String()) resp, err := getChanges(p.endpoint, p.id.String())
if err != nil { if err != nil {
...@@ -137,6 +165,8 @@ func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID { ...@@ -137,6 +165,8 @@ func (p *PrincipalNetworkDomainAdapter) PendingChanges() []uuid.UUID {
return filterChanges(ppb.Change_PENDING, resp) return filterChanges(ppb.Change_PENDING, resp)
} }
// CommittedChanges sends an API call to the controller requesting
// the UUIDs of all committed changes
func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID { func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID {
resp, err := getChanges(p.endpoint, p.id.String()) resp, err := getChanges(p.endpoint, p.id.String())
if err != nil { if err != nil {
...@@ -146,10 +176,12 @@ func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID { ...@@ -146,10 +176,12 @@ func (p *PrincipalNetworkDomainAdapter) CommittedChanges() []uuid.UUID {
return filterChanges(ppb.Change_COMMITTED, resp) return filterChanges(ppb.Change_COMMITTED, resp)
} }
// GetChange sends an API call to the controller requesting the specified change
func (p *PrincipalNetworkDomainAdapter) GetChange(uuid.UUID, ...int) (change.Change, error) { func (p *PrincipalNetworkDomainAdapter) GetChange(uuid.UUID, ...int) (change.Change, error) {
return nil, &errors.ErrNotYetImplemented{} return nil, &errors.ErrNotYetImplemented{}
} }
// Commit sends an API call to the controller committing the specified change
func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error { func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error {
resp, err := commit(p.endpoint, p.id.String(), cuid.String()) resp, err := commit(p.endpoint, p.id.String(), cuid.String())
if err != nil { if err != nil {
...@@ -159,6 +191,7 @@ func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error { ...@@ -159,6 +191,7 @@ func (p *PrincipalNetworkDomainAdapter) Commit(cuid uuid.UUID) error {
return nil return nil
} }
// Confirm sends an API call to the controller confirming the specified change
func (p *PrincipalNetworkDomainAdapter) Confirm(cuid uuid.UUID) error { func (p *PrincipalNetworkDomainAdapter) Confirm(cuid uuid.UUID) error {
resp, err := confirm(p.endpoint, p.id.String(), cuid.String()) resp, err := confirm(p.endpoint, p.id.String(), cuid.String())
if err != nil { if err != nil {
......
...@@ -321,7 +321,8 @@ func (pnd *pndImplementation) RequestAll(path string) error { ...@@ -321,7 +321,8 @@ func (pnd *pndImplementation) RequestAll(path string) error {
return nil return nil
} }
// ChangeOND creates a change from the provided Operation, path and value. The Change is Pending and // ChangeOND creates a change from the provided Operation, path and value.
// The Change is Pending and times out after the specified timeout period
func (pnd *pndImplementation) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error { func (pnd *pndImplementation) ChangeOND(uuid uuid.UUID, operation ppb.ApiOperation, path string, value ...string) error {
d, err := pnd.devices.GetDevice(uuid) d, err := pnd.devices.GetDevice(uuid)
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment