2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024-2025 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the 'License');
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an 'AS IS' BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.integration.functional.ncmp
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse
25 import org.onap.cps.ncmp.api.inventory.models.CmHandleState
26 import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
27 import org.onap.cps.ncmp.api.inventory.models.LockReasonCategory
28 import org.onap.cps.ncmp.api.inventory.models.UpgradedCmHandles
29 import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl
30 import spock.util.concurrent.PollingConditions
32 class CmHandleUpgradeSpec extends CpsIntegrationSpecBase {
34 NetworkCmProxyInventoryFacadeImpl objectUnderTest
36 def cmHandleId = 'ch-1'
37 def cmHandleIdWithExistingModuleSetTag = 'ch-2'
40 objectUnderTest = networkCmProxyInventoryFacade
43 def 'Upgrade CM-handle with and without (new) module set tags.'() {
44 given: 'a CM-handle is created with expected initial modules: M1 and M2'
45 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M2']
46 registerCmHandle(DMI1_URL, cmHandleId, initialModuleSetTag)
47 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
49 when: "the CM-handle is upgraded with given moduleSetTag '${updatedModuleSetTag}'"
50 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [cmHandleId], moduleSetTag: updatedModuleSetTag)
51 def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistration(
52 new DmiPluginRegistration(dmiPlugin: DMI1_URL, upgradedCmHandles: cmHandlesToUpgrade))
54 then: 'registration gives successful response'
55 assert dmiPluginRegistrationResponse.upgradedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
57 and: 'CM-handle is in LOCKED state due to MODULE_UPGRADE'
58 def cmHandleCompositeState = objectUnderTest.getCmHandleCompositeState(cmHandleId)
59 assert cmHandleCompositeState.cmHandleState == CmHandleState.LOCKED
60 assert cmHandleCompositeState.lockReason.lockReasonCategory == LockReasonCategory.MODULE_UPGRADE
61 assert cmHandleCompositeState.lockReason.details == "Upgrade to ModuleSetTag: ${updatedModuleSetTag}"
63 when: 'DMI will return different modules for upgrade: M1 and M3'
64 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M3']
66 and: 'the module sync watchdog is triggered twice'
67 2.times { moduleSyncWatchdog.moduleSyncAdvisedCmHandles() }
69 then: 'CM-handle goes to READY state'
70 new PollingConditions().within(MODULE_SYNC_WAIT_TIME_IN_SECONDS, () -> {
71 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(cmHandleId).cmHandleState
74 and: 'the CM-handle has expected moduleSetTag'
75 assert objectUnderTest.getNcmpServiceCmHandle(cmHandleId).moduleSetTag == updatedModuleSetTag
77 and: 'CM-handle has expected updated modules: M1 and M3'
78 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
80 cleanup: 'deregister CM-handle and remove all associated module resources'
81 deregisterCmHandle(DMI1_URL, cmHandleId)
83 where: 'following module set tags are used'
84 initialModuleSetTag | updatedModuleSetTag
85 NO_MODULE_SET_TAG | NO_MODULE_SET_TAG
86 NO_MODULE_SET_TAG | 'new@set'
87 'initial set' | NO_MODULE_SET_TAG
88 'initial set' | 'new@set'
91 def 'Upgrade CM-handle with existing moduleSetTag.'() {
92 given: 'DMI will return modules for registration'
93 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M2']
94 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleIdWithExistingModuleSetTag] = ['M1', 'M3']
95 and: "an existing CM-handle handle with moduleSetTag '${updatedModuleSetTag}'"
96 registerCmHandle(DMI1_URL, cmHandleIdWithExistingModuleSetTag, updatedModuleSetTag)
97 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleIdWithExistingModuleSetTag).moduleName.sort()
98 and: "a CM-handle with moduleSetTag '${initialModuleSetTag}' which will be upgraded"
99 registerCmHandle(DMI1_URL, cmHandleId, initialModuleSetTag)
100 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
102 when: "CM-handle is upgraded to moduleSetTag '${updatedModuleSetTag}'"
103 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [cmHandleId], moduleSetTag: updatedModuleSetTag)
104 def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistration(
105 new DmiPluginRegistration(dmiPlugin: DMI1_URL, upgradedCmHandles: cmHandlesToUpgrade))
107 then: 'registration gives successful response'
108 assert dmiPluginRegistrationResponse.upgradedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
110 and: 'the module sync watchdog is triggered twice'
111 2.times { moduleSyncWatchdog.moduleSyncAdvisedCmHandles() }
113 and: 'CM-handle goes to READY state'
114 new PollingConditions().within(MODULE_SYNC_WAIT_TIME_IN_SECONDS, () -> {
115 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(cmHandleId).cmHandleState
118 and: 'the CM-handle has expected moduleSetTag'
119 assert objectUnderTest.getNcmpServiceCmHandle(cmHandleId).moduleSetTag == updatedModuleSetTag
121 and: 'CM-handle has expected updated modules: M1 and M3'
122 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
124 cleanup: 'deregister CM-handle'
125 deregisterCmHandles(DMI1_URL, [cmHandleId, cmHandleIdWithExistingModuleSetTag])
128 initialModuleSetTag | updatedModuleSetTag
129 NO_MODULE_SET_TAG | 'module@Set2'
130 'module@Set1' | 'module@Set2'
133 def 'Skip upgrade of CM-handle with same moduleSetTag as before.'() {
134 given: 'an existing CM-handle with expected initial modules: M1 and M2'
135 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M2']
136 registerCmHandle(DMI1_URL, cmHandleId, 'same')
137 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
139 when: 'CM-handle is upgraded with the same moduleSetTag'
140 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [cmHandleId], moduleSetTag: 'same')
141 objectUnderTest.updateDmiRegistration(
142 new DmiPluginRegistration(dmiPlugin: DMI1_URL, upgradedCmHandles: cmHandlesToUpgrade))
144 then: 'CM-handle remains in READY state'
145 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(cmHandleId).cmHandleState
147 and: 'the CM-handle has same moduleSetTag as before'
148 assert objectUnderTest.getNcmpServiceCmHandle(cmHandleId).moduleSetTag == 'same'
150 then: 'CM-handle has same modules as before: M1 and M2'
151 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(cmHandleId).moduleName.sort()
153 cleanup: 'deregister CM-handle'
154 deregisterCmHandle(DMI1_URL, cmHandleId)
157 def 'Upgrade of CM-handle fails due to DMI error.'() {
158 given: 'a CM-handle exists'
159 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M2']
160 registerCmHandle(DMI1_URL, cmHandleId, 'oldTag')
161 and: 'DMI is not available for upgrade'
162 dmiDispatcher1.isAvailable = false
164 when: 'the CM-handle is upgraded'
165 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [cmHandleId], moduleSetTag: 'newTag')
166 objectUnderTest.updateDmiRegistration(
167 new DmiPluginRegistration(dmiPlugin: DMI1_URL, upgradedCmHandles: cmHandlesToUpgrade))
169 and: 'the module sync watchdog is triggered twice'
170 2.times { moduleSyncWatchdog.moduleSyncAdvisedCmHandles() }
172 then: 'CM-handle goes to LOCKED state with reason MODULE_UPGRADE_FAILED'
173 new PollingConditions().within(MODULE_SYNC_WAIT_TIME_IN_SECONDS, () -> {
174 def cmHandleCompositeState = objectUnderTest.getCmHandleCompositeState(cmHandleId)
175 assert cmHandleCompositeState.cmHandleState == CmHandleState.LOCKED
176 assert cmHandleCompositeState.lockReason.lockReasonCategory == LockReasonCategory.MODULE_UPGRADE_FAILED
179 and: 'the CM-handle has same moduleSetTag as before'
180 assert objectUnderTest.getNcmpServiceCmHandle(cmHandleId).moduleSetTag == 'oldTag'
182 cleanup: 'deregister CM-handle'
183 deregisterCmHandle(DMI1_URL, cmHandleId)