blob: b70531a1e22662d5ceb7f698d8b074a5c3373072 [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 {
Rohan Agrawal31f21802020-06-12 05:38:46 +000071 logger.Fatalf(ctx, "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})
Rohan Agrawal31f21802020-06-12 05:38:46 +000080 logger.Infow(ctx, "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 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000108 logger.Fatal(ctx, 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 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000117 logger.Fatal(ctx, 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
Rohan Agrawal31f21802020-06-12 05:38:46 +0000128 logger.Warn(ctx, 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
Rohan Agrawal31f21802020-06-12 05:38:46 +0000139 logger.Warn(ctx, 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 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000148 logger.Fatal(ctx, 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
Rohan Agrawal31f21802020-06-12 05:38:46 +0000159 logger.Warn(ctx, 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 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000168 logger.Fatal(ctx, 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
Rohan Agrawal31f21802020-06-12 05:38:46 +0000179 logger.Warn(ctx, 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)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000200 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000209 logger.Infow(ctx, "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)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000239 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000246 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000263 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000279 logger.Infow(ctx, "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)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000321 logger.Infow(ctx, "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})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000330 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000347 logger.Infow(ctx, "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{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000358 logger.Infow(ctx, "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
Kent Hagermanfa9d6d42020-05-25 11:49:40 -0400364 ports, err := stub.ListLogicalDevicePorts(ctx, &voltha.ID{Id: ld.Id})
365 assert.Nil(t, err)
366 assert.Equal(t, 2, len(ports.Items))
khenaidoo731697e2019-01-29 16:03:29 -0500367 }
368
369 //7. Disable all ONUs & check status & check logical device
370 for id, d := range devices {
371 ctx := context.Background()
372 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400373 response, err := stub.DisableDevice(ctx, &common.ID{Id: id})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000374 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500375 assert.Nil(t, err)
376 }
377 }
378
379 // Wait for all the changes to be populated
380 time.Sleep(3 * time.Second)
381
382 ctx = context.Background()
383 response, err = stub.ListDevices(ctx, &empty.Empty{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000384 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500385 assert.Nil(t, err)
386 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400387 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500388 if d.Type == "simulated_onu" {
389 assert.Equal(t, d.AdminState, voltha.AdminState_DISABLED)
390 devices[d.Id] = d
391 } else {
392 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
393 }
394 }
395
396 ctx = context.Background()
397 lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000398 logger.Infow(ctx, "response", log.Fields{"res": response, "error": lerr})
khenaidoo731697e2019-01-29 16:03:29 -0500399 assert.Nil(t, lerr)
400 assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400401 for _, ld := range lresponse.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500402 logicalDevices[ld.Id] = ld
403 // Ensure each logical device have one port - only olt port
Kent Hagermanfa9d6d42020-05-25 11:49:40 -0400404 ports, err := stub.ListLogicalDevicePorts(ctx, &common.ID{Id: ld.Id})
405 assert.Nil(t, err)
406 assert.Equal(t, 1, len(ports.Items))
khenaidoo731697e2019-01-29 16:03:29 -0500407 }
408
409 //8. Enable all ONUs & check status & check logical device
410 for id, d := range devices {
411 ctx := context.Background()
412 if d.Type == "simulated_onu" {
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400413 response, err := stub.EnableDevice(ctx, &common.ID{Id: id})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000414 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500415 assert.Nil(t, err)
416 }
417 }
418
419 // Wait for all the changes to be populated
420 time.Sleep(3 * time.Second)
421
422 ctx = context.Background()
423 response, err = stub.ListDevices(ctx, &empty.Empty{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000424 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500425 assert.Nil(t, err)
426 assert.Equal(t, len(devices), len(response.Items))
Kent Hagerman0ab4cb22019-04-24 13:13:35 -0400427 for _, d := range response.Items {
khenaidoo731697e2019-01-29 16:03:29 -0500428 assert.Equal(t, d.AdminState, voltha.AdminState_ENABLED)
429 devices[d.Id] = d
430 }
431
432 //ctx = context.Background()
433 //lresponse, lerr = stub.ListLogicalDevices(ctx, &empty.Empty{})
Rohan Agrawal31f21802020-06-12 05:38:46 +0000434 //logger.Infow(ctx, "response", log.Fields{"res": response, "error": lerr})
khenaidoo731697e2019-01-29 16:03:29 -0500435 //assert.Nil(t, lerr)
436 //assert.Equal(t, numberOfOLTDevices, len(lresponse.Items))
437 //for _, ld := range (lresponse.Items) {
438 // logicalDevices[ld.Id] = ld
439 // // Ensure each logical device have two ports
440 // assert.Equal(t, 2, len(ld.Ports))
441 //}
442
443 //9. Disable all OLTs & check status & check logical device
444
445 //10. Enable all OLTs & Enable all ONUs & check status & check logical device
446
447 //11. Disable all OLTs & check status & check logical device
448
449 //12. Delete all Devices & check status & check logical device
450
451 ////13. Store simulated adapters
452 //stopSimulatedOLTAndONUAdapters()
453 //
454 ////14. Store the core
455 //stopCore()
456 //
457 ////15. Stop Kafka and Etcd
458 //stopKafka()
459 //stopEtcd()
460}
461
khenaidoo731697e2019-01-29 16:03:29 -0500462func TestGetDevice(t *testing.T) {
463 var id common.ID
464 id.Id = "anyid"
465 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
466 response, err := stub.GetDevice(ctx, &id)
467 assert.Nil(t, response)
468 st, _ := status.FromError(err)
469 assert.Equal(t, id.Id, st.Message())
470 assert.Equal(t, codes.NotFound, st.Code())
471}
472
473func TestUpdateLogLevelError(t *testing.T) {
474 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
475 level := voltha.Logging{PackageName: "github.com/opencord/voltha-go/rw_core/core", Level: common.LogLevel_ERROR}
476 response, err := stub.UpdateLogLevel(ctx, &level)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000477 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500478 assert.Equal(t, &empty.Empty{}, response)
479 assert.Nil(t, err)
480}
481
482func TestGetVoltha(t *testing.T) {
483 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
484 response, err := stub.GetVoltha(ctx, &empty.Empty{})
485 assert.Nil(t, response)
486 st, _ := status.FromError(err)
487 assert.Equal(t, "UnImplemented", st.Message())
488}
489
490func TestUpdateLogLevelDebug(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_DEBUG}
493 response, err := stub.UpdateLogLevel(ctx, &level)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000494 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500495 assert.Equal(t, &empty.Empty{}, response)
496 assert.Nil(t, err)
497}
498
499func TestGetCoreInstance(t *testing.T) {
500 id := &voltha.ID{Id: "getCoreInstance"}
501 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
502 response, err := stub.GetCoreInstance(ctx, id)
503 assert.Nil(t, response)
504 st, _ := status.FromError(err)
505 assert.Equal(t, "UnImplemented", st.Message())
506}
507
508func TestGetLogicalDevice(t *testing.T) {
509 id := &voltha.ID{Id: "getLogicalDevice"}
510 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
511 response, err := stub.GetLogicalDevice(ctx, id)
512 assert.Nil(t, response)
513 st, _ := status.FromError(err)
514 assert.Equal(t, id.Id, st.Message())
515 assert.Equal(t, codes.NotFound, st.Code())
516}
517
518func TestGetLogicalDevicePort(t *testing.T) {
519 id := &voltha.LogicalPortId{Id: "GetLogicalDevicePort"}
520 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
521 response, err := stub.GetLogicalDevicePort(ctx, id)
522 assert.Nil(t, response)
523 st, _ := status.FromError(err)
524 assert.Equal(t, "UnImplemented", st.Message())
525}
526
527func TestListLogicalDevicePorts(t *testing.T) {
528 id := &voltha.ID{Id: "listLogicalDevicePorts"}
529 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
530 response, err := stub.ListLogicalDevicePorts(ctx, id)
531 assert.Nil(t, response)
532 st, _ := status.FromError(err)
533 assert.Equal(t, "UnImplemented", st.Message())
534}
535
536func TestListLogicalDeviceFlows(t *testing.T) {
537 id := &voltha.ID{Id: "ListLogicalDeviceFlows"}
538 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
539 response, err := stub.ListLogicalDeviceFlows(ctx, id)
540 assert.Nil(t, response)
541 st, _ := status.FromError(err)
542 assert.Equal(t, "UnImplemented", st.Message())
543}
544
545func TestListLogicalDeviceFlowGroups(t *testing.T) {
546 id := &voltha.ID{Id: "ListLogicalDeviceFlowGroups"}
547 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
548 response, err := stub.ListLogicalDeviceFlowGroups(ctx, id)
549 assert.Nil(t, response)
550 st, _ := status.FromError(err)
551 assert.Equal(t, "UnImplemented", st.Message())
552}
553
554func TestListDevices(t *testing.T) {
555 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
556 response, _ := stub.ListDevices(ctx, &empty.Empty{})
557 assert.Equal(t, len(response.Items), 0)
558}
559
560func TestListAdapters(t *testing.T) {
561 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
562 response, err := stub.ListAdapters(ctx, &empty.Empty{})
563 assert.Nil(t, response)
564 st, _ := status.FromError(err)
565 assert.Equal(t, "UnImplemented", st.Message())
566}
567
568func TestListLogicalDevices(t *testing.T) {
569 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
570 response, _ := stub.ListLogicalDevices(ctx, &empty.Empty{})
571 assert.Equal(t, len(response.Items), 0)
572}
573
574func TestListCoreInstances(t *testing.T) {
575 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
576 response, err := stub.ListCoreInstances(ctx, &empty.Empty{})
577 assert.Nil(t, response)
578 st, _ := status.FromError(err)
579 assert.Equal(t, "UnImplemented", st.Message())
580}
581
582func TestCreateDevice(t *testing.T) {
583 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
584 device := &voltha.Device{Id: "newdevice"}
585 response, err := stub.CreateDevice(ctx, device)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000586 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500587 assert.Equal(t, &voltha.Device{Id: "newdevice"}, response)
588 assert.Nil(t, err)
589}
590
591func TestEnableDevice(t *testing.T) {
592 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
593 id := &voltha.ID{Id: "enabledevice"}
594 response, err := stub.EnableDevice(ctx, id)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000595 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500596 assert.Equal(t, &empty.Empty{}, response)
597 assert.Nil(t, err)
598}
599
600func TestDisableDevice(t *testing.T) {
601 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
602 id := &voltha.ID{Id: "DisableDevice"}
603 response, err := stub.DisableDevice(ctx, id)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000604 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500605 assert.Equal(t, &empty.Empty{}, response)
606 assert.Nil(t, err)
607}
608
609func TestRebootDevice(t *testing.T) {
610 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
611 id := &voltha.ID{Id: "RebootDevice"}
612 response, err := stub.RebootDevice(ctx, id)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000613 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500614 assert.Equal(t, &empty.Empty{}, response)
615 assert.Nil(t, err)
616}
617
618func TestDeleteDevice(t *testing.T) {
619 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
620 id := &voltha.ID{Id: "DeleteDevice"}
621 response, err := stub.DeleteDevice(ctx, id)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000622 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500623 assert.Equal(t, &empty.Empty{}, response)
624 assert.Nil(t, err)
625}
626
627func TestEnableLogicalDevicePort(t *testing.T) {
628 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
629 id := &voltha.LogicalPortId{Id: "EnableLogicalDevicePort"}
630 response, err := stub.EnableLogicalDevicePort(ctx, id)
631 if e, ok := status.FromError(err); ok {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000632 logger.Infow(ctx, "response", log.Fields{"error": err, "errorcode": e.Code(), "msg": e.Message()})
khenaidoo731697e2019-01-29 16:03:29 -0500633 }
Rohan Agrawal31f21802020-06-12 05:38:46 +0000634 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500635 assert.Equal(t, &empty.Empty{}, response)
636 assert.Nil(t, err)
637}
638
639func TestDisableLogicalDevicePort(t *testing.T) {
640 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
641 id := &voltha.LogicalPortId{Id: "DisableLogicalDevicePort"}
642 response, err := stub.DisableLogicalDevicePort(ctx, id)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000643 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500644 assert.Equal(t, &empty.Empty{}, response)
645 assert.Nil(t, err)
646}
647
648func TestUpdateLogicalDeviceFlowGroupTable(t *testing.T) {
649 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
650 flow := &openflow_13.FlowGroupTableUpdate{Id: "UpdateLogicalDeviceFlowGroupTable"}
651 response, err := stub.UpdateLogicalDeviceFlowGroupTable(ctx, flow)
Rohan Agrawal31f21802020-06-12 05:38:46 +0000652 logger.Infow(ctx, "response", log.Fields{"res": response, "error": err})
khenaidoo731697e2019-01-29 16:03:29 -0500653 assert.Equal(t, &empty.Empty{}, response)
654 assert.Nil(t, err)
655}
656
657func TestGetImageDownloadStatus(t *testing.T) {
658 ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs(testMode, "true"))
659 img := &voltha.ImageDownload{Id: "GetImageDownloadStatus"}
660 response, err := stub.GetImageDownloadStatus(ctx, img)
661 assert.Nil(t, response)
662 st, _ := status.FromError(err)
663 assert.Equal(t, "UnImplemented", st.Message())
664}
665
666// TODO: complete the remaining tests
667
668func shutdown() {
669 conn.Close()
670}
671
672func TestMain(m *testing.M) {
673 setup()
674 code := m.Run()
675 shutdown()
676 os.Exit(code)
677}