blob: 4df728f5fd1715e3adff9c892d92a3b5a5a3e15f [file] [log] [blame]
khenaidoo0a822f92019-05-08 15:15:57 -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 core
17
18import (
npujar1d86a522019-11-14 17:11:16 +053019 "reflect"
20 "testing"
21
22 "github.com/opencord/voltha-go/rw_core/coreif"
khenaidooab1f7bd2019-11-14 14:00:27 -050023 "github.com/opencord/voltha-go/rw_core/mocks"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080024 "github.com/opencord/voltha-lib-go/v3/pkg/log"
25 "github.com/opencord/voltha-protos/v3/go/voltha"
khenaidoo0a822f92019-05-08 15:15:57 -040026 "github.com/stretchr/testify/assert"
khenaidoo0a822f92019-05-08 15:15:57 -040027)
28
29var transitionMap *TransitionMap
npujar1d86a522019-11-14 17:11:16 +053030var tdm coreif.DeviceManager
khenaidoo0a822f92019-05-08 15:15:57 -040031
32type testDeviceManager struct {
khenaidooab1f7bd2019-11-14 14:00:27 -050033 mocks.DeviceManager
khenaidoo0a822f92019-05-08 15:15:57 -040034}
35
36func newTestDeviceManager() *testDeviceManager {
37 return &testDeviceManager{}
38}
39
khenaidoo0a822f92019-05-08 15:15:57 -040040func init() {
khenaidooab1f7bd2019-11-14 14:00:27 -050041 if _, err := log.AddPackage(log.JSON, log.WarnLevel, nil); err != nil {
42 log.Fatal("failure-adding-package-core")
43 }
khenaidoo0a822f92019-05-08 15:15:57 -040044 tdm = newTestDeviceManager()
45 transitionMap = NewTransitionMap(tdm)
46}
47
serkant.uluderya2ae470f2020-01-21 11:13:09 -080048func getDevice(root bool, admin voltha.AdminState_Types, conn voltha.ConnectStatus_Types, oper voltha.OperStatus_Types) *voltha.Device {
khenaidoo0a822f92019-05-08 15:15:57 -040049 return &voltha.Device{
50 Id: "test",
51 Root: root,
52 AdminState: admin,
53 ConnectStatus: conn,
54 OperStatus: oper,
55 }
56}
57
58func assertInvalidTransition(t *testing.T, from *voltha.Device, to *voltha.Device) {
59 handlers := transitionMap.GetTransitionHandler(from, to)
60 assert.Equal(t, 1, len(handlers))
61 assert.True(t, reflect.ValueOf(tdm.NotifyInvalidTransition).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
62}
63
64func assertNoOpTransition(t *testing.T, from *voltha.Device, to *voltha.Device) {
65 handlers := transitionMap.GetTransitionHandler(from, to)
66 assert.Equal(t, 0, len(handlers))
67}
68
69func TestValidTransitions(t *testing.T) {
khenaidoo59ef7be2019-06-21 12:40:28 -040070 from := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
71 to := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
khenaidoo0a822f92019-05-08 15:15:57 -040072 handlers := transitionMap.GetTransitionHandler(from, to)
73 assert.Equal(t, 1, len(handlers))
khenaidoo59ef7be2019-06-21 12:40:28 -040074 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
khenaidoo0a822f92019-05-08 15:15:57 -040075
khenaidoo59ef7be2019-06-21 12:40:28 -040076 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
77 to = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
78 handlers = transitionMap.GetTransitionHandler(from, to)
79 assert.Equal(t, 1, len(handlers))
80 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
81
82 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
83 to = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
84 handlers = transitionMap.GetTransitionHandler(from, to)
85 assert.Equal(t, 1, len(handlers))
86 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
87
88 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
89 to = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
90 handlers = transitionMap.GetTransitionHandler(from, to)
91 assert.Equal(t, 1, len(handlers))
92 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
93
94 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
khenaidoo0a822f92019-05-08 15:15:57 -040095 to = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
96 handlers = transitionMap.GetTransitionHandler(from, to)
97 assert.Equal(t, 1, len(handlers))
98 assert.True(t, reflect.ValueOf(tdm.CreateLogicalDevice).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
99
khenaidoo59ef7be2019-06-21 12:40:28 -0400100 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
khenaidoo0a822f92019-05-08 15:15:57 -0400101 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
102 handlers = transitionMap.GetTransitionHandler(from, to)
103 assert.Equal(t, 1, len(handlers))
104 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
105
khenaidoo59ef7be2019-06-21 12:40:28 -0400106 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
107 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
108 handlers = transitionMap.GetTransitionHandler(from, to)
109 assert.Equal(t, 1, len(handlers))
110 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
111
112 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_DISCOVERED)
113 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
114 handlers = transitionMap.GetTransitionHandler(from, to)
115 assert.Equal(t, 1, len(handlers))
116 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
117
118 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
119 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
120 handlers = transitionMap.GetTransitionHandler(from, to)
121 assert.Equal(t, 1, len(handlers))
122 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
123
124 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_DISCOVERED)
125 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
126 handlers = transitionMap.GetTransitionHandler(from, to)
127 assert.Equal(t, 1, len(handlers))
128 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
129
130 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
131 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
132 handlers = transitionMap.GetTransitionHandler(from, to)
133 assert.Equal(t, 1, len(handlers))
134 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
135
136 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
137 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
138 handlers = transitionMap.GetTransitionHandler(from, to)
139 assert.Equal(t, 1, len(handlers))
140 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
141
142 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
143 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE)
144 handlers = transitionMap.GetTransitionHandler(from, to)
145 assert.Equal(t, 1, len(handlers))
146 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
147
148 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
149 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
150 handlers = transitionMap.GetTransitionHandler(from, to)
151 assert.Equal(t, 1, len(handlers))
152 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
153
154 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVATING)
155 to = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_ACTIVE)
156 handlers = transitionMap.GetTransitionHandler(from, to)
157 assert.Equal(t, 1, len(handlers))
158 assert.True(t, reflect.ValueOf(tdm.SetupUNILogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
159
khenaidoo59ef7be2019-06-21 12:40:28 -0400160 from = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
161 to = getDevice(true, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
162 handlers = transitionMap.GetTransitionHandler(from, to)
163 assert.Equal(t, 1, len(handlers))
164 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
165
166 from = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
167 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
168 handlers = transitionMap.GetTransitionHandler(from, to)
169 assert.Equal(t, 1, len(handlers))
170 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
khenaidoo0a822f92019-05-08 15:15:57 -0400171
172 from = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
173 to = getDevice(true, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
174 handlers = transitionMap.GetTransitionHandler(from, to)
Devmalya Paul84169b52019-08-27 19:31:44 -0400175 assert.Equal(t, 4, len(handlers))
176 assert.True(t, reflect.ValueOf(tdm.DisableAllChildDevices).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
177 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
178 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
179 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
khenaidoo0a822f92019-05-08 15:15:57 -0400180
khenaidoo59ef7be2019-06-21 12:40:28 -0400181 from = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
182 to = getDevice(true, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
183 handlers = transitionMap.GetTransitionHandler(from, to)
Devmalya Paul84169b52019-08-27 19:31:44 -0400184 assert.Equal(t, 4, len(handlers))
185 assert.True(t, reflect.ValueOf(tdm.DisableAllChildDevices).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
186 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
187 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
188 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
khenaidoo59ef7be2019-06-21 12:40:28 -0400189
190 from = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
191 to = getDevice(true, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_FAILED)
192 handlers = transitionMap.GetTransitionHandler(from, to)
Devmalya Paul84169b52019-08-27 19:31:44 -0400193 assert.Equal(t, 4, len(handlers))
194 assert.True(t, reflect.ValueOf(tdm.DisableAllChildDevices).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
195 assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
196 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
197 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
khenaidoo59ef7be2019-06-21 12:40:28 -0400198
khenaidoo0a822f92019-05-08 15:15:57 -0400199 from = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
200 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
201 handlers = transitionMap.GetTransitionHandler(from, to)
Chaitrashree G Se935b332020-02-04 17:48:20 -0500202 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())
khenaidoo59ef7be2019-06-21 12:40:28 -0400206
207 from = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
208 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
209 handlers = transitionMap.GetTransitionHandler(from, to)
Chaitrashree G Se935b332020-02-04 17:48:20 -0500210 assert.Equal(t, 3, len(handlers))
211 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
212 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
213 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
khenaidoo59ef7be2019-06-21 12:40:28 -0400214
215 from = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
216 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED)
217 handlers = transitionMap.GetTransitionHandler(from, to)
Chaitrashree G Se935b332020-02-04 17:48:20 -0500218 assert.Equal(t, 3, len(handlers))
219 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
220 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
221 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
222
223 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
224 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
225 handlers = transitionMap.GetTransitionHandler(from, to)
226 assert.Equal(t, 3, len(handlers))
227 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
228 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
229 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
230
231 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_UNKNOWN)
232 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
233 handlers = transitionMap.GetTransitionHandler(from, to)
234 assert.Equal(t, 3, len(handlers))
235 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
236 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
237 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
238
239 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
240 to = getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_FAILED)
241 handlers = transitionMap.GetTransitionHandler(from, to)
242 assert.Equal(t, 3, len(handlers))
243 assert.True(t, reflect.ValueOf(tdm.ChildDeviceLost).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
244 assert.True(t, reflect.ValueOf(tdm.DeleteLogicalPorts).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
245 assert.True(t, reflect.ValueOf(tdm.RunPostDeviceDelete).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
khenaidoo0a822f92019-05-08 15:15:57 -0400246}
247
248func TestInvalidTransitions(t *testing.T) {
khenaidoo59ef7be2019-06-21 12:40:28 -0400249 from := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVE)
250 to := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
khenaidoo0a822f92019-05-08 15:15:57 -0400251 assertInvalidTransition(t, from, to)
252
khenaidoo59ef7be2019-06-21 12:40:28 -0400253 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
254 to = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidoo0a822f92019-05-08 15:15:57 -0400255 assertInvalidTransition(t, from, to)
256
khenaidoo59ef7be2019-06-21 12:40:28 -0400257 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidoo0a822f92019-05-08 15:15:57 -0400258 to = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
259 assertInvalidTransition(t, from, to)
260
khenaidoo59ef7be2019-06-21 12:40:28 -0400261 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
khenaidoo0a822f92019-05-08 15:15:57 -0400262 to = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
263 assertInvalidTransition(t, from, to)
264
265 from = getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
266 to = getDevice(true, voltha.AdminState_UNKNOWN, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
267 assertInvalidTransition(t, from, to)
268
269 from = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
270 to = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
271 assertInvalidTransition(t, from, to)
272
273 from = getDevice(true, voltha.AdminState_DOWNLOADING_IMAGE, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
274 to = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
275 assertInvalidTransition(t, from, to)
276}
277
278func TestNoOpTransitions(t *testing.T) {
279 from := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
280 to := getDevice(true, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
281 assertNoOpTransition(t, from, to)
282
283 from = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
284 to = getDevice(true, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
285 assertNoOpTransition(t, from, to)
286
287 from = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
288 to = getDevice(true, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
289 assertNoOpTransition(t, from, to)
290
291 from = getDevice(false, voltha.AdminState_ENABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
292 to = getDevice(false, voltha.AdminState_DISABLED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_UNKNOWN)
293 assertNoOpTransition(t, from, to)
294
295 from = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_UNKNOWN, voltha.OperStatus_ACTIVATING)
296 to = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
297 assertNoOpTransition(t, from, to)
298
299 from = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_DISCOVERED)
300 to = getDevice(false, voltha.AdminState_PREPROVISIONED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVATING)
301 assertNoOpTransition(t, from, to)
302}