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