From e53d09ea02e5f1cfcff0b7614a5e69effaa707a7 Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Wed, 25 Mar 2020 00:01:55 +0200 Subject: add tenantId and lcpCloudRegion to vfm instance during delete vfm during delete vfm get tenantId and lcpCloudRegion from parent vnf and them to vfm instance Issue-ID: VID-795 Signed-off-by: Alexey Sandler Change-Id: I66969f936e8cd5fa4e9867decebadd28186a1851 Signed-off-by: Alexey Sandler --- .../utils/vfModule/vfModule.reducers.spec.ts | 124 +++++++++------------ .../storeUtil/utils/vfModule/vfModule.reducers.ts | 8 ++ 2 files changed, 58 insertions(+), 74 deletions(-) (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/vfModule') diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts index 91b749e0d..9ef440fc5 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts @@ -106,28 +106,7 @@ describe('vfModuleReducer', () => { test('#UPDATE_VFMODULE_FEILD: should update field with some value', () => { const newFieldName = 'newFieldName'; const newFieldValue = 'newFieldValue'; - let oldState = { - serviceHierarchy: { - 'serviceModelId': {} - }, - serviceInstance: { - 'serviceModelId': { - vnfs: { - 'vnfStoreKey': { - vfModules: { - 'modelName': { - 'dynamicModelName1': { - isMissingData: true, - action: 'None' - }, - 'dynamicModelName2': {}, - } - } - } - } - } - } - }; + let oldState = getReduxState(); let newState = vfModuleReducer(oldState, { @@ -222,40 +201,24 @@ test('#UPDATE_VFMODULE_POSITION: should update position', () => { }); test('#DELETE_ACTION_VF_MODULE_INSTANCE', () => { - let vfModule = vfModuleReducer({ - serviceHierarchy: { - 'serviceModelId': {} - }, - serviceInstance: { - 'serviceModelId': { - vnfs: { - 'vnfStoreKey': { - vfModules: { - 'modelName': { - 'dynamicModelName1': { - isMissingData: true, - action: 'None' - }, - 'dynamicModelName2': {}, - } - } - } - } - } - } - }, - { - type: VfModuleActions.DELETE_ACTION_VF_MODULE_INSTANCE, - dynamicModelName: 'dynamicModelName1', - vnfStoreKey: 'vnfStoreKey', - serviceId: 'serviceModelId' - }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule()) + .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; expect(vfModule).toBeDefined(); expect(vfModule.isMissingData).toBeTruthy(); expect(vfModule.action).toEqual(ServiceInstanceActions.None_Delete); }); +test('#DELETE_ACTION_VF_MODULE_INSTANCE set tenantId and lcpCloudRegion to VFM', () => { + let vfModule = vfModuleReducer(getReduxState(), getDeleteActionVfModule()) + .serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1']; + + expect(vfModule).toBeDefined(); + expect(vfModule.tenantId).toEqual('tenantId'); + expect(vfModule.lcpCloudRegionId).toEqual('lcpCloudRegionId'); + +}); + test('#UNDO_DELETE_ACTION_VF_MODULE_INSTANCE', () => { let vfModule = vfModuleReducer({ serviceHierarchy: { @@ -291,28 +254,7 @@ test('#UNDO_DELETE_ACTION_VF_MODULE_INSTANCE', () => { }); test('#UPGRADE_VFMODULE', () => { - let vfModule = vfModuleReducer({ - serviceHierarchy: { - 'serviceModelId': {} - }, - serviceInstance: { - 'serviceModelId': { - vnfs: { - 'vnfStoreKey': { - vfModules: { - 'modelName': { - 'dynamicModelName1': { - isMissingData: true, - action: 'None' - }, - 'dynamicModelName2': {}, - } - } - } - } - } - } - }, + let vfModule = vfModuleReducer(getReduxState(), { type: VfModuleActions.UPGRADE_VFMODULE, dynamicModelName: 'dynamicModelName1', @@ -358,5 +300,39 @@ test('#UNDO_UPGRADE_VFMODULE', () => { expect(vfModule.action).toEqual(ServiceInstanceActions.None); }); -}) -; +function getReduxState() { + return { + serviceHierarchy: { + 'serviceModelId': {} + }, + serviceInstance: { + 'serviceModelId': { + vnfs: { + 'vnfStoreKey': { + tenantId: 'tenantId', + lcpCloudRegionId: 'lcpCloudRegionId', + vfModules: { + 'modelName': { + 'dynamicModelName1': { + isMissingData: true, + action: 'None', + }, + 'dynamicModelName2': {}, + } + } + } + } + } + } + } +} + +function getDeleteActionVfModule() { + return { + type: VfModuleActions.DELETE_ACTION_VF_MODULE_INSTANCE, + dynamicModelName: 'dynamicModelName1', + vnfStoreKey: 'vnfStoreKey', + serviceId: 'serviceModelId' + } +} +}); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts index 2e91f8771..1ab275e05 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts @@ -79,6 +79,7 @@ export function vfModuleReducer(state: ServiceState , action: Action) : ServiceS let oldAction = newState.serviceInstance[(action).serviceId].vnfs[(action).vnfStoreKey].vfModules[key][firstKey].action; if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; newState.serviceInstance[(action).serviceId].vnfs[(action).vnfStoreKey].vfModules[key][firstKey].action = (oldAction + '_Delete') as ServiceInstanceActions; + setLcpCloudRegionIdAndTenantIdFromVnf(newState, (action).serviceId, (action).vnfStoreKey, key, firstKey); updateIsMissingDataOnDeleteVFModule(newState, (action).serviceId, (action).vnfStoreKey, key); return newState; } @@ -177,6 +178,13 @@ const updateIsMissingDataOnDeleteVFModule = (state: any, serviceModelId: string, }); }; +const setLcpCloudRegionIdAndTenantIdFromVnf = (state: any, serviceModelId: string, vnfStoreKey: string, key: string, firstKey: string) :void => { + let tenantId = state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].tenantId; + let lcpCloudRegion = state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].lcpCloudRegionId; + + state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].vfModules[key][firstKey].tenantId = tenantId; + state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].vfModules[key][firstKey].lcpCloudRegionId = lcpCloudRegion; +} const updateUniqueNames = (oldName : string, newName : string, serviceInstance : ServiceInstance) : void => { let existingNames = serviceInstance.existingNames; -- cgit 1.2.3-korg