blob: cef7af998004fee199990bddf72f1b788804c465 [file] [log] [blame]
Kent Hagerman6031aad2020-07-29 16:36:33 -04001/*
2 * Copyright 2019-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 */
16package state
17
18import (
19 "context"
20 "fmt"
21 "reflect"
22 "testing"
23
khenaidood948f772021-08-11 17:49:24 -040024 "github.com/opencord/voltha-protos/v5/go/core"
25
26 "github.com/opencord/voltha-protos/v5/go/voltha"
Kent Hagerman6031aad2020-07-29 16:36:33 -040027 "github.com/stretchr/testify/assert"
28)
29
30var transitionMap *TransitionMap
31var tdm DeviceManager
32
33type testDeviceManager struct {
34 DeviceManager
35}
36
37func newTestDeviceManager() *testDeviceManager {
38 return &testDeviceManager{}
39}
40
41func init() {
42 tdm = newTestDeviceManager()
43 transitionMap = NewTransitionMap(tdm)
44}
45
46func getDevice(root bool, admin voltha.AdminState_Types, conn voltha.ConnectStatus_Types, oper voltha.OperStatus_Types) *voltha.Device {
47 return &voltha.Device{
48 Id: "test",
49 Root: root,
50 AdminState: admin,
51 ConnectStatus: conn,
52 OperStatus: oper,
53 }
54}
55
56func assertInvalidTransition(t *testing.T, device, prevDevice *voltha.Device) {
khenaidood948f772021-08-11 17:49:24 -040057 handlers := transitionMap.getTransitionHandler(context.Background(), device, prevDevice, core.DeviceTransientState_NONE,
58 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -040059 assert.Equal(t, 1, len(handlers))
60 assert.True(t, reflect.ValueOf(tdm.NotifyInvalidTransition).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
61}
62
khenaidood948f772021-08-11 17:49:24 -040063func assertNoOpTransition(t *testing.T, device, prevDevice *voltha.Device, transientState core.DeviceTransientState_Types) {
Maninder0aabf0c2021-03-17 14:55:14 +053064 handlers := transitionMap.getTransitionHandler(context.Background(), device, prevDevice, transientState,
65 transientState)
Kent Hagerman6031aad2020-07-29 16:36:33 -040066 assert.Equal(t, 0, len(handlers))
67}
68
69func TestValidTransitions(t *testing.T) {
70 ctx := context.Background()
Himani Chawla2ba1c9c2020-10-07 13:19:03 +053071
Kent Hagerman6031aad2020-07-29 16:36:33 -040072 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
73 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -040074 handlers := transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
75 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -040076 assert.Equal(t, 1, len(handlers))
77 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
78
79 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
80 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -040081 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
82 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -040083 assert.Equal(t, 1, len(handlers))
84 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
85
86 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
87 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -040088 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
89 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -040090 assert.Equal(t, 1, len(handlers))
91 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
92
93 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
94 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -040095 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
96 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -040097 assert.Equal(t, 1, len(handlers))
98 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
99
100 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
101 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400102 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
103 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400104 assert.Equal(t, 1, len(handlers))
105 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
106
107 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
108 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400109 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
110 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400111 assert.Equal(t, 1, len(handlers))
112 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
113
114 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
115 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400116 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
117 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400118 assert.Equal(t, 1, len(handlers))
119 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
120
121 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
122 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400123 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
124 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400125 assert.Equal(t, 1, len(handlers))
126 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
127
128 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
129 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400130 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
131 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400132 assert.Equal(t, 1, len(handlers))
133 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
134
135 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_DISCOVERED)
136 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400137 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
138 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400139 assert.Equal(t, 1, len(handlers))
140 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
141
142 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
143 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400144 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
145 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400146 assert.Equal(t, 1, len(handlers))
147 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
148
149 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
150 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400151 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
152 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400153 assert.Equal(t, 1, len(handlers))
154 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
155
156 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
157 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400158 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
159 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400160 assert.Equal(t, 1, len(handlers))
161 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
162
163 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
164 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400165 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
166 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400167 assert.Equal(t, 1, len(handlers))
168 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
169
170 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
171 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400172 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
173 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400174 assert.Equal(t, 1, len(handlers))
175 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
176
177 previousDevice = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530178 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400179 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_FORCE_DELETING,
180 core.DeviceTransientState_ANY)
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530181 assert.Equal(t, 1, len(handlers))
182 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
183
184 previousDevice = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
185 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400186 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_DELETING_POST_ADAPTER_RESPONSE,
187 core.DeviceTransientState_ANY)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400188 assert.Equal(t, 1, len(handlers))
189 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
190
191 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530192 device = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400193 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_FORCE_DELETING,
194 core.DeviceTransientState_ANY)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400195 assert.Equal(t, 1, len(handlers))
196 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
197
198 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530199 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400200 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_FORCE_DELETING,
201 core.DeviceTransientState_ANY)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400202 assert.Equal(t, 3, len(handlers))
203 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
204 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
205 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
206
207 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
208 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400209 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
210 core.DeviceTransientState_NONE)
serkant.uluderyaad1e6832020-12-17 21:08:38 +0300211 assert.Equal(t, 5, len(handlers))
Kent Hagerman6031aad2020-07-29 16:36:33 -0400212 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
Andrea Campanella832cff62021-11-05 17:05:18 +0100213 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
214 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalMeters).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
serkant.uluderyaad1e6832020-12-17 21:08:38 +0300215 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
216 assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[4]).Pointer())
Kent Hagerman6031aad2020-07-29 16:36:33 -0400217
218 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
219 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400220 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
221 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400222 assert.Equal(t, 1, len(handlers))
223 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
224
225 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
226 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400227 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
228 core.DeviceTransientState_NONE)
serkant.uluderyaad1e6832020-12-17 21:08:38 +0300229 assert.Equal(t, 5, len(handlers))
Kent Hagerman6031aad2020-07-29 16:36:33 -0400230 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
Andrea Campanella832cff62021-11-05 17:05:18 +0100231 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
232 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalMeters).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
serkant.uluderyaad1e6832020-12-17 21:08:38 +0300233 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
234 assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[4]).Pointer())
Kent Hagerman6031aad2020-07-29 16:36:33 -0400235
236 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
237 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400238 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_NONE,
239 core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400240 assert.Equal(t, 1, len(handlers))
241 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
242
Maninder0aabf0c2021-03-17 14:55:14 +0530243 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
244 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400245 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
246 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530247 assert.Equal(t, 1, len(handlers))
248 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
249
250 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
251 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400252 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
253 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530254 assert.Equal(t, 1, len(handlers))
255 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
256
257 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
258 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
khenaidood948f772021-08-11 17:49:24 -0400259 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
260 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530261 assert.Equal(t, 1, len(handlers))
262 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
263
264 previousDevice = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
265 device = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400266 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
267 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530268 assert.Equal(t, 1, len(handlers))
269 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
270
271 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
272 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400273 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
274 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530275 assert.Equal(t, 1, len(handlers))
276 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
277
Maninder581cf4b2021-06-16 22:42:07 +0530278 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
279 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400280 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
281 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder581cf4b2021-06-16 22:42:07 +0530282 assert.Equal(t, 1, len(handlers))
283 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
284
285 previousDevice = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
286 device = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400287 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
288 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder581cf4b2021-06-16 22:42:07 +0530289 assert.Equal(t, 1, len(handlers))
290 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
291
292 previousDevice = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
293 device = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400294 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
295 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder581cf4b2021-06-16 22:42:07 +0530296 assert.Equal(t, 1, len(handlers))
297 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
298
299 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
300 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400301 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
302 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder581cf4b2021-06-16 22:42:07 +0530303 assert.Equal(t, 1, len(handlers))
304 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
305
306 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
307 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_RECONCILING_FAILED)
khenaidood948f772021-08-11 17:49:24 -0400308 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS,
309 core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder581cf4b2021-06-16 22:42:07 +0530310 assert.Equal(t, 1, len(handlers))
311 assert.True(t, reflect.ValueOf(tdm.ReconcilingCleanup).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
312
Kent Hagerman6031aad2020-07-29 16:36:33 -0400313 var deleteDeviceTest = struct {
314 previousDevices []*voltha.Device
315 devices []*voltha.Device
316 expectedParentHandlers []transitionHandler
317 expectedChildHandlers []transitionHandler
318 }{
319 previousDevices: []*voltha.Device{
320 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED),
321 getDevice(false, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
322 getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
323 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
324 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE),
325 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN),
326 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN),
327 },
328 devices: []*voltha.Device{
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530329 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
330 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN),
331 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_FAILED),
Kent Hagerman6031aad2020-07-29 16:36:33 -0400332 },
333 expectedParentHandlers: []transitionHandler{
334 tdm.DeleteAllLogicalPorts,
335 tdm.DeleteAllChildDevices,
Andrea Campanella832cff62021-11-05 17:05:18 +0100336 tdm.DeleteAllLogicalMeters,
Kent Hagerman6031aad2020-07-29 16:36:33 -0400337 tdm.RunPostDeviceDelete,
338 },
339 expectedChildHandlers: []transitionHandler{
340 tdm.ChildDeviceLost,
341 tdm.DeleteLogicalPorts,
342 tdm.RunPostDeviceDelete,
343 },
344 }
345
346 testName := "delete-parent-device-post-provisioning"
347 for _, previousDevice := range deleteDeviceTest.previousDevices {
348 for _, device := range deleteDeviceTest.devices {
349 device.Root = true
350 t.Run(testName, func(t *testing.T) {
khenaidood948f772021-08-11 17:49:24 -0400351 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_FORCE_DELETING,
352 core.DeviceTransientState_ANY)
Andrea Campanella832cff62021-11-05 17:05:18 +0100353 assert.Equal(t, 4, len(handlers))
Kent Hagerman6031aad2020-07-29 16:36:33 -0400354 for idx, expHandler := range deleteDeviceTest.expectedParentHandlers {
355 assert.True(t, reflect.ValueOf(expHandler).Pointer() == reflect.ValueOf(handlers[idx]).Pointer())
356 }
357 })
358 }
359 }
360
361 testName = "delete-child-device"
362 for _, previousDevice := range deleteDeviceTest.previousDevices {
363 for _, device := range deleteDeviceTest.devices {
364 device.Root = false
365 t.Run(testName, func(t *testing.T) {
khenaidood948f772021-08-11 17:49:24 -0400366 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice, core.DeviceTransientState_FORCE_DELETING,
367 core.DeviceTransientState_ANY)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400368 assert.Equal(t, 3, len(handlers))
369 for idx, expHandler := range deleteDeviceTest.expectedChildHandlers {
370 assert.True(t, reflect.ValueOf(expHandler).Pointer() == reflect.ValueOf(handlers[idx]).Pointer())
371 }
372 })
373 }
374 }
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530375
Kent Hagerman6031aad2020-07-29 16:36:33 -0400376}
377
378func TestInvalidTransitions(t *testing.T) {
379 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
380 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
381 assertInvalidTransition(t, device, previousDevice)
382
383 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
384 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
385 assertInvalidTransition(t, device, previousDevice)
386
387 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
388 device = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
389 assertInvalidTransition(t, device, previousDevice)
390
391 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400392 device = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
393 assertInvalidTransition(t, device, previousDevice)
394
395 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
396 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
397 assertInvalidTransition(t, device, previousDevice)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400398}
399
400func TestNoOpTransitions(t *testing.T) {
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530401
Kent Hagerman6031aad2020-07-29 16:36:33 -0400402 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
403 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400404 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400405
406 previousDevice = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
407 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400408 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400409
410 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
411 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400412 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400413
414 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
415 device = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400416 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400417
418 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
419 device = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
khenaidood948f772021-08-11 17:49:24 -0400420 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400421
422 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
423 device = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
khenaidood948f772021-08-11 17:49:24 -0400424 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Andrea Campanella3614a922021-02-25 12:40:42 +0100425
426 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
427 device = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400428 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Andrea Campanella3614a922021-02-25 12:40:42 +0100429
430 previousDevice = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
431 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
khenaidood948f772021-08-11 17:49:24 -0400432 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_NONE)
Maninder0aabf0c2021-03-17 14:55:14 +0530433
434 previousDevice = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
435 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400436 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530437
438 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
439 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400440 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530441
442 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
443 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400444 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530445
446 previousDevice = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
447 device = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400448 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530449
450 previousDevice = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
451 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400452 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530453
454 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
455 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400456 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530457
458 previousDevice = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
459 device = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400460 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530461
462 previousDevice = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
463 device = getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400464 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Maninder0aabf0c2021-03-17 14:55:14 +0530465
466 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
467 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_RECONCILING)
khenaidood948f772021-08-11 17:49:24 -0400468 assertNoOpTransition(t, device, previousDevice, core.DeviceTransientState_RECONCILE_IN_PROGRESS)
Kent Hagerman6031aad2020-07-29 16:36:33 -0400469}
470
471func TestMatch(t *testing.T) {
Himani Chawla2ba1c9c2020-10-07 13:19:03 +0530472 best := &match{admin: currPrevStateMatch, oper: currPrevStateMatch, conn: currPrevStateMatch, transient: currWildcardMatch}
473 m := &match{admin: currStateOnlyMatch, oper: currWildcardMatch, conn: currWildcardMatch, transient: currWildcardMatch}
Kent Hagerman6031aad2020-07-29 16:36:33 -0400474 fmt.Println(m.isBetterMatch(best), m.toInt(), best.toInt())
475}