Skip to content

Commit

Permalink
5560: [TEST]: Add methods to break/restore ISLs in test
Browse files Browse the repository at this point in the history
Implements #5560

* Replaced places in tests where port is set up/down
with waiting for ISL get up/down with reusable methods
  • Loading branch information
pkazlenka committed Mar 14, 2024
1 parent 638ba59 commit 5ca8b02
Show file tree
Hide file tree
Showing 35 changed files with 420 additions and 1,131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.openkilda.functionaltests.helpers

import groovy.util.logging.Slf4j
import org.openkilda.messaging.info.event.IslChangeType
import org.openkilda.testing.model.topology.TopologyDefinition
import org.openkilda.testing.model.topology.TopologyDefinition.Isl
import org.openkilda.testing.service.northbound.NorthboundService
import org.openkilda.testing.service.northbound.NorthboundServiceV2
import org.openkilda.testing.tools.IslUtils
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

import static groovyx.gpars.GParsExecutorsPool.withPool
import static org.openkilda.messaging.info.event.IslChangeType.DISCOVERED
import static org.openkilda.messaging.info.event.IslChangeType.FAILED
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE

/**
* Holds utility methods for manipulating y-flows.
*/
@Component
@Slf4j
@Scope(SCOPE_PROTOTYPE)
class IslHelper {
@Autowired
TopologyDefinition topology
@Autowired @Qualifier("islandNbV2")
NorthboundServiceV2 northboundV2
@Autowired @Qualifier("islandNb")
NorthboundService northbound
@Autowired
IslUtils islUtils
@Autowired
PortAntiflapHelper antiflapHelper


def breakIsl(Isl islToBreak) {
if (getIslStatus(islToBreak).equals(DISCOVERED)) {
antiflapHelper.portDown(islToBreak.getSrcSwitch().getDpId(), islToBreak.getSrcPort())
}
islUtils.waitForIslStatus([islToBreak], FAILED)
}

def breakIsls(Set<Isl> islsToBreak) {
withPool {
islsToBreak.eachParallel{
breakIsl(it)
}
}
}

def breakIsls(List<Isl> islsToBreak) {
breakIsls(islsToBreak as Set)
}

def restoreIsl(Isl islToRestore) {
if(!getIslStatus(islToRestore).equals(DISCOVERED)) {
withPool{
[{antiflapHelper.portUp(islToRestore.getSrcSwitch().getDpId(), islToRestore.getSrcPort())},
{antiflapHelper.portUp(islToRestore.getDstSwitch().getDpId(), islToRestore.getDstPort())}
].eachParallel{it()}
}
}
islUtils.waitForIslStatus([islToRestore], DISCOVERED)
}

def restoreIsls(Set<Isl> islsToRestore) {
withPool {
islsToRestore.eachParallel{
restoreIsl(it)
}
}
}

def restoreIsls(List<Isl> islsToRestore) {
restoreIsls(islsToRestore as Set)
}

def getIslStatus(Isl isl) {
def islInfo = islUtils.getIslInfo(isl)
if (islInfo.isPresent()) {
return islInfo.get().state
} else {
return null
}

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

import org.openkilda.functionaltests.helpers.IslHelper
import org.openkilda.functionaltests.helpers.model.SwitchPairs

import static groovyx.gpars.GParsPool.withPool
Expand All @@ -13,11 +14,9 @@ import org.openkilda.functionaltests.helpers.StatsHelper
import org.openkilda.functionaltests.helpers.SwitchHelper
import org.openkilda.functionaltests.helpers.TopologyHelper
import org.openkilda.functionaltests.helpers.Wrappers
import org.openkilda.model.SwitchId
import org.openkilda.testing.model.topology.TopologyDefinition
import org.openkilda.testing.service.database.Database
import org.openkilda.testing.service.floodlight.FloodlightsHelper
import org.openkilda.testing.service.labservice.LabService
import org.openkilda.testing.service.lockkeeper.LockKeeperService
import org.openkilda.testing.service.northbound.NorthboundService
import org.openkilda.testing.service.northbound.NorthboundServiceV2
Expand Down Expand Up @@ -71,6 +70,8 @@ class BaseSpecification extends Specification {
StatsHelper statsHelper
@Autowired @Shared
SwitchPairs switchPairs
@Autowired @Shared
IslHelper islHelper

@Value('${spring.profiles.active}') @Shared
String profile
Expand Down
Loading

0 comments on commit 5ca8b02

Please sign in to comment.