sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/hex" |
| 21 | "encoding/json" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 22 | "math/rand" |
| 23 | "reflect" |
| 24 | "strconv" |
| 25 | "testing" |
| 26 | "time" |
| 27 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 28 | "github.com/golang/protobuf/proto" |
| 29 | "github.com/google/uuid" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 31 | "github.com/opencord/voltha-protos/v3/go/common" |
| 32 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 33 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 34 | "github.com/stretchr/testify/assert" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | var ( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 38 | TestProxyRoot Root |
| 39 | TestProxyRootLogicalDevice *Proxy |
| 40 | TestProxyRootDevice *Proxy |
| 41 | TestProxyRootAdapter *Proxy |
| 42 | TestProxyDeviceID string |
| 43 | TestProxyAdapterID string |
| 44 | TestProxyLogicalDeviceID string |
| 45 | TestProxyTargetDeviceID string |
| 46 | TestProxyTargetLogicalDeviceID string |
| 47 | TestProxyLogicalPorts []*voltha.LogicalPort |
| 48 | TestProxyPorts []*voltha.Port |
| 49 | TestProxyStats *openflow_13.OfpFlowStats |
| 50 | TestProxyFlows *openflow_13.Flows |
| 51 | TestProxyDevice *voltha.Device |
| 52 | TestProxyLogicalDevice *voltha.LogicalDevice |
| 53 | TestProxyAdapter *voltha.Adapter |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 54 | ) |
| 55 | |
| 56 | func init() { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 57 | var err error |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 58 | TestProxyRoot = NewRoot(&voltha.Voltha{}, nil) |
| 59 | if TestProxyRootLogicalDevice, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 60 | log.With(log.Fields{"error": err}).Fatal("Cannot create logical device proxy") |
| 61 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 62 | if TestProxyRootDevice, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 63 | log.With(log.Fields{"error": err}).Fatal("Cannot create device proxy") |
| 64 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 65 | if TestProxyRootAdapter, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 66 | log.With(log.Fields{"error": err}).Fatal("Cannot create adapter proxy") |
| 67 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 68 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 69 | TestProxyLogicalPorts = []*voltha.LogicalPort{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 70 | { |
| 71 | Id: "123", |
| 72 | DeviceId: "logicalport-0-device-id", |
| 73 | DevicePortNo: 123, |
| 74 | RootPort: false, |
| 75 | }, |
| 76 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 77 | TestProxyPorts = []*voltha.Port{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 78 | { |
| 79 | PortNo: 123, |
| 80 | Label: "test-port-0", |
| 81 | Type: voltha.Port_PON_OLT, |
| 82 | AdminState: common.AdminState_ENABLED, |
| 83 | OperStatus: common.OperStatus_ACTIVE, |
| 84 | DeviceId: "etcd_port-0-device-id", |
| 85 | Peers: []*voltha.Port_PeerPort{}, |
| 86 | }, |
| 87 | } |
| 88 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 89 | TestProxyStats = &openflow_13.OfpFlowStats{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 90 | Id: 1111, |
| 91 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 92 | TestProxyFlows = &openflow_13.Flows{ |
| 93 | Items: []*openflow_13.OfpFlowStats{TestProxyStats}, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 94 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 95 | TestProxyDevice = &voltha.Device{ |
| 96 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 97 | Type: "simulated_olt", |
| 98 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 99 | AdminState: voltha.AdminState_PREPROVISIONED, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 100 | Flows: TestProxyFlows, |
| 101 | Ports: TestProxyPorts, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 102 | } |
| 103 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 104 | TestProxyLogicalDevice = &voltha.LogicalDevice{ |
| 105 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 106 | DatapathId: 0, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 107 | Ports: TestProxyLogicalPorts, |
| 108 | Flows: TestProxyFlows, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 109 | } |
| 110 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 111 | TestProxyAdapter = &voltha.Adapter{ |
| 112 | Id: TestProxyAdapterID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 113 | Vendor: "test-adapter-vendor", |
| 114 | Version: "test-adapter-version", |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | func TestProxy_1_1_1_Add_NewDevice(t *testing.T) { |
| 119 | devIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 120 | TestProxyDeviceID = "0001" + hex.EncodeToString(devIDBin)[:12] |
| 121 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 122 | |
| 123 | preAddExecuted := make(chan struct{}) |
| 124 | postAddExecuted := make(chan struct{}) |
| 125 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 126 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 127 | devicesProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/devices", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 128 | if err != nil { |
| 129 | log.With(log.Fields{"error": err}).Fatal("Cannot create devices proxy") |
| 130 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 131 | devicesProxy.RegisterCallback(PreAdd, commonCallback2, "PRE_ADD Device container changes") |
| 132 | devicesProxy.RegisterCallback(PostAdd, commonCallback2, "POST_ADD Device container changes") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 133 | |
| 134 | // Register ADD instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 135 | TestProxyRootDevice.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions", &preAddExecutedPtr) |
| 136 | TestProxyRootDevice.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 137 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 138 | added, err := TestProxyRootDevice.Add(context.Background(), "/devices", TestProxyDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 139 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 140 | BenchmarkProxyLogger.Errorf("Failed to add test proxy device due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 141 | assert.NotNil(t, err) |
| 142 | } |
| 143 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 144 | t.Error("Failed to add device") |
| 145 | } else { |
| 146 | t.Logf("Added device : %+v", added) |
| 147 | } |
| 148 | |
| 149 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 150 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 151 | } |
| 152 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 153 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // Verify that the added device can now be retrieved |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 157 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 158 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 159 | BenchmarkProxyLogger.Errorf("Failed get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 160 | assert.NotNil(t, err) |
| 161 | } |
| 162 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 163 | t.Error("Failed to find added device") |
| 164 | } else { |
| 165 | djson, _ := json.Marshal(d) |
| 166 | t.Logf("Found device: %s", string(djson)) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 171 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 172 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 173 | added, err := TestProxyRootDevice.Add(context.Background(), "/devices", TestProxyDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 174 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 175 | BenchmarkProxyLogger.Errorf("Failed to add device to test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 176 | assert.NotNil(t, err) |
| 177 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 178 | if added.(proto.Message).String() != reflect.ValueOf(TestProxyDevice).Interface().(proto.Message).String() { |
| 179 | t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, added) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | func verifyGotResponse(callbackIndicator <-chan struct{}) bool { |
| 184 | timeout := time.After(1 * time.Second) |
| 185 | // Wait until the channel closes, or we time out |
| 186 | select { |
| 187 | case <-callbackIndicator: |
| 188 | // Received response successfully |
| 189 | return true |
| 190 | |
| 191 | case <-timeout: |
| 192 | // Got a timeout! fail with a timeout error |
| 193 | return false |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func TestProxy_1_1_3_Add_NewAdapter(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 198 | TestProxyAdapterID = "test-adapter" |
| 199 | TestProxyAdapter.Id = TestProxyAdapterID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 200 | preAddExecuted := make(chan struct{}) |
| 201 | postAddExecuted := make(chan struct{}) |
| 202 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 203 | |
| 204 | // Register ADD instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 205 | TestProxyRootAdapter.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions for adapters", &preAddExecutedPtr) |
| 206 | TestProxyRootAdapter.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions for adapters", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 207 | |
| 208 | // Add the adapter |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 209 | added, err := TestProxyRootAdapter.Add(context.Background(), "/adapters", TestProxyAdapter, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 210 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 211 | BenchmarkProxyLogger.Errorf("Failed to add adapter to test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 212 | assert.NotNil(t, err) |
| 213 | } |
| 214 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 215 | t.Error("Failed to add adapter") |
| 216 | } else { |
| 217 | t.Logf("Added adapter : %+v", added) |
| 218 | } |
| 219 | |
| 220 | verifyGotResponse(postAddExecuted) |
| 221 | |
| 222 | // Verify that the added device can now be retrieved |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 223 | d, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 224 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 225 | BenchmarkProxyLogger.Errorf("Failed to retrieve device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 226 | assert.NotNil(t, err) |
| 227 | } |
| 228 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 229 | t.Error("Failed to find added adapter") |
| 230 | } else { |
| 231 | djson, _ := json.Marshal(d) |
| 232 | t.Logf("Found adapter: %s", string(djson)) |
| 233 | } |
| 234 | |
| 235 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 236 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 237 | } |
| 238 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 239 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | func TestProxy_1_2_1_Get_AllDevices(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 244 | devices, err := TestProxyRootDevice.Get(context.Background(), "/devices", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 245 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 246 | BenchmarkProxyLogger.Errorf("Failed to get all devices info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 247 | assert.NotNil(t, err) |
| 248 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 249 | if len(devices.([]interface{})) == 0 { |
| 250 | t.Error("there are no available devices to retrieve") |
| 251 | } else { |
| 252 | // Save the target device id for later tests |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 253 | TestProxyTargetDeviceID = devices.([]interface{})[0].(*voltha.Device).Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 254 | t.Logf("retrieved all devices: %+v", devices) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 259 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 260 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 261 | BenchmarkProxyLogger.Errorf("Failed to get single device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 262 | assert.NotNil(t, err) |
| 263 | } |
| 264 | if !reflect.ValueOf(d).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 265 | t.Errorf("Failed to find device : %s", TestProxyTargetDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 266 | } else { |
| 267 | djson, _ := json.Marshal(d) |
| 268 | t.Logf("Found device: %s", string(djson)) |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | func TestProxy_1_3_1_Update_Device(t *testing.T) { |
| 273 | var fwVersion int |
| 274 | |
| 275 | preUpdateExecuted := make(chan struct{}) |
| 276 | postUpdateExecuted := make(chan struct{}) |
| 277 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 278 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 279 | retrieved, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 280 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 281 | BenchmarkProxyLogger.Errorf("Failed to get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 282 | assert.NotNil(t, err) |
| 283 | } |
| 284 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 285 | t.Error("Failed to get device") |
| 286 | } else { |
| 287 | t.Logf("Found raw device (root proxy): %+v", retrieved) |
| 288 | |
| 289 | if retrieved.(*voltha.Device).FirmwareVersion == "n/a" { |
| 290 | fwVersion = 0 |
| 291 | } else { |
| 292 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.Device).FirmwareVersion) |
| 293 | fwVersion++ |
| 294 | } |
| 295 | |
| 296 | retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion) |
| 297 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 298 | TestProxyRootDevice.RegisterCallback( |
| 299 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 300 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 301 | "PreUpdate instructions (root proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 302 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 303 | TestProxyRootDevice.RegisterCallback( |
| 304 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 305 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 306 | "PostUpdate instructions (root proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 307 | ) |
| 308 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 309 | afterUpdate, err := TestProxyRootDevice.Update(context.Background(), "/devices/"+TestProxyTargetDeviceID, retrieved, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 310 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 311 | BenchmarkProxyLogger.Errorf("Failed to update device info test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 312 | assert.NotNil(t, err) |
| 313 | } |
| 314 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 315 | t.Error("Failed to update device") |
| 316 | } else { |
| 317 | t.Logf("Updated device : %+v", afterUpdate) |
| 318 | } |
| 319 | |
| 320 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 321 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 322 | } |
| 323 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 324 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 325 | } |
| 326 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 327 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 328 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 329 | BenchmarkProxyLogger.Errorf("Failed to get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 330 | assert.NotNil(t, err) |
| 331 | } |
| 332 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 333 | t.Error("Failed to find updated device (root proxy)") |
| 334 | } else { |
| 335 | djson, _ := json.Marshal(d) |
| 336 | t.Logf("Found device (root proxy): %s raw: %+v", string(djson), d) |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | func TestProxy_1_3_2_Update_DeviceFlows(t *testing.T) { |
| 342 | // Get a device proxy and update a specific port |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 343 | devFlowsProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/devices/"+TestProxyDeviceID+"/flows", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 344 | if err != nil { |
| 345 | log.With(log.Fields{"error": err}).Fatal("Cannot create device flows proxy") |
| 346 | } |
| 347 | flows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 348 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 349 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 350 | assert.NotNil(t, err) |
| 351 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 352 | flows.(*openflow_13.Flows).Items[0].TableId = 2244 |
| 353 | |
| 354 | preUpdateExecuted := make(chan struct{}) |
| 355 | postUpdateExecuted := make(chan struct{}) |
| 356 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 357 | |
| 358 | devFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 359 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 360 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 361 | "PreUpdate instructions (flows proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 362 | ) |
| 363 | devFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 364 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 365 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 366 | "PostUpdate instructions (flows proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 367 | ) |
| 368 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 369 | kvFlows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 370 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 371 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 372 | assert.NotNil(t, err) |
| 373 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 374 | |
| 375 | if reflect.DeepEqual(flows, kvFlows) { |
| 376 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 377 | } |
| 378 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 379 | updated, err := devFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "") |
| 380 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 381 | BenchmarkProxyLogger.Errorf("Failed to update flows in device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 382 | assert.NotNil(t, err) |
| 383 | } |
| 384 | if updated == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 385 | t.Error("Failed to update flow") |
| 386 | } else { |
| 387 | t.Logf("Updated flows : %+v", updated) |
| 388 | } |
| 389 | |
| 390 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 391 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 392 | } |
| 393 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 394 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 395 | } |
| 396 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 397 | d, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 398 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 399 | BenchmarkProxyLogger.Errorf("Failed to get flows in device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 400 | assert.NotNil(t, err) |
| 401 | } |
| 402 | if d == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 403 | t.Error("Failed to find updated flows (flows proxy)") |
| 404 | } else { |
| 405 | djson, _ := json.Marshal(d) |
| 406 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 407 | } |
| 408 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 409 | d, err = TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID+"/flows", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 410 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 411 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 412 | assert.NotNil(t, err) |
| 413 | } |
| 414 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 415 | t.Error("Failed to find updated flows (root proxy)") |
| 416 | } else { |
| 417 | djson, _ := json.Marshal(d) |
| 418 | t.Logf("Found flows (root proxy): %s", string(djson)) |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | func TestProxy_1_3_3_Update_Adapter(t *testing.T) { |
| 423 | preUpdateExecuted := make(chan struct{}) |
| 424 | postUpdateExecuted := make(chan struct{}) |
| 425 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 426 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 427 | adaptersProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/adapters", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 428 | if err != nil { |
| 429 | log.With(log.Fields{"error": err}).Fatal("Cannot create adapters proxy") |
| 430 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 431 | retrieved, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 432 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 433 | BenchmarkProxyLogger.Errorf("Failed to retrieve adapter info from adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 434 | assert.NotNil(t, err) |
| 435 | } |
| 436 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 437 | t.Error("Failed to get adapter") |
| 438 | } else { |
| 439 | t.Logf("Found raw adapter (root proxy): %+v", retrieved) |
| 440 | |
| 441 | retrieved.(*voltha.Adapter).Version = "test-adapter-version-2" |
| 442 | |
| 443 | adaptersProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 444 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 445 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 446 | "PreUpdate instructions for adapters", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 447 | ) |
| 448 | adaptersProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 449 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 450 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 451 | "PostUpdate instructions for adapters", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 452 | ) |
| 453 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 454 | afterUpdate, err := adaptersProxy.Update(context.Background(), "/"+TestProxyAdapterID, retrieved, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 455 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 456 | BenchmarkProxyLogger.Errorf("Failed to update adapter info in adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 457 | assert.NotNil(t, err) |
| 458 | } |
| 459 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 460 | t.Error("Failed to update adapter") |
| 461 | } else { |
| 462 | t.Logf("Updated adapter : %+v", afterUpdate) |
| 463 | } |
| 464 | |
| 465 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 466 | t.Error("PreUpdate callback for adapter was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 467 | } |
| 468 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 469 | t.Error("PostUpdate callback for adapter was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 470 | } |
| 471 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 472 | d, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 473 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 474 | BenchmarkProxyLogger.Errorf("Failed to get updated adapter info from adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 475 | assert.NotNil(t, err) |
| 476 | } |
| 477 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 478 | t.Error("Failed to find updated adapter (root proxy)") |
| 479 | } else { |
| 480 | djson, _ := json.Marshal(d) |
| 481 | t.Logf("Found adapter (root proxy): %s raw: %+v", string(djson), d) |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | func TestProxy_1_4_1_Remove_Device(t *testing.T) { |
| 487 | preRemoveExecuted := make(chan struct{}) |
| 488 | postRemoveExecuted := make(chan struct{}) |
| 489 | preRemoveExecutedPtr, postRemoveExecutedPtr := preRemoveExecuted, postRemoveExecuted |
| 490 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 491 | TestProxyRootDevice.RegisterCallback( |
| 492 | PreRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 493 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 494 | "PreRemove instructions (root proxy)", &preRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 495 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 496 | TestProxyRootDevice.RegisterCallback( |
| 497 | PostRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 498 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 499 | "PostRemove instructions (root proxy)", &postRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 500 | ) |
| 501 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 502 | removed, err := TestProxyRootDevice.Remove(context.Background(), "/devices/"+TestProxyDeviceID, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 503 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 504 | BenchmarkProxyLogger.Errorf("Failed to remove device from devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 505 | assert.NotNil(t, err) |
| 506 | } |
| 507 | if removed == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 508 | t.Error("Failed to remove device") |
| 509 | } else { |
| 510 | t.Logf("Removed device : %+v", removed) |
| 511 | } |
| 512 | |
| 513 | if !verifyGotResponse(preRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 514 | t.Error("PreRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 515 | } |
| 516 | if !verifyGotResponse(postRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 517 | t.Error("PostRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 518 | } |
| 519 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 520 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 521 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 522 | BenchmarkProxyLogger.Errorf("Failed to get device info from devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 523 | assert.NotNil(t, err) |
| 524 | } |
| 525 | if reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 526 | djson, _ := json.Marshal(d) |
| 527 | t.Errorf("Device was not removed - %s", djson) |
| 528 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 529 | t.Logf("Device was removed: %s", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) { |
| 534 | |
| 535 | ldIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 536 | TestProxyLogicalDeviceID = "0001" + hex.EncodeToString(ldIDBin)[:12] |
| 537 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 538 | |
| 539 | preAddExecuted := make(chan struct{}) |
| 540 | postAddExecuted := make(chan struct{}) |
| 541 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 542 | |
| 543 | // Register |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 544 | TestProxyRootLogicalDevice.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions", &preAddExecutedPtr) |
| 545 | TestProxyRootLogicalDevice.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 546 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 547 | added, err := TestProxyRootLogicalDevice.Add(context.Background(), "/logical_devices", TestProxyLogicalDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 548 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 549 | BenchmarkProxyLogger.Errorf("Failed to add new logical device into proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 550 | assert.NotNil(t, err) |
| 551 | } |
| 552 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 553 | t.Error("Failed to add logical device") |
| 554 | } else { |
| 555 | t.Logf("Added logical device : %+v", added) |
| 556 | } |
| 557 | |
| 558 | verifyGotResponse(postAddExecuted) |
| 559 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 560 | ld, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 561 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 562 | BenchmarkProxyLogger.Errorf("Failed to get logical device info from logical device proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 563 | assert.NotNil(t, err) |
| 564 | } |
| 565 | if !reflect.ValueOf(ld).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 566 | t.Error("Failed to find added logical device") |
| 567 | } else { |
| 568 | ldJSON, _ := json.Marshal(ld) |
| 569 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 570 | } |
| 571 | |
| 572 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 573 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 574 | } |
| 575 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 576 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 581 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 582 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 583 | added, err := TestProxyRootLogicalDevice.Add(context.Background(), "/logical_devices", TestProxyLogicalDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 584 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 585 | BenchmarkProxyLogger.Errorf("Failed to add logical device due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 586 | assert.NotNil(t, err) |
| 587 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 588 | if added.(proto.Message).String() != reflect.ValueOf(TestProxyLogicalDevice).Interface().(proto.Message).String() { |
| 589 | t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, added) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 594 | logicalDevices, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 595 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 596 | BenchmarkProxyLogger.Errorf("Failed to get all logical devices from proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 597 | assert.NotNil(t, err) |
| 598 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 599 | if len(logicalDevices.([]interface{})) == 0 { |
| 600 | t.Error("there are no available logical devices to retrieve") |
| 601 | } else { |
| 602 | // Save the target device id for later tests |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 603 | TestProxyTargetLogicalDeviceID = logicalDevices.([]interface{})[0].(*voltha.LogicalDevice).Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 604 | t.Logf("retrieved all logical devices: %+v", logicalDevices) |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 609 | ld, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 610 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 611 | BenchmarkProxyLogger.Errorf("Failed to get single logical device from proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 612 | assert.NotNil(t, err) |
| 613 | } |
| 614 | if !reflect.ValueOf(ld).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 615 | t.Errorf("Failed to find logical device : %s", TestProxyTargetLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 616 | } else { |
| 617 | ldJSON, _ := json.Marshal(ld) |
| 618 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 619 | } |
| 620 | |
| 621 | } |
| 622 | |
| 623 | func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) { |
| 624 | var fwVersion int |
| 625 | preUpdateExecuted := make(chan struct{}) |
| 626 | postUpdateExecuted := make(chan struct{}) |
| 627 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 628 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 629 | retrieved, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 630 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 631 | BenchmarkProxyLogger.Errorf("Failed to get logical devices due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 632 | assert.NotNil(t, err) |
| 633 | } |
| 634 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 635 | t.Error("Failed to get logical device") |
| 636 | } else { |
| 637 | t.Logf("Found raw logical device (root proxy): %+v", retrieved) |
| 638 | |
| 639 | if retrieved.(*voltha.LogicalDevice).RootDeviceId == "" { |
| 640 | fwVersion = 0 |
| 641 | } else { |
| 642 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.LogicalDevice).RootDeviceId) |
| 643 | fwVersion++ |
| 644 | } |
| 645 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 646 | TestProxyRootLogicalDevice.RegisterCallback( |
| 647 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 648 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 649 | "PreUpdate instructions (root proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 650 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 651 | TestProxyRootLogicalDevice.RegisterCallback( |
| 652 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 653 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 654 | "PostUpdate instructions (root proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 655 | ) |
| 656 | |
| 657 | retrieved.(*voltha.LogicalDevice).RootDeviceId = strconv.Itoa(fwVersion) |
| 658 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 659 | afterUpdate, err := TestProxyRootLogicalDevice.Update(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, retrieved, false, |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 660 | "") |
| 661 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 662 | BenchmarkProxyLogger.Errorf("Faield to update logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 663 | assert.NotNil(t, err) |
| 664 | } |
| 665 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 666 | t.Error("Failed to update logical device") |
| 667 | } else { |
| 668 | t.Logf("Updated logical device : %+v", afterUpdate) |
| 669 | } |
| 670 | |
| 671 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 672 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 673 | } |
| 674 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 675 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 676 | } |
| 677 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 678 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 679 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 680 | BenchmarkProxyLogger.Errorf("Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 681 | assert.NotNil(t, err) |
| 682 | } |
| 683 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 684 | t.Error("Failed to find updated logical device (root proxy)") |
| 685 | } else { |
| 686 | djson, _ := json.Marshal(d) |
| 687 | |
| 688 | t.Logf("Found logical device (root proxy): %s raw: %+v", string(djson), d) |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | func TestProxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) { |
| 694 | // Get a device proxy and update a specific port |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 695 | ldFlowsProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID+"/flows", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 696 | if err != nil { |
| 697 | log.With(log.Fields{"error": err}).Fatal("Failed to create logical device flows proxy") |
| 698 | } |
| 699 | flows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 700 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 701 | BenchmarkProxyLogger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 702 | assert.NotNil(t, err) |
| 703 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 704 | flows.(*openflow_13.Flows).Items[0].TableId = rand.Uint32() |
| 705 | t.Logf("before updated flows: %+v", flows) |
| 706 | |
| 707 | ldFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 708 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 709 | commonCallback2, |
| 710 | ) |
| 711 | ldFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 712 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 713 | commonCallback2, |
| 714 | ) |
| 715 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 716 | kvFlows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 717 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 718 | BenchmarkProxyLogger.Errorf("Faield to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 719 | assert.NotNil(t, err) |
| 720 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 721 | if reflect.DeepEqual(flows, kvFlows) { |
| 722 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 723 | } |
| 724 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 725 | updated, err := ldFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "") |
| 726 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 727 | BenchmarkProxyLogger.Errorf("Failed to update flows in logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 728 | assert.NotNil(t, err) |
| 729 | } |
| 730 | if updated == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 731 | t.Error("Failed to update logical device flows") |
| 732 | } else { |
| 733 | t.Logf("Updated logical device flows : %+v", updated) |
| 734 | } |
| 735 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 736 | if d, _ := ldFlowsProxy.Get(context.Background(), "/", 0, false, ""); d == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 737 | t.Error("Failed to find updated logical device flows (flows proxy)") |
| 738 | } else { |
| 739 | djson, _ := json.Marshal(d) |
| 740 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 741 | } |
| 742 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 743 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID+"/flows", 0, false, |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 744 | "") |
| 745 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 746 | BenchmarkProxyLogger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 747 | assert.NotNil(t, err) |
| 748 | } |
| 749 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 750 | t.Error("Failed to find updated logical device flows (root proxy)") |
| 751 | } else { |
| 752 | djson, _ := json.Marshal(d) |
| 753 | t.Logf("Found logical device flows (root proxy): %s", string(djson)) |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | func TestProxy_2_4_1_Remove_Device(t *testing.T) { |
| 758 | preRemoveExecuted := make(chan struct{}) |
| 759 | postRemoveExecuted := make(chan struct{}) |
| 760 | preRemoveExecutedPtr, postRemoveExecutedPtr := preRemoveExecuted, postRemoveExecuted |
| 761 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 762 | TestProxyRootLogicalDevice.RegisterCallback( |
| 763 | PreRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 764 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 765 | "PreRemove instructions (root proxy)", &preRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 766 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 767 | TestProxyRootLogicalDevice.RegisterCallback( |
| 768 | PostRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 769 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 770 | "PostRemove instructions (root proxy)", &postRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 771 | ) |
| 772 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 773 | removed, err := TestProxyRootLogicalDevice.Remove(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 774 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 775 | BenchmarkProxyLogger.Errorf("Failed to remove device from logical devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 776 | assert.NotNil(t, err) |
| 777 | } |
| 778 | if removed == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 779 | t.Error("Failed to remove logical device") |
| 780 | } else { |
| 781 | t.Logf("Removed device : %+v", removed) |
| 782 | } |
| 783 | |
| 784 | if !verifyGotResponse(preRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 785 | t.Error("PreRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 786 | } |
| 787 | if !verifyGotResponse(postRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 788 | t.Error("PostRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 789 | } |
| 790 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 791 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 792 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 793 | BenchmarkProxyLogger.Errorf("Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 794 | assert.NotNil(t, err) |
| 795 | } |
| 796 | if reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 797 | djson, _ := json.Marshal(d) |
| 798 | t.Errorf("Device was not removed - %s", djson) |
| 799 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 800 | t.Logf("Device was removed: %s", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | // ----------------------------- |
| 805 | // Callback tests |
| 806 | // ----------------------------- |
| 807 | |
| 808 | func TestProxy_Callbacks_1_Register(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 809 | TestProxyRootDevice.RegisterCallback(PreAdd, firstCallback, "abcde", "12345") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 810 | |
| 811 | m := make(map[string]string) |
| 812 | m["name"] = "fghij" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 813 | TestProxyRootDevice.RegisterCallback(PreAdd, secondCallback, m, 1.2345) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 814 | |
| 815 | d := &voltha.Device{Id: "12345"} |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 816 | TestProxyRootDevice.RegisterCallback(PreAdd, thirdCallback, "klmno", d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | func TestProxy_Callbacks_2_Invoke_WithNoInterruption(t *testing.T) { |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 820 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 821 | defer cancel() |
| 822 | TestProxyRootDevice.InvokeCallbacks(ctx, PreAdd, false, nil) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | func TestProxy_Callbacks_3_Invoke_WithInterruption(t *testing.T) { |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 826 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 827 | defer cancel() |
| 828 | TestProxyRootDevice.InvokeCallbacks(ctx, PreAdd, true, nil) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | func TestProxy_Callbacks_4_Unregister(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 832 | TestProxyRootDevice.UnregisterCallback(PreAdd, firstCallback) |
| 833 | TestProxyRootDevice.UnregisterCallback(PreAdd, secondCallback) |
| 834 | TestProxyRootDevice.UnregisterCallback(PreAdd, thirdCallback) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | //func TestProxy_Callbacks_5_Add(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 838 | // TestProxyRootDevice.Root.AddCallback(TestProxyRootDevice.InvokeCallbacks, PostUpdate, false, "some data", "some new data") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 839 | //} |
| 840 | // |
| 841 | //func TestProxy_Callbacks_6_Execute(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 842 | // TestProxyRootDevice.Root.ExecuteCallbacks() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 843 | //} |