Skip to content

Commit

Permalink
Migrating away from onos-topo/api/device API to onos-api/go/onos/topo…
Browse files Browse the repository at this point in the history
… API (v2) (#1245)

* Added device/device.go as a shim entity

* Starting to use the shim

* Listers all pass; tests still fail

* Checkpoint...

* Just two test failures remaining

* Fixed store to reflect new Atomix error returns

* Fixed filter mock to depend on device.go shim

* Fixed an import and passing through of kind/type between conversions

* Added conversion of TLS config between device and object; carried through attributes

* Fixed a test assertion expected/actual order
  • Loading branch information
tomikazi committed Dec 17, 2020
1 parent d5c9967 commit d48393f
Show file tree
Hide file tree
Showing 67 changed files with 1,181 additions and 2,305 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Expand Up @@ -40,3 +40,6 @@ issues:
text: "SA1019:"
- path: pkg/utils
text: "copylocks"
- path: pkg/store/device/store.go
linters:
- scopelint
3 changes: 3 additions & 0 deletions go.mod
Expand Up @@ -7,6 +7,7 @@ require (
github.com/atomix/go-client v0.4.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/docker/docker v1.13.1 // indirect
github.com/go-playground/overalls v0.0.0-20191218162659-7df9f728c018 // indirect
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3
Expand All @@ -15,6 +16,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/goveralls v0.0.7 // indirect
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20201130213019-492043aed0df
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20201130213019-492043aed0df
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20201130213019-492043aed0df
Expand All @@ -32,6 +34,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.5.1
github.com/yookoala/realpath v1.0.0 // indirect
go.uber.org/multierr v1.4.0 // indirect
google.golang.org/grpc v1.33.2
gopkg.in/yaml.v2 v2.2.8
Expand Down
40 changes: 12 additions & 28 deletions go.sum

Large diffs are not rendered by default.

114 changes: 57 additions & 57 deletions pkg/config/load/onos-config-load-sample-gnmi.yaml
@@ -1,62 +1,62 @@
setrequest:
prefix:
prefix:
elem:
- name: e2node
target: ""
delete: [ ]
replace: [ ]
update:
- path:
elem:
- name: e2node
target: ""
delete: []
replace: []
update:
- path:
elem:
- name: intervals
- name: RadioMeasReportPerUe
target: 315010-0001420
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001420
val:
uintvalue:
uintval: 21
- path:
elem:
- name: intervals
key: {}
- name: RadioMeasReportPerUe
key: {}
target: 315010-0001421
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001421
val:
uintvalue:
uintval: 21
- path:
elem:
- name: intervals
- name: RadioMeasReportPerUe
target: 315010-0001422
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001422
val:
uintvalue:
uintval: 21
extension:
- name: intervals
- name: RadioMeasReportPerUe
target: 315010-0001420
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001420
val:
uintvalue:
uintval: 21
- path:
elem:
- name: intervals
key: { }
- name: RadioMeasReportPerUe
key: { }
target: 315010-0001421
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001421
val:
uintvalue:
uintval: 21
- path:
elem:
- name: intervals
- name: RadioMeasReportPerUe
target: 315010-0001422
val:
uintvalue:
uintval: 20
- path:
elem:
- name: intervals
- name: RadioMeasReportPerCell
target: 315010-0001422
val:
uintvalue:
uintval: 21
extension:
- id: 101
value: 1.0.0
- id: 102
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/load/set.role-aether-ops.yaml
Expand Up @@ -6,8 +6,8 @@ setrequest:
- name: role
key:
roleid: aether-ops
delete: []
replace: []
delete: [ ]
replace: [ ]
update:
- path:
elem:
Expand Down
13 changes: 7 additions & 6 deletions pkg/controller/change/device/controller.go
Expand Up @@ -16,12 +16,14 @@ package device

import (
"fmt"
"github.com/onosproject/onos-api/go/onos/topo"
"strings"

types "github.com/onosproject/onos-api/go/onos/config"
changetypes "github.com/onosproject/onos-api/go/onos/config/change"
devicechange "github.com/onosproject/onos-api/go/onos/config/change/device"
"github.com/onosproject/onos-config/pkg/controller"
topodevice "github.com/onosproject/onos-config/pkg/device"
"github.com/onosproject/onos-config/pkg/southbound"
changestore "github.com/onosproject/onos-config/pkg/store/change/device"
devicechangeutils "github.com/onosproject/onos-config/pkg/store/change/device/utils"
Expand All @@ -30,7 +32,6 @@ import (
mastershipstore "github.com/onosproject/onos-config/pkg/store/mastership"
"github.com/onosproject/onos-config/pkg/utils/values"
"github.com/onosproject/onos-lib-go/pkg/logging"
topodevice "github.com/onosproject/onos-topo/api/device"
)

var log = logging.GetLogger("controller", "change", "device")
Expand Down Expand Up @@ -91,7 +92,7 @@ func (r *Reconciler) Reconcile(id types.ID) (controller.Result, error) {
device, err := r.devices.Get(topodevice.ID(change.Change.DeviceID))
if err != nil {
return controller.Result{}, err
} else if getProtocolState(device) != topodevice.ChannelState_CONNECTED {
} else if getProtocolState(device) != topo.ChannelState_CONNECTED {
// If the device is not available, fail the change
change.Status.State = changetypes.State_FAILED
change.Status.Reason = changetypes.Reason_ERROR
Expand Down Expand Up @@ -191,17 +192,17 @@ func (r *Reconciler) translateAndSendChange(change *devicechange.Change) error {
return nil
}

func getProtocolState(device *topodevice.Device) topodevice.ChannelState {
func getProtocolState(device *topodevice.Device) topo.ChannelState {
// Find the gNMI protocol state for the device
var protocol *topodevice.ProtocolState
var protocol *topo.ProtocolState
for _, p := range device.Protocols {
if p.Protocol == topodevice.Protocol_GNMI {
if p.Protocol == topo.Protocol_GNMI {
protocol = p
break
}
}
if protocol == nil {
return topodevice.ChannelState_UNKNOWN_CHANNEL_STATE
return topo.ChannelState_UNKNOWN_CHANNEL_STATE
}
return protocol.ChannelState
}
Expand Down
48 changes: 25 additions & 23 deletions pkg/controller/change/device/controller_test.go
Expand Up @@ -24,6 +24,8 @@ import (
devicechange "github.com/onosproject/onos-api/go/onos/config/change/device"
"github.com/onosproject/onos-api/go/onos/config/device"
devicetype "github.com/onosproject/onos-api/go/onos/config/device"
"github.com/onosproject/onos-api/go/onos/topo"
topodevice "github.com/onosproject/onos-config/pkg/device"
"github.com/onosproject/onos-config/pkg/events"
"github.com/onosproject/onos-config/pkg/modelregistry"
"github.com/onosproject/onos-config/pkg/southbound"
Expand All @@ -32,9 +34,9 @@ import (
devicechangeutils "github.com/onosproject/onos-config/pkg/store/change/device/utils"
devicestore "github.com/onosproject/onos-config/pkg/store/device"
"github.com/onosproject/onos-config/pkg/store/stream"
"github.com/onosproject/onos-config/pkg/test/mocks"
southboundmock "github.com/onosproject/onos-config/pkg/test/mocks/southbound"
storemock "github.com/onosproject/onos-config/pkg/test/mocks/store"
topodevice "github.com/onosproject/onos-topo/api/device"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
Expand Down Expand Up @@ -474,48 +476,48 @@ func newStores(t *testing.T) (devicestore.Store, devicechanges.Store) {
devices := map[topodevice.ID]*topodevice.Device{
topodevice.ID(device1): {
ID: topodevice.ID(device1),
Protocols: []*topodevice.ProtocolState{
Protocols: []*topo.ProtocolState{
{
Protocol: topodevice.Protocol_GNMI,
ConnectivityState: topodevice.ConnectivityState_REACHABLE,
ChannelState: topodevice.ChannelState_CONNECTED,
Protocol: topo.Protocol_GNMI,
ConnectivityState: topo.ConnectivityState_REACHABLE,
ChannelState: topo.ChannelState_CONNECTED,
},
},
},
topodevice.ID(device2): {
ID: topodevice.ID(device2),
Protocols: []*topodevice.ProtocolState{
Protocols: []*topo.ProtocolState{
{
Protocol: topodevice.Protocol_GNMI,
ConnectivityState: topodevice.ConnectivityState_REACHABLE,
ChannelState: topodevice.ChannelState_CONNECTED,
Protocol: topo.Protocol_GNMI,
ConnectivityState: topo.ConnectivityState_REACHABLE,
ChannelState: topo.ChannelState_CONNECTED,
},
},
},
topodevice.ID(dcDevice): {
ID: topodevice.ID(dcDevice),
Protocols: []*topodevice.ProtocolState{
Protocols: []*topo.ProtocolState{
{
Protocol: topodevice.Protocol_GNMI,
ConnectivityState: topodevice.ConnectivityState_UNREACHABLE,
ChannelState: topodevice.ChannelState_DISCONNECTED,
Protocol: topo.Protocol_GNMI,
ConnectivityState: topo.ConnectivityState_UNREACHABLE,
ChannelState: topo.ChannelState_DISCONNECTED,
},
},
},
}

stream := NewMockDeviceService_ListClient(ctrl)
stream.EXPECT().Recv().Return(&topodevice.ListResponse{Device: devices[topodevice.ID(device1)]}, nil)
stream.EXPECT().Recv().Return(&topodevice.ListResponse{Device: devices[topodevice.ID(device2)]}, nil)
stream.EXPECT().Recv().Return(&topodevice.ListResponse{Device: devices[topodevice.ID(dcDevice)]}, nil)
stream := mocks.NewMockTopo_WatchClient(ctrl)
stream.EXPECT().Recv().Return(&topo.WatchResponse{Event: topo.Event{Object: *topodevice.ToObject(devices[topodevice.ID(device1)])}}, nil)
stream.EXPECT().Recv().Return(&topo.WatchResponse{Event: topo.Event{Object: *topodevice.ToObject(devices[topodevice.ID(device2)])}}, nil)
stream.EXPECT().Recv().Return(&topo.WatchResponse{Event: topo.Event{Object: *topodevice.ToObject(devices[topodevice.ID(dcDevice)])}}, nil)
stream.EXPECT().Recv().Return(nil, io.EOF)

client := NewMockDeviceServiceClient(ctrl)
client.EXPECT().List(gomock.Any(), gomock.Any()).Return(stream, nil).AnyTimes()
client := mocks.NewMockTopoClient(ctrl)
client.EXPECT().Watch(gomock.Any(), gomock.Any()).Return(stream, nil).AnyTimes()
client.EXPECT().Get(gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, in *topodevice.GetRequest, opts ...grpc.CallOption) (*topodevice.GetResponse, error) {
return &topodevice.GetResponse{
Device: devices[in.ID],
DoAndReturn(func(ctx context.Context, in *topo.GetRequest, opts ...grpc.CallOption) (*topo.GetResponse, error) {
return &topo.GetResponse{
Object: topodevice.ToObject(devices[topodevice.ID(in.ID)]),
}, nil
}).AnyTimes()

Expand Down Expand Up @@ -543,7 +545,7 @@ func mockTargetDevice(t *testing.T, name device.ID, ctrl *gomock.Controller) {
Version: v1,
Timeout: &timeout,
Credentials: topodevice.Credentials{},
TLS: topodevice.TlsConfig{},
TLS: topodevice.TLSConfig{},
Type: "TestDevice",
Role: "leaf",
}
Expand Down

0 comments on commit d48393f

Please sign in to comment.