Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new flowHelper method: getFlowHistoryByAction #2791

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,6 +11,7 @@ import org.openkilda.messaging.payload.flow.FlowCreatePayload
import org.openkilda.messaging.payload.flow.FlowEndpointPayload
import org.openkilda.messaging.payload.flow.FlowPayload
import org.openkilda.messaging.payload.flow.FlowState
import org.openkilda.messaging.payload.history.FlowHistoryPayload
import org.openkilda.model.Flow
import org.openkilda.northbound.dto.v2.flows.FlowEndpointV2
import org.openkilda.testing.model.topology.TopologyDefinition
Expand Down Expand Up @@ -261,6 +262,28 @@ class FlowHelper {
}
}

/**
* Check that flow state is changed correctly after corresponding flow history action.
*
* @param flowId
* @param timeFrom history will requested from this timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be

* @param event sequence of flow history actions
* @param state expected flow state
*/
void verifyFlowState(String flowId, Long timeFrom, FlowHistoryEvent event, state) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a strict type for state

def timeTo = timeFrom ? System.currentTimeSeconds() : null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this is kind of tricky. timeTo based on timeFrom, why would you do this? Very strange and not intuitive approach

def flowHistory = northbound.getFlowHistory(flowId, timeFrom, timeTo).findAll {
it.action == event.initAction.toString()
}
assert flowHistory.size() == 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that you want to limit your method with this condition? What if there were more actions on the flow? I'm not insisting, but for me it kind of limits where it can be used or forces to use the 'from' timestamp. that's fine I guess, but requires a lot of 'timestamp' vars for long tests

assert flowHistory.first().histories.last().action == event.finalAction.toString()
assert northbound.getFlowStatus(flowId).status == state
}

void verifyFlowState(String flowId, FlowHistoryEvent event, FlowState state) {
verifyFlowState(flowId, null, event, state)
}
rtretyak marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns flow endpoint with randomly chosen vlan.
*
Expand Down
@@ -0,0 +1,24 @@
package org.openkilda.functionaltests.helpers

enum FlowHistoryAction {
rtretyak marked this conversation as resolved.
Show resolved Hide resolved
//action
FLOW_CREATING("Flow creating"),
FLOW_UPDATING("Flow updating"),
FLOW_REROUTING("Flow rerouting"),

//nested action
SET_THE_FLOW_STATUS_TO_UP("Set the flow status to UP."),
SET_THE_FLOW_STATUS_TO_DOWN("Set the flow status to down."),
FLOW_WAS_VALIDATED_SUCCESSFULLY("Flow was validated successfully"),
rtretyak marked this conversation as resolved.
Show resolved Hide resolved

public final String action

FlowHistoryAction(String action) {
this.action = action
}

@Override
String toString() {
return action
}
}
@@ -0,0 +1,16 @@
package org.openkilda.functionaltests.helpers

enum FlowHistoryEvent {

REROUTE_SUCCESS(FlowHistoryAction.FLOW_REROUTING, FlowHistoryAction.SET_THE_FLOW_STATUS_TO_UP),
REROUTE_FAIL(FlowHistoryAction.FLOW_REROUTING, FlowHistoryAction.SET_THE_FLOW_STATUS_TO_DOWN),
REROUTE_FAIL_PROTECTED_PATH(FlowHistoryAction.FLOW_REROUTING, FlowHistoryAction.FLOW_WAS_VALIDATED_SUCCESSFULLY),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused how FLOW_REROUTING + FLOW_WAS_VALIDATED_SUCCESSFULLY is related to protected paths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied it from flowHistory output after flowState was changed to DEGRADED

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you call it like that? It clearly means that flow is validated after reroute and I would agree with that, but the 'reroute fail for protected path' is just a special case of your test. The flow is validated, and you expect a degraded status in your exact special test, that's fine. But you cannot globally assume that 'rerouting + successfull validation' means 'reroute for protected path failed', that breaks laws of logic. Crocodiles are green, crocodiles are dangerous. Grass is green -> grass is dangerous?


public final FlowHistoryAction initAction
public final FlowHistoryAction finalAction

FlowHistoryEvent(FlowHistoryAction initAction, FlowHistoryAction finalAction){
this.initAction = initAction
this.finalAction = finalAction
}
}
Expand Up @@ -8,6 +8,7 @@ import static org.openkilda.testing.Constants.WAIT_OFFSET

import org.openkilda.functionaltests.HealthCheckSpecification
import org.openkilda.functionaltests.extension.tags.Tags
import org.openkilda.functionaltests.helpers.FlowHistoryEvent
import org.openkilda.functionaltests.helpers.PathHelper
import org.openkilda.functionaltests.helpers.Wrappers
import org.openkilda.functionaltests.helpers.model.SwitchPair
Expand Down Expand Up @@ -75,7 +76,9 @@ class AutoRerouteSpec extends HealthCheckSpecification {
antiflap.portDown(isl.dstSwitch.dpId, isl.dstPort)

then: "The flow becomes 'Down'"
Wrappers.wait(rerouteDelay + WAIT_OFFSET) { assert northbound.getFlowStatus(flow.id).status == FlowState.DOWN }
Wrappers.wait(rerouteDelay + WAIT_OFFSET) {
flowHelper.verifyFlowState(flow.id, FlowHistoryEvent.REROUTE_FAIL, FlowState.DOWN)
}

when: "ISL goes back up"
antiflap.portUp(isl.dstSwitch.dpId, isl.dstPort)
Expand Down
Expand Up @@ -10,6 +10,7 @@ import static org.openkilda.testing.Constants.WAIT_OFFSET

import org.openkilda.functionaltests.HealthCheckSpecification
import org.openkilda.functionaltests.extension.tags.Tags
import org.openkilda.functionaltests.helpers.FlowHistoryEvent
import org.openkilda.functionaltests.helpers.Wrappers
import org.openkilda.messaging.error.MessageError
import org.openkilda.messaging.info.event.IslChangeType
Expand All @@ -22,7 +23,6 @@ import org.openkilda.testing.tools.FlowTrafficExamBuilder

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.client.HttpClientErrorException
import spock.lang.Ignore
import spock.lang.Narrative
import spock.lang.See
import spock.lang.Unroll
Expand Down Expand Up @@ -893,17 +893,22 @@ class ProtectedPathSpec extends HealthCheckSpecification {
antiflap.portDown(protectedIsls[0].dstSwitch.dpId, protectedIsls[0].dstPort)

then: "Flow state is changed to DEGRADED"
Wrappers.wait(WAIT_OFFSET) { assert northbound.getFlowStatus(flow.id).status == FlowState.DEGRADED }
Wrappers.wait(WAIT_OFFSET) {
flowHelper.verifyFlowState(flow.id, FlowHistoryEvent.REROUTE_FAIL_PROTECTED_PATH, FlowState.DEGRADED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is literally false expression. You are not verifying that the reroute failed for protected path, you are just checking that a successful validation happened.

}
verifyAll(northbound.getFlow(flow.id).flowStatusDetails) {
mainFlowPathStatus == "Up"
protectedFlowPathStatus == "Down"
}

when: "Break ISL on the main path (bring port down) for changing the flow state to DOWN"
Long timestampBeforeDown = System.currentTimeSeconds()
antiflap.portDown(currentIsls[0].dstSwitch.dpId, currentIsls[0].dstPort)

then: "Flow state is changed to DOWN"
Wrappers.wait(WAIT_OFFSET) { assert northbound.getFlowStatus(flow.id).status == FlowState.DOWN }
Wrappers.wait(WAIT_OFFSET) {
flowHelper.verifyFlowState(flow.id, timestampBeforeDown, FlowHistoryEvent.REROUTE_FAIL, FlowState.DOWN)
}
verifyAll(northbound.getFlow(flow.id).flowStatusDetails) {
mainFlowPathStatus == "Down"
protectedFlowPathStatus == "Down"
Expand Down Expand Up @@ -942,13 +947,14 @@ class ProtectedPathSpec extends HealthCheckSpecification {
"Could not swap paths: Protected flow path $flow.id is not in ACTIVE state"

when: "Restore ISL for the protected path"
Long timestampBeforeUP = System.currentTimeSeconds()
antiflap.portUp(protectedIsls[0].srcSwitch.dpId, protectedIsls[0].srcPort)
antiflap.portUp(protectedIsls[0].dstSwitch.dpId, protectedIsls[0].dstPort)

then: "Flow state is changed to UP"
//it often fails in scope of the whole spec on the hardware env, that's why '* 1.5' is added
Wrappers.wait(discoveryInterval * 1.5 + WAIT_OFFSET) {
assert northbound.getFlowStatus(flow.id).status == FlowState.UP
flowHelper.verifyFlowState(flow.id, timestampBeforeUP, FlowHistoryEvent.REROUTE_SUCCESS, FlowState.UP)
}

and: "Cleanup: Restore topology, delete flows and reset costs"
Expand Down