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

[TEST]: Improvement: Switch: New interaction approach #5759

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.openkilda.functionaltests.helpers

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

@Component
class KildaProperties {

public static int DISCOVERY_EXHAUSTED_INTERVAL
public static int ANTIFLAP_MIN
public static int ANTIFLAP_COOLDOWN
public static int DISCOVERY_TIMEOUT
public static double BURST_COEFFICIENT
public static String TOPO_DISCO_TOPIC
public static Properties PRODUCER_PROPS

@Autowired
KildaProperties( @Value('${discovery.exhausted.interval}') int discoveryExhaustedInterval,
@Value('${antiflap.min}') int antiflapMin,
@Value('${antiflap.cooldown}') int antiflapCooldown,
@Value('${discovery.timeout}') int discoveryTimeout,
@Value('${burst.coefficient}') double burstCoefficient,
@Autowired @Qualifier("kafkaProducerProperties") Properties producerProps,
@Value("#{kafkaTopicsConfig.getTopoDiscoTopic()}") String topoDiscoTopic) {

DISCOVERY_EXHAUSTED_INTERVAL = discoveryExhaustedInterval
ANTIFLAP_MIN = antiflapMin
ANTIFLAP_COOLDOWN = antiflapCooldown
DISCOVERY_TIMEOUT = discoveryTimeout
BURST_COEFFICIENT = burstCoefficient
TOPO_DISCO_TOPIC = topoDiscoTopic
PRODUCER_PROPS = producerProps

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openkilda.functionaltests.helpers

import org.openkilda.messaging.model.SwitchPropertiesDto.RttState
import org.openkilda.testing.service.northbound.payloads.SwitchSyncExtendedResult

import groovy.transform.Memoized
import org.openkilda.functionaltests.helpers.model.SwitchDbData
Expand All @@ -22,7 +23,6 @@ import org.openkilda.model.cookie.ServiceCookie.ServiceCookieTag
import org.openkilda.northbound.dto.v1.switches.MeterInfoDto
import org.openkilda.northbound.dto.v1.switches.SwitchDto
import org.openkilda.northbound.dto.v1.switches.SwitchPropertiesDto
import org.openkilda.northbound.dto.v1.switches.SwitchSyncResult
import org.openkilda.northbound.dto.v2.flows.FlowMirrorPointPayload
import org.openkilda.northbound.dto.v2.switches.LagPortRequest
import org.openkilda.northbound.dto.v2.switches.LagPortResponse
Expand Down Expand Up @@ -695,20 +695,20 @@ class SwitchHelper {
assert result == switchValidateInfo.asExpected
}

static SwitchSyncResult synchronize(SwitchId switchId, boolean removeExcess=true) {
static SwitchSyncExtendedResult synchronize(SwitchId switchId, boolean removeExcess=true) {
return northbound.get().synchronizeSwitch(switchId, removeExcess)
}

/**
* Synchronizes each switch from the list and returns a map of SwitchSyncResults, where the key is
* Synchronizes each switch from the list and returns a map of SwitchSyncExtendedResults, where the key is
* SwitchId and the value is result of synchronization if there were entries which had to be fixed.
* I.e. if all the switches were in expected state, then empty list is returned. If there were only
* two switches in unexpected state, than resulting map will have only two entries, etc.
* @param switchesToSynchronize SwitchIds which should be synchronized
* @return Map of SwitchIds and SwitchSyncResults for switches which weren't in expected state before
* @return Map of SwitchIds and SwitchSyncExtendedResult for switches which weren't in expected state before
* the synchronization
*/
static Map<SwitchId, SwitchSyncResult> synchronizeAndCollectFixedDiscrepancies(List<SwitchId> switchesToSynchronize) {
static Map<SwitchId, SwitchSyncExtendedResult> synchronizeAndCollectFixedDiscrepancies(List<SwitchId> switchesToSynchronize) {
return withPool {
switchesToSynchronize.collectParallel { [it, northbound.get().synchronizeSwitch(it, true)] }
.collectEntries { [(it[0]): it[1]] }
Expand All @@ -724,13 +724,13 @@ class SwitchHelper {
}

/**
* Synchronizes the switch and returns an optional SwitchSyncResult if the switch was in an unexpected state
* Synchronizes the switch and returns an optional SwitchSyncExtendedResult if the switch was in an unexpected state
* before the synchronization.
* @param switchToSynchronize SwitchId to synchronize
* @return optional SwitchSyncResult if the switch was in an unexpected state
* @return optional SwitchSyncExtendedResult if the switch was in an unexpected state
* before the synchronization
*/
static Optional<SwitchSyncResult> synchronizeAndCollectFixedDiscrepancies(SwitchId switchToSynchronize) {
static Optional<SwitchSyncExtendedResult> synchronizeAndCollectFixedDiscrepancies(SwitchId switchToSynchronize) {
return Optional.ofNullable(synchronizeAndCollectFixedDiscrepancies([switchToSynchronize]).get(switchToSynchronize))
}

Expand All @@ -739,7 +739,7 @@ class SwitchHelper {
* @param switchesToSynchronize
* @return
*/
static Map<SwitchId, SwitchSyncResult> synchronizeAndCollectFixedDiscrepancies(Set<SwitchId> switchesToSynchronize) {
static Map<SwitchId, SwitchSyncExtendedResult> synchronizeAndCollectFixedDiscrepancies(Set<SwitchId> switchesToSynchronize) {
return synchronizeAndCollectFixedDiscrepancies(switchesToSynchronize as List)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import static org.springframework.beans.factory.config.ConfigurableBeanFactory.S

import org.openkilda.functionaltests.helpers.builder.FlowBuilder
import org.openkilda.functionaltests.helpers.model.FlowExtended
import org.openkilda.functionaltests.helpers.model.SwitchExtended
import org.openkilda.functionaltests.helpers.model.SwitchPair
import org.openkilda.functionaltests.helpers.model.SwitchPortVlan
import org.openkilda.functionaltests.model.cleanup.CleanupManager
Expand Down Expand Up @@ -52,6 +53,14 @@ class FlowFactory {
return new FlowBuilder(srcSwitch, dstSwitch, northbound, northboundV2, topology, cleanupManager, database, useTraffgenPorts, busyEndpoints)
}

FlowBuilder getBuilder(SwitchExtended srcSwitch, SwitchExtended dstSwitch, boolean useTraffgenPorts = true, List<SwitchPortVlan> busyEndpoints = []) {
yuliiamir marked this conversation as resolved.
Show resolved Hide resolved
getBuilder(srcSwitch.sw, dstSwitch.sw, useTraffgenPorts, busyEndpoints)
}

FlowBuilder getSingleSwBuilder(SwitchExtended srcSwitch, boolean useTraffgenPorts = true, List<SwitchPortVlan> busyEndpoints = []) {
getBuilder(srcSwitch.sw, srcSwitch.sw, useTraffgenPorts, busyEndpoints)
}

/*
This method allows random Flow creation on specified switches and waits for it
to become UP by default or to be in an expected state.
Expand All @@ -66,6 +75,16 @@ class FlowFactory {
return getBuilder(srcSwitch, dstSwitch, useTraffgenPorts, busyEndpoints).build().create(expectedFlowState)
}

FlowExtended getRandom(SwitchExtended srcSwitch, SwitchExtended dstSwitch, boolean useTraffgenPorts = true, FlowState expectedFlowState = UP,
List<SwitchPortVlan> busyEndpoints = []) {
getRandom(srcSwitch.sw, dstSwitch.sw)
}

FlowExtended getSingleSwRandom(SwitchExtended srcSwitch, boolean useTraffgenPorts = true, FlowState expectedFlowState = UP,
List<SwitchPortVlan> busyEndpoints = []) {
getRandom(srcSwitch.sw, srcSwitch.sw)
}

FlowExtended getRandomV1(Switch srcSwitch, Switch dstSwitch, boolean useTraffgenPorts = true, FlowState expectedFlowState = UP,
List<SwitchPortVlan> busyEndpoints = []) {
return getBuilder(srcSwitch, dstSwitch, useTraffgenPorts, busyEndpoints).build().createV1(expectedFlowState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.openkilda.functionaltests.helpers.factory

import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE

import org.openkilda.functionaltests.helpers.model.SwitchExtended
import org.openkilda.functionaltests.model.cleanup.CleanupManager
import org.openkilda.testing.model.topology.TopologyDefinition
import org.openkilda.testing.model.topology.TopologyDefinition.Switch
import org.openkilda.testing.service.database.Database
import org.openkilda.testing.service.lockkeeper.LockKeeperService
import org.openkilda.testing.service.northbound.NorthboundService
import org.openkilda.testing.service.northbound.NorthboundServiceV2

import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component

@Slf4j
@Component
@Scope(SCOPE_PROTOTYPE)
class SwitchFactory {

@Autowired @Qualifier("islandNb")
NorthboundService northbound
@Autowired @Qualifier("islandNbV2")
NorthboundServiceV2 northboundV2
@Autowired
TopologyDefinition topology
@Autowired
Database database
@Autowired
LockKeeperService lockKeeper
@Autowired
CleanupManager cleanupManager

SwitchExtended get(Switch sw) {
List<Integer> islPorts = []
topology.getRelatedIsls(sw).each {
it?.srcSwitch?.dpId != sw.dpId ?: islPorts.add(it.srcPort)
it?.dstSwitch?.dpId != sw.dpId ?: islPorts.add(it.dstPort)
}
List<Integer> traffGen = topology.traffGens.findAll{ it.switchConnected.dpId == sw.dpId }.switchPort
return new SwitchExtended(sw, islPorts, traffGen,
northbound, northboundV2, database, lockKeeper, cleanupManager)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.openkilda.functionaltests.helpers.model

import static org.openkilda.functionaltests.helpers.Wrappers.wait
import static org.openkilda.functionaltests.model.cleanup.CleanupActionType.DELETE_LAG_LOGICAL_PORT
import static org.openkilda.testing.Constants.WAIT_OFFSET

import org.openkilda.functionaltests.model.cleanup.CleanupManager
import org.openkilda.model.SwitchId
import org.openkilda.northbound.dto.v2.switches.LagPortRequest
import org.openkilda.northbound.dto.v2.switches.LagPortResponse
import org.openkilda.testing.service.northbound.NorthboundServiceV2

import com.fasterxml.jackson.annotation.JsonIgnore
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.util.logging.Slf4j

@Slf4j
@EqualsAndHashCode(excludes = 'northboundV2, cleanupManager')
@ToString(includeNames = true, excludes = 'northboundV2, cleanupManager')
class LagPort {

SwitchId switchId
Set<Integer> portNumbers
int logicalPortNumber
boolean lacpReply

@JsonIgnore
NorthboundServiceV2 northboundV2
@JsonIgnore
CleanupManager cleanupManager

LagPort(SwitchId switchId,
Set<Integer> portNumbers,
NorthboundServiceV2 northboundV2,
CleanupManager cleanupManager) {
this.switchId = switchId
this.portNumbers = portNumbers
this.northboundV2 = northboundV2
this.cleanupManager = cleanupManager
}

LagPort(SwitchId switchId,
int logicalPortNumber,
List<Integer> portNumbers,
boolean lacpReply,
NorthboundServiceV2 northboundV2,
CleanupManager cleanupManager) {
this.switchId = switchId
this.logicalPortNumber = logicalPortNumber
this.lacpReply = lacpReply
this.portNumbers = portNumbers
this.northboundV2 = northboundV2
this.cleanupManager = cleanupManager
}


LagPort create(boolean lacpReply = null) {
def lagDetails = northboundV2.createLagLogicalPort(switchId, new LagPortRequest(portNumbers , lacpReply))
cleanupManager.addAction(DELETE_LAG_LOGICAL_PORT, { northboundV2.deleteLagLogicalPort(switchId, lagDetails.logicalPortNumber) })
new LagPort(switchId, lagDetails.logicalPortNumber, lagDetails.portNumbers, lagDetails.lacpReply, northboundV2, cleanupManager)
}

LagPort update(LagPortRequest updateRequest) {
def lagDetails = northboundV2.updateLagLogicalPort(switchId, logicalPortNumber, updateRequest)
new LagPort(switchId, lagDetails.logicalPortNumber, lagDetails.portNumbers, lagDetails.lacpReply, northboundV2, cleanupManager)
}

LagPortResponse sendDeleteRequest() {
northboundV2.deleteLagLogicalPort(switchId, logicalPortNumber)
}

LagPortResponse delete() {
def lagDetails = sendDeleteRequest()
wait(WAIT_OFFSET) {
assert !northboundV2.getLagLogicalPort(switchId).logicalPortNumber.contains(logicalPortNumber)
}
return lagDetails
}
}
Loading
Loading