Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2017 Open Networking Foundation ( ONF ) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | ( at your option ) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
| 22 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run |
| 23 | import random |
| 24 | from random import randint |
| 25 | from datetime import datetime |
| 26 | import time |
| 27 | |
| 28 | class SRHAFuncs(): |
| 29 | |
| 30 | def __init__( self ): |
| 31 | self.default = '' |
| 32 | self.topo = dict() |
| 33 | self.topo[ '2x2' ] = ( 2, 2, '', '2x2 Leaf-spine' ) |
| 34 | self.topo[ '4x4' ] = ( 4, 4, '--leaf=4 --spine=4', '4x4 Leaf-spine' ) |
| 35 | |
| 36 | def runTest( self, main, caseNum, numNodes, Topo, minFlow, isRandom, isKillingSwitch ): |
| 37 | if not hasattr( main, 'apps' ): |
| 38 | run.initTest( main ) |
| 39 | |
| 40 | description = "High Availability tests - " + \ |
| 41 | self.generateDescription( isRandom, isKillingSwitch ) + \ |
| 42 | self.topo[ Topo ][ 3 ] |
| 43 | main.case( description ) |
| 44 | run.config( main, Topo ) |
| 45 | run.installOnos( main ) |
| 46 | run.loadJson( main ) |
| 47 | run.loadChart( main ) |
| 48 | run.startMininet( main, 'cord_fabric.py', args=self.topo[ Topo ][ 2 ] ) |
| 49 | # pre-configured routing and bridging test |
| 50 | run.checkFlows( main, minFlowCount=minFlow ) |
| 51 | run.pingAll( main ) |
| 52 | switch = self.topo[ Topo ][ 0 ] + self.topo[ Topo ][ 1 ] |
| 53 | link = ( self.topo[ Topo ][ 0 ] + self.topo[ Topo ][ 1 ] ) * self.topo[ Topo ][ 0 ] |
| 54 | self.generateRandom( isRandom ) |
| 55 | for i in range( 0, main.failures ): |
| 56 | toKill = self.getNextNum( isRandom, main.Cluster.numCtrls, i ) |
| 57 | run.killOnos( main, [ toKill ], '{}'.format( switch ), |
| 58 | '{}'.format( link ), '{}'.format( numNodes - 1 ) ) |
| 59 | run.pingAll( main, 'CASE{}_ONOS_Failure{}'.format( caseNum, i + 1 ) ) |
| 60 | if isKillingSwitch: |
| 61 | self.killAndRecoverSwitch( main, caseNum, numNodes, |
| 62 | Topo, minFlow, isRandom, |
| 63 | i, switch, link ) |
| 64 | run.recoverOnos( main, [ toKill ], '{}'.format( switch ), |
| 65 | '{}'.format( link ), '{}'.format( numNodes ) ) |
| 66 | run.checkFlows( main, minFlowCount=minFlow, |
| 67 | tag='CASE{}_ONOS{}_Recovery'.format( caseNum, i + 1 ) ) |
| 68 | run.pingAll( main, 'CASE{}_ONOS_Recovery{}'.format( caseNum, i + 1 ) ) |
| 69 | # TODO Dynamic config of hosts in subnet |
| 70 | # TODO Dynamic config of host not in subnet |
| 71 | # TODO Dynamic config of vlan xconnect |
| 72 | # TODO Vrouter integration |
| 73 | # TODO Mcast integration |
| 74 | if hasattr( main, 'Mininet1' ): |
| 75 | run.cleanup( main ) |
| 76 | else: |
| 77 | # TODO: disconnect TestON from the physical network |
| 78 | pass |
| 79 | |
| 80 | def generateDescription( self, isRandom, isKillingSwitch ): |
| 81 | return "ONOS " + ( "random " if isRandom else "" ) + "failures" +\ |
| 82 | ( " and Switch " + ( "random " if isRandom else "" ) + "failures " |
| 83 | if isKillingSwitch else " " ) |
| 84 | |
| 85 | def generateRandom( self, isRandom ): |
| 86 | if isRandom: |
| 87 | random.seed( datetime.now() ) |
| 88 | |
| 89 | def getNextNum( self, isRandom, numCtrl, pos ): |
| 90 | return randint( 0, ( numCtrl - 1 ) ) if isRandom else pos % numCtrl |
| 91 | |
| 92 | def killAndRecoverSwitch( self, main, caseNum, numNodes, Topo, minFlow, isRandom, pos, numSwitch, numLink ): |
| 93 | switchToKill = self.getNextNum( isRandom, self.topo[ Topo ][ 0 ], pos ) |
| 94 | run.killSwitch( main, main.spines[ switchToKill ][ 'name' ], |
| 95 | switches='{}'.format( numSwitch - 1 ), |
| 96 | links='{}'.format( numLink - numSwitch ) ) |
| 97 | time.sleep( main.switchSleep ) |
| 98 | run.pingAll( main, "CASE{}_SWITCH_Failure{}".format( caseNum, pos + 1 ) ) |
| 99 | run.recoverSwitch( main, main.spines[ switchToKill ][ 'name' ], |
| 100 | switches='{}'.format( numSwitch ), |
| 101 | links='{}'.format( numLink ) ) |
| 102 | run.checkFlows( main, minFlowCount=minFlow, |
| 103 | tag="CASE{}_SWITCH_Recovery{}".format( caseNum, pos + 1 ) ) |
| 104 | run.pingAll( main, "CASE{}_SWITCH_Recovery{}".format( caseNum, pos + 1 ) ) |