Test changes:
- Check moduleSetTag (and alternateId) in unit test of get CM handle.
- Verify moduleSetTag is updated in tests of CM handle upgrade.
Code changes:
- Set moduleSetTag when converting a YangModelCmHandle to
NcmpServiceCmHandle.
- Set moduleSetTag in YangModelCmHandle copy constructor.
- Minor refactor using StringUtils::isBlank.
Issue-ID: CPS-2027
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I6a9a92aa58d15c6ecf5a6bb21aa5c9d6ec8dc817
final List<YangModelCmHandle.Property> publicProperties = yangModelCmHandle.getPublicProperties();
ncmpServiceCmHandle.setCmHandleId(yangModelCmHandle.getId());
ncmpServiceCmHandle.setCompositeState(yangModelCmHandle.getCompositeState());
final List<YangModelCmHandle.Property> publicProperties = yangModelCmHandle.getPublicProperties();
ncmpServiceCmHandle.setCmHandleId(yangModelCmHandle.getId());
ncmpServiceCmHandle.setCompositeState(yangModelCmHandle.getCompositeState());
+ ncmpServiceCmHandle.setModuleSetTag(yangModelCmHandle.getModuleSetTag());
ncmpServiceCmHandle.setAlternateId(yangModelCmHandle.getAlternateId());
setDmiProperties(dmiProperties, ncmpServiceCmHandle);
setPublicProperties(publicProperties, ncmpServiceCmHandle);
ncmpServiceCmHandle.setAlternateId(yangModelCmHandle.getAlternateId());
setDmiProperties(dmiProperties, ncmpServiceCmHandle);
setPublicProperties(publicProperties, ncmpServiceCmHandle);
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
copy.dmiProperties = original.getDmiProperties() == null ? null : new ArrayList<>(original.getDmiProperties());
copy.publicProperties =
original.getPublicProperties() == null ? null : new ArrayList<>(original.getPublicProperties());
copy.dmiProperties = original.getDmiProperties() == null ? null : new ArrayList<>(original.getDmiProperties());
copy.publicProperties =
original.getPublicProperties() == null ? null : new ArrayList<>(original.getPublicProperties());
+ copy.moduleSetTag = original.getModuleSetTag();
copy.alternateId = original.getAlternateId();
return copy;
}
copy.alternateId = original.getAlternateId();
return copy;
}
* @return dmi service name
*/
public String resolveDmiServiceName(final RequiredDmiService requiredService) {
* @return dmi service name
*/
public String resolveDmiServiceName(final RequiredDmiService requiredService) {
- if (isNullEmptyOrBlank(dmiServiceName)) {
+ if (StringUtils.isBlank(dmiServiceName)) {
if (RequiredDmiService.DATA.equals(requiredService)) {
return dmiDataServiceName;
}
if (RequiredDmiService.DATA.equals(requiredService)) {
return dmiDataServiceName;
}
return yangModelCmHandleProperties;
}
return yangModelCmHandleProperties;
}
- private static boolean isNullEmptyOrBlank(final String serviceName) {
- return Strings.isNullOrEmpty(serviceName) || serviceName.isBlank();
- }
-
@AllArgsConstructor
@Data
public static class Property {
@AllArgsConstructor
@Data
public static class Property {
given: 'the system returns a yang modelled cm handle'
def dmiServiceName = 'some service name'
def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
given: 'the system returns a yang modelled cm handle'
def dmiServiceName = 'some service name'
def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
- lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
- lastUpdateTime: 'some-timestamp',
- dataSyncEnabled: false,
- dataStores: dataStores())
+ lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(),
+ lastUpdateTime: 'some-timestamp',
+ dataSyncEnabled: false,
+ dataStores: dataStores())
def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')]
def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')]
def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')]
def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')]
+ def moduleSetTag = 'some-module-set-tag'
+ def alternateId = 'some-alternate-id'
def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName,
def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName,
- dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState)
+ dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState,
+ moduleSetTag: moduleSetTag, alternateId: alternateId)
1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
when: 'getting cm handle details for a given cm handle id from ncmp service'
def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle')
1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
when: 'getting cm handle details for a given cm handle id from ncmp service'
def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle')
result.class == NcmpServiceCmHandle.class
and: 'the cm handle contains the cm handle id'
result.cmHandleId == 'some-cm-handle'
result.class == NcmpServiceCmHandle.class
and: 'the cm handle contains the cm handle id'
result.cmHandleId == 'some-cm-handle'
+ and: 'the cm handle contains the alternate id'
+ result.alternateId == 'some-alternate-id'
+ and: 'the cm handle contains the module-set-tag'
+ result.moduleSetTag == 'some-module-set-tag'
and: 'the cm handle contains the DMI Properties'
result.dmiProperties ==[ Book:'Romance Novel' ]
and: 'the cm handle contains the public Properties'
result.publicProperties == [ "Public Book":'Public Romance Novel' ]
and: 'the cm handle contains the cm handle composite state'
result.compositeState == compositeState
and: 'the cm handle contains the DMI Properties'
result.dmiProperties ==[ Book:'Romance Novel' ]
and: 'the cm handle contains the public Properties'
result.publicProperties == [ "Public Book":'Public Romance Novel' ]
and: 'the cm handle contains the cm handle composite state'
result.compositeState == compositeState
}
def 'Get cm handle public properties'() {
}
def 'Get cm handle public properties'() {
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState('ch-3').cmHandleState
})
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState('ch-3').cmHandleState
})
+ and: 'the CM-handle has expected moduleSetTag'
+ assert objectUnderTest.getNcmpServiceCmHandle('ch-3').moduleSetTag == 'B'
+
and: 'the CM-handle has expected modules from module set "B": M1 and M3'
and: 'the CM-handle has expected modules from module set "B": M1 and M3'
- ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences('ch-3').moduleName.sort()
+ assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences('ch-3').moduleName.sort()
cleanup: 'deregister CM handles'
deregisterCmHandles(DMI_URL, ['ch-1', 'ch-2', 'ch-3'])
cleanup: 'deregister CM handles'
deregisterCmHandles(DMI_URL, ['ch-1', 'ch-2', 'ch-3'])
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
})
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
})
+ and: 'the CM-handle has expected moduleSetTag'
+ assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == updatedModuleSetTag
+
and: 'CM-handle has expected updated modules: M1 and M3'
assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
and: 'CM-handle has expected updated modules: M1 and M3'
assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
})
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
})
+ and: 'the CM-handle has expected moduleSetTag'
+ assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == updatedModuleSetTag
+
and: 'CM-handle has expected updated modules: M1 and M3'
assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
and: 'CM-handle has expected updated modules: M1 and M3'
assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
then: 'CM-handle remains in READY state'
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
then: 'CM-handle remains in READY state'
assert CmHandleState.READY == objectUnderTest.getCmHandleCompositeState(CM_HANDLE_ID).cmHandleState
- and: 'CM-handle has same modules as before: M1 and M2'
+ and: 'the CM-handle has same moduleSetTag as before'
+ assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == 'same'
+
+ then: 'CM-handle has same modules as before: M1 and M2'
assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
cleanup: 'deregister CM-handle'
assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort()
cleanup: 'deregister CM-handle'
def 'Upgrade of CM-handle fails due to DMI error.'() {
given: 'an existing CM-handle'
def 'Upgrade of CM-handle fails due to DMI error.'() {
given: 'an existing CM-handle'
- registerCmHandle(DMI_URL, CM_HANDLE_ID, NO_MODULE_SET_TAG, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE)
+ registerCmHandle(DMI_URL, CM_HANDLE_ID, 'oldTag', INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE)
and: 'DMI returns error code'
mockDmiServer.expect(anything()).andRespond(withStatus(HttpStatus.SERVICE_UNAVAILABLE))
when: "CM-handle is upgraded"
and: 'DMI returns error code'
mockDmiServer.expect(anything()).andRespond(withStatus(HttpStatus.SERVICE_UNAVAILABLE))
when: "CM-handle is upgraded"
- def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: NO_MODULE_SET_TAG)
+ def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'newTag')
networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
networkCmProxyDataService.updateDmiRegistrationAndSyncModule(
new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade))
assert cmHandleCompositeState.lockReason.lockReasonCategory == LockReasonCategory.MODULE_UPGRADE_FAILED
})
assert cmHandleCompositeState.lockReason.lockReasonCategory == LockReasonCategory.MODULE_UPGRADE_FAILED
})
+ and: 'the CM-handle has same moduleSetTag as before'
+ assert objectUnderTest.getNcmpServiceCmHandle(CM_HANDLE_ID).moduleSetTag == 'oldTag'
+
cleanup: 'deregister CM-handle'
deregisterCmHandle(DMI_URL, CM_HANDLE_ID)
}
cleanup: 'deregister CM-handle'
deregisterCmHandle(DMI_URL, CM_HANDLE_ID)
}