blob: 5828d932386c5ea8facb4b65f9b0378d7759f2b7 [file] [log] [blame]
Devin Lim57221b02018-02-14 15:45:36 -08001"""
2Copyright 2017 Open Networking Foundation ( ONF )
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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
22from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run
23import random
24from random import randint
25from datetime import datetime
26import time
27
28class SRHAFuncs():
29
30 def __init__( self ):
31 self.default = ''
Siddesh167bc882021-03-23 21:03:43 +000032 self.topo = run.getTopo()
Devin Lim57221b02018-02-14 15:45:36 -080033
Siddesh167bc882021-03-23 21:03:43 +000034 def runTest( self, main, caseNum, numNodes, topology, minFlow, isRandom, isKillingSwitch ):
Jon Hall9b0de1f2020-08-24 15:38:04 -070035 try:
36 if not hasattr( main, 'apps' ):
37 run.initTest( main )
Devin Lim57221b02018-02-14 15:45:36 -080038
Jon Hall9b0de1f2020-08-24 15:38:04 -070039 description = "High Availability tests - " + \
40 self.generateDescription( isRandom, isKillingSwitch ) + \
Siddesh167bc882021-03-23 21:03:43 +000041 self.topo[ topology ][ 'description' ]
Jon Hall9b0de1f2020-08-24 15:38:04 -070042 main.case( description )
Siddesh167bc882021-03-23 21:03:43 +000043 run.config( main, topology )
Jon Hall9b0de1f2020-08-24 15:38:04 -070044 run.installOnos( main )
Jon Hall06fd0df2021-01-25 15:50:06 -080045 if not main.persistentSetup:
46 run.loadJson( main )
Jon Hall9b0de1f2020-08-24 15:38:04 -070047 run.loadChart( main )
Siddesh167bc882021-03-23 21:03:43 +000048 run.startMininet( main, 'cord_fabric.py', args=self.topo[ topology ][ 'mininetArgs' ] )
Jon Hall06fd0df2021-01-25 15:50:06 -080049 if not main.persistentSetup:
50 # xconnects need to be loaded after topology
51 run.loadXconnects( main )
Jon Hall9b0de1f2020-08-24 15:38:04 -070052 # pre-configured routing and bridging test
53 run.checkFlows( main, minFlowCount=minFlow )
54 run.pingAll( main )
Siddesh167bc882021-03-23 21:03:43 +000055 switch = self.topo[ topology ][ 'spines' ] + self.topo[ topology ][ 'leaves' ]
56 link = ( self.topo[ topology ][ 'spines' ] + self.topo[ topology ][ 'leaves' ] ) * self.topo[ topology ][ 'spines' ]
Jon Hall9b0de1f2020-08-24 15:38:04 -070057 self.generateRandom( isRandom )
58 for i in range( 0, main.failures ):
59 toKill = self.getNextNum( isRandom, main.Cluster.numCtrls, i )
60 run.killOnos( main, [ toKill ], '{}'.format( switch ),
61 '{}'.format( link ), '{}'.format( numNodes - 1 ) )
62 run.pingAll( main, 'CASE{}_ONOS_Failure{}'.format( caseNum, i + 1 ) )
63 if isKillingSwitch:
64 self.killAndRecoverSwitch( main, caseNum, numNodes,
Siddesh167bc882021-03-23 21:03:43 +000065 topology, minFlow, isRandom,
Jon Hall9b0de1f2020-08-24 15:38:04 -070066 i, switch, link )
67 run.recoverOnos( main, [ toKill ], '{}'.format( switch ),
68 '{}'.format( link ), '{}'.format( numNodes ) )
69 run.checkFlows( main, minFlowCount=minFlow,
70 tag='CASE{}_ONOS{}_Recovery'.format( caseNum, i + 1 ) )
71 run.pingAll( main, 'CASE{}_ONOS_Recovery{}'.format( caseNum, i + 1 ) )
72 # TODO Dynamic config of hosts in subnet
73 # TODO Dynamic config of host not in subnet
74 # TODO Dynamic config of vlan xconnect
75 # TODO Vrouter integration
76 # TODO Mcast integration
Jon Hall9b0de1f2020-08-24 15:38:04 -070077 except Exception as e:
78 main.log.exception( "Error in runTest" )
79 main.skipCase( result="FAIL", msg=e )
Jon Hallf69e3162020-09-01 09:08:44 -070080 finally:
81 run.cleanup( main )
Devin Lim57221b02018-02-14 15:45:36 -080082
83 def generateDescription( self, isRandom, isKillingSwitch ):
84 return "ONOS " + ( "random " if isRandom else "" ) + "failures" +\
85 ( " and Switch " + ( "random " if isRandom else "" ) + "failures "
86 if isKillingSwitch else " " )
87
88 def generateRandom( self, isRandom ):
89 if isRandom:
90 random.seed( datetime.now() )
91
92 def getNextNum( self, isRandom, numCtrl, pos ):
93 return randint( 0, ( numCtrl - 1 ) ) if isRandom else pos % numCtrl
94
Siddesh167bc882021-03-23 21:03:43 +000095 def killAndRecoverSwitch( self, main, caseNum, numNodes, topology, minFlow, isRandom, pos, numSwitch, numLink ):
96 switchToKill = self.getNextNum( isRandom, self.topo[ topology ][ 'spines' ], pos )
Devin Lim57221b02018-02-14 15:45:36 -080097 run.killSwitch( main, main.spines[ switchToKill ][ 'name' ],
98 switches='{}'.format( numSwitch - 1 ),
99 links='{}'.format( numLink - numSwitch ) )
100 time.sleep( main.switchSleep )
101 run.pingAll( main, "CASE{}_SWITCH_Failure{}".format( caseNum, pos + 1 ) )
102 run.recoverSwitch( main, main.spines[ switchToKill ][ 'name' ],
103 switches='{}'.format( numSwitch ),
104 links='{}'.format( numLink ) )
105 run.checkFlows( main, minFlowCount=minFlow,
106 tag="CASE{}_SWITCH_Recovery{}".format( caseNum, pos + 1 ) )
107 run.pingAll( main, "CASE{}_SWITCH_Recovery{}".format( caseNum, pos + 1 ) )