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" |
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" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 29 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
| 30 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 31 | "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v4/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{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 174 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 175 | 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] | 176 | assert.NotNil(t, err) |
| 177 | } else if !have { |
| 178 | t.Error("Failed to find added device") |
| 179 | } else { |
| 180 | if d.String() != TestProxyDevice.String() { |
| 181 | t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, d) |
| 182 | } |
| 183 | djson, _ := json.Marshal(d) |
| 184 | t.Logf("Found device: %s", string(djson)) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 185 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 186 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | func TestProxy_1_1_3_Add_NewAdapter(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 190 | ctx := context.Background() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 191 | TestProxyAdapterID = "test-adapter" |
| 192 | TestProxyAdapter.Id = TestProxyAdapterID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 193 | |
| 194 | // Add the adapter |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 195 | if err := TestProxyRootAdapter.Set(context.Background(), TestProxyAdapterID, TestProxyAdapter); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 196 | 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] | 197 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 198 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 199 | t.Logf("Added adapter : %+v", TestProxyAdapter.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 200 | } |
| 201 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 202 | // Verify that the added device can now be retrieved |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 203 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 204 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 205 | 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] | 206 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 207 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 208 | t.Error("Failed to find added adapter") |
| 209 | } else { |
| 210 | djson, _ := json.Marshal(d) |
| 211 | t.Logf("Found adapter: %s", string(djson)) |
| 212 | } |
| 213 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | func TestProxy_1_2_1_Get_AllDevices(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 217 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 218 | var devices []*voltha.Device |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 219 | if err := TestProxyRootDevice.List(context.Background(), &devices); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 220 | 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] | 221 | assert.NotNil(t, err) |
| 222 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 223 | if len(devices) == 0 { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 224 | t.Error("there are no available devices to retrieve") |
| 225 | } else { |
| 226 | // Save the target device id for later tests |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 227 | TestProxyTargetDeviceID = devices[0].Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 228 | t.Logf("retrieved all devices: %+v", devices) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 233 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 234 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 235 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 236 | 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] | 237 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 238 | } else if !have { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 239 | t.Errorf("Failed to find device : %s", TestProxyTargetDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 240 | } else { |
| 241 | djson, _ := json.Marshal(d) |
| 242 | t.Logf("Found device: %s", string(djson)) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | func TestProxy_1_3_1_Update_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 247 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 248 | var fwVersion int |
| 249 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 250 | retrieved := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 251 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 252 | 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] | 253 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 254 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 255 | t.Error("Failed to get device") |
| 256 | } else { |
| 257 | t.Logf("Found raw device (root proxy): %+v", retrieved) |
| 258 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 259 | if retrieved.FirmwareVersion == "n/a" { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 260 | fwVersion = 0 |
| 261 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 262 | fwVersion, _ = strconv.Atoi(retrieved.FirmwareVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 263 | fwVersion++ |
| 264 | } |
| 265 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 266 | retrieved.FirmwareVersion = strconv.Itoa(fwVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 267 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 268 | if err := TestProxyRootDevice.Set(context.Background(), TestProxyTargetDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 269 | 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] | 270 | assert.NotNil(t, err) |
| 271 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 272 | afterUpdate := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 273 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, afterUpdate); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 274 | 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] | 275 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 276 | t.Error("Failed to update device") |
| 277 | } else { |
| 278 | t.Logf("Updated device : %+v", afterUpdate) |
| 279 | } |
| 280 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 281 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 282 | if have, err := TestProxyRootDevice.Get(context.Background(), TestProxyTargetDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 283 | 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] | 284 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 285 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 286 | t.Error("Failed to find updated device (root proxy)") |
| 287 | } else { |
| 288 | djson, _ := json.Marshal(d) |
| 289 | t.Logf("Found device (root proxy): %s raw: %+v", string(djson), d) |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 294 | func TestProxy_1_3_3_Update_Adapter(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 295 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 296 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 297 | adaptersProxy := NewDBPath(mockBackend).Proxy("adapters") |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 298 | |
| 299 | retrieved := &voltha.Adapter{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 300 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 301 | 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] | 302 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 303 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 304 | t.Error("Failed to get adapter") |
| 305 | } else { |
| 306 | t.Logf("Found raw adapter (root proxy): %+v", retrieved) |
| 307 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 308 | retrieved.Version = "test-adapter-version-2" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 309 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 310 | if err := adaptersProxy.Set(context.Background(), TestProxyAdapterID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 311 | 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] | 312 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 313 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 314 | t.Logf("Updated adapter : %s", retrieved.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 317 | d := &voltha.Adapter{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 318 | if have, err := TestProxyRootAdapter.Get(context.Background(), TestProxyAdapterID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 319 | 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] | 320 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 321 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 322 | t.Error("Failed to find updated adapter (root proxy)") |
| 323 | } else { |
| 324 | djson, _ := json.Marshal(d) |
| 325 | t.Logf("Found adapter (root proxy): %s raw: %+v", string(djson), d) |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func TestProxy_1_4_1_Remove_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 331 | ctx := context.Background() |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 332 | if err := TestProxyRootDevice.Remove(context.Background(), TestProxyDeviceID); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 333 | 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] | 334 | t.Errorf("failed to remove device: %s", err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 335 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 336 | t.Logf("Removed device : %+v", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 337 | } |
| 338 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 339 | d := &voltha.Device{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 340 | have, err := TestProxyRootDevice.Get(context.Background(), TestProxyDeviceID, d) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 341 | if err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 342 | 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] | 343 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 344 | } else if have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 345 | djson, _ := json.Marshal(d) |
| 346 | t.Errorf("Device was not removed - %s", djson) |
| 347 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 348 | t.Logf("Device was removed: %s", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 353 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 354 | |
| 355 | ldIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 356 | TestProxyLogicalDeviceID = "0001" + hex.EncodeToString(ldIDBin)[:12] |
| 357 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 358 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 359 | if err := TestProxyRootLogicalDevice.Set(context.Background(), TestProxyLogicalDeviceID, TestProxyLogicalDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 360 | 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] | 361 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 362 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 363 | t.Logf("Added logical device : %s", TestProxyLogicalDevice.Id) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 364 | } |
| 365 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 366 | ld := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 367 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyLogicalDeviceID, ld); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 368 | 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] | 369 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 370 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 371 | t.Error("Failed to find added logical device") |
| 372 | } else { |
| 373 | ldJSON, _ := json.Marshal(ld) |
| 374 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 375 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 379 | ctx := context.Background() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 380 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 381 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 382 | if err := TestProxyRootLogicalDevice.Set(context.Background(), "logical_devices", TestProxyLogicalDevice); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 383 | 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] | 384 | assert.NotNil(t, err) |
| 385 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 386 | |
| 387 | device := &voltha.LogicalDevice{} |
| 388 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), "logical_devices", device); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 389 | 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] | 390 | assert.NotNil(t, err) |
| 391 | } else if !have { |
| 392 | t.Error("Failed to find added logical device") |
| 393 | } else { |
| 394 | if device.String() != TestProxyLogicalDevice.String() { |
| 395 | t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, device) |
| 396 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
| 400 | func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 401 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 402 | var logicalDevices []*voltha.LogicalDevice |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 403 | if err := TestProxyRootLogicalDevice.List(context.Background(), &logicalDevices); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 404 | 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] | 405 | assert.NotNil(t, err) |
| 406 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 407 | if len(logicalDevices) == 0 { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 408 | t.Error("there are no available logical devices to retrieve") |
| 409 | } else { |
| 410 | // Save the target device id for later tests |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 411 | TestProxyTargetLogicalDeviceID = logicalDevices[0].Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 412 | t.Logf("retrieved all logical devices: %+v", logicalDevices) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 417 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 418 | ld := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 419 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, ld); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 420 | 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] | 421 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 422 | } else if !have { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 423 | t.Errorf("Failed to find logical device : %s", TestProxyTargetLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 424 | } else { |
| 425 | ldJSON, _ := json.Marshal(ld) |
| 426 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 427 | } |
| 428 | |
| 429 | } |
| 430 | |
| 431 | func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 432 | ctx := context.Background() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 433 | var fwVersion int |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 434 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 435 | retrieved := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 436 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 437 | 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] | 438 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 439 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 440 | t.Error("Failed to get logical device") |
| 441 | } else { |
| 442 | t.Logf("Found raw logical device (root proxy): %+v", retrieved) |
| 443 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 444 | if retrieved.RootDeviceId == "" { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 445 | fwVersion = 0 |
| 446 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 447 | fwVersion, _ = strconv.Atoi(retrieved.RootDeviceId) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 448 | fwVersion++ |
| 449 | } |
| 450 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 451 | retrieved.RootDeviceId = strconv.Itoa(fwVersion) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 452 | |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 453 | if err := TestProxyRootLogicalDevice.Set(context.Background(), TestProxyTargetLogicalDeviceID, retrieved); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 454 | 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] | 455 | assert.NotNil(t, err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 456 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 457 | t.Log("Updated logical device") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 458 | } |
| 459 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 460 | d := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 461 | if have, err := TestProxyRootLogicalDevice.Get(context.Background(), TestProxyTargetLogicalDeviceID, d); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 462 | 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] | 463 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 464 | } else if !have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 465 | t.Error("Failed to find updated logical device (root proxy)") |
| 466 | } else { |
| 467 | djson, _ := json.Marshal(d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 468 | t.Logf("Found logical device (root proxy): %s raw: %+v", string(djson), d) |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 473 | func TestProxy_2_4_1_Remove_Device(t *testing.T) { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 474 | ctx := context.Background() |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 475 | if err := TestProxyRootLogicalDevice.Remove(context.Background(), "logical_devices/"+TestProxyLogicalDeviceID); err != nil { |
Girish Kumar | f8d4f8d | 2020-08-18 11:45:30 +0000 | [diff] [blame] | 476 | 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] | 477 | t.Errorf("Failed to remove logical device: %s", err) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 478 | } else { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 479 | t.Logf("Removed device : %+v", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 480 | } |
| 481 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 482 | d := &voltha.LogicalDevice{} |
| 483 | 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] | 484 | 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] | 485 | assert.NotNil(t, err) |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 486 | } else if have { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 487 | djson, _ := json.Marshal(d) |
| 488 | t.Errorf("Device was not removed - %s", djson) |
| 489 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 490 | t.Logf("Device was removed: %s", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 491 | } |
| 492 | } |