diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-21 12:38:05 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-02-21 12:38:05 +0000 |
commit | a1ab76467ce2d096e3d51eaf144cfe043ef1c241 (patch) | |
tree | 6e6d1d5392cbdd2f246d3f9c0d75a1f0a8148fca /cps-ncmp-service/src/test | |
parent | 18316c037509c4fddf382d8512c6af620019c7b8 (diff) |
Upgrade yang modules using module set tag
- New algorithm is implemented as per the pseudo code -> https://wiki.onap.org/display/DW/CPS-1733%3A+Upgrade+YANG+Schema-Set+for+CM+Handle+Using+a+Module+Set+Tag
Issue-ID: CPS-2027
Change-Id: I78fc1c8f927de1a1b814c3c1c62351dda58f2139
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
4 files changed, 17 insertions, 101 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy index 572adb8f0f..313d1b4afd 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy @@ -21,14 +21,14 @@ package org.onap.cps.ncmp.api.impl -import java.util.stream.Collectors - import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR +import java.util.stream.Collectors +import org.onap.cps.ncmp.api.impl.inventory.CompositeState import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker import org.onap.cps.ncmp.api.models.UpgradedCmHandles @@ -72,7 +72,6 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def mockTrustLevelManager = Mock(TrustLevelManager) def mockAlternateIdChecker = Mock(AlternateIdChecker) def objectUnderTest = getObjectUnderTest() - def mockModuleSetTagCache = [:] def setup() { // always accept all cm handles @@ -89,6 +88,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag')) and: 'cm handles are persisted' mockInventoryPersistence.getYangModelCmHandles(['cmhandle-2']) >> [new YangModelCmHandle()] + mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: CmHandleState.READY)) and: 'cm handle is in READY state' mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> true when: 'registration is processed' @@ -96,7 +96,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { then: 'cm-handles are removed first' 1 * objectUnderTest.parseAndProcessDeletedCmHandlesInRegistration(*_) and: 'de-registered cm handle entry is removed from in progress map' - 2 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2') + 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2') then: 'cm-handles are created' 1 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(*_) then: 'cm-handles are updated' @@ -110,15 +110,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server') dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag')) and: 'exception while checking cm handle state' - mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> isReady + mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> new YangModelCmHandle(id: 'cmhandle-3', moduleSetTag: '', compositeState: new CompositeState(cmHandleState: cmHandleState)) when: 'registration is processed' def result = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration) then: 'upgrade operation contains expected error code' - assert result.upgradedCmHandles.status[0] == expectedResponseStatus + assert result.upgradedCmHandles[0].status == expectedResponseStatus where: 'the following parameters are used' - scenario | isReady || expectedResponseStatus - 'READY' | true || Status.SUCCESS - 'Not READY' | false || Status.FAILURE + scenario | cmHandleState || expectedResponseStatus + 'READY' | CmHandleState.READY || Status.SUCCESS + 'Not READY' | CmHandleState.LOCKED || Status.FAILURE } def 'DMI Registration upgrade with exception #scenario'() { @@ -126,7 +126,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server') dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag')) and: 'exception while checking cm handle state' - mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> { throw exception } + mockInventoryPersistence.getYangModelCmHandle('cmhandle-3') >> { throw exception } when: 'registration is processed' def result = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration) then: 'upgrade operation contains expected error code' @@ -453,7 +453,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations, mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries, stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService, - mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager, mockAlternateIdChecker, mockModuleSetTagCache)) + mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager, mockAlternateIdChecker)) } def addPersistedYangModelCmHandles(ids) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index 9221f31866..fc548ebe9b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -81,7 +81,6 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def stubTrustLevelPerDmiPlugin = Stub(Map<String, TrustLevel>) def mockTrustLevelManager = Mock(TrustLevelManager) def mockAlternateIdChecker = Mock(AlternateIdChecker) - def mockModuleSetTagCache = [:] def NO_TOPIC = null def NO_REQUEST_ID = null @@ -100,8 +99,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { stubModuleSyncStartedOnCmHandles, stubTrustLevelPerDmiPlugin, mockTrustLevelManager, - mockAlternateIdChecker, - mockModuleSetTagCache) + mockAlternateIdChecker) def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy deleted file mode 100644 index 8a6a32bd8d..0000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.ncmp.api.impl.config.embeddedcache - -import com.hazelcast.config.Config -import com.hazelcast.core.Hazelcast -import org.onap.cps.spi.model.ModuleReference -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import spock.lang.Specification - -@SpringBootTest(classes = [ModuleSetTagCacheConfig]) -class ModuleSetTagCacheConfigSpec extends Specification { - - @Autowired - private Map<String, Collection<ModuleReference>> moduleSetTagCache - - def 'Embedded (hazelcast) caches for module set tag.'() { - expect: 'system is able to create an instance of a map to hold module set tags' - assert null != moduleSetTagCache - and: 'there is at least 1 instance' - assert Hazelcast.allHazelcastInstances.size() > 0 - and: 'hazelcast instance name of module set tag is correct' - assert Hazelcast.allHazelcastInstances.name.contains('moduleSetTags') - } - - def 'Verify configs of module set tag distributed object.'(){ - when: 'retrieving the map config of module set tag' - def cacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config - def moduleSetTagMapConfig = cacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig') - then: 'the module set tag map config has correct backup counts' - assert moduleSetTagMapConfig.backupCount == 3 - assert moduleSetTagMapConfig.asyncBackupCount == 3 - } - - def 'Verify deployment network configs of distributed cache of module set tag object.'() { - given: 'network config of module set tag cache' - def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig - expect: 'module set tag cache has the correct settings' - assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled - assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled - } - - def 'Verify network of module set tag cache'() { - given: 'Synchronization config object and test configuration' - def objectUnderTest = new ModuleSetTagCacheConfig() - def testConfig = new Config() - when: 'kubernetes properties are enabled' - objectUnderTest.cacheKubernetesEnabled = true - objectUnderTest.cacheKubernetesServiceName = 'test-service-name' - and: 'method called to update the discovery mode' - objectUnderTest.updateDiscoveryMode(testConfig) - then: 'applied properties are reflected' - assert testConfig.networkConfig.join.kubernetesConfig.enabled - assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name' - - } -} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy index de783ed2ca..b0ff6d886a 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy @@ -50,10 +50,9 @@ class ModuleSyncServiceSpec extends Specification { def mockCmHandleQueries = Mock(CmHandleQueries) def mockCpsDataService = Mock(CpsDataService) def mockJsonObjectMapper = Mock(JsonObjectMapper) - def mockModuleSetTagCache = [:] def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService, - mockCmHandleQueries, mockCpsDataService, mockCpsAnchorService, mockJsonObjectMapper, mockModuleSetTagCache) + mockCmHandleQueries, mockCpsDataService, mockCpsAnchorService, mockJsonObjectMapper) def expectedDataspaceName = NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME def static cmHandleWithModuleSetTag = new DataNodeBuilder().withXpath("//cm-handles[@module-set-tag='tag-1'][@id='otherId']").withAnchor('otherId').build() @@ -96,11 +95,7 @@ class ModuleSyncServiceSpec extends Specification { and: 'some module references' def moduleReferences = [ new ModuleReference('module1','1') ] and: 'cache or DMI operations returns some module references for upgraded cm handle' - if (populateCache) { - mockModuleSetTagCache.put('tag-1', moduleReferences) - } else { - mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences - } + mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences and: 'none of these module references are new (unknown to the system)' mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> [] and: 'CPS-Core returns list of existing module resources for TBD' @@ -118,10 +113,9 @@ class ModuleSyncServiceSpec extends Specification { and: 'No anchor is created for the upgraded cm handle' 0 * mockCpsAnchorService.createAnchor(*_) where: 'the following parameters are used' - scenario | populateCache | existingCmHandlesWithSameTag || expectedCallsToUpgradeSchemaSet | expectedCallsToCeateSchemaSet - 'new' | false | [] || 0 | 1 - 'in cache' | true | [] || 1 | 0 - 'in database' | false | [cmHandleWithModuleSetTag] || 1 | 0 + scenario | existingCmHandlesWithSameTag || expectedCallsToUpgradeSchemaSet | expectedCallsToCeateSchemaSet + 'new' | [] || 1 | 0 + 'in database' | [cmHandleWithModuleSetTag] || 1 | 0 } def 'upgrade model for a existing cm handle'() { |