diff options
author | DylanB95EST <dylan.byrne@est.tech> | 2022-07-19 11:36:10 +0100 |
---|---|---|
committer | DylanB95EST <dylan.byrne@est.tech> | 2022-07-28 15:34:27 +0100 |
commit | 6ddbe4af2b73a306dec89e55b8350c09b8c5766b (patch) | |
tree | 51532d5e27374191f1389f9da45582eafc82163e /cps-ncmp-service/src/test | |
parent | fe835cb6e0030c00d08f9eb84c3f7bb2b3d90c2e (diff) |
Enable/Disable Data Sync for Cm Handle
-Create API Which will enable/disable data sync enabled flag
-Default functionality of module sync watchdog is to set to false
-Remove global config param
-Will set initial sync state based on data sync enabled flag
-Throws an Exception if the same data sync enabled flag tries
to be set
-Throws Exception if state is not in READY
-Data Sync enabled must be true to complete data sync process
- Delete all resource data within fragment table related
to synced cm handle when data sync is set to false
Issue-ID: CPS-1133
Change-Id: Ib47bbd8293f083c1d705d91bd0def74e6a105c72
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
6 files changed, 77 insertions, 34 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 1ee1ad2f60..2aa08b8e7f 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 @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.api.impl import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler @@ -60,6 +61,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def mockInventoryPersistence = Mock(InventoryPersistence) def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandlerQueryService) def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler) + def mockCpsDataService = Mock(CpsDataService) def objectUnderTest = getObjectUnderTest() def 'DMI Registration: Create, Update & Delete operations are processed in the right order'() { @@ -351,6 +353,6 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def getObjectUnderTest() { return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations, mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, stubbedNetworkCmProxyCmHandlerQueryService, - mockLcmEventsCmHandleStateHandler)) + mockLcmEventsCmHandleStateHandler, mockCpsDataService)) } } 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 d112557671..a372defc66 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 @@ -34,6 +34,7 @@ import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters import org.onap.cps.ncmp.api.models.ConditionApiProperties import org.onap.cps.ncmp.api.models.DmiPluginRegistration import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.model.CmHandleQueryServiceParameters import spock.lang.Shared @@ -79,7 +80,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { nullNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsCmHandlerQueryService, - mockLcmEventsCmHandleStateHandler) + mockLcmEventsCmHandleStateHandler, + mockCpsDataService) def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" @@ -311,14 +313,6 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleId('some-cm-handle') } - - def dataStores() { - CompositeState.DataStores.builder() - .operationalDataStore(CompositeState.Operational.builder() - .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) - .lastSyncTime('some-timestamp').build()).build() - } - def 'Execute cm handle search'() { given: 'valid CmHandleQueryApiParameters input' def cmHandleQueryApiParameters = new CmHandleQueryApiParameters() @@ -335,4 +329,51 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { then: 'result is the same collection as returned by the CPS Data Service' assert result.stream().map(d -> d.cmHandleId).collect(Collectors.toSet()) == ['cm-handle-id-1'] as Set } + + def 'Set Cm Handle Data Sync Enabled Flag where data sync flag is #scenario'() { + given: 'an existing cm handle composite state' + def compositeState = new CompositeState(cmHandleState: CmHandleState.READY, dataSyncEnabled: initialDataSyncEnabledFlag, + dataStores: CompositeState.DataStores.builder() + .operationalDataStore(CompositeState.Operational.builder() + .dataStoreSyncState(initialDataSyncState) + .build()).build()) + and: 'get cm handle state returns the composite state for the given cm handle id' + mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState + when: 'set data sync enabled is called with the data sync enabled flag set to #dataSyncEnabledFlag' + objectUnderTest.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag) + then: 'the data sync enabled flag is set to #dataSyncEnabled' + compositeState.dataSyncEnabled == dataSyncEnabledFlag + and: 'the data store sync state is set to #expectedDataStoreSyncState' + compositeState.dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState + and: 'the cps data service to delete data nodes is invoked the expected number of times' + deleteDataNodeExpectedNumberOfInvocation * mockCpsDataService.deleteDataNode('NFP-Operational', 'some-cm-handle-id', '/netconf-state', _) + and: 'the inventory persistence service to update node leaves is called with the correct values' + saveCmHandleStateExpectedNumberOfInvocations * mockInventoryPersistence.saveCmHandleState('some-cm-handle-id', compositeState) + where: 'the following data sync enabled flag is used' + scenario | dataSyncEnabledFlag | initialDataSyncEnabledFlag | initialDataSyncState || expectedDataStoreSyncState | deleteDataNodeExpectedNumberOfInvocation | saveCmHandleStateExpectedNumberOfInvocations + 'enabled' | true | false | DataStoreSyncState.NONE_REQUESTED || DataStoreSyncState.UNSYNCHRONIZED | 0 | 1 + 'disabled' | false | true | DataStoreSyncState.UNSYNCHRONIZED || DataStoreSyncState.NONE_REQUESTED | 0 | 1 + 'disabled where sync-state is currently SYNCHRONIZED' | false | true | DataStoreSyncState.SYNCHRONIZED || DataStoreSyncState.NONE_REQUESTED | 1 | 1 + 'is set to existing flag state' | true | true | DataStoreSyncState.UNSYNCHRONIZED || DataStoreSyncState.UNSYNCHRONIZED | 0 | 0 + } + + def 'Set cm Handle Data Sync Enabled flag with following cm handle not in ready state exception' () { + given: 'a cm handle composite state' + def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: false) + and: 'get cm handle state returns the composite state for the given cm handle id' + mockInventoryPersistence.getCmHandleState('some-cm-handle-id') >> compositeState + when: 'set data sync enabled is called with the data sync enabled flag set to true' + objectUnderTest.setDataSyncEnabled('some-cm-handle-id', true) + then: 'the expected exception is thrown' + thrown(CpsException) + and: 'the inventory persistence service to update node leaves is not invoked' + 0 * mockInventoryPersistence.saveCmHandleState(_, _) + } + + def dataStores() { + CompositeState.DataStores.builder() + .operationalDataStore(CompositeState.Operational.builder() + .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) + .lastSyncTime('some-timestamp').build()).build() + } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy index b4e57c78b5..b3436792de 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy @@ -94,29 +94,25 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) } - def 'Update and Publish Events on State Change to READY with #scenario'() { + def 'Update and Publish Events on State Change to READY'() { given: 'Cm Handle represented as YangModelCmHandle' compositeState = new CompositeState(cmHandleState: ADVISED) yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState) and: 'global sync flag is set' - objectUnderTest.isGlobalDataSyncCacheEnabled = dataSyncCacheEnabled + compositeState.setDataSyncEnabled(false) when: 'update cmhandle state is invoked' objectUnderTest.updateCmHandleState(yangModelCmHandle, READY) then: 'state is saved using inventory persistence with expected dataSyncState' 1 * mockInventoryPersistence.saveCmHandleState(cmHandleId, _) >> { args-> { def result = (args[1] as CompositeState) - assert result.dataSyncEnabled == dataSyncCacheEnabled - assert result.dataStores.operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState + assert result.dataSyncEnabled == false + assert result.dataStores.operationalDataStore.dataStoreSyncState == DataStoreSyncState.NONE_REQUESTED } } and: 'event service is called to publish event' 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) - where: - scenario | dataSyncCacheEnabled || expectedDataStoreSyncState - 'data sync cache enabled' | true || DataStoreSyncState.UNSYNCHRONIZED - 'data sync cache is not enabled' | false || DataStoreSyncState.NONE_REQUESTED } def 'Update cmHandle state to "DELETING"' (){ diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy index f2cd2b51f7..c7e6b6d354 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy @@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.event.lcm import com.fasterxml.jackson.databind.ObjectMapper import org.apache.kafka.clients.consumer.KafkaConsumer -import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsPublisher import org.onap.cps.ncmp.api.utils.MessagingSpec import org.onap.cps.ncmp.utils.TestUtils import org.onap.cps.utils.JsonObjectMapper diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy index 20880ca3b3..650a779a42 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncSpec.groovy @@ -26,6 +26,7 @@ import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.inventory.InventoryPersistence import org.onap.cps.ncmp.api.inventory.DataStoreSyncState +import spock.lang.Shared import spock.lang.Specification class DataSyncSpec extends Specification { @@ -36,6 +37,7 @@ class DataSyncSpec extends Specification { def mockSyncUtils = Mock(SyncUtils) + @Shared def jsonString = '{"stores:bookstore":{"categories":[{"code":"01"}]}}' def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils) @@ -48,7 +50,7 @@ class DataSyncSpec extends Specification { def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED'() { given: 'sample resource data' - def resourceData = jsonString; + def resourceData = jsonString and: 'sync utilities return a cm handle twice' mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null] when: 'data sync poll is executed' @@ -71,18 +73,24 @@ class DataSyncSpec extends Specification { 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState) } - def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED which return empty data from Node'() { - given: 'cm handles in an ready state and operational sync state in unsynchronized' - and: 'sync utilities return a cm handle twice' - mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle1, null] + def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED which return empty data from Node because #scenario'() { + given: 'a yang model cm handle' + def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', compositeState: new CompositeState(dataSyncEnabled: dataSyncEnabled)) + and: 'sync utilities returns a single cm handle' + mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle, null] when: 'data sync poll is executed' objectUnderTest.executeUnSynchronizedReadyCmHandlePoll() then: 'the inventory persistence cm handle returns a composite state for the first cm handle' - 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle-1') >> compositeState + 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle') >> compositeState and: 'the sync util returns first resource data' - 1 * mockSyncUtils.getResourceData('some-cm-handle-1') >> null + 1 * mockSyncUtils.getResourceData('some-cm-handle') >> resourceData and: 'the cm-handle data is not saved' 0 * mockCpsDataService.saveData('NFP-Operational', 'some-cm-handle-1', jsonString, _) + where: + scenario | dataSyncEnabled | resourceData + 'data sync is not enabled' | false | jsonString + 'resource data is null' | true | null + 'data sync is not enabled and resource data is null' | false | null } def createSampleYangModelCmHandle(cmHandleId) { @@ -92,7 +100,7 @@ class DataSyncSpec extends Specification { def getCompositeState() { def cmHandleState = CmHandleState.READY - def compositeState = new CompositeState(cmHandleState: cmHandleState) + def compositeState = new CompositeState(cmHandleState: cmHandleState, dataSyncEnabled: true) compositeState.setDataStores(CompositeState.DataStores.builder() .operationalDataStore(CompositeState.Operational.builder().dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED) .build()).build()) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy index 7455438cc2..41f2160bc0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy @@ -47,13 +47,12 @@ class ModuleSyncWatchdogSpec extends Specification { def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService, stubbedMap as ConcurrentHashMap) - def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles where #scenario'() { + def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() { given: 'cm handles in an advised state and a data sync state' def compositeState1 = new CompositeState(cmHandleState: cmHandleState) def compositeState2 = new CompositeState(cmHandleState: cmHandleState) def yangModelCmHandle1 = new YangModelCmHandle(id: 'some-cm-handle', compositeState: compositeState1) def yangModelCmHandle2 = new YangModelCmHandle(id: 'some-cm-handle-2', compositeState: compositeState2) - objectUnderTest.isGlobalDataSyncCacheEnabled = dataSyncCacheEnabled and: 'sync utilities return a cm handle twice' mockSyncUtils.getAdvisedCmHandles() >> [yangModelCmHandle1, yangModelCmHandle2] when: 'module sync poll is executed' @@ -66,8 +65,10 @@ class ModuleSyncWatchdogSpec extends Specification { 1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle1) then: 'the composite state cm handle state is now READY' assert compositeState1.getCmHandleState() == CmHandleState.READY + and: 'the data sync enabled flag is set correctly' + compositeState1.getDataSyncEnabled() == false and: 'the data store sync state returns the expected state' - compositeState1.getDataStores().operationalDataStore.dataStoreSyncState == expectedDataStoreSyncState + compositeState1.getDataStores().operationalDataStore.dataStoreSyncState == DataStoreSyncState.NONE_REQUESTED and: 'the first cm handle state is updated' 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle', compositeState1) then: 'the inventory persistence cm handle returns a composite state for the second cm handle' @@ -78,10 +79,6 @@ class ModuleSyncWatchdogSpec extends Specification { assert compositeState2.getCmHandleState() == CmHandleState.READY and: 'the second cm handle state is updated' 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState2) - where: - scenario | dataSyncCacheEnabled || expectedDataStoreSyncState - 'data sync cache enabled' | true || DataStoreSyncState.UNSYNCHRONIZED - 'data sync cache is not enabled' | false || DataStoreSyncState.NONE_REQUESTED } def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handle with failure'() { |