jenkins | 9301fd0 | 2015-02-10 14:13:33 -0800 | [diff] [blame^] | 1 | # ScaleOutTemplate --> LinkEventTp |
| 2 | # |
| 3 | # CASE1 starts number of nodes specified in param file |
| 4 | # |
| 5 | # cameron@onlab.us |
| 6 | |
| 7 | import sys |
| 8 | import os |
| 9 | |
| 10 | |
| 11 | class LinkEventTP: |
| 12 | |
| 13 | def __init__( self ): |
| 14 | self.default = '' |
| 15 | |
| 16 | def CASE1( self, main ): |
| 17 | import os.path |
| 18 | global clusterCount |
| 19 | clusterCount = 1 |
| 20 | |
| 21 | checkoutBranch = main.params[ 'GIT' ][ 'checkout' ] |
| 22 | gitPull = main.params[ 'GIT' ][ 'autopull' ] |
| 23 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 24 | BENCHIp = main.params[ 'BENCH' ][ 'ip1' ] |
| 25 | BENCHUser = main.params[ 'BENCH' ][ 'user' ] |
| 26 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 27 | ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 28 | ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 29 | flickerRate = main.params[ 'TEST' ][ 'flickerRate'] |
| 30 | |
| 31 | |
| 32 | main.log.step( "Cleaning Enviornment..." ) |
| 33 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 34 | main.ONOSbench.onosUninstall( ONOS2Ip ) |
| 35 | main.ONOSbench.onosUninstall( ONOS3Ip ) |
| 36 | |
| 37 | main.step( "Git checkout and pull " + checkoutBranch ) |
| 38 | if gitPull == 'on': |
| 39 | checkoutResult = main.ONOSbench.gitCheckout( checkoutBranch ) |
| 40 | pullResult = main.ONOSbench.gitPull() |
| 41 | |
| 42 | else: |
| 43 | checkoutResult = main.TRUE |
| 44 | pullResult = main.TRUE |
| 45 | main.log.info( "Skipped git checkout and pull" ) |
| 46 | |
| 47 | #mvnResult = main.ONOSbench.cleanInstall() |
| 48 | |
| 49 | main.step( "Set cell for ONOS cli env" ) |
| 50 | main.ONOS1cli.setCell( cellName ) |
| 51 | main.ONOS2cli.setCell( cellName ) |
| 52 | main.ONOS3cli.setCell( cellName ) |
| 53 | |
| 54 | ### configuring file to enable flicker ### |
| 55 | main.log.info(" Configuring null provider to enable flicker. Flicker Rate = " + flickerRate ) |
| 56 | homeDir = os.path.expanduser('~') |
| 57 | main.log.info(homeDir) |
| 58 | localPath = "/ONOS/tools/package/etc/org.onosproject.provider.nil.link.impl.NullLinkProvider.cfg" |
| 59 | filePath = homeDir + localPath |
| 60 | main.log.info(filePath) |
| 61 | |
| 62 | configFile = open(filePath, 'w+') |
| 63 | main.log.info("File opened") |
| 64 | configFile.write("# Sample configurations for the NullLinkProvider.\n") |
| 65 | configFile.write("# \n") |
| 66 | configFile.write("# If enabled, generates LinkDetected and LinkVanished events\n") |
| 67 | configFile.write("# to make the link appear to be flapping.\n") |
| 68 | configFile.write("#\n") |
| 69 | configFile.write("flicker = true\n") |
| 70 | configFile.write("#\n") |
| 71 | configFile.write("# If enabled, sets the time between LinkEvent generation,\n") |
| 72 | configFile.write("# in milliseconds.\n") |
| 73 | configFile.write("#\n") |
| 74 | configFile.write("eventRate = " + flickerRate) |
| 75 | configFile.close() |
| 76 | main.log.info("Configuration completed") |
| 77 | |
| 78 | ############################# |
| 79 | #config file default topo provider |
| 80 | ########################### |
| 81 | |
| 82 | ### configure deafult topo provider event rate ###?????????????????? |
| 83 | localPath = main.params[ 'TEST' ][ 'configFile' ] |
| 84 | filePath = homeDir + localPath |
| 85 | main.log.info(filePath) |
| 86 | configFile = open(filePath, 'w+') |
| 87 | main.log.info("File Opened") |
| 88 | configFile.write("maxEvents = 1\n") |
| 89 | configFile.write("maxIdleMs = 0\n") |
| 90 | configFile.write("maxBatchMs = 0\n") |
| 91 | main.log.info("File written and closed") |
| 92 | |
| 93 | main.step( "Creating ONOS package" ) |
| 94 | packageResult = main.ONOSbench.onosPackage() # no file or directory |
| 95 | |
| 96 | main.step( "Installing ONOS package" ) |
| 97 | install1Result = main.ONOSbench.onosInstall( node=ONOS1Ip ) |
| 98 | |
| 99 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 100 | main.step( "Applying cell file to environment" ) |
| 101 | cellApplyResult = main.ONOSbench.setCell( cellName ) |
| 102 | main.step( "verify cells" ) |
| 103 | verifyCellResult = main.ONOSbench.verifyCell() |
| 104 | |
| 105 | main.step( "Set cell for ONOS cli env" ) |
| 106 | main.ONOS1cli.setCell( cellName ) |
| 107 | |
| 108 | cli1 = main.ONOS1cli.startOnosCli( ONOS1Ip ) |
| 109 | |
| 110 | def CASE2( self, main ): |
| 111 | """ |
| 112 | Increase number of nodes and initiate CLI |
| 113 | """ |
| 114 | import time |
| 115 | global clusterCount |
| 116 | |
| 117 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 118 | ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 119 | ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 120 | #ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ] |
| 121 | #ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ] |
| 122 | #ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ] |
| 123 | #ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ] |
| 124 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 125 | scale = int( main.params[ 'SCALE' ] ) |
| 126 | |
| 127 | # Cluster size increased everytime the case is defined |
| 128 | clusterCount += scale |
| 129 | |
| 130 | main.log.report( "Increasing cluster size to " + |
| 131 | str( clusterCount ) ) |
| 132 | installResult = main.FALSE |
| 133 | |
| 134 | if scale == 2: |
| 135 | if clusterCount == 3: |
| 136 | main.log.info( "Installing nodes 2 and 3" ) |
| 137 | install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip ) |
| 138 | install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip ) |
| 139 | cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip ) |
| 140 | cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip ) |
| 141 | installResult = main.TRUE |
| 142 | |
| 143 | if scale == 1: |
| 144 | if clusterCount == 2: |
| 145 | main.log.info( "Installing node 2" ) |
| 146 | install2Result = main.ONOSbench.onosInstall( node=ONOS2Ip ) |
| 147 | cli2 = main.ONOS2cli.startOnosCli( ONOS2Ip ) |
| 148 | installResult = main.TRUE |
| 149 | |
| 150 | if clusterCount == 3: |
| 151 | main.log.info( "Installing node 3" ) |
| 152 | install3Result = main.ONOSbench.onosInstall( node=ONOS3Ip ) |
| 153 | cli3 = main.ONOS3cli.startOnosCli( ONOS3Ip ) |
| 154 | installResult = main.TRUE |
| 155 | |
| 156 | |
| 157 | def CASE3( self, main ): |
| 158 | import time |
| 159 | import json |
| 160 | import string |
| 161 | import csv |
| 162 | |
| 163 | linkResult = main.FALSE |
| 164 | |
| 165 | testDelay = main.params[ 'TEST' ][ 'wait'] |
| 166 | time.sleep( float( testDelay ) ) |
| 167 | |
| 168 | metric1 = main.params[ 'TEST' ][ 'metric1' ] |
| 169 | metric2 = main.params[ 'TEST' ][ 'metric2' ] |
| 170 | testDuration = main.params[ 'TEST' ][ 'duration' ] |
| 171 | stop = time.time() + float( testDuration ) |
| 172 | |
| 173 | main.ONOS1cli.featureInstall("onos-null") |
| 174 | |
| 175 | msg = ( "Starting test loop for " + str(testDuration) + " seconds" ) |
| 176 | main.log.info( msg ) |
| 177 | logInterval = main.params[ 'TEST' ][ 'log_interval' ] |
| 178 | |
| 179 | while time.time() < stop: |
| 180 | time.sleep( float( logInterval ) ) |
| 181 | |
| 182 | JsonStr1 = main.ONOS1cli.topologyEventsMetrics() |
| 183 | JsonObj1 = json.loads( JsonStr1 ) |
| 184 | msg = ( "Node 1 Link Event TP: " + str( JsonObj1[ metric1 ][ 'm1_rate' ] ) ) |
| 185 | main.log.info( msg ) |
| 186 | msg = ( "Node 1 Graph Event TP: " + str( JsonObj1[ metric2 ][ 'm1_rate' ] ) ) |
| 187 | main.log.info( msg ) |
| 188 | |
| 189 | lastGraphRate = round(JsonObj1[ metric2 ][ 'm1_rate' ],2) |
| 190 | lastLinkRate = round(JsonObj1[ metric1 ][ 'm1_rate' ],2) |
| 191 | |
| 192 | msg = ( "Final Link Event TP: " + str( lastLinkRate ) ) |
| 193 | main.log.report( msg ) |
| 194 | msg = ( "Final Graph Event TP: " + str( lastGraphRate ) ) |
| 195 | main.log.report( msg ) |
| 196 | |
| 197 | linkResult = main.TRUE |
| 198 | ''' |
| 199 | jenkinsReport = open('LinkEventTP.csv', 'w') |
| 200 | jenkinsReport.write("T1 - Node 1, T2 - Node 1, T2 - Node 2, T3 - Node 1, T3 - Node 2, T3 - Node 3\n") |
| 201 | jenkinsReport.write(str(lastRate1)) |
| 202 | jenkinsReport.write("\n") |
| 203 | jenkinsReport.close() |
| 204 | |
| 205 | dbReportS1 = open('LinkEventTP-S1.csv','w') #must be the name of the test "-S" followed by the scale |
| 206 | dbReportS1.write(str(linkResult)) |
| 207 | dbReportS1.write("\n") |
| 208 | dbReportS1.write(str(lastRate1)) |
| 209 | dbReportS1.write("\n") #additional newline needed for bash script reading |
| 210 | dbReportS1.close() |
| 211 | ''' |
| 212 | |
| 213 | |
| 214 | def CASE4( self, main ): |
| 215 | import time |
| 216 | import json |
| 217 | import string |
| 218 | |
| 219 | linkResult = main.FALSE |
| 220 | |
| 221 | testDelay = main.params[ 'TEST' ][ 'wait'] |
| 222 | time.sleep( float( testDelay ) ) |
| 223 | |
| 224 | getMetric = main.params[ 'TEST' ][ 'metric1' ] |
| 225 | testDuration = main.params[ 'TEST' ][ 'duration' ] |
| 226 | stop = time.time() + float( testDuration ) |
| 227 | |
| 228 | main.ONOS2cli.featureInstall("onos-null") |
| 229 | |
| 230 | msg = ( "Starting test loop for " + str(testDuration) + " seconds" ) |
| 231 | main.log.info( msg ) |
| 232 | logInterval = main.params[ 'TEST' ][ 'log_interval' ] |
| 233 | |
| 234 | while time.time() < stop: |
| 235 | time.sleep( float( logInterval ) ) |
| 236 | |
| 237 | JsonStr1 = main.ONOS1cli.topologyEventsMetrics() |
| 238 | JsonObj1 = json.loads( JsonStr1 ) |
| 239 | msg = ( "Node 1 TP: " + str( JsonObj1[ getMetric ][ 'm1_rate' ] ) ) |
| 240 | main.log.info( msg ) |
| 241 | lastRate1 = round(JsonObj1[ getMetric ][ 'm1_rate' ],2) |
| 242 | |
| 243 | |
| 244 | JsonStr2 = main.ONOS2cli.topologyEventsMetrics() |
| 245 | JsonObj2 = json.loads( JsonStr2 ) |
| 246 | msg = ( "Node 2 TP: " + str( JsonObj2[ getMetric ][ 'm1_rate' ] ) ) |
| 247 | main.log.info( msg ) |
| 248 | lastRate2 = round(JsonObj2[ getMetric ][ 'm1_rate' ],2) |
| 249 | |
| 250 | |
| 251 | msg = ( "Final TP on node 1: " + str( lastRate1 ) ) |
| 252 | main.log.report( msg ) |
| 253 | |
| 254 | msg = ( "Final TP on node 2: " + str( lastRate2 ) ) |
| 255 | main.log.report( msg ) |
| 256 | |
| 257 | linkResult = main.TRUE |
| 258 | |
| 259 | jenkinsReport = open('LinkEventTP.csv', 'a') |
| 260 | jenkinsReport.write(str(lastRate1)) |
| 261 | jenkinsReport.write(", ") |
| 262 | jenkinsReport.write(str(lastRate2)) |
| 263 | jenkinsReport.write(", ") |
| 264 | jenkinsReport.close() |
| 265 | |
| 266 | dbReportS2 = open('LinkEventTP-S2.csv','w') #must be the name of the test "-S" followed by the scale |
| 267 | dbReportS2.write(str(linkResult)) |
| 268 | dbReportS2.write("\n") |
| 269 | dbReportS2.write(str(lastRate1)) |
| 270 | dbReportS2.write("\n") |
| 271 | dbReportS2.write(str(lastRate2)) |
| 272 | dbReportS2.write("\n") |
| 273 | dbReportS2.close() |
| 274 | |
| 275 | |
| 276 | |
| 277 | def CASE5( self, main ): |
| 278 | import time |
| 279 | import json |
| 280 | import string |
| 281 | |
| 282 | linkResult = main.FALSE |
| 283 | |
| 284 | testDelay = main.params[ 'TEST' ][ 'wait'] |
| 285 | time.sleep( float( testDelay ) ) |
| 286 | |
| 287 | getMetric = main.params[ 'TEST' ][ 'metric1' ] |
| 288 | testDuration = main.params[ 'TEST' ][ 'duration' ] |
| 289 | stop = time.time() + float( testDuration ) |
| 290 | |
| 291 | main.ONOS3cli.featureInstall("onos-null") |
| 292 | |
| 293 | msg = ( "Starting test loop for " + str(testDuration) + " seconds" ) |
| 294 | main.log.info( msg ) |
| 295 | logInterval = main.params[ 'TEST' ][ 'log_interval' ] |
| 296 | |
| 297 | while time.time() < stop: |
| 298 | time.sleep( float( logInterval ) ) |
| 299 | |
| 300 | JsonStr1 = main.ONOS1cli.topologyEventsMetrics() |
| 301 | JsonObj1 = json.loads( JsonStr1 ) |
| 302 | msg = ( "Node 1 TP: " + str( JsonObj1[ getMetric ][ 'm1_rate' ] ) ) |
| 303 | main.log.info( msg ) |
| 304 | lastRate1 = round(JsonObj1[ getMetric ][ 'm1_rate' ],2) |
| 305 | |
| 306 | JsonStr2 = main.ONOS2cli.topologyEventsMetrics() |
| 307 | JsonObj2 = json.loads( JsonStr2 ) |
| 308 | msg = ( "Node 2 TP: " + str( JsonObj2[ getMetric ][ 'm1_rate' ] ) ) |
| 309 | main.log.info( msg ) |
| 310 | lastRate2 = round(JsonObj2[ getMetric ][ 'm1_rate' ],2) |
| 311 | |
| 312 | JsonStr3 = main.ONOS3cli.topologyEventsMetrics() |
| 313 | JsonObj3 = json.loads( JsonStr3 ) |
| 314 | msg = ( "Node 3 TP: " + str( JsonObj3[ getMetric ][ 'm1_rate' ] ) ) |
| 315 | main.log.info( msg ) |
| 316 | lastRate3 = round(JsonObj3[ getMetric ][ 'm1_rate' ],2) |
| 317 | |
| 318 | msg = ( "Final TP on node 1: " + str( lastRate1 ) ) |
| 319 | main.log.report( msg ) |
| 320 | |
| 321 | msg = ( "Final TP on node 2: " + str( lastRate2 ) ) |
| 322 | main.log.report( msg ) |
| 323 | |
| 324 | msg = ( "Final TP on node 3: " + str( lastRate3 ) ) |
| 325 | main.log.report( msg ) |
| 326 | |
| 327 | linkResult = main.TRUE |
| 328 | |
| 329 | jenkinsReport = open('LinkEventTP.csv', 'a') |
| 330 | jenkinsReport.write(str(lastRate1)) |
| 331 | jenkinsReport.write(", ") |
| 332 | jenkinsReport.write(str(lastRate2)) |
| 333 | jenkinsReport.write(", ") |
| 334 | jenkinsReport.write(str(lastRate3)) |
| 335 | jenkinsReport.close() |
| 336 | |
| 337 | dbReportS3 = open('LinkEventTP-S3.csv','w') #must be the name of the test "-S" followed by the scale |
| 338 | dbReportS3.write(str(linkResult)) |
| 339 | dbReportS3.write("\n") |
| 340 | dbReportS3.write(str(lastRate1)) |
| 341 | dbReportS3.write("\n") |
| 342 | dbReportS3.write(str(lastRate2)) |
| 343 | dbReportS3.write("\n") |
| 344 | dbReportS3.write(str(lastRate3)) |
| 345 | dbReportS3.write("\n") |
| 346 | dbReportS3.close() |
| 347 | |
| 348 | |