blob: faf374f58962568e4661db5b0afe786ff290fe89 [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
11 def __init__( self ) :
12 self.default = ''
13
14 def CASE1( self, main ) :
15 """
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
32 PULL_CODE = False
33 if main.params[ 'Git' ] == 'True':
34 PULL_CODE = True
35 cell_name = main.params[ 'ENV' ][ 'cellName' ]
36
37 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
38
39 main.step( "Applying cell variable to environment" )
40 cell_result = main.ONOSbench.set_cell( cell_name )
41 verify_result = main.ONOSbench.verify_cell()
42
43 main.log.report( "Uninstalling ONOS" )
44 main.ONOSbench.onos_uninstall( ONOS1_ip )
45
46 clean_install_result = main.TRUE
47 git_pull_result = main.TRUE
48
49 main.step( "Compiling the latest version of ONOS" )
50 if PULL_CODE:
51 main.step( "Git checkout and pull master" )
52 main.ONOSbench.git_checkout( "master" )
53 git_pull_result = main.ONOSbench.git_pull()
54
55 main.step( "Using mvn clean & install" )
56 clean_install_result = main.TRUE
57 if git_pull_result == main.TRUE:
58 clean_install_result = main.ONOSbench.clean_install()
59 else:
60 main.log.warn( "Did not pull new code so skipping mvn " +
61 "clean install" )
62 main.ONOSbench.get_version( report=True )
63
64 cell_result = main.ONOSbench.set_cell( cell_name )
65 verify_result = main.ONOSbench.verify_cell()
66 main.step( "Creating ONOS package" )
67 package_result = main.ONOSbench.onos_package()
68
69 main.step( "Installing ONOS package" )
70 onos1_install_result = main.ONOSbench.onos_install( options="-f",
71 node=ONOS1_ip )
72
73 main.step( "Checking if ONOS is up yet" )
74 for i in range( 2 ):
75 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
76 if onos1_isup:
77 break
78 if not onos1_isup:
79 main.log.report( "ONOS1 didn't start!" )
80
81 # TODO: if it becomes an issue, we can retry this step a few times
82
83 cli_result = main.ONOScli1.start_onos_cli( ONOS1_ip )
84
85 case1_result = ( clean_install_result and package_result and
86 cell_result and verify_result and
87 onos1_install_result and
88 onos1_isup and cli_result )
89
90 utilities.assert_equals( expect=main.TRUE, actual=case1_result,
91 onpass="Test startup successful",
92 onfail="Test startup NOT successful" )
93
94 if case1_result == main.FALSE:
95 main.cleanup()
96 main.exit()
97
98 def CASE2( self, main ) :
99 """
100 Assign mastership to controller
101 """
102 import re
103
104 main.log.report( "Assigning switches to controller" )
105 main.case( "Assigning Controller" )
106 main.step( "Assign switches to controller" )
107
108 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
109 ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
110
111 for i in range( 1, 14 ):
112 main.Mininet1.assign_sw_controller(
113 sw=str( i ),
114 ip1=ONOS1_ip,
115 port1=ONOS1_port )
116
117 mastership_check = main.TRUE
118 for i in range( 1, 14 ):
119 response = main.Mininet1.get_sw_controller( "s" + str( i ) )
120 try:
121 main.log.info( str( response ) )
122 except:
123 main.log.info( repr( response ) )
124 if re.search( "tcp:" + ONOS1_ip, response ):
125 mastership_check = mastership_check and main.TRUE
126 else:
127 mastership_check = main.FALSE
128 if mastership_check == main.TRUE:
129 main.log.report( "Switch mastership assigned correctly" )
130 utilities.assert_equals(
131 expect=main.TRUE,
132 actual=mastership_check,
133 onpass="Switch mastership assigned correctly",
134 onfail="Switches not assigned correctly to controllers" )
135
136 def CASE3( self, main ) :
137 """
138 Assign intents
139 """
140 import time
141
142 main.log.report( "Run Pingall" )
143 main.case( "Run Pingall" )
144
145 # install onos-app-fwd
146 main.log.info( "Install reactive forwarding app" )
147 main.ONOScli1.feature_install( "onos-app-fwd" )
148
149 # REACTIVE FWD test
150 ping_result = main.FALSE
151 time1 = time.time()
152 ping_result = main.Mininet1.pingall()
153 time2 = time.time()
154 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
155
156 # uninstall onos-app-fwd
157 main.log.info( "Uninstall reactive forwarding app" )
158 main.ONOScli1.feature_uninstall( "onos-app-fwd" )
159
160 utilities.assert_equals( expect=main.TRUE, actual=ping_result,
161 onpass="All hosts are reachable",
162 onfail="Some pings failed" )