andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 1 | |
| 2 | """ |
| 3 | Startup related methods for ONOS |
| 4 | |
| 5 | Guidelines: |
| 6 | * Group sequential functionalities together |
| 7 | * Methods should not prohibit cross platform execution |
| 8 | * Return main.TRUE on success or comprehensive error message |
| 9 | on failure (TBD) |
| 10 | """ |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 11 | import time |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 12 | import json |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 13 | |
| 14 | def __init__( self ): |
| 15 | self.ip = '127.0.0.1' |
| 16 | |
| 17 | def gitPullAndMci( branchName, commitLog=False ): |
| 18 | """ |
| 19 | Pull from branch repository specified and compile changes |
| 20 | If commitLog is True, report commit information |
| 21 | |
| 22 | Any errors / warnings will be handled by respective |
| 23 | driver function calls |
| 24 | """ |
| 25 | co = main.ONOSbench.gitCheckout( branchName ) |
| 26 | gp = main.ONOSbench.gitPull() |
| 27 | ci = main.ONOSbench.cleanInstall() |
| 28 | |
| 29 | if co and gp and ci == main.TRUE: |
| 30 | if commitLog: |
| 31 | main.log.report( 'Commit information - ' ) |
| 32 | main.ONOSbench.getVersion(report=True) |
| 33 | |
| 34 | return main.TRUE |
| 35 | |
| 36 | else: |
| 37 | # TODO: Comprehensive error message |
| 38 | return 'git pull and mci failed' |
| 39 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 40 | def initOnosStartupSequence( cellName, appStr, benchIp, mnIp, onosIps ): |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 41 | """ |
| 42 | Startup sequence includes the following: |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 43 | * Create cell file |
| 44 | * Set cell variables on ONOS bench |
| 45 | * Verify cell |
| 46 | * Create ONOS package |
| 47 | * Force install ONOS package |
| 48 | * Start ONOS service |
| 49 | * Start ONOS cli |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 50 | """ |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 51 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 52 | # NOTE: leave out create cell file until bug addressed |
| 53 | #cf = main.ONOSbench.createCellFile( benchIp, cellName, mnIp, |
| 54 | # str(appStr), *onosIps ) |
| 55 | numNodes = len(onosIps) |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 56 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 57 | sc = main.ONOSbench.setCell( cellName ) |
| 58 | vc = main.ONOSbench.verifyCell() |
| 59 | op = main.ONOSbench.onosPackage() |
| 60 | for addr in onosIps: |
| 61 | oi = main.ONOSbench.onosInstall( node = addr ) |
| 62 | |
| 63 | time.sleep( 5 ) |
| 64 | |
| 65 | iu = main.TRUE |
| 66 | for node in onosIps: |
| 67 | iu = iu and main.ONOSbench.isup( node ) |
| 68 | |
| 69 | cli = main.TRUE |
| 70 | for node in range( 0, numNodes ): |
| 71 | cli = cli and main.CLIs[node].startOnosCli( onosIps[node] ) |
| 72 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 73 | # Check if all nodes are discovered correctly using |
| 74 | # 'nodes' command in Onos Cli |
| 75 | na = main.TRUE |
| 76 | try: |
| 77 | nodeCmdJson = json.loads( main.CLIs[0].nodes() ) |
| 78 | for node in nodeCmdJson: |
| 79 | if node['state'] != 'ACTIVE': |
| 80 | main.log.warn( str( node['id'] ) + |
| 81 | ' Node is not in ACTIVE state.' ) |
| 82 | na = main.FALSE |
| 83 | if na != main.FALSE: |
| 84 | main.log.info( 'All nodes discovered successfully' ) |
| 85 | except Exception: |
| 86 | main.log.error( 'nodes command did not execute properly' ) |
| 87 | return main.FALSE |
| 88 | |
| 89 | if sc and vc and op and oi and iu and cli and na == main.TRUE: |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 90 | return main.TRUE |
| 91 | else: |
| 92 | return main.FALSE |
| 93 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 94 | def addAndStartOnosNode( nodeIps ): |
| 95 | """ |
| 96 | A scale-out scenario that adds specified list of |
| 97 | nodes and starts those instances. |
| 98 | |
| 99 | Ex) nodeIps = ['10.0.0.2', '10.0.0.3', 10.0.0.4'] |
| 100 | """ |
| 101 | main.log.info( 'addAndStartOnosNode implement me!' ) |
| 102 | |