Exclude outdated validation results from list

If a plan has been updated (or deleted and re-created), we don't want to
show validation results from before the update.

This plan excludes validation results, so the validation statuses are up
to date.

Change-Id: I8e10e3e5ff43d7c867394eab0e6a74695fffb094
Closes-Bug: #1715364
(cherry picked from commit b64f42f448)
This commit is contained in:
Florian Fuchs 2017-09-06 12:44:10 +02:00 committed by Beth Elwell
parent efc6cde2f8
commit fd0c8880fd
3 changed files with 81 additions and 3 deletions

View File

@ -223,4 +223,57 @@ describe(' validations selectors', () => {
expect(filtered.get('check-network-gateway')).toBeDefined();
});
});
describe('getMostRecentPlanUpdate', () => {
it('returns 0 if there are no executions', () => {
const executions = Map({});
expect(
selectors.getMostRecentPlanUpdate(executions, 'overcloud')
).toEqual(0);
});
it('returns 0 if there are no relevant executions', () => {
const executions = Map({
one: Map({
workflow_name: 'tripleo.baremetal.v1.introspect',
updated_at: 1504686886000
})
});
expect(
selectors.getMostRecentPlanUpdate(executions, 'overcloud')
).toEqual(0);
});
it('returns the most recent update time', () => {
const executions = Map({
one: WorkflowExecution({
workflow_name: 'tripleo.baremetal.v1.introspect',
updated_at: 1500000000007
}),
two: WorkflowExecution({
workflow_name: 'tripleo.plan_management.v1.create_deployment_plan',
updated_at: 1500000000004,
input: Map({ container: 'overcloud' })
}),
three: WorkflowExecution({
workflow_name: 'tripleo.plan_management.v1.update_deployment_plan',
updated_at: 1500000000003,
input: Map({ container: 'overcloud' })
}),
four: WorkflowExecution({
workflow_name: 'tripleo.plan_management.v1.delete_deployment_plan',
updated_at: 1500000000006,
input: Map({ container: 'overcloud' })
}),
five: WorkflowExecution({
workflow_name: 'tripleo.plan_management.v1.update_deployment_plan',
updated_at: 1500000000005,
input: Map({ container: 'another-cloud' })
})
});
expect(
selectors.getMostRecentPlanUpdate(executions, 'overcloud')
).toEqual(1500000000004);
});
});
});

View File

@ -24,6 +24,6 @@ export const WorkflowExecution = Record({
params: Map(),
state: undefined,
state_info: undefined,
updated_at: undefined,
updated_at: 0,
workflow_name: undefined
});

View File

@ -31,10 +31,15 @@ const validationsToolbarFilter = state =>
export const getValidationExecutionsForCurrentPlan = createSelector(
[executions, getCurrentPlanName],
(executions, currentPlanName) => {
const mostRecentPlanUpdate = getMostRecentPlanUpdate(
executions,
currentPlanName
);
return executions.filter(
execution =>
execution.get('workflow_name') === MistralConstants.VALIDATIONS_RUN &&
execution.getIn(['input', 'plan']) === currentPlanName
execution.getIn(['input', 'plan']) === currentPlanName &&
execution.get('updated_at') > mostRecentPlanUpdate
);
}
);
@ -55,7 +60,8 @@ export const getValidationsWithResults = createSelector(
);
/**
* Filter validations using the active Toolbar filters
* Filter validations using the active Toolbar filters.
* Only include validations younger than the most recent update to a plan.
*/
export const getFilteredValidations = createSelector(
[getValidationsWithResults, validationsToolbarFilter],
@ -99,6 +105,25 @@ export const getFilteredValidations = createSelector(
}
);
/**
* Helper function to get the most recent time a plan has been updated or
* created.
*/
export const getMostRecentPlanUpdate = (executions, planName) => {
return (
executions
.filter(
execution =>
[MistralConstants.PLAN_UPDATE, MistralConstants.PLAN_CREATE].includes(
execution.workflow_name
) && execution.getIn(['input', 'container']) === planName
)
.map(execution => execution.get('updated_at'))
.sort()
.last() || 0
);
};
/**
* Helper function to get a validation results by validation name
*/