blob: 39d7d0be53981946da7984422e0f3f33ec6d718b [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
24 "github.com/opencord/voltha-protos/v3/go/voltha"
25 "github.com/stretchr/testify/assert"
26)
27
28var transitionMap *TransitionMap
29var tdm DeviceManager
30
31type testDeviceManager struct {
32 DeviceManager
33}
34
35func newTestDeviceManager() *testDeviceManager {
36 return &testDeviceManager{}
37}
38
39func init() {
40 tdm = newTestDeviceManager()
41 transitionMap = NewTransitionMap(tdm)
42}
43
44func getDevice(root bool, admin voltha.AdminState_Types, conn voltha.ConnectStatus_Types, oper voltha.OperStatus_Types) *voltha.Device {
45 return &voltha.Device{
46 Id: "test",
47 Root: root,
48 AdminState: admin,
49 ConnectStatus: conn,
50 OperStatus: oper,
51 }
52}
53
54func assertInvalidTransition(t *testing.T, device, prevDevice *voltha.Device) {
55 handlers := transitionMap.getTransitionHandler(context.Background(), device, prevDevice)
56 assert.Equal(t, 1, len(handlers))
57 assert.True(t, reflect.ValueOf(tdm.NotifyInvalidTransition).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
58}
59
60func assertNoOpTransition(t *testing.T, device, prevDevice *voltha.Device) {
61 handlers := transitionMap.getTransitionHandler(context.Background(), device, prevDevice)
62 assert.Equal(t, 0, len(handlers))
63}
64
65func TestValidTransitions(t *testing.T) {
66 ctx := context.Background()
67 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
68 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
69 handlers := transitionMap.getTransitionHandler(ctx, device, previousDevice)
70 assert.Equal(t, 1, len(handlers))
71 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
72
73 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
74 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
75 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
76 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_UNREACHABLE, voltha.OperStatus_ACTIVE)
81 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
82 assert.Equal(t, 1, len(handlers))
83 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
84
85 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
86 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
87 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
88 assert.Equal(t, 1, len(handlers))
89 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
90
91 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
92 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
93 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
94 assert.Equal(t, 1, len(handlers))
95 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
96
97 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
98 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
99 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
100 assert.Equal(t, 1, len(handlers))
101 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
102
103 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
104 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
105 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
106 assert.Equal(t, 1, len(handlers))
107 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
108
109 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
110 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
111 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
112 assert.Equal(t, 1, len(handlers))
113 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
114
115 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
116 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
117 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
118 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_UNREACHABLE, voltha.OperStatus_DISCOVERED)
122 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
123 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
124 assert.Equal(t, 1, len(handlers))
125 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
126
127 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
128 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
129 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
130 assert.Equal(t, 1, len(handlers))
131 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
132
133 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
134 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
135 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
136 assert.Equal(t, 1, len(handlers))
137 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
138
139 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
140 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
141 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
142 assert.Equal(t, 1, len(handlers))
143 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
144
145 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
146 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
147 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
148 assert.Equal(t, 1, len(handlers))
149 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
150
151 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
152 device = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
153 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
154 assert.Equal(t, 1, len(handlers))
155 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
156
157 previousDevice = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
158 device = getDevice(true, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
159 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
160 assert.Equal(t, 1, len(handlers))
161 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
162
163 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
164 device = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
165 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
166 assert.Equal(t, 1, len(handlers))
167 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
168
169 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
170 device = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED)
171 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
172 assert.Equal(t, 3, len(handlers))
173 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
174 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
175 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
176
177 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
178 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
179 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
180 assert.Equal(t, 4, len(handlers))
181 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
182 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
183 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
184 assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
185
186 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
187 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
188 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
189 assert.Equal(t, 1, len(handlers))
190 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
191
192 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
193 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
194 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
195 assert.Equal(t, 4, len(handlers))
196 assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
197 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
198 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
199 assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
200
201 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
202 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
203 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
204 assert.Equal(t, 1, len(handlers))
205 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
206
207 var deleteDeviceTest = struct {
208 previousDevices []*voltha.Device
209 devices []*voltha.Device
210 expectedParentHandlers []transitionHandler
211 expectedChildHandlers []transitionHandler
212 }{
213 previousDevices: []*voltha.Device{
214 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED),
215 getDevice(false, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
216 getDevice(false, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
217 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
218 getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE),
219 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN),
220 getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN),
221 },
222 devices: []*voltha.Device{
223 getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN),
224 getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN),
225 getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_FAILED),
226 },
227 expectedParentHandlers: []transitionHandler{
228 tdm.DeleteAllLogicalPorts,
229 tdm.DeleteAllChildDevices,
230 tdm.DeleteLogicalDevice,
231 tdm.RunPostDeviceDelete,
232 },
233 expectedChildHandlers: []transitionHandler{
234 tdm.ChildDeviceLost,
235 tdm.DeleteLogicalPorts,
236 tdm.RunPostDeviceDelete,
237 },
238 }
239
240 testName := "delete-parent-device-post-provisioning"
241 for _, previousDevice := range deleteDeviceTest.previousDevices {
242 for _, device := range deleteDeviceTest.devices {
243 device.Root = true
244 t.Run(testName, func(t *testing.T) {
245 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
246 assert.Equal(t, 4, len(handlers))
247 for idx, expHandler := range deleteDeviceTest.expectedParentHandlers {
248 assert.True(t, reflect.ValueOf(expHandler).Pointer() == reflect.ValueOf(handlers[idx]).Pointer())
249 }
250 })
251 }
252 }
253
254 testName = "delete-child-device"
255 for _, previousDevice := range deleteDeviceTest.previousDevices {
256 for _, device := range deleteDeviceTest.devices {
257 device.Root = false
258 t.Run(testName, func(t *testing.T) {
259 handlers = transitionMap.getTransitionHandler(ctx, device, previousDevice)
260 assert.Equal(t, 3, len(handlers))
261 for idx, expHandler := range deleteDeviceTest.expectedChildHandlers {
262 assert.True(t, reflect.ValueOf(expHandler).Pointer() == reflect.ValueOf(handlers[idx]).Pointer())
263 }
264 })
265 }
266 }
267}
268
269func TestInvalidTransitions(t *testing.T) {
270 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
271 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
272 assertInvalidTransition(t, device, previousDevice)
273
274 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
275 device = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
276 assertInvalidTransition(t, device, previousDevice)
277
278 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
279 device = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
280 assertInvalidTransition(t, device, previousDevice)
281
282 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
283 device = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
284 assertInvalidTransition(t, device, previousDevice)
285
286 previousDevice = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
287 device = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
288 assertInvalidTransition(t, device, previousDevice)
289
290 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
291 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
292 assertInvalidTransition(t, device, previousDevice)
293
294 previousDevice = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
295 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
296 assertInvalidTransition(t, device, previousDevice)
297}
298
299func TestNoOpTransitions(t *testing.T) {
300 previousDevice := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
301 device := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
302 assertNoOpTransition(t, device, previousDevice)
303
304 previousDevice = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
305 device = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
306 assertNoOpTransition(t, device, previousDevice)
307
308 previousDevice = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
309 device = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
310 assertNoOpTransition(t, device, previousDevice)
311
312 previousDevice = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
313 device = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
314 assertNoOpTransition(t, device, previousDevice)
315
316 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
317 device = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
318 assertNoOpTransition(t, device, previousDevice)
319
320 previousDevice = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
321 device = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
322 assertNoOpTransition(t, device, previousDevice)
323}
324
325func TestMatch(t *testing.T) {
326 best := &match{admin: currPrevStateMatch, oper: currPrevStateMatch, conn: currPrevStateMatch}
327 m := &match{admin: currStateOnlyMatch, oper: currWildcardMatch, conn: currWildcardMatch}
328 fmt.Println(m.isBetterMatch(best), m.toInt(), best.toInt())
329}