blob: ac9da6cd445062404c553afae03d676cdf425b9f [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
khenaidoo731697e2019-01-29 16:03:29 -050053func setup() {
khenaidoo731697e2019-01-29 16:03:29 -050054 //Start kafka and Etcd
55 startKafka()
56 startEtcd()
57 time.Sleep(10 * time.Second) //TODO: Find a better way to ascertain they are up
58
59 stub = setupGrpcConnection()
60 testMode = common.TestModeKeys_api_test.String()
61 devices = make(map[string]*voltha.Device)
62}
63
64func setupGrpcConnection() voltha.VolthaServiceClient {
65 grpcHostIP := os.Getenv("DOCKER_HOST_IP")
66 grpcPort := 50057
67 grpcHost := fmt.Sprintf("%s:%d", grpcHostIP, grpcPort)
68 var err error
69 conn, err = grpc.Dial(grpcHost, grpc.WithInsecure())
70 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +000071 logger.Fatalf("did not connect: %s", err)
khenaidoo731697e2019-01-29 16:03:29 -050072 }
73 return voltha.NewVolthaServiceClient(conn)
74}
75
76func clearAllDevices(clearMap bool) {
77 for key, _ := range devices {
78 ctx := context.Background()
79 response, err := stub.DeleteDevice(ctx, &voltha.ID{Id: key})
Girish Kumarf56a4682020-03-20 20:07:46 +000080 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -050081 if clearMap {
82 delete(devices, key)
83 }
84 }
85}
86
87// Verify if all ids are present in the global list of devices
88func hasAllIds(ids *voltha.IDs) bool {
89 if ids == nil && len(devices) == 0 {
90 return true
91 }
92 if ids == nil {
93 return false
94 }
95 for _, id := range ids.Items {
96 if _, exist := devices[id.Id]; !exist {
97 return false
98 }
99 }
100 return true
101}
102
103func startKafka() {
104 fmt.Println("Starting Kafka and Etcd ...")
105 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400106 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-zk-kafka-test.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500107 if err := cmd.Run(); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000108 logger.Fatal(err)
khenaidoo731697e2019-01-29 16:03:29 -0500109 }
110}
111
112func startEtcd() {
113 fmt.Println("Starting Etcd ...")
114 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400115 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-etcd.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500116 if err := cmd.Run(); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000117 logger.Fatal(err)
khenaidoo731697e2019-01-29 16:03:29 -0500118 }
119}
120
121func stopKafka() {
122 fmt.Println("Stopping Kafka and Etcd ...")
123 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400124 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-zk-kafka-test.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500125 if err := cmd.Run(); err != nil {
126 // ignore error - as this is mostly due network being left behind as its being used by other
127 // containers
Girish Kumarf56a4682020-03-20 20:07:46 +0000128 logger.Warn(err)
khenaidoo731697e2019-01-29 16:03:29 -0500129 }
130}
131
132func stopEtcd() {
133 fmt.Println("Stopping Etcd ...")
134 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400135 cmd := exec.Command(command, "-f", "../../../compose/docker-compose-etcd.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500136 if err := cmd.Run(); err != nil {
137 // ignore error - as this is mostly due network being left behind as its being used by other
138 // containers
Girish Kumarf56a4682020-03-20 20:07:46 +0000139 logger.Warn(err)
khenaidoo731697e2019-01-29 16:03:29 -0500140 }
141}
142
143func startCore() {
144 fmt.Println("Starting voltha core ...")
145 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400146 cmd := exec.Command(command, "-f", "../../../compose/rw_core.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500147 if err := cmd.Run(); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000148 logger.Fatal(err)
khenaidoo731697e2019-01-29 16:03:29 -0500149 }
150}
151
152func stopCore() {
153 fmt.Println("Stopping voltha core ...")
154 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400155 cmd := exec.Command(command, "-f", "../../../compose/rw_core.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500156 if err := cmd.Run(); err != nil {
157 // ignore error - as this is mostly due network being left behind as its being used by other
158 // containers
Girish Kumarf56a4682020-03-20 20:07:46 +0000159 logger.Warn(err)
khenaidoo731697e2019-01-29 16:03:29 -0500160 }
161}
162
163func startSimulatedOLTAndONUAdapters() {
164 fmt.Println("Starting simulated OLT and ONU adapters ...")
165 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400166 cmd := exec.Command(command, "-f", "../../../compose/adapters-simulated.yml", "up", "-d")
khenaidoo731697e2019-01-29 16:03:29 -0500167 if err := cmd.Run(); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000168 logger.Fatal(err)
khenaidoo731697e2019-01-29 16:03:29 -0500169 }
170}
171
172func stopSimulatedOLTAndONUAdapters() {
173 fmt.Println("Stopping simulated OLT and ONU adapters ...")
174 command := "docker-compose"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400175 cmd := exec.Command(command, "-f", "../../../compose/adapters-simulated.yml", "down")
khenaidoo731697e2019-01-29 16:03:29 -0500176 if err := cmd.Run(); err != nil {
177 // ignore error - as this is mostly due network being left behind as its being used by other
178 // containers
Girish Kumarf56a4682020-03-20 20:07:46 +0000179 logger.Warn(err)
khenaidoo731697e2019-01-29 16:03:29 -0500180 }
181}
182
khenaidoo731697e2019-01-29 16:03:29 -0500183func TestListDeviceIds(t *testing.T) {
184 fmt.Println("Testing list Devices Ids ...")
185 //0. Start kafka and Ectd
186 startKafka()
187 startEtcd()
188
189 //1. Start the core
190 startCore()
191
192 // Wait until it's up - TODO: find a better way to check
193 time.Sleep(10 * time.Second)
194
195 //2. Create a set of devices into the Core
196 for i := 0; i < 10; i++ {
197 ctx := context.Background()
198 device := &voltha.Device{Type: "simulated_olt"}
199 response, err := stub.CreateDevice(ctx, device)
Girish Kumarf56a4682020-03-20 20:07:46 +0000200 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500201 assert.NotNil(t, response)
202 assert.Nil(t, err)
203 devices[response.Id] = response
204 }
205
206 //3. Verify devices have been added correctly
207 ctx := context.Background()
208 response, err := stub.ListDeviceIds(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000209 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500210 assert.Nil(t, err)
211 assert.True(t, hasAllIds(response))
212
213 //4. Stop the core
214 stopCore()
215
216 //5. Stop Kafka and Etcd
217 stopKafka()
218 stopEtcd()
219}
220
221func TestReconcileDevices(t *testing.T) {
222 fmt.Println("Testing Reconcile Devices ...")
223
224 //0. Start kafka and Ectd
225 startKafka()
226 startEtcd()
227
228 //1. Start the core
229 startCore()
230
231 // Wait until it's up - TODO: find a better way to check
232 time.Sleep(10 * time.Second)
233
234 //2. Create a set of devices into the Core
235 for i := 0; i < 10; i++ {
236 ctx := context.Background()
237 device := &voltha.Device{Type: "simulated_olt"}
238 response, err := stub.CreateDevice(ctx, device)
Girish Kumarf56a4682020-03-20 20:07:46 +0000239 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500240 assert.Nil(t, err)
241 devices[response.Id] = response
242 }
243 //3. Verify devices have been added correctly
244 ctx := context.Background()
245 response, err := stub.ListDeviceIds(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000246 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500247 assert.Nil(t, err)
248 assert.True(t, hasAllIds(response))
249
250 //4. Stop the core and restart it. This will start the core with no data in memory but
251 // etcd will still have the data.
252 stopCore()
253 time.Sleep(5 * time.Second)
254 startCore()
255 time.Sleep(10 * time.Second)
256
257 //5. Setup the connection again
258 stub = setupGrpcConnection()
259
260 //6. Verify there are no devices left
261 ctx = context.Background()
262 response, err = stub.ListDeviceIds(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000263 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500264 assert.Nil(t, err)
265 assert.Equal(t, len(response.Items), 0)
266
267 //7. Invoke reconcile with all stored list
268 toRestore := &voltha.IDs{Items: make([]*voltha.ID, 0)}
269 for key, _ := range devices {
270 toRestore.Items = append(toRestore.Items, &voltha.ID{Id: key})
271 }
272 ctx = context.Background()
273 _, err = stub.ReconcileDevices(ctx, toRestore)
274 assert.Nil(t, err)
275
276 //8. Verify all devices have been restored
277 ctx = context.Background()
278 response, err = stub.ListDeviceIds(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000279 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500280 assert.Nil(t, err)
281 assert.True(t, hasAllIds(response))
282
283 for _, id := range response.Items {
284 fmt.Println("id", id.Id)
285 }
286
287 //9. Store the core
288 stopCore()
289
290 //10. Stop Kafka and Etcd
291 stopKafka()
292 stopEtcd()
293}
294
295func TestDeviceManagement(t *testing.T) {
296 fmt.Println("Testing Device Management ...")
297
298 numberOfOLTDevices := 1
299
300 //0. Start kafka and Ectd
301 startKafka()
302 startEtcd()
303
304 //1. Start the core
305 startCore()
306
307 //2. Start the simulated adapters
308 startSimulatedOLTAndONUAdapters()
309
310 // Wait until the core and adapters sync up
311 time.Sleep(10 * time.Second)
312
313 //3. Create a set of devices into the Core
314 devices = make(map[string]*voltha.Device)
315 logicalDevices := make(map[string]*voltha.LogicalDevice)
316 for i := 0; i < numberOfOLTDevices; i++ {
317 ctx := context.Background()
318 randomMacAddress := strings.ToUpper(com.GetRandomMacAddress())
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400319 device := &voltha.Device{Type: "simulated_olt", MacAddress: randomMacAddress}
khenaidoo731697e2019-01-29 16:03:29 -0500320 response, err := stub.CreateDevice(ctx, device)
Girish Kumarf56a4682020-03-20 20:07:46 +0000321 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500322 assert.Nil(t, err)
323 devices[response.Id] = response
324 }
325
326 //4. Enable all the devices
327 for id, _ := range devices {
328 ctx := context.Background()
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400329 response, err := stub.EnableDevice(ctx, &common.ID{Id: id})
Girish Kumarf56a4682020-03-20 20:07:46 +0000330 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500331 assert.Nil(t, err)
332 }
333
334 // Wait until all devices have been enabled
335 if numberOfOLTDevices < 5 {
336 time.Sleep(3 * time.Second)
337 } else if numberOfOLTDevices < 20 {
338 time.Sleep(20 * time.Second)
339 } else {
340 time.Sleep(30 * time.Second)
341 }
342 //time.Sleep(1 * time.Second * time.Duration(numberOfDevices))
343
344 //5. Verify that all devices are in enabled state
345 ctx := context.Background()
346 response, err := stub.ListDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000347 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500348 assert.Nil(t, err)
349 assert.Equal(t, len(devices)*2, len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400350 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500351 devices[d.Id] = d
352 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
353 }
354
355 //6. Get the logical devices
356 ctx = context.Background()
357 lresponse, lerr := stub.ListLogicalDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000358 logger.Infow("response", log.Fields{"res": response, "error": lerr})
khenaidoo731697e2019-01-29 16:03:29 -0500359 assert.Nil(t, lerr)
360 assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400361 for _, ld := range lresponse.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500362 logicalDevices[ld.Id] = ld
363 // Ensure each logical device have two ports
364 assert.Equal(t, 2, len(ld.Ports))
365 }
366
367 //7. Disable all ONUs & check status & check logical device
368 for id, d := range devices {
369 ctx := context.Background()
370 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400371 response, err := stub.DisableDevice(ctx, &common.ID{Id: id})
Girish Kumarf56a4682020-03-20 20:07:46 +0000372 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500373 assert.Nil(t, err)
374 }
375 }
376
377 // Wait for all the changes to be populated
378 time.Sleep(3 * time.Second)
379
380 ctx = context.Background()
381 response, err = stub.ListDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000382 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500383 assert.Nil(t, err)
384 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400385 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500386 if d.Type == "simulated_onu" {
387 assert.Equal(t, d.AdminState, voltha.AdminState_DISABLED)
388 devices[d.Id] = d
389 } else {
390 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
391 }
392 }
393
394 ctx = context.Background()
395 lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000396 logger.Infow("response", log.Fields{"res": response, "error": lerr})
khenaidoo731697e2019-01-29 16:03:29 -0500397 assert.Nil(t, lerr)
398 assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400399 for _, ld := range lresponse.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500400 logicalDevices[ld.Id] = ld
401 // Ensure each logical device have one port - only olt port
402 assert.Equal(t, 1, len(ld.Ports))
403 }
404
405 //8. Enable all ONUs & check status & check logical device
406 for id, d := range devices {
407 ctx := context.Background()
408 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400409 response, err := stub.EnableDevice(ctx, &common.ID{Id: id})
Girish Kumarf56a4682020-03-20 20:07:46 +0000410 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500411 assert.Nil(t, err)
412 }
413 }
414
415 // Wait for all the changes to be populated
416 time.Sleep(3 * time.Second)
417
418 ctx = context.Background()
419 response, err = stub.ListDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000420 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500421 assert.Nil(t, err)
422 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400423 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500424 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
425 devices[d.Id] = d
426 }
427
428 //ctx = context.Background()
429 //lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
Girish Kumarf56a4682020-03-20 20:07:46 +0000430 //logger.Infow("response", log.Fields{"res": response, "error": lerr})
khenaidoo731697e2019-01-29 16:03:29 -0500431 //assert.Nil(t, lerr)
432 //assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
433 //for _, ld := range (lresponse.Items) {
434 // logicalDevices[ld.Id] = ld
435 // // Ensure each logical device have two ports
436 // assert.Equal(t, 2, len(ld.Ports))
437 //}
438
439 //9. Disable all OLTs & check status & check logical device
440
441 //10. Enable all OLTs & Enable all ONUs & check status & check logical device
442
443 //11. Disable all OLTs & check status & check logical device
444
445 //12. Delete all Devices & check status & check logical device
446
447 ////13. Store simulated adapters
448 //stopSimulatedOLTAndONUAdapters()
449 //
450 ////14. Store the core
451 //stopCore()
452 //
453 ////15. Stop Kafka and Etcd
454 //stopKafka()
455 //stopEtcd()
456}
457
khenaidoo731697e2019-01-29 16:03:29 -0500458func TestGetDevice(t *testing.T) {
459 var id common.ID
460 id.Id = "anyid"
461 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
462 response, err := stub.GetDevice(ctx, &id)
463 assert.Nil(t, response)
464 st, _ := status.FromError(err)
465 assert.Equal(t, id.Id, st.Message())
466 assert.Equal(t, codes.NotFound, st.Code())
467}
468
469func TestUpdateLogLevelError(t *testing.T) {
470 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
471 level := voltha.Logging{PackageName: "github.com/opencord/voltha-go/rw_core/core", Level: common.LogLevel_ERROR}
472 response, err := stub.UpdateLogLevel(ctx, &level)
Girish Kumarf56a4682020-03-20 20:07:46 +0000473 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500474 assert.Equal(t, &empty.Empty{}, response)
475 assert.Nil(t, err)
476}
477
478func TestGetVoltha(t *testing.T) {
479 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
480 response, err := stub.GetVoltha(ctx, &empty.Empty{})
481 assert.Nil(t, response)
482 st, _ := status.FromError(err)
483 assert.Equal(t, "UnImplemented", st.Message())
484}
485
486func TestUpdateLogLevelDebug(t *testing.T) {
487 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
488 level := voltha.Logging{PackageName: "github.com/opencord/voltha-go/rw_core/core", Level: common.LogLevel_DEBUG}
489 response, err := stub.UpdateLogLevel(ctx, &level)
Girish Kumarf56a4682020-03-20 20:07:46 +0000490 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500491 assert.Equal(t, &empty.Empty{}, response)
492 assert.Nil(t, err)
493}
494
495func TestGetCoreInstance(t *testing.T) {
496 id := &voltha.ID{Id: "getCoreInstance"}
497 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
498 response, err := stub.GetCoreInstance(ctx, id)
499 assert.Nil(t, response)
500 st, _ := status.FromError(err)
501 assert.Equal(t, "UnImplemented", st.Message())
502}
503
504func TestGetLogicalDevice(t *testing.T) {
505 id := &voltha.ID{Id: "getLogicalDevice"}
506 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
507 response, err := stub.GetLogicalDevice(ctx, id)
508 assert.Nil(t, response)
509 st, _ := status.FromError(err)
510 assert.Equal(t, id.Id, st.Message())
511 assert.Equal(t, codes.NotFound, st.Code())
512}
513
514func TestGetLogicalDevicePort(t *testing.T) {
515 id := &voltha.LogicalPortId{Id: "GetLogicalDevicePort"}
516 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
517 response, err := stub.GetLogicalDevicePort(ctx, id)
518 assert.Nil(t, response)
519 st, _ := status.FromError(err)
520 assert.Equal(t, "UnImplemented", st.Message())
521}
522
523func TestListLogicalDevicePorts(t *testing.T) {
524 id := &voltha.ID{Id: "listLogicalDevicePorts"}
525 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
526 response, err := stub.ListLogicalDevicePorts(ctx, id)
527 assert.Nil(t, response)
528 st, _ := status.FromError(err)
529 assert.Equal(t, "UnImplemented", st.Message())
530}
531
532func TestListLogicalDeviceFlows(t *testing.T) {
533 id := &voltha.ID{Id: "ListLogicalDeviceFlows"}
534 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
535 response, err := stub.ListLogicalDeviceFlows(ctx, id)
536 assert.Nil(t, response)
537 st, _ := status.FromError(err)
538 assert.Equal(t, "UnImplemented", st.Message())
539}
540
541func TestListLogicalDeviceFlowGroups(t *testing.T) {
542 id := &voltha.ID{Id: "ListLogicalDeviceFlowGroups"}
543 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
544 response, err := stub.ListLogicalDeviceFlowGroups(ctx, id)
545 assert.Nil(t, response)
546 st, _ := status.FromError(err)
547 assert.Equal(t, "UnImplemented", st.Message())
548}
549
550func TestListDevices(t *testing.T) {
551 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
552 response, _ := stub.ListDevices(ctx, &empty.Empty{})
553 assert.Equal(t, len(response.Items), 0)
554}
555
556func TestListAdapters(t *testing.T) {
557 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
558 response, err := stub.ListAdapters(ctx, &empty.Empty{})
559 assert.Nil(t, response)
560 st, _ := status.FromError(err)
561 assert.Equal(t, "UnImplemented", st.Message())
562}
563
564func TestListLogicalDevices(t *testing.T) {
565 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
566 response, _ := stub.ListLogicalDevices(ctx, &empty.Empty{})
567 assert.Equal(t, len(response.Items), 0)
568}
569
570func TestListCoreInstances(t *testing.T) {
571 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
572 response, err := stub.ListCoreInstances(ctx, &empty.Empty{})
573 assert.Nil(t, response)
574 st, _ := status.FromError(err)
575 assert.Equal(t, "UnImplemented", st.Message())
576}
577
578func TestCreateDevice(t *testing.T) {
579 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
580 device := &voltha.Device{Id: "newdevice"}
581 response, err := stub.CreateDevice(ctx, device)
Girish Kumarf56a4682020-03-20 20:07:46 +0000582 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500583 assert.Equal(t, &voltha.Device{Id: "newdevice"}, response)
584 assert.Nil(t, err)
585}
586
587func TestEnableDevice(t *testing.T) {
588 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
589 id := &voltha.ID{Id: "enabledevice"}
590 response, err := stub.EnableDevice(ctx, id)
Girish Kumarf56a4682020-03-20 20:07:46 +0000591 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500592 assert.Equal(t, &empty.Empty{}, response)
593 assert.Nil(t, err)
594}
595
596func TestDisableDevice(t *testing.T) {
597 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
598 id := &voltha.ID{Id: "DisableDevice"}
599 response, err := stub.DisableDevice(ctx, id)
Girish Kumarf56a4682020-03-20 20:07:46 +0000600 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500601 assert.Equal(t, &empty.Empty{}, response)
602 assert.Nil(t, err)
603}
604
605func TestRebootDevice(t *testing.T) {
606 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
607 id := &voltha.ID{Id: "RebootDevice"}
608 response, err := stub.RebootDevice(ctx, id)
Girish Kumarf56a4682020-03-20 20:07:46 +0000609 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500610 assert.Equal(t, &empty.Empty{}, response)
611 assert.Nil(t, err)
612}
613
614func TestDeleteDevice(t *testing.T) {
615 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
616 id := &voltha.ID{Id: "DeleteDevice"}
617 response, err := stub.DeleteDevice(ctx, id)
Girish Kumarf56a4682020-03-20 20:07:46 +0000618 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500619 assert.Equal(t, &empty.Empty{}, response)
620 assert.Nil(t, err)
621}
622
623func TestEnableLogicalDevicePort(t *testing.T) {
624 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
625 id := &voltha.LogicalPortId{Id: "EnableLogicalDevicePort"}
626 response, err := stub.EnableLogicalDevicePort(ctx, id)
627 if e, ok := status.FromError(err); ok {
Girish Kumarf56a4682020-03-20 20:07:46 +0000628 logger.Infow("response", log.Fields{"error": err, "errorcode": e.Code(), "msg": e.Message()})
khenaidoo731697e2019-01-29 16:03:29 -0500629 }
Girish Kumarf56a4682020-03-20 20:07:46 +0000630 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500631 assert.Equal(t, &empty.Empty{}, response)
632 assert.Nil(t, err)
633}
634
635func TestDisableLogicalDevicePort(t *testing.T) {
636 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
637 id := &voltha.LogicalPortId{Id: "DisableLogicalDevicePort"}
638 response, err := stub.DisableLogicalDevicePort(ctx, id)
Girish Kumarf56a4682020-03-20 20:07:46 +0000639 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500640 assert.Equal(t, &empty.Empty{}, response)
641 assert.Nil(t, err)
642}
643
644func TestUpdateLogicalDeviceFlowGroupTable(t *testing.T) {
645 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
646 flow := &openflow_13.FlowGroupTableUpdate{Id: "UpdateLogicalDeviceFlowGroupTable"}
647 response, err := stub.UpdateLogicalDeviceFlowGroupTable(ctx, flow)
Girish Kumarf56a4682020-03-20 20:07:46 +0000648 logger.Infow("response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500649 assert.Equal(t, &empty.Empty{}, response)
650 assert.Nil(t, err)
651}
652
653func TestGetImageDownloadStatus(t *testing.T) {
654 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
655 img := &voltha.ImageDownload{Id: "GetImageDownloadStatus"}
656 response, err := stub.GetImageDownloadStatus(ctx, img)
657 assert.Nil(t, response)
658 st, _ := status.FromError(err)
659 assert.Equal(t, "UnImplemented", st.Message())
660}
661
662// TODO: complete the remaining tests
663
664func shutdown() {
665 conn.Close()
666}
667
668func TestMain(m *testing.M) {
669 setup()
670 code := m.Run()
671 shutdown()
672 os.Exit(code)
673}