2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 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
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
25 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
26 import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
27 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
28 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
29 import org.onap.cps.ncmp.api.models.UpgradedCmHandles
30 import spock.util.concurrent.PollingConditions
32 class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase {
34 NetworkCmProxyDataService objectUnderTest
36 static final CM_HANDLE_ID = 'ch-1'
37 static final CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG = 'ch-2'
40 objectUnderTest = networkCmProxyDataService
43 def 'Upgrade CM-handle with new moduleSetTag or no moduleSetTag.'() {
44 given: 'a CM-handle is created with expected initial modules: M1 and M2'
45 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID] = ['M1', 'M2']
46 registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag)
47 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
49 when: "the CM-handle is upgraded with given moduleSetTag '${updatedModuleSetTag}'"
50 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: updatedModuleSetTag)
51 def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
52 new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
54 then: 'registration gives successful response'
55 assert dmiPluginRegistrationResponse.upgradedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(CM_HANDLE_ID)]
57 and: 'CM-handle is in LOCKED state due to MODULE_UPGRADE'
58 def cmHandleCompositeState = objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID)
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 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID] = ['M1', 'M3']
65 and: 'module sync runs'
66 moduleSyncWatchdog.resetPreviouslyFailedCmHandles()
67 moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
69 then: 'CM-handle goes to READY state'
70 new PollingConditions().eventually {
71 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
74 and: 'the CM-handle has expected moduleSetTag'
75 assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == updatedModuleSetTag
77 and: 'CM-handle has expected updated modules: M1 and M3'
78 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
80 cleanup: 'deregister CM-handle'
81 deregisterCmHandle(DMI_URL, CM_HANDLE_ID)
84 initialModuleSetTag | updatedModuleSetTag
85 NO_MODULE_SET_TAG | NO_MODULE_SET_TAG
86 NO_MODULE_SET_TAG | 'new'
87 'initial' | NO_MODULE_SET_TAG
91 def 'Upgrade CM-handle with existing moduleSetTag.'() {
92 given: 'DMI will return modules for registration'
93 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID] = ['M1', 'M2']
94 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG] = ['M1', 'M3']
95 and: "an existing CM-handle handle with moduleSetTag '${updatedModuleSetTag}'"
96 registerCmHandle(DMI_URL, CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG, updatedModuleSetTag)
97 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG).moduleName.sort()
98 and: "a CM-handle with moduleSetTag '${initialModuleSetTag}' which will be upgraded"
99 registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag)
100 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
102 when: "CM-handle is upgraded to moduleSetTag '${updatedModuleSetTag}'"
103 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: updatedModuleSetTag)
104 def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
105 new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
107 then: 'registration gives successful response'
108 assert dmiPluginRegistrationResponse.upgradedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(CM_HANDLE_ID)]
110 when: 'module sync runs'
111 moduleSyncWatchdog.resetPreviouslyFailedCmHandles()
112 moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
114 then: 'CM-handle goes to READY state'
115 new PollingConditions().eventually {
116 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
119 and: 'the CM-handle has expected moduleSetTag'
120 assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == updatedModuleSetTag
122 and: 'CM-handle has expected updated modules: M1 and M3'
123 assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
125 cleanup: 'deregister CM-handle'
126 deregisterCmHandles(DMI_URL, [CM_HANDLE_ID, CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG])
129 initialModuleSetTag | updatedModuleSetTag
130 NO_MODULE_SET_TAG | 'moduleSet2'
131 'moduleSet1' | 'moduleSet2'
134 def 'Skip upgrade of CM-handle with same moduleSetTag as before.'() {
135 given: 'an existing CM-handle with expected initial modules: M1 and M2'
136 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID] = ['M1', 'M2']
137 registerCmHandle(DMI_URL, CM_HANDLE_ID, 'same')
138 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
140 when: 'CM-handle is upgraded with the same moduleSetTag'
141 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'same')
142 networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
143 new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
145 then: 'CM-handle remains in READY state'
146 assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
148 and: 'the CM-handle has same moduleSetTag as before'
149 assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == 'same'
151 then: 'CM-handle has same modules as before: M1 and M2'
152 assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
154 cleanup: 'deregister CM-handle'
155 deregisterCmHandle(DMI_URL, CM_HANDLE_ID)
158 def 'Upgrade of CM-handle fails due to DMI error.'() {
159 given: 'a CM-handle exists'
160 dmiDispatcher.moduleNamesPerCmHandleId[CM_HANDLE_ID] = ['M1', 'M2']
161 registerCmHandle(DMI_URL, CM_HANDLE_ID, 'oldTag')
162 and: 'DMI is not available for upgrade'
163 dmiDispatcher.isAvailable = false
165 when: 'the CM-handle is upgraded'
166 def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'newTag')
167 networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
168 new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
170 and: 'module sync runs'
171 moduleSyncWatchdog.resetPreviouslyFailedCmHandles()
172 moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
174 then: 'CM-handle goes to LOCKED state with reason MODULE_UPGRADE_FAILED'
175 new PollingConditions(timeout: 3).eventually {
176 def cmHandleCompositeState = objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID)
177 assert cmHandleCompositeState.cmHandleState == CmHandleState.LOCKED
178 assert cmHandleCompositeState.lockReason.lockReasonCategory == LockReasonCategory.MODULE_UPGRADE_FAILED
181 and: 'the CM-handle has same moduleSetTag as before'
182 assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == 'oldTag'
184 cleanup: 'deregister CM-handle'
185 deregisterCmHandle(DMI_URL, CM_HANDLE_ID)