blob: c03b0f180cb899deb853d45ddbb0465efe6e1f99 [file] [log] [blame]
Jon Hallf1f285d2015-01-12 10:58:08 -08001"""
2Description: This test is an example of a simple single node ONOS test
3
4List of test cases:
5CASE1: Compile ONOS and push it to the test machine
6CASE2: Assign mastership to controller
7CASE3: Pingall
8"""
9class PingallExample:
10
kelvin-onlabd3b64892015-01-20 13:26:24 -080011 def __init__( self ):
Jon Hallf1f285d2015-01-12 10:58:08 -080012 self.default = ''
13
kelvin-onlabd3b64892015-01-20 13:26:24 -080014 def CASE1( self, main ):
Jon Hallf1f285d2015-01-12 10:58:08 -080015 """
16 CASE1 is to compile ONOS and push it to the test machines
17
18 Startup sequence:
19 git pull
20 mvn clean install
21 onos-package
22 cell <name>
23 onos-verify-cell
24 onos-install -f
25 onos-wait-for-start
26 """
27 desc = "ONOS Single node cluster restart HA test - initialization"
28 main.log.report( desc )
29 main.case( "Setting up test environment" )
30
31 # load some vairables from the params file
kelvin-onlabd3b64892015-01-20 13:26:24 -080032 PULLCODE = False
Jon Hallf1f285d2015-01-12 10:58:08 -080033 if main.params[ 'Git' ] == 'True':
kelvin-onlabd3b64892015-01-20 13:26:24 -080034 PULLCODE = True
35 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hallf1f285d2015-01-12 10:58:08 -080036
kelvin-onlabd3b64892015-01-20 13:26:24 -080037 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
Jon Hallf1f285d2015-01-12 10:58:08 -080038
39 main.step( "Applying cell variable to environment" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080040 cellResult = main.ONOSbench.setCell( cellName )
41 verifyResult = main.ONOSbench.verifyCell()
Jon Hallf1f285d2015-01-12 10:58:08 -080042
43 main.log.report( "Uninstalling ONOS" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080044 main.ONOSbench.onosUninstall( ONOS1Ip )
Jon Hallf1f285d2015-01-12 10:58:08 -080045
kelvin-onlabd3b64892015-01-20 13:26:24 -080046 cleanInstallResult = main.TRUE
47 gitPullResult = main.TRUE
Jon Hallf1f285d2015-01-12 10:58:08 -080048
49 main.step( "Compiling the latest version of ONOS" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080050 if PULLCODE:
Jon Hallf1f285d2015-01-12 10:58:08 -080051 main.step( "Git checkout and pull master" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080052 main.ONOSbench.gitCheckout( "master" )
53 gitPullResult = main.ONOSbench.gitPull()
Jon Hallf1f285d2015-01-12 10:58:08 -080054
55 main.step( "Using mvn clean & install" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080056 cleanInstallResult = main.TRUE
57 if gitPullResult == main.TRUE:
58 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hallf1f285d2015-01-12 10:58:08 -080059 else:
60 main.log.warn( "Did not pull new code so skipping mvn " +
61 "clean install" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080062 main.ONOSbench.getVersion( report=True )
Jon Hallf1f285d2015-01-12 10:58:08 -080063
kelvin-onlabd3b64892015-01-20 13:26:24 -080064 cellResult = main.ONOSbench.setCell( cellName )
65 verifyResult = main.ONOSbench.verifyCell()
Jon Hallf1f285d2015-01-12 10:58:08 -080066 main.step( "Creating ONOS package" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080067 packageResult = main.ONOSbench.onosPackage()
Jon Hallf1f285d2015-01-12 10:58:08 -080068
69 main.step( "Installing ONOS package" )
kelvin-onlabd3b64892015-01-20 13:26:24 -080070 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
71 node=ONOS1Ip )
Jon Hallf1f285d2015-01-12 10:58:08 -080072
73 main.step( "Checking if ONOS is up yet" )
74 for i in range( 2 ):
kelvin-onlabd3b64892015-01-20 13:26:24 -080075 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
76 if onos1Isup:
Jon Hallf1f285d2015-01-12 10:58:08 -080077 break
kelvin-onlabd3b64892015-01-20 13:26:24 -080078 if not onos1Isup:
Jon Hallf1f285d2015-01-12 10:58:08 -080079 main.log.report( "ONOS1 didn't start!" )
80
81 # TODO: if it becomes an issue, we can retry this step a few times
82
kelvin-onlabd3b64892015-01-20 13:26:24 -080083 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hallf1f285d2015-01-12 10:58:08 -080084
kelvin-onlabd3b64892015-01-20 13:26:24 -080085 case1Result = ( cleanInstallResult and packageResult and
86 cellResult and verifyResult and
87 onos1InstallResult and
88 onos1Isup and cliResult )
Jon Hallf1f285d2015-01-12 10:58:08 -080089
kelvin-onlabd3b64892015-01-20 13:26:24 -080090 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
kelvin-onlaba72405f2015-01-20 15:59:41 -080091 onpass="Test startup successful",
92 onfail="Test startup NOT successful" )
Jon Hallf1f285d2015-01-12 10:58:08 -080093
kelvin-onlabd3b64892015-01-20 13:26:24 -080094 if case1Result == main.FALSE:
Jon Hallf1f285d2015-01-12 10:58:08 -080095 main.cleanup()
96 main.exit()
Jon Hall882f8952015-03-26 19:43:26 -070097
kelvin-onlab52730b52015-02-04 16:59:18 -080098 # Starting the mininet using the old way
99 main.step( "Starting Mininet ..." )
100 netIsUp = main.Mininet1.startNet()
101 if netIsUp:
102 main.log.info("Mininet CLI is up")
103 else:
104 main.log.info("Mininet CLI is down")
Jon Hallf1f285d2015-01-12 10:58:08 -0800105
kelvin-onlabd3b64892015-01-20 13:26:24 -0800106 def CASE2( self, main ):
Jon Hallf1f285d2015-01-12 10:58:08 -0800107 """
108 Assign mastership to controller
109 """
110 import re
111
112 main.log.report( "Assigning switches to controller" )
113 main.case( "Assigning Controller" )
114 main.step( "Assign switches to controller" )
115
kelvin-onlabd3b64892015-01-20 13:26:24 -0800116 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
117 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hallf1f285d2015-01-12 10:58:08 -0800118
119 for i in range( 1, 14 ):
kelvin-onlabd3b64892015-01-20 13:26:24 -0800120 main.Mininet1.assignSwController(
Jon Hallf1f285d2015-01-12 10:58:08 -0800121 sw=str( i ),
kelvin-onlabd3b64892015-01-20 13:26:24 -0800122 ip1=ONOS1Ip,
123 port1=ONOS1Port )
Jon Hallf1f285d2015-01-12 10:58:08 -0800124
kelvin-onlabd3b64892015-01-20 13:26:24 -0800125 mastershipCheck = main.TRUE
Jon Hallf1f285d2015-01-12 10:58:08 -0800126 for i in range( 1, 14 ):
kelvin-onlabd3b64892015-01-20 13:26:24 -0800127 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallf1f285d2015-01-12 10:58:08 -0800128 try:
129 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800130 except Exception:
Jon Hallf1f285d2015-01-12 10:58:08 -0800131 main.log.info( repr( response ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800132 if re.search( "tcp:" + ONOS1Ip, response ):
133 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallf1f285d2015-01-12 10:58:08 -0800134 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800135 mastershipCheck = main.FALSE
136 if mastershipCheck == main.TRUE:
Jon Hallf1f285d2015-01-12 10:58:08 -0800137 main.log.report( "Switch mastership assigned correctly" )
138 utilities.assert_equals(
139 expect=main.TRUE,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800140 actual=mastershipCheck,
Jon Hallf1f285d2015-01-12 10:58:08 -0800141 onpass="Switch mastership assigned correctly",
142 onfail="Switches not assigned correctly to controllers" )
143
kelvin-onlabd3b64892015-01-20 13:26:24 -0800144 def CASE3( self, main ):
Jon Hallf1f285d2015-01-12 10:58:08 -0800145 """
Jon Hall146f1522015-03-24 15:33:24 -0700146 Install forwarding app, Pingall and unistall the app
Jon Hallf1f285d2015-01-12 10:58:08 -0800147 """
148 import time
149
150 main.log.report( "Run Pingall" )
151 main.case( "Run Pingall" )
152
153 # install onos-app-fwd
Jon Hall882f8952015-03-26 19:43:26 -0700154 main.step( "Activate reactive forwarding app" )
155 main.ONOScli1.activateApp( "org.onosproject.fwd" )
Jon Hallf1f285d2015-01-12 10:58:08 -0800156
157 # REACTIVE FWD test
Jon Hall882f8952015-03-26 19:43:26 -0700158 main.step( "Run the pingall command in Mininet" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800159 pingResult = main.FALSE
Jon Hallf1f285d2015-01-12 10:58:08 -0800160 time1 = time.time()
kelvin-onlabd3b64892015-01-20 13:26:24 -0800161 pingResult = main.Mininet1.pingall()
Jon Hallf1f285d2015-01-12 10:58:08 -0800162 time2 = time.time()
163 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
164
165 # uninstall onos-app-fwd
Jon Hall882f8952015-03-26 19:43:26 -0700166 main.step( "Deactivate reactive forwarding app" )
167 main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
Jon Hallf1f285d2015-01-12 10:58:08 -0800168
kelvin-onlabd3b64892015-01-20 13:26:24 -0800169 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
kelvin-onlaba72405f2015-01-20 15:59:41 -0800170 onpass="All hosts are reachable",
171 onfail="Some pings failed" )