sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 1 | /* |
Joey Armstrong | 393daca | 2023-07-06 08:47:54 -0400 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 3 | |
Joey Armstrong | 393daca | 2023-07-06 08:47:54 -0400 | [diff] [blame] | 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 |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 7 | |
Joey Armstrong | 393daca | 2023-07-06 08:47:54 -0400 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 9 | |
Joey Armstrong | 393daca | 2023-07-06 08:47:54 -0400 | [diff] [blame] | 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. |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 15 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/hex" |
| 21 | "encoding/json" |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 22 | "strconv" |
| 23 | "strings" |
| 24 | "sync" |
| 25 | "testing" |
| 26 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 27 | "github.com/google/uuid" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 29 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 31 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 33 | "github.com/stretchr/testify/assert" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | var ( |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 37 | BenchmarkProxyLogger log.CLogger |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 38 | TestProxyRootLogicalDevice *Proxy |
| 39 | TestProxyRootDevice *Proxy |
| 40 | TestProxyRootAdapter *Proxy |
| 41 | TestProxyDeviceID string |
| 42 | TestProxyAdapterID string |
| 43 | TestProxyLogicalDeviceID string |
| 44 | TestProxyTargetDeviceID string |
| 45 | TestProxyTargetLogicalDeviceID string |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 46 | TestProxyStats *openflow_13.OfpFlowStats |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 47 | TestProxyDevice *voltha.Device |
| 48 | TestProxyLogicalDevice *voltha.LogicalDevice |
| 49 | TestProxyAdapter *voltha.Adapter |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 50 | ) |
| 51 | |
| 52 | func init() { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 53 | BenchmarkProxyLogger, _ = log.RegisterPackage(log.JSON, log.DebugLevel, log.Fields{"instanceId": "PLT"}) |
| 54 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 55 | //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"}) |
| 56 | //Setup default logger - applies for packages that do not have specific logger set |
| 57 | if _, err := log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": "PLT"}); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 58 | BenchmarkProxyLogger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 59 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 60 | |
| 61 | // Update all loggers (provisioned via init) with a common field |
| 62 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": "PLT"}); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 63 | BenchmarkProxyLogger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 64 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 65 | log.SetPackageLogLevel("github.com/opencord/voltha-go/db/model", log.DebugLevel) |
| 66 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 67 | proxy := NewDBPath(mockBackend) |
| 68 | TestProxyRootLogicalDevice = proxy.Proxy("logical_devices") |
| 69 | TestProxyRootDevice = proxy.Proxy("device") |
| 70 | TestProxyRootAdapter = proxy.Proxy("adapters") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 71 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 72 | TestProxyStats = &openflow_13.OfpFlowStats{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 73 | Id: 1111, |
| 74 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 75 | TestProxyDevice = &voltha.Device{ |
| 76 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 77 | Type: "simulated_olt", |
| 78 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 79 | AdminState: voltha.AdminState_PREPROVISIONED, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 80 | } |
| 81 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 82 | TestProxyLogicalDevice = &voltha.LogicalDevice{ |
| 83 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 84 | DatapathId: 0, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 85 | } |
| 86 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 87 | TestProxyAdapter = &voltha.Adapter{ |
| 88 | Id: TestProxyAdapterID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 89 | Vendor: "test-adapter-vendor", |
| 90 | Version: "test-adapter-version", |
| 91 | } |
| 92 | } |
| 93 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 94 | type mockKV struct { |
| 95 | kvstore.Client // pretend we implement everything |
| 96 | |
| 97 | mutex sync.RWMutex |
| 98 | data map[string]interface{} |
| 99 | } |
| 100 | |
| 101 | func (kv *mockKV) List(_ context.Context, key string) (map[string]*kvstore.KVPair, error) { |
| 102 | kv.mutex.RLock() |
| 103 | defer kv.mutex.RUnlock() |
| 104 | |
| 105 | ret := make(map[string]*kvstore.KVPair, len(kv.data)) |
| 106 | for k, v := range kv.data { |
| 107 | if strings.HasPrefix(k, key) { |
| 108 | ret[k] = &kvstore.KVPair{Key: k, Value: v} |
| 109 | } |
| 110 | } |
| 111 | return ret, nil |
| 112 | } |
| 113 | func (kv *mockKV) Get(_ context.Context, key string) (*kvstore.KVPair, error) { |
| 114 | kv.mutex.RLock() |
| 115 | defer kv.mutex.RUnlock() |
| 116 | |
| 117 | if val, have := kv.data[key]; have { |
| 118 | return &kvstore.KVPair{Key: key, Value: val}, nil |
| 119 | } |
| 120 | return nil, nil |
| 121 | } |
| 122 | func (kv *mockKV) Put(_ context.Context, key string, value interface{}) error { |
| 123 | kv.mutex.Lock() |
| 124 | defer kv.mutex.Unlock() |
| 125 | |
| 126 | kv.data[key] = value |
| 127 | return nil |
| 128 | } |
| 129 | func (kv *mockKV) Delete(_ context.Context, key string) error { |
| 130 | kv.mutex.Lock() |
| 131 | defer kv.mutex.Unlock() |
| 132 | |
| 133 | delete(kv.data, key) |
| 134 | return nil |
| 135 | } |
| 136 | |
| 137 | var mockBackend = &db.Backend{Client: &mockKV{data: make(map[string]interface{})}} |
| 138 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 139 | func TestProxy_1_1_1_Add_NewDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 140 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 141 | devIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 142 | TestProxyDeviceID = "0001" + hex.EncodeToString(devIDBin)[:12] |
| 143 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 144 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 145 | if err := TestProxyRootDevice.Set(context.Background(), TestProxyDeviceID, TestProxyDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 146 | BenchmarkProxyLogger.Errorf(ctx, "Failed to add test proxy device due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 147 | t.Errorf("failed to add device: %s", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 148 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 149 | t.Logf("Added device : %+v", TestProxyDevice.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 150 | |
| 151 | // Verify that the added device can now be retrieved |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 152 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 153 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 154 | BenchmarkProxyLogger.Errorf(ctx, "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] | 155 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 156 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 157 | t.Error("Failed to find added device") |
| 158 | } else { |
| 159 | djson, _ := json.Marshal(d) |
| 160 | t.Logf("Found device: %s", string(djson)) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 165 | ctx := context.Background() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 166 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 167 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 168 | if err := TestProxyRootDevice.Set(context.Background(), "devices", TestProxyDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 169 | BenchmarkProxyLogger.Errorf(ctx, "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] | 170 | assert.NotNil(t, err) |
| 171 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 172 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 173 | d := &voltha.Device{} |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 174 | |
| 175 | have, err := TestProxyRootDevice.Get(context.Background(), TestProxyDeviceID, d) |
| 176 | if err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 177 | BenchmarkProxyLogger.Errorf(ctx, "Failed get device info from test proxy due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 178 | assert.NotNil(t, err) |
| 179 | } else if !have { |
| 180 | t.Error("Failed to find added device") |
| 181 | } else { |
| 182 | if d.String() != TestProxyDevice.String() { |
| 183 | t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, d) |
| 184 | } |
| 185 | djson, _ := json.Marshal(d) |
| 186 | t.Logf("Found device: %s", string(djson)) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 187 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 188 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | func TestProxy_1_1_3_Add_NewAdapter(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 192 | ctx := context.Background() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 193 | TestProxyAdapterID = "test-adapter" |
| 194 | TestProxyAdapter.Id = TestProxyAdapterID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 195 | |
| 196 | // Add the adapter |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 197 | if err := TestProxyRootAdapter.Set(context.Background(), TestProxyAdapterID, TestProxyAdapter); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 198 | BenchmarkProxyLogger.Errorf(ctx, "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] | 199 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 200 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 201 | t.Logf("Added adapter : %+v", TestProxyAdapter.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 202 | } |
| 203 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 204 | // Verify that the added device can now be retrieved |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 205 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 206 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 207 | BenchmarkProxyLogger.Errorf(ctx, "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] | 208 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 209 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 210 | t.Error("Failed to find added adapter") |
| 211 | } else { |
| 212 | djson, _ := json.Marshal(d) |
| 213 | t.Logf("Found adapter: %s", string(djson)) |
| 214 | } |
| 215 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | func TestProxy_1_2_1_Get_AllDevices(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 219 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 220 | var devices []*voltha.Device |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 221 | if err := TestProxyRootDevice.List(context.Background(), &devices); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 222 | BenchmarkProxyLogger.Errorf(ctx, "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] | 223 | assert.NotNil(t, err) |
| 224 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 225 | if len(devices) == 0 { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 226 | t.Error("there are no available devices to retrieve") |
| 227 | } else { |
| 228 | // Save the target device id for later tests |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 229 | TestProxyTargetDeviceID = devices[0].Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 230 | t.Logf("retrieved all devices: %+v", devices) |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 235 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 236 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 237 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 238 | BenchmarkProxyLogger.Errorf(ctx, "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] | 239 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 240 | } else if !have { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 241 | t.Errorf("Failed to find device : %s", TestProxyTargetDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 242 | } else { |
| 243 | djson, _ := json.Marshal(d) |
| 244 | t.Logf("Found device: %s", string(djson)) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | func TestProxy_1_3_1_Update_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 249 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 250 | var fwVersion int |
| 251 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 252 | retrieved := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 253 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 254 | BenchmarkProxyLogger.Errorf(ctx, "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] | 255 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 256 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 257 | t.Error("Failed to get device") |
| 258 | } else { |
| 259 | t.Logf("Found raw device (root proxy): %+v", retrieved) |
| 260 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 261 | if retrieved.FirmwareVersion == "n/a" { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 262 | fwVersion = 0 |
| 263 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 264 | fwVersion, _ = strconv.Atoi(retrieved.FirmwareVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 265 | fwVersion++ |
| 266 | } |
| 267 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 268 | retrieved.FirmwareVersion = strconv.Itoa(fwVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 269 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 270 | if err := TestProxyRootDevice.Set(context.Background(), TestProxyTargetDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 271 | BenchmarkProxyLogger.Errorf(ctx, "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] | 272 | assert.NotNil(t, err) |
| 273 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 274 | afterUpdate := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 275 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, afterUpdate); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 276 | BenchmarkProxyLogger.Errorf(ctx, "Failed to get device info from test proxy due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 277 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 278 | t.Error("Failed to update device") |
| 279 | } else { |
| 280 | t.Logf("Updated device : %+v", afterUpdate) |
| 281 | } |
| 282 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 283 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 284 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 285 | BenchmarkProxyLogger.Errorf(ctx, "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] | 286 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 287 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 288 | t.Error("Failed to find updated device (root proxy)") |
| 289 | } else { |
| 290 | djson, _ := json.Marshal(d) |
| 291 | t.Logf("Found device (root proxy): %s raw: %+v", string(djson), d) |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 296 | func TestProxy_1_3_3_Update_Adapter(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 297 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 298 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 299 | adaptersProxy := NewDBPath(mockBackend).Proxy("adapters") |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 300 | |
| 301 | retrieved := &voltha.Adapter{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 302 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 303 | BenchmarkProxyLogger.Errorf(ctx, "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] | 304 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 305 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 306 | t.Error("Failed to get adapter") |
| 307 | } else { |
| 308 | t.Logf("Found raw adapter (root proxy): %+v", retrieved) |
| 309 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 310 | retrieved.Version = "test-adapter-version-2" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 311 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 312 | if err := adaptersProxy.Set(context.Background(), TestProxyAdapterID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 313 | BenchmarkProxyLogger.Errorf(ctx, "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] | 314 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 315 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 316 | t.Logf("Updated adapter : %s", retrieved.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 319 | d := &voltha.Adapter{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 320 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 321 | BenchmarkProxyLogger.Errorf(ctx, "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] | 322 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 323 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 324 | t.Error("Failed to find updated adapter (root proxy)") |
| 325 | } else { |
| 326 | djson, _ := json.Marshal(d) |
| 327 | t.Logf("Found adapter (root proxy): %s raw: %+v", string(djson), d) |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | func TestProxy_1_4_1_Remove_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 333 | ctx := context.Background() |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 334 | if err := TestProxyRootDevice.Remove(context.Background(), TestProxyDeviceID); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 335 | BenchmarkProxyLogger.Errorf(ctx, "Failed to remove device from devices proxy due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 336 | t.Errorf("failed to remove device: %s", err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 337 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 338 | t.Logf("Removed device : %+v", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 341 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 342 | have, err := TestProxyRootDevice.Get(context.Background(), TestProxyDeviceID, d) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 343 | if err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 344 | BenchmarkProxyLogger.Errorf(ctx, "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] | 345 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 346 | } else if have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 347 | djson, _ := json.Marshal(d) |
| 348 | t.Errorf("Device was not removed - %s", djson) |
| 349 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 350 | t.Logf("Device was removed: %s", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 355 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 356 | |
| 357 | ldIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 358 | TestProxyLogicalDeviceID = "0001" + hex.EncodeToString(ldIDBin)[:12] |
| 359 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 360 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 361 | if err := TestProxyRootLogicalDevice.Set(context.Background(), TestProxyLogicalDeviceID, TestProxyLogicalDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 362 | BenchmarkProxyLogger.Errorf(ctx, "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] | 363 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 364 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 365 | t.Logf("Added logical device : %s", TestProxyLogicalDevice.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 366 | } |
| 367 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 368 | ld := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 369 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyLogicalDeviceID, ld); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 370 | BenchmarkProxyLogger.Errorf(ctx, "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] | 371 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 372 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 373 | t.Error("Failed to find added logical device") |
| 374 | } else { |
| 375 | ldJSON, _ := json.Marshal(ld) |
| 376 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 377 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 381 | ctx := context.Background() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 382 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 383 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 384 | if err := TestProxyRootLogicalDevice.Set(context.Background(), "logical_devices", TestProxyLogicalDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 385 | BenchmarkProxyLogger.Errorf(ctx, "Failed to add logical device due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 386 | assert.NotNil(t, err) |
| 387 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 388 | |
| 389 | device := &voltha.LogicalDevice{} |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 390 | have, err := TestProxyRootLogicalDevice.Get(context.Background(), "logical_devices", device) |
| 391 | if err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 392 | BenchmarkProxyLogger.Errorf(ctx, "Failed to get logical device info from logical device proxy due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 393 | assert.NotNil(t, err) |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 394 | return |
| 395 | } |
| 396 | if !have { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 397 | t.Error("Failed to find added logical device") |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 398 | return |
| 399 | } |
| 400 | if device.String() != TestProxyLogicalDevice.String() { |
| 401 | t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, device) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 406 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 407 | var logicalDevices []*voltha.LogicalDevice |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 408 | if err := TestProxyRootLogicalDevice.List(context.Background(), &logicalDevices); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 409 | BenchmarkProxyLogger.Errorf(ctx, "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] | 410 | assert.NotNil(t, err) |
| 411 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 412 | if len(logicalDevices) == 0 { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 413 | t.Error("there are no available logical devices to retrieve") |
| 414 | } else { |
| 415 | // Save the target device id for later tests |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 416 | TestProxyTargetLogicalDeviceID = logicalDevices[0].Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 417 | t.Logf("retrieved all logical devices: %+v", logicalDevices) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 422 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 423 | ld := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 424 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, ld); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 425 | BenchmarkProxyLogger.Errorf(ctx, "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] | 426 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 427 | } else if !have { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 428 | t.Errorf("Failed to find logical device : %s", TestProxyTargetLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 429 | } else { |
| 430 | ldJSON, _ := json.Marshal(ld) |
| 431 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 432 | } |
| 433 | |
| 434 | } |
| 435 | |
| 436 | func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 437 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 438 | var fwVersion int |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 439 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 440 | retrieved := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 441 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 442 | BenchmarkProxyLogger.Errorf(ctx, "Failed to get logical devices due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 443 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 444 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 445 | t.Error("Failed to get logical device") |
| 446 | } else { |
| 447 | t.Logf("Found raw logical device (root proxy): %+v", retrieved) |
| 448 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 449 | if retrieved.RootDeviceId == "" { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 450 | fwVersion = 0 |
| 451 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 452 | fwVersion, _ = strconv.Atoi(retrieved.RootDeviceId) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 453 | fwVersion++ |
| 454 | } |
| 455 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 456 | retrieved.RootDeviceId = strconv.Itoa(fwVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 457 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 458 | if err := TestProxyRootLogicalDevice.Set(context.Background(), TestProxyTargetLogicalDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 459 | BenchmarkProxyLogger.Errorf(ctx, "Faield to update logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 460 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 461 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 462 | t.Log("Updated logical device") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 465 | d := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 466 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 467 | BenchmarkProxyLogger.Errorf(ctx, "Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 468 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 469 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 470 | t.Error("Failed to find updated logical device (root proxy)") |
| 471 | } else { |
| 472 | djson, _ := json.Marshal(d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 473 | t.Logf("Found logical device (root proxy): %s raw: %+v", string(djson), d) |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 478 | func TestProxy_2_4_1_Remove_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 479 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 480 | if err := TestProxyRootLogicalDevice.Remove(context.Background(), "logical_devices/"+TestProxyLogicalDeviceID); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 481 | BenchmarkProxyLogger.Errorf(ctx, "Failed to remove device from logical devices proxy due to error: %v", err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 482 | t.Errorf("Failed to remove logical device: %s", err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 483 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 484 | t.Logf("Removed device : %+v", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 485 | } |
| 486 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 487 | d := &voltha.LogicalDevice{} |
| 488 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), "logical_devices/"+TestProxyLogicalDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 489 | BenchmarkProxyLogger.Errorf(ctx, "Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 490 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 491 | } else if have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 492 | djson, _ := json.Marshal(d) |
| 493 | t.Errorf("Device was not removed - %s", djson) |
| 494 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 495 | t.Logf("Device was removed: %s", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 496 | } |
| 497 | } |