blob: 22a61c2ead89aaf02da0b31cc35d134288bf13bb [file] [log] [blame]
cbabua9e04cc2019-10-03 12:35:45 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
cbabubef89432019-10-18 11:47:27 +020017/*
18This file contains unit test cases for functions in the file openolt.go.
19This file also implements the fields struct to mock the Openolt and few utility functions.
20*/
21
Scott Bakerdbd960e2020-02-28 08:57:51 -080022//Package core provides the utility for olt devices, flows and statistics
23package core
cbabua9e04cc2019-10-03 12:35:45 +053024
25import (
26 "context"
27 "errors"
Esin Karamanccb714b2019-11-29 15:02:06 +000028 com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
29 fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
30 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
David K. Bainbridge794735f2020-02-11 21:01:37 -080031 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080032 "github.com/opencord/voltha-openolt-adapter/internal/pkg/config"
Thomas Lee S94109f12020-03-03 16:39:29 +053033 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Esin Karamanccb714b2019-11-29 15:02:06 +000034 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
35 "github.com/opencord/voltha-protos/v3/go/openflow_13"
36 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
37 "github.com/opencord/voltha-protos/v3/go/voltha"
kesavand39e0aa32020-01-28 20:58:50 -050038 "reflect"
39 "sync"
40 "testing"
cbabua9e04cc2019-10-03 12:35:45 +053041)
42
cbabubef89432019-10-18 11:47:27 +020043// mocks the OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053044type fields struct {
45 deviceHandlers map[string]*DeviceHandler
46 coreProxy *com.CoreProxy
47 adapterProxy *com.AdapterProxy
48 eventProxy *com.EventProxy
npujarec5762e2020-01-01 14:08:48 +053049 kafkaICProxy kafka.InterContainerProxy
cbabua9e04cc2019-10-03 12:35:45 +053050 numOnus int
Neha Sharma3f221ae2020-04-29 19:02:12 +000051 KVStoreAddress string
cbabua9e04cc2019-10-03 12:35:45 +053052 KVStoreType string
53 exitChannel chan int
54 lockDeviceHandlersMap sync.RWMutex
55 ctx context.Context
56}
57
cbabubef89432019-10-18 11:47:27 +020058// mockOlt mocks OpenOLT struct.
cbabua9e04cc2019-10-03 12:35:45 +053059func mockOlt() *fields {
cbabua9e04cc2019-10-03 12:35:45 +053060 dh := newMockDeviceHandler()
61 newOlt := &fields{}
62 newOlt.deviceHandlers = map[string]*DeviceHandler{}
63 newOlt.deviceHandlers[dh.device.Id] = dh
64 return newOlt
65}
66
cbabubef89432019-10-18 11:47:27 +020067// testOltObject maps fields type to OpenOLt type.
cbabua9e04cc2019-10-03 12:35:45 +053068func testOltObject(testOlt *fields) *OpenOLT {
69 return &OpenOLT{
70 deviceHandlers: testOlt.deviceHandlers,
71 coreProxy: testOlt.coreProxy,
72 adapterProxy: testOlt.adapterProxy,
73 eventProxy: testOlt.eventProxy,
74 kafkaICProxy: testOlt.kafkaICProxy,
75 numOnus: testOlt.numOnus,
Neha Sharma3f221ae2020-04-29 19:02:12 +000076 KVStoreAddress: testOlt.KVStoreAddress,
cbabua9e04cc2019-10-03 12:35:45 +053077 KVStoreType: testOlt.KVStoreType,
78 exitChannel: testOlt.exitChannel,
79 }
80}
81
cbabubef89432019-10-18 11:47:27 +020082// mockDevice mocks Device.
cbabua9e04cc2019-10-03 12:35:45 +053083func mockDevice() *voltha.Device {
84 device := &voltha.Device{
85 Id: "olt",
86 Root: true,
87 ParentId: "logical_device",
88 Ports: []*voltha.Port{
89 {PortNo: 1, Label: "pon"},
90 {PortNo: 2, Label: "nni"},
91 },
92 ProxyAddress: &voltha.Device_ProxyAddress{
93 DeviceId: "olt",
94 DeviceType: "onu",
95 ChannelId: 1,
96 ChannelGroupId: 1,
97 },
98 ConnectStatus: 1,
99 }
100 return device
101}
102
103func TestNewOpenOLT(t *testing.T) {
104 tests := []struct {
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530105 name string
106 fields *fields
107 configFlags *config.AdapterFlags
108 want *OpenOLT
cbabua9e04cc2019-10-03 12:35:45 +0530109 }{
Neha Sharma3f221ae2020-04-29 19:02:12 +0000110 {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"},
111 &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}},
112 {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"},
113 &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}},
114 {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"},
115 &OpenOLT{numOnus: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}},
cbabua9e04cc2019-10-03 12:35:45 +0530116 }
117 for _, tt := range tests {
118 t.Run(tt.name, func(t *testing.T) {
119 if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy,
Abhilash Laxmeshwarf9942e92020-01-07 15:32:44 +0530120 tt.fields.eventProxy, tt.configFlags); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil {
cbabua9e04cc2019-10-03 12:35:45 +0530121 t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want)
122 }
123 })
124 }
125}
126
127func TestOpenOLT_Abandon_device(t *testing.T) {
128 type args struct {
129 device *voltha.Device
130 }
131 tests := []struct {
132 name string
133 fields *fields
134 args args
135 wantErr error
136 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530137 {"abandon_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
138 {"abandon_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
139 {"abandon_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530140 }
141 for _, tt := range tests {
142 t.Run(tt.name, func(t *testing.T) {
143 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800144 if err := oo.Abandon_device(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530145 t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr)
146 }
147 })
148 }
149}
150
151func TestOpenOLT_Activate_image_update(t *testing.T) {
152 type args struct {
153 device *voltha.Device
154 request *voltha.ImageDownload
155 }
156 tests := []struct {
157 name string
158 fields *fields
159 args args
160 want *voltha.ImageDownload
161 wantErr error
162 }{
163 {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530164 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530165 {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530166 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530167 {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530168 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530169 }
170 for _, tt := range tests {
171 t.Run(tt.name, func(t *testing.T) {
172 oo := testOltObject(tt.fields)
173 got, err := oo.Activate_image_update(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800174 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530175 t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr)
176 }
177 })
178 }
179}
180
181func TestOpenOLT_Adapter_descriptor(t *testing.T) {
182 tests := []struct {
183 name string
184 fields *fields
185 wantErr error
186 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530187 {"adapter_descriptor-1", &fields{}, olterrors.ErrNotImplemented},
188 {"adapter_descriptor-2", &fields{}, olterrors.ErrNotImplemented},
189 {"adapter_descriptor-3", &fields{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530190 }
191 for _, tt := range tests {
192 t.Run(tt.name, func(t *testing.T) {
193 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800194 if err := oo.Adapter_descriptor(); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530195 t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr)
196 }
197 })
198 }
199}
200
201func TestOpenOLT_Adopt_device(t *testing.T) {
202 type args struct {
203 device *voltha.Device
204 }
205 var device = mockDevice()
kesavand39e0aa32020-01-28 20:58:50 -0500206 device.Id = "olt"
Thomas Lee S94109f12020-03-03 16:39:29 +0530207 nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530208 tests := []struct {
209 name string
210 fields *fields
211 args args
212 wantErr error
213 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800214 {"adopt_device-1", mockOlt(), args{}, nilDevice},
215 {"adopt_device-2", mockOlt(), args{device}, nilDevice},
216 {"adopt_device-3", mockOlt(), args{mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530217 }
218 for _, tt := range tests {
219 t.Run(tt.name, func(t *testing.T) {
220 oo := testOltObject(tt.fields)
221 err := oo.Adopt_device(tt.args.device)
222 if (err != nil) && (reflect.TypeOf(err) !=
223 reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) {
224 t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr)
225 }
226 if err == nil {
227 t.Log("return'd nil")
228 }
229 })
230 }
231}
232
233func TestOpenOLT_Cancel_image_download(t *testing.T) {
234 type args struct {
235 device *voltha.Device
236 request *voltha.ImageDownload
237 }
238 tests := []struct {
239 name string
240 fields *fields
241 args args
242 want *voltha.ImageDownload
243 wantErr error
244 }{
245 {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530246 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530247 {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530248 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530249 {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530250 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530251 }
252 for _, tt := range tests {
253 t.Run(tt.name, func(t *testing.T) {
254 oo := testOltObject(tt.fields)
255 got, err := oo.Cancel_image_download(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800256 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530257 t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr)
258 }
259 })
260 }
261}
262
263func TestOpenOLT_Delete_device(t *testing.T) {
264 type args struct {
265 device *voltha.Device
266 }
267 tests := []struct {
268 name string
269 fields *fields
270 args args
271 wantErr error
272 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800273 {"delete_device-1", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530274 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530275 }
276 for _, tt := range tests {
277 t.Run(tt.name, func(t *testing.T) {
278 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800279 if err := oo.Delete_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530280 t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr)
281 }
282 })
283 }
284}
285
286func TestOpenOLT_Device_types(t *testing.T) {
287 tests := []struct {
288 name string
289 fields *fields
290 want *voltha.DeviceTypes
291 wantErr error
292 }{
293 {"device_types-1", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530294 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530295 {"device_types-2", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530296 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530297 {"device_types-3", &fields{}, &voltha.DeviceTypes{},
Thomas Lee S94109f12020-03-03 16:39:29 +0530298 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530299 }
300 for _, tt := range tests {
301 t.Run(tt.name, func(t *testing.T) {
302 oo := testOltObject(tt.fields)
303 got, err := oo.Device_types()
David K. Bainbridge794735f2020-02-11 21:01:37 -0800304 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530305 t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr)
306 }
307 })
308 }
309}
310
311func TestOpenOLT_Disable_device(t *testing.T) {
312 type args struct {
313 device *voltha.Device
314 }
315 tests := []struct {
316 name string
317 fields *fields
318 args args
319 wantErr error
320 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800321 {"disable_device-1", mockOlt(), args{mockDevice()}, nil},
322 {"disable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530323 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530324 }
325 for _, tt := range tests {
326 t.Run(tt.name, func(t *testing.T) {
327 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800328 if err := oo.Disable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530329 t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr)
330 }
331 })
332 }
333}
334
335func TestOpenOLT_Download_image(t *testing.T) {
336 type args struct {
337 device *voltha.Device
338 request *voltha.ImageDownload
339 }
340 tests := []struct {
341 name string
342 fields *fields
343 args args
344 want *voltha.ImageDownload
345 wantErr error
346 }{
347 {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530348 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530349 {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530350 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530351 {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530352 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530353 }
354 for _, tt := range tests {
355 t.Run(tt.name, func(t *testing.T) {
356 oo := testOltObject(tt.fields)
357 got, err := oo.Download_image(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800358 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530359 t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr)
360 }
361 })
362 }
363}
364
365func TestOpenOLT_Get_device_details(t *testing.T) {
366 type args struct {
367 device *voltha.Device
368 }
369 tests := []struct {
370 name string
371 fields *fields
372 args args
373 wantErr error
374 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530375 {"get_device_details-1", &fields{}, args{}, olterrors.ErrNotImplemented},
376 {"get_device_details-2", &fields{}, args{}, olterrors.ErrNotImplemented},
377 {"get_device_details-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530378 }
379 for _, tt := range tests {
380 t.Run(tt.name, func(t *testing.T) {
381 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800382 if err := oo.Get_device_details(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530383 t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr)
384 }
385 })
386 }
387}
388
389func TestOpenOLT_Get_image_download_status(t *testing.T) {
390 type args struct {
391 device *voltha.Device
392 request *voltha.ImageDownload
393 }
394 tests := []struct {
395 name string
396 fields *fields
397 args args
398 want *voltha.ImageDownload
399 wantErr error
400 }{
401 {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530402 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530403 {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530404 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530405 {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530406 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530407 }
408 for _, tt := range tests {
409 t.Run(tt.name, func(t *testing.T) {
410 oo := testOltObject(tt.fields)
411 got, err := oo.Get_image_download_status(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800412 if err != tt.wantErr && got == nil {
413 t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v",
414 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530415 }
416 })
417 }
418}
419
420func TestOpenOLT_Get_ofp_device_info(t *testing.T) {
421 type args struct {
422 device *voltha.Device
423 }
424 tests := []struct {
425 name string
426 fields *fields
427 args args
428 want *ic.SwitchCapability
429 wantErr error
430 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800431 {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{
432 Desc: &openflow_13.OfpDesc{
433 MfrDesc: "VOLTHA Project",
434 HwDesc: "open_pon",
435 SwDesc: "open_pon",
436 },
437 SwitchFeatures: &openflow_13.OfpSwitchFeatures{
438 NBuffers: uint32(256),
439 NTables: uint32(2),
440 Capabilities: uint32(15),
441 },
442 }, nil},
443 {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil,
Thomas Lee S94109f12020-03-03 16:39:29 +0530444 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530445 }
446 for _, tt := range tests {
447 t.Run(tt.name, func(t *testing.T) {
448 oo := testOltObject(tt.fields)
449 got, err := oo.Get_ofp_device_info(tt.args.device)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800450 if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) {
451 t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v",
452 got, tt.want, err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530453 }
454 })
455 }
456}
457
cbabua9e04cc2019-10-03 12:35:45 +0530458func TestOpenOLT_Health(t *testing.T) {
459 tests := []struct {
460 name string
461 fields *fields
462 want *voltha.HealthStatus
463 wantErr error
464 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530465 {"health-1", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
466 {"health-2", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
467 {"health-3", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530468 }
469 for _, tt := range tests {
470 t.Run(tt.name, func(t *testing.T) {
471 oo := testOltObject(tt.fields)
472 got, err := oo.Health()
David K. Bainbridge794735f2020-02-11 21:01:37 -0800473 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530474 t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr)
475 }
476 })
477 }
478}
479
480func TestOpenOLT_Process_inter_adapter_message(t *testing.T) {
481 type args struct {
482 msg *ic.InterAdapterMessage
483 }
484 var message1 = args{
485 msg: &ic.InterAdapterMessage{
486 Header: &ic.InterAdapterHeader{
487 Id: "olt",
488 ProxyDeviceId: "",
489 ToDeviceId: "onu1",
490 },
491 },
492 }
493 var message2 = args{
494 msg: &ic.InterAdapterMessage{
495 Header: &ic.InterAdapterHeader{
496 Id: "olt",
497 ProxyDeviceId: "olt",
498 ToDeviceId: "olt",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800499 Type: ic.InterAdapterMessageType_OMCI_REQUEST,
500 },
501 },
502 }
503 var message3 = args{
504 msg: &ic.InterAdapterMessage{
505 Header: &ic.InterAdapterHeader{
506 Id: "olt",
507 ProxyDeviceId: "olt",
508 ToDeviceId: "olt",
509 Type: ic.InterAdapterMessageType_FLOW_REQUEST,
cbabua9e04cc2019-10-03 12:35:45 +0530510 },
511 },
512 }
513 tests := []struct {
David K. Bainbridge794735f2020-02-11 21:01:37 -0800514 name string
515 fields *fields
516 args args
517 wantErrType reflect.Type
cbabua9e04cc2019-10-03 12:35:45 +0530518 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800519 {"process_inter_adaptor_messgae-1", mockOlt(), message1,
Thomas Lee S94109f12020-03-03 16:39:29 +0530520 reflect.TypeOf(&olterrors.ErrNotFound{})},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800521 {"process_inter_adaptor_messgae-2", mockOlt(), message2,
Girish Kumarf26e4882020-03-05 06:49:10 +0000522 reflect.TypeOf(&olterrors.ErrAdapter{})},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800523 {"process_inter_adaptor_messgae-3", mockOlt(), message3,
Thomas Lee S94109f12020-03-03 16:39:29 +0530524 reflect.TypeOf(&olterrors.ErrInvalidValue{})},
cbabua9e04cc2019-10-03 12:35:45 +0530525 }
526 for _, tt := range tests {
527 t.Run(tt.name, func(t *testing.T) {
528 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800529 if err := oo.Process_inter_adapter_message(tt.args.msg); reflect.TypeOf(err) != tt.wantErrType {
530 t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v",
531 reflect.TypeOf(err), tt.wantErrType)
cbabua9e04cc2019-10-03 12:35:45 +0530532 }
533 })
534 }
535}
536
537func TestOpenOLT_Reboot_device(t *testing.T) {
538 type args struct {
539 device *voltha.Device
540 }
541 tests := []struct {
542 name string
543 fields *fields
544 args args
545 wantErr error
546 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800547 {"reboot_device-1", mockOlt(), args{mockDevice()}, nil},
548 {"reboot_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530549 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530550 }
551 for _, tt := range tests {
552 t.Run(tt.name, func(t *testing.T) {
553 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800554 if err := oo.Reboot_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530555 t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr)
556 }
557 })
558 }
559}
560
561func TestOpenOLT_Receive_packet_out(t *testing.T) {
562 acts := []*ofp.OfpAction{
563 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))),
564 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
565 fu.Output(1),
566 }
567 type args struct {
568 deviceID string
569 egressPortNo int
570 packet *openflow_13.OfpPacketOut
571 }
572 pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" +
573 "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" +
574 "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")}
575 tests := []struct {
576 name string
577 fields *fields
578 args args
579 wantErr error
580 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800581 {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530582 {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout},
Thomas Lee S94109f12020-03-03 16:39:29 +0530583 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530584 }
585 for _, tt := range tests {
586 t.Run(tt.name, func(t *testing.T) {
587 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800588 if err := oo.Receive_packet_out(tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530589 t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr)
590 }
591 })
592 }
593}
594
595func TestOpenOLT_Reconcile_device(t *testing.T) {
596 type args struct {
597 device *voltha.Device
598 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530599 expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil)
cbabua9e04cc2019-10-03 12:35:45 +0530600 tests := []struct {
601 name string
602 fields *fields
603 args args
604 wantErr error
605 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800606 {"reconcile_device-1", &fields{}, args{}, expectedError},
607 {"reconcile_device-2", &fields{}, args{}, expectedError},
608 {"reconcile_device-3", &fields{}, args{}, expectedError},
cbabua9e04cc2019-10-03 12:35:45 +0530609 }
610 for _, tt := range tests {
611 t.Run(tt.name, func(t *testing.T) {
612 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800613 if err := oo.Reconcile_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530614 t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr)
615 }
616 })
617 }
618}
619
620func TestOpenOLT_Reenable_device(t *testing.T) {
621 type args struct {
622 device *voltha.Device
623 }
624 tests := []struct {
625 name string
626 fields *fields
627 args args
628 wantErr error
629 }{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800630 {"reenable_device-1", mockOlt(), args{mockDevice()}, nil},
631 {"reenable_device-2", &fields{}, args{mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530632 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530633 }
634 for _, tt := range tests {
635 t.Run(tt.name, func(t *testing.T) {
636 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800637 if err := oo.Reenable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530638 t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr)
639 }
640 })
641 }
642}
643
644func TestOpenOLT_Revert_image_update(t *testing.T) {
645 type args struct {
646 device *voltha.Device
647 request *voltha.ImageDownload
648 }
649 tests := []struct {
650 name string
651 fields *fields
652 args args
653 want *voltha.ImageDownload
654 wantErr error
655 }{
656 {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530657 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530658 {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530659 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530660 {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"},
Thomas Lee S94109f12020-03-03 16:39:29 +0530661 olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530662 }
663 for _, tt := range tests {
664 t.Run(tt.name, func(t *testing.T) {
665 oo := testOltObject(tt.fields)
666 got, err := oo.Revert_image_update(tt.args.device, tt.args.request)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800667 if err != tt.wantErr && got == nil {
cbabua9e04cc2019-10-03 12:35:45 +0530668 t.Log("error :", err)
669 }
670 })
671 }
672}
673
674func TestOpenOLT_Self_test_device(t *testing.T) {
675 type args struct {
676 device *voltha.Device
677 }
678 tests := []struct {
679 name string
680 fields *fields
681 args args
682 wantErr error
683 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530684 {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented},
685 {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented},
686 {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530687 }
688 for _, tt := range tests {
689 t.Run(tt.name, func(t *testing.T) {
690 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800691 if err := oo.Self_test_device(tt.args.device); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530692 t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr)
693 }
694 })
695 }
696}
697
698func TestOpenOLT_Start(t *testing.T) {
699 type args struct {
700 ctx context.Context
701 }
702 tests := []struct {
703 name string
704 fields *fields
705 args args
706 wantErr error
707 }{
708 {"start-1", &fields{}, args{}, errors.New("start error")},
709 }
710 for _, tt := range tests {
711 t.Run(tt.name, func(t *testing.T) {
712 oo := testOltObject(tt.fields)
713 if err := oo.Start(tt.args.ctx); err != nil {
714 t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr)
715 }
716 })
717 }
718}
719
720func TestOpenOLT_Stop(t *testing.T) {
721 type args struct {
722 ctx context.Context
723 }
724 tests := []struct {
725 name string
726 fields *fields
727 args args
728 wantErr error
729 }{
730 {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")},
731 }
732 for _, tt := range tests {
733 t.Run(tt.name, func(t *testing.T) {
734 oo := testOltObject(tt.fields)
735 oo.Start(tt.args.ctx)
736 if err := oo.Stop(tt.args.ctx); err != nil {
737 t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
738 }
739 })
740 }
741}
742
Devmalya Pauldd23a992019-11-14 07:06:31 +0000743func TestOpenOLT_Suppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530744 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000745 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530746 }
747 tests := []struct {
748 name string
749 fields *fields
750 args args
751 wantErr error
752 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530753 {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
754 {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
755 {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530756 }
757 for _, tt := range tests {
758 t.Run(tt.name, func(t *testing.T) {
759 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800760 if err := oo.Suppress_event(tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000761 t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530762 }
763 })
764 }
765}
766
Devmalya Pauldd23a992019-11-14 07:06:31 +0000767func TestOpenOLT_Unsuppress_event(t *testing.T) {
cbabua9e04cc2019-10-03 12:35:45 +0530768 type args struct {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000769 filter *voltha.EventFilter
cbabua9e04cc2019-10-03 12:35:45 +0530770 }
771 tests := []struct {
772 name string
773 fields *fields
774 args args
775 wantErr error
776 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530777 {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented},
778 {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented},
779 {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530780 }
781 for _, tt := range tests {
782 t.Run(tt.name, func(t *testing.T) {
783 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800784 if err := oo.Unsuppress_event(tt.args.filter); err != tt.wantErr {
Devmalya Pauldd23a992019-11-14 07:06:31 +0000785 t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr)
cbabua9e04cc2019-10-03 12:35:45 +0530786 }
787 })
788 }
789}
790
791func TestOpenOLT_Update_flows_bulk(t *testing.T) {
792 type args struct {
793 device *voltha.Device
794 flows *voltha.Flows
795 groups *voltha.FlowGroups
796 flowMetadata *voltha.FlowMetadata
797 }
798 tests := []struct {
799 name string
800 fields *fields
801 args args
802 wantErr error
803 }{
Thomas Lee S94109f12020-03-03 16:39:29 +0530804 {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented},
805 {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented},
806 {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented},
cbabua9e04cc2019-10-03 12:35:45 +0530807 }
808 for _, tt := range tests {
809 t.Run(tt.name, func(t *testing.T) {
810 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800811 if err := oo.Update_flows_bulk(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); err != tt.wantErr {
cbabua9e04cc2019-10-03 12:35:45 +0530812 t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr)
813 }
814 })
815 }
816}
817
818func TestOpenOLT_Update_flows_incrementally(t *testing.T) {
819 type args struct {
820 device *voltha.Device
821 flows *openflow_13.FlowChanges
822 groups *openflow_13.FlowGroupChanges
823 flowMetadata *voltha.FlowMetadata
824 }
825
826 tests := []struct {
827 name string
828 fields *fields
829 args args
830 wantErr error
831 }{
832 {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()},
Thomas Lee S94109f12020-03-03 16:39:29 +0530833 olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
David K. Bainbridge794735f2020-02-11 21:01:37 -0800834 {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil},
cbabua9e04cc2019-10-03 12:35:45 +0530835 }
836 for _, tt := range tests {
837 t.Run(tt.name, func(t *testing.T) {
838 oo := testOltObject(tt.fields)
David K. Bainbridge794735f2020-02-11 21:01:37 -0800839 if err := oo.Update_flows_incrementally(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530840 t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr)
841 }
842 })
843 }
844}
845
846func TestOpenOLT_Update_pm_config(t *testing.T) {
847 type args struct {
848 device *voltha.Device
849 pmConfigs *voltha.PmConfigs
850 }
851 tests := []struct {
852 name string
853 fields *fields
854 args args
855 wantErr error
856 }{
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000857 {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil},
858 {"update_pm_config-2", &fields{}, args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)},
cbabua9e04cc2019-10-03 12:35:45 +0530859 }
860 for _, tt := range tests {
861 t.Run(tt.name, func(t *testing.T) {
862 oo := testOltObject(tt.fields)
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000863 if err := oo.Update_pm_config(tt.args.device, tt.args.pmConfigs); !reflect.DeepEqual(err, tt.wantErr) {
cbabua9e04cc2019-10-03 12:35:45 +0530864 t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr)
865 }
866
867 })
868 }
869}
870
871func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) {
872 type args struct {
873 agent *DeviceHandler
874 }
875 tests := []struct {
876 name string
877 fields *fields
878 args args
879 }{
880 {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}},
881 }
882 for _, tt := range tests {
883 t.Run(tt.name, func(t *testing.T) {
884 oo := testOltObject(tt.fields)
885 oo.deleteDeviceHandlerToMap(tt.args.agent)
886 if len(oo.deviceHandlers) > 0 {
887 t.Errorf("delete device manager failed")
888 }
889 })
890 }
891}
kesavand39e0aa32020-01-28 20:58:50 -0500892
893func TestOpenOLT_Enable_port(t *testing.T) {
894 type args struct {
895 deviceID string
896 port *voltha.Port
897 }
898 tests := []struct {
899 name string
900 fields *fields
901 args args
902 wantErr bool
903 }{
904 // TODO: Add test cases.
905 {"Enable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
906 {"Enable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
907 }
908 for _, tt := range tests {
909 t.Run(tt.name, func(t *testing.T) {
910 oo := testOltObject(tt.fields)
911 if err := oo.Enable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
912 t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr)
913 }
914 })
915 }
916}
917
918func TestOpenOLT_Disable_port(t *testing.T) {
919 type args struct {
920 deviceID string
921 port *voltha.Port
922 }
923 tests := []struct {
924 name string
925 fields *fields
926 args args
927 wantErr bool
928 }{
929 // TODO: Add test cases.
930 {"Disable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false},
931 {"Disable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true},
932 }
933 for _, tt := range tests {
934 t.Run(tt.name, func(t *testing.T) {
935 oo := testOltObject(tt.fields)
936 if err := oo.Disable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr {
937 t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr)
938 }
939 })
940 }
941}