blob: 16ee92bb31cf2d13c1528ba9b6401426ba50ac82 [file] [log] [blame]
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04001// +build integration
2
khenaidoo731697e2019-01-29 16:03:29 -05003/*
4 * Copyright 2018-present Open Networking Foundation
5
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://www.apache.org/licenses/LICENSE-2.0
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040018
khenaidoo297cd252019-02-07 22:10:23 -050019package api
khenaidoo731697e2019-01-29 16:03:29 -050020
21import (
22 "context"
23 "fmt"
npujar12732342019-11-14 17:28:40 +053024 "os"
25 "os/exec"
26 "strings"
27 "testing"
28 "time"
29
khenaidoo731697e2019-01-29 16:03:29 -050030 "github.com/golang/protobuf/ptypes/empty"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080031 com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
32 "github.com/opencord/voltha-lib-go/v3/pkg/log"
33 "github.com/opencord/voltha-protos/v3/go/common"
34 "github.com/opencord/voltha-protos/v3/go/openflow_13"
35 "github.com/opencord/voltha-protos/v3/go/voltha"
khenaidoo731697e2019-01-29 16:03:29 -050036 "github.com/stretchr/testify/assert"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/grpc/metadata"
40 "google.golang.org/grpc/status"
khenaidoo731697e2019-01-29 16:03:29 -050041)
42
43var conn *grpc.ClientConn
44var stub voltha.VolthaServiceClient
45var testMode string
46
47/*
48Prerequite: These tests require the rw_core to run prior to executing these test cases.
49*/
50
51var devices map[string]*voltha.Device
52
53//func init() {
54// log.AddPackage(log.JSON, log.ErrorLevel, nil)
55// log.UpdateAllLoggers(log.Fields{"instanceId": "testing"})
56// log.SetAllLogLevel(log.ErrorLevel)
57//
58// //Start kafka and Etcd
59// startKafkaEtcd()
60// time.Sleep(10 * time.Second) //TODO: Find a better way to ascertain they are up
61//
62// stub = setupGrpcConnection()
63// stub = voltha.NewVolthaServiceClient(conn)
64// devices = make(map[string]*voltha.Device)
65//}
66
67func setup() {
68 var err error
69
70 if _, err = log.AddPackage(log.JSON, log.WarnLevel, log.Fields{"instanceId": "testing"}); err != nil {
71 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
72 }
73 log.UpdateAllLoggers(log.Fields{"instanceId": "testing"})
74 log.SetAllLogLevel(log.ErrorLevel)
75
76 //Start kafka and Etcd
77 startKafka()
78 startEtcd()
79 time.Sleep(10 * time.Second) //TODO: Find a better way to ascertain they are up
80
81 stub = setupGrpcConnection()
82 testMode = common.TestModeKeys_api_test.String()
83 devices = make(map[string]*voltha.Device)
84}
85
86func setupGrpcConnection() voltha.VolthaServiceClient {
87 grpcHostIP := os.Getenv("DOCKER_HOST_IP")
88 grpcPort := 50057
89 grpcHost := fmt.Sprintf("%s:%d", grpcHostIP, grpcPort)
90 var err error
91 conn, err = grpc.Dial(grpcHost, grpc.WithInsecure())
92 if err != nil {
93 log.Fatalf("did not connect: %s", err)
94 }
95 return voltha.NewVolthaServiceClient(conn)
96}
97
98func clearAllDevices(clearMap bool) {
99 for key, _ := range devices {
100 ctx := context.Background()
101 response, err := stub.DeleteDevice(ctx, &voltha.ID{Id: key})
102 log.Infow("response", log.Fields{"res": response, "error": err})
103 if clearMap {
104 delete(devices, key)
105 }
106 }
107}
108
109// Verify if all ids are present in the global list of devices
110func hasAllIds(ids *voltha.IDs) bool {
111 if ids == nil && len(devices) == 0 {
112 return true
113 }
114 if ids == nil {
115 return false
116 }
117 for _, id := range ids.Items {
118 if _, exist := devices[id.Id]; !exist {
119 return false
120 }
121 }
122 return true
123}
124
125func startKafka() {
126 fmt.Println("Starting Kafka and Etcd ...")
127 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400128 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-zk-kafka-test.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500129 if err := cmd.Run(); err != nil {
130 log.Fatal(err)
131 }
132}
133
134func startEtcd() {
135 fmt.Println("Starting Etcd ...")
136 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400137 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-etcd.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500138 if err := cmd.Run(); err != nil {
139 log.Fatal(err)
140 }
141}
142
143func stopKafka() {
144 fmt.Println("Stopping Kafka and Etcd ...")
145 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400146 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-zk-kafka-test.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500147 if err := cmd.Run(); err != nil {
148 // ignore error - as this is mostly due network being left behind as its being used by other
149 // containers
150 log.Warn(err)
151 }
152}
153
154func stopEtcd() {
155 fmt.Println("Stopping Etcd ...")
156 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400157 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-etcd.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500158 if err := cmd.Run(); err != nil {
159 // ignore error - as this is mostly due network being left behind as its being used by other
160 // containers
161 log.Warn(err)
162 }
163}
164
165func startCore() {
166 fmt.Println("Starting voltha core ...")
167 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400168 cmd := exec.Command(command, "-f", "../../../compose/rw_core.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500169 if err := cmd.Run(); err != nil {
170 log.Fatal(err)
171 }
172}
173
174func stopCore() {
175 fmt.Println("Stopping voltha core ...")
176 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400177 cmd := exec.Command(command, "-f", "../../../compose/rw_core.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500178 if err := cmd.Run(); err != nil {
179 // ignore error - as this is mostly due network being left behind as its being used by other
180 // containers
181 log.Warn(err)
182 }
183}
184
185func startSimulatedOLTAndONUAdapters() {
186 fmt.Println("Starting simulated OLT and ONU adapters ...")
187 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400188 cmd := exec.Command(command, "-f", "../../../compose/adapters-simulated.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500189 if err := cmd.Run(); err != nil {
190 log.Fatal(err)
191 }
192}
193
194func stopSimulatedOLTAndONUAdapters() {
195 fmt.Println("Stopping simulated OLT and ONU adapters ...")
196 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400197 cmd := exec.Command(command, "-f", "../../../compose/adapters-simulated.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500198 if err := cmd.Run(); err != nil {
199 // ignore error - as this is mostly due network being left behind as its being used by other
200 // containers
201 log.Warn(err)
202 }
203}
204
khenaidoo731697e2019-01-29 16:03:29 -0500205func TestListDeviceIds(t *testing.T) {
206 fmt.Println("Testing list Devices Ids ...")
207 //0. Start kafka and Ectd
208 startKafka()
209 startEtcd()
210
211 //1. Start the core
212 startCore()
213
214 // Wait until it's up - TODO: find a better way to check
215 time.Sleep(10 * time.Second)
216
217 //2. Create a set of devices into the Core
218 for i := 0; i < 10; i++ {
219 ctx := context.Background()
220 device := &voltha.Device{Type: "simulated_olt"}
221 response, err := stub.CreateDevice(ctx, device)
222 log.Infow("response", log.Fields{"res": response, "error": err})
223 assert.NotNil(t, response)
224 assert.Nil(t, err)
225 devices[response.Id] = response
226 }
227
228 //3. Verify devices have been added correctly
229 ctx := context.Background()
230 response, err := stub.ListDeviceIds(ctx, &empty.Empty{})
231 log.Infow("response", log.Fields{"res": response, "error": err})
232 assert.Nil(t, err)
233 assert.True(t, hasAllIds(response))
234
235 //4. Stop the core
236 stopCore()
237
238 //5. Stop Kafka and Etcd
239 stopKafka()
240 stopEtcd()
241}
242
243func TestReconcileDevices(t *testing.T) {
244 fmt.Println("Testing Reconcile Devices ...")
245
246 //0. Start kafka and Ectd
247 startKafka()
248 startEtcd()
249
250 //1. Start the core
251 startCore()
252
253 // Wait until it's up - TODO: find a better way to check
254 time.Sleep(10 * time.Second)
255
256 //2. Create a set of devices into the Core
257 for i := 0; i < 10; i++ {
258 ctx := context.Background()
259 device := &voltha.Device{Type: "simulated_olt"}
260 response, err := stub.CreateDevice(ctx, device)
261 log.Infow("response", log.Fields{"res": response, "error": err})
262 assert.Nil(t, err)
263 devices[response.Id] = response
264 }
265 //3. Verify devices have been added correctly
266 ctx := context.Background()
267 response, err := stub.ListDeviceIds(ctx, &empty.Empty{})
268 log.Infow("response", log.Fields{"res": response, "error": err})
269 assert.Nil(t, err)
270 assert.True(t, hasAllIds(response))
271
272 //4. Stop the core and restart it. This will start the core with no data in memory but
273 // etcd will still have the data.
274 stopCore()
275 time.Sleep(5 * time.Second)
276 startCore()
277 time.Sleep(10 * time.Second)
278
279 //5. Setup the connection again
280 stub = setupGrpcConnection()
281
282 //6. Verify there are no devices left
283 ctx = context.Background()
284 response, err = stub.ListDeviceIds(ctx, &empty.Empty{})
285 log.Infow("response", log.Fields{"res": response, "error": err})
286 assert.Nil(t, err)
287 assert.Equal(t, len(response.Items), 0)
288
289 //7. Invoke reconcile with all stored list
290 toRestore := &voltha.IDs{Items: make([]*voltha.ID, 0)}
291 for key, _ := range devices {
292 toRestore.Items = append(toRestore.Items, &voltha.ID{Id: key})
293 }
294 ctx = context.Background()
295 _, err = stub.ReconcileDevices(ctx, toRestore)
296 assert.Nil(t, err)
297
298 //8. Verify all devices have been restored
299 ctx = context.Background()
300 response, err = stub.ListDeviceIds(ctx, &empty.Empty{})
301 log.Infow("response", log.Fields{"res": response, "error": err})
302 assert.Nil(t, err)
303 assert.True(t, hasAllIds(response))
304
305 for _, id := range response.Items {
306 fmt.Println("id", id.Id)
307 }
308
309 //9. Store the core
310 stopCore()
311
312 //10. Stop Kafka and Etcd
313 stopKafka()
314 stopEtcd()
315}
316
317func TestDeviceManagement(t *testing.T) {
318 fmt.Println("Testing Device Management ...")
319
320 numberOfOLTDevices := 1
321
322 //0. Start kafka and Ectd
323 startKafka()
324 startEtcd()
325
326 //1. Start the core
327 startCore()
328
329 //2. Start the simulated adapters
330 startSimulatedOLTAndONUAdapters()
331
332 // Wait until the core and adapters sync up
333 time.Sleep(10 * time.Second)
334
335 //3. Create a set of devices into the Core
336 devices = make(map[string]*voltha.Device)
337 logicalDevices := make(map[string]*voltha.LogicalDevice)
338 for i := 0; i < numberOfOLTDevices; i++ {
339 ctx := context.Background()
340 randomMacAddress := strings.ToUpper(com.GetRandomMacAddress())
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400341 device := &voltha.Device{Type: "simulated_olt", MacAddress: randomMacAddress}
khenaidoo731697e2019-01-29 16:03:29 -0500342 response, err := stub.CreateDevice(ctx, device)
343 log.Infow("response", log.Fields{"res": response, "error": err})
344 assert.Nil(t, err)
345 devices[response.Id] = response
346 }
347
348 //4. Enable all the devices
349 for id, _ := range devices {
350 ctx := context.Background()
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400351 response, err := stub.EnableDevice(ctx, &common.ID{Id: id})
khenaidoo731697e2019-01-29 16:03:29 -0500352 log.Infow("response", log.Fields{"res": response, "error": err})
353 assert.Nil(t, err)
354 }
355
356 // Wait until all devices have been enabled
357 if numberOfOLTDevices < 5 {
358 time.Sleep(3 * time.Second)
359 } else if numberOfOLTDevices < 20 {
360 time.Sleep(20 * time.Second)
361 } else {
362 time.Sleep(30 * time.Second)
363 }
364 //time.Sleep(1 * time.Second * time.Duration(numberOfDevices))
365
366 //5. Verify that all devices are in enabled state
367 ctx := context.Background()
368 response, err := stub.ListDevices(ctx, &empty.Empty{})
369 log.Infow("response", log.Fields{"res": response, "error": err})
370 assert.Nil(t, err)
371 assert.Equal(t, len(devices)*2, len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400372 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500373 devices[d.Id] = d
374 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
375 }
376
377 //6. Get the logical devices
378 ctx = context.Background()
379 lresponse, lerr := stub.ListLogicalDevices(ctx, &empty.Empty{})
380 log.Infow("response", log.Fields{"res": response, "error": lerr})
381 assert.Nil(t, lerr)
382 assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400383 for _, ld := range lresponse.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500384 logicalDevices[ld.Id] = ld
385 // Ensure each logical device have two ports
386 assert.Equal(t, 2, len(ld.Ports))
387 }
388
389 //7. Disable all ONUs & check status & check logical device
390 for id, d := range devices {
391 ctx := context.Background()
392 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400393 response, err := stub.DisableDevice(ctx, &common.ID{Id: id})
khenaidoo731697e2019-01-29 16:03:29 -0500394 log.Infow("response", log.Fields{"res": response, "error": err})
395 assert.Nil(t, err)
396 }
397 }
398
399 // Wait for all the changes to be populated
400 time.Sleep(3 * time.Second)
401
402 ctx = context.Background()
403 response, err = stub.ListDevices(ctx, &empty.Empty{})
404 log.Infow("response", log.Fields{"res": response, "error": err})
405 assert.Nil(t, err)
406 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400407 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500408 if d.Type == "simulated_onu" {
409 assert.Equal(t, d.AdminState, voltha.AdminState_DISABLED)
410 devices[d.Id] = d
411 } else {
412 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
413 }
414 }
415
416 ctx = context.Background()
417 lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
418 log.Infow("response", log.Fields{"res": response, "error": lerr})
419 assert.Nil(t, lerr)
420 assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400421 for _, ld := range lresponse.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500422 logicalDevices[ld.Id] = ld
423 // Ensure each logical device have one port - only olt port
424 assert.Equal(t, 1, len(ld.Ports))
425 }
426
427 //8. Enable all ONUs & check status & check logical device
428 for id, d := range devices {
429 ctx := context.Background()
430 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400431 response, err := stub.EnableDevice(ctx, &common.ID{Id: id})
khenaidoo731697e2019-01-29 16:03:29 -0500432 log.Infow("response", log.Fields{"res": response, "error": err})
433 assert.Nil(t, err)
434 }
435 }
436
437 // Wait for all the changes to be populated
438 time.Sleep(3 * time.Second)
439
440 ctx = context.Background()
441 response, err = stub.ListDevices(ctx, &empty.Empty{})
442 log.Infow("response", log.Fields{"res": response, "error": err})
443 assert.Nil(t, err)
444 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400445 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500446 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
447 devices[d.Id] = d
448 }
449
450 //ctx = context.Background()
451 //lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
452 //log.Infow("response", log.Fields{"res": response, "error": lerr})
453 //assert.Nil(t, lerr)
454 //assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
455 //for _, ld := range (lresponse.Items) {
456 // logicalDevices[ld.Id] = ld
457 // // Ensure each logical device have two ports
458 // assert.Equal(t, 2, len(ld.Ports))
459 //}
460
461 //9. Disable all OLTs & check status & check logical device
462
463 //10. Enable all OLTs & Enable all ONUs & check status & check logical device
464
465 //11. Disable all OLTs & check status & check logical device
466
467 //12. Delete all Devices & check status & check logical device
468
469 ////13. Store simulated adapters
470 //stopSimulatedOLTAndONUAdapters()
471 //
472 ////14. Store the core
473 //stopCore()
474 //
475 ////15. Stop Kafka and Etcd
476 //stopKafka()
477 //stopEtcd()
478}
479
khenaidoo731697e2019-01-29 16:03:29 -0500480func TestGetDevice(t *testing.T) {
481 var id common.ID
482 id.Id = "anyid"
483 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
484 response, err := stub.GetDevice(ctx, &id)
485 assert.Nil(t, response)
486 st, _ := status.FromError(err)
487 assert.Equal(t, id.Id, st.Message())
488 assert.Equal(t, codes.NotFound, st.Code())
489}
490
491func TestUpdateLogLevelError(t *testing.T) {
492 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
493 level := voltha.Logging{PackageName: "github.com/opencord/voltha-go/rw_core/core", Level: common.LogLevel_ERROR}
494 response, err := stub.UpdateLogLevel(ctx, &level)
495 log.Infow("response", log.Fields{"res": response, "error": err})
496 assert.Equal(t, &empty.Empty{}, response)
497 assert.Nil(t, err)
498}
499
500func TestGetVoltha(t *testing.T) {
501 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
502 response, err := stub.GetVoltha(ctx, &empty.Empty{})
503 assert.Nil(t, response)
504 st, _ := status.FromError(err)
505 assert.Equal(t, "UnImplemented", st.Message())
506}
507
508func TestUpdateLogLevelDebug(t *testing.T) {
509 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
510 level := voltha.Logging{PackageName: "github.com/opencord/voltha-go/rw_core/core", Level: common.LogLevel_DEBUG}
511 response, err := stub.UpdateLogLevel(ctx, &level)
512 log.Infow("response", log.Fields{"res": response, "error": err})
513 assert.Equal(t, &empty.Empty{}, response)
514 assert.Nil(t, err)
515}
516
517func TestGetCoreInstance(t *testing.T) {
518 id := &voltha.ID{Id: "getCoreInstance"}
519 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
520 response, err := stub.GetCoreInstance(ctx, id)
521 assert.Nil(t, response)
522 st, _ := status.FromError(err)
523 assert.Equal(t, "UnImplemented", st.Message())
524}
525
526func TestGetLogicalDevice(t *testing.T) {
527 id := &voltha.ID{Id: "getLogicalDevice"}
528 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
529 response, err := stub.GetLogicalDevice(ctx, id)
530 assert.Nil(t, response)
531 st, _ := status.FromError(err)
532 assert.Equal(t, id.Id, st.Message())
533 assert.Equal(t, codes.NotFound, st.Code())
534}
535
536func TestGetLogicalDevicePort(t *testing.T) {
537 id := &voltha.LogicalPortId{Id: "GetLogicalDevicePort"}
538 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
539 response, err := stub.GetLogicalDevicePort(ctx, id)
540 assert.Nil(t, response)
541 st, _ := status.FromError(err)
542 assert.Equal(t, "UnImplemented", st.Message())
543}
544
545func TestListLogicalDevicePorts(t *testing.T) {
546 id := &voltha.ID{Id: "listLogicalDevicePorts"}
547 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
548 response, err := stub.ListLogicalDevicePorts(ctx, id)
549 assert.Nil(t, response)
550 st, _ := status.FromError(err)
551 assert.Equal(t, "UnImplemented", st.Message())
552}
553
554func TestListLogicalDeviceFlows(t *testing.T) {
555 id := &voltha.ID{Id: "ListLogicalDeviceFlows"}
556 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
557 response, err := stub.ListLogicalDeviceFlows(ctx, id)
558 assert.Nil(t, response)
559 st, _ := status.FromError(err)
560 assert.Equal(t, "UnImplemented", st.Message())
561}
562
563func TestListLogicalDeviceFlowGroups(t *testing.T) {
564 id := &voltha.ID{Id: "ListLogicalDeviceFlowGroups"}
565 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
566 response, err := stub.ListLogicalDeviceFlowGroups(ctx, id)
567 assert.Nil(t, response)
568 st, _ := status.FromError(err)
569 assert.Equal(t, "UnImplemented", st.Message())
570}
571
572func TestListDevices(t *testing.T) {
573 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
574 response, _ := stub.ListDevices(ctx, &empty.Empty{})
575 assert.Equal(t, len(response.Items), 0)
576}
577
578func TestListAdapters(t *testing.T) {
579 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
580 response, err := stub.ListAdapters(ctx, &empty.Empty{})
581 assert.Nil(t, response)
582 st, _ := status.FromError(err)
583 assert.Equal(t, "UnImplemented", st.Message())
584}
585
586func TestListLogicalDevices(t *testing.T) {
587 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
588 response, _ := stub.ListLogicalDevices(ctx, &empty.Empty{})
589 assert.Equal(t, len(response.Items), 0)
590}
591
592func TestListCoreInstances(t *testing.T) {
593 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
594 response, err := stub.ListCoreInstances(ctx, &empty.Empty{})
595 assert.Nil(t, response)
596 st, _ := status.FromError(err)
597 assert.Equal(t, "UnImplemented", st.Message())
598}
599
600func TestCreateDevice(t *testing.T) {
601 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
602 device := &voltha.Device{Id: "newdevice"}
603 response, err := stub.CreateDevice(ctx, device)
604 log.Infow("response", log.Fields{"res": response, "error": err})
605 assert.Equal(t, &voltha.Device{Id: "newdevice"}, response)
606 assert.Nil(t, err)
607}
608
609func TestEnableDevice(t *testing.T) {
610 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
611 id := &voltha.ID{Id: "enabledevice"}
612 response, err := stub.EnableDevice(ctx, id)
613 log.Infow("response", log.Fields{"res": response, "error": err})
614 assert.Equal(t, &empty.Empty{}, response)
615 assert.Nil(t, err)
616}
617
618func TestDisableDevice(t *testing.T) {
619 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
620 id := &voltha.ID{Id: "DisableDevice"}
621 response, err := stub.DisableDevice(ctx, id)
622 log.Infow("response", log.Fields{"res": response, "error": err})
623 assert.Equal(t, &empty.Empty{}, response)
624 assert.Nil(t, err)
625}
626
627func TestRebootDevice(t *testing.T) {
628 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
629 id := &voltha.ID{Id: "RebootDevice"}
630 response, err := stub.RebootDevice(ctx, id)
631 log.Infow("response", log.Fields{"res": response, "error": err})
632 assert.Equal(t, &empty.Empty{}, response)
633 assert.Nil(t, err)
634}
635
636func TestDeleteDevice(t *testing.T) {
637 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
638 id := &voltha.ID{Id: "DeleteDevice"}
639 response, err := stub.DeleteDevice(ctx, id)
640 log.Infow("response", log.Fields{"res": response, "error": err})
641 assert.Equal(t, &empty.Empty{}, response)
642 assert.Nil(t, err)
643}
644
645func TestEnableLogicalDevicePort(t *testing.T) {
646 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
647 id := &voltha.LogicalPortId{Id: "EnableLogicalDevicePort"}
648 response, err := stub.EnableLogicalDevicePort(ctx, id)
649 if e, ok := status.FromError(err); ok {
650 log.Infow("response", log.Fields{"error": err, "errorcode": e.Code(), "msg": e.Message()})
651 }
652 log.Infow("response", log.Fields{"res": response, "error": err})
653 assert.Equal(t, &empty.Empty{}, response)
654 assert.Nil(t, err)
655}
656
657func TestDisableLogicalDevicePort(t *testing.T) {
658 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
659 id := &voltha.LogicalPortId{Id: "DisableLogicalDevicePort"}
660 response, err := stub.DisableLogicalDevicePort(ctx, id)
661 log.Infow("response", log.Fields{"res": response, "error": err})
662 assert.Equal(t, &empty.Empty{}, response)
663 assert.Nil(t, err)
664}
665
666func TestUpdateLogicalDeviceFlowGroupTable(t *testing.T) {
667 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
668 flow := &openflow_13.FlowGroupTableUpdate{Id: "UpdateLogicalDeviceFlowGroupTable"}
669 response, err := stub.UpdateLogicalDeviceFlowGroupTable(ctx, flow)
670 log.Infow("response", log.Fields{"res": response, "error": err})
671 assert.Equal(t, &empty.Empty{}, response)
672 assert.Nil(t, err)
673}
674
675func TestGetImageDownloadStatus(t *testing.T) {
676 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
677 img := &voltha.ImageDownload{Id: "GetImageDownloadStatus"}
678 response, err := stub.GetImageDownloadStatus(ctx, img)
679 assert.Nil(t, response)
680 st, _ := status.FromError(err)
681 assert.Equal(t, "UnImplemented", st.Message())
682}
683
684// TODO: complete the remaining tests
685
686func shutdown() {
687 conn.Close()
688}
689
690func TestMain(m *testing.M) {
691 setup()
692 code := m.Run()
693 shutdown()
694 os.Exit(code)
695}