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