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 |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 7 | * Methods should not be dependent on platform |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 8 | * Return main.TRUE on success or comprehensive error message |
| 9 | on failure (TBD) |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 10 | * All methods should be consistent in expected behavior |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 11 | """ |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 12 | import time |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 13 | import json |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 14 | |
| 15 | def __init__( self ): |
| 16 | self.ip = '127.0.0.1' |
| 17 | |
| 18 | def gitPullAndMci( branchName, commitLog=False ): |
| 19 | """ |
| 20 | Pull from branch repository specified and compile changes |
| 21 | If commitLog is True, report commit information |
| 22 | |
| 23 | Any errors / warnings will be handled by respective |
| 24 | driver function calls |
| 25 | """ |
| 26 | co = main.ONOSbench.gitCheckout( branchName ) |
| 27 | gp = main.ONOSbench.gitPull() |
| 28 | ci = main.ONOSbench.cleanInstall() |
| 29 | |
| 30 | if co and gp and ci == main.TRUE: |
| 31 | if commitLog: |
| 32 | main.log.report( 'Commit information - ' ) |
| 33 | main.ONOSbench.getVersion(report=True) |
| 34 | |
| 35 | return main.TRUE |
| 36 | |
| 37 | else: |
| 38 | # TODO: Comprehensive error message |
| 39 | return 'git pull and mci failed' |
| 40 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 41 | def initOnosStartupSequence( cellName, appStr, benchIp, mnIp, onosIps ): |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 42 | """ |
| 43 | Startup sequence includes the following: |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 44 | * Create cell file |
| 45 | * Set cell variables on ONOS bench |
| 46 | * Verify cell |
| 47 | * Create ONOS package |
| 48 | * Force install ONOS package |
| 49 | * Start ONOS service |
| 50 | * Start ONOS cli |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 51 | |
| 52 | Also verifies that Onos is up and running by |
| 53 | 'isup' driver function which executs |
| 54 | 'onos-wait-for-start' |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 55 | """ |
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 | # NOTE: leave out create cell file until bug addressed |
| 58 | #cf = main.ONOSbench.createCellFile( benchIp, cellName, mnIp, |
| 59 | # str(appStr), *onosIps ) |
| 60 | numNodes = len(onosIps) |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 61 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 62 | sc = main.ONOSbench.setCell( cellName ) |
| 63 | vc = main.ONOSbench.verifyCell() |
| 64 | op = main.ONOSbench.onosPackage() |
| 65 | for addr in onosIps: |
| 66 | oi = main.ONOSbench.onosInstall( node = addr ) |
| 67 | |
| 68 | time.sleep( 5 ) |
| 69 | |
| 70 | iu = main.TRUE |
| 71 | for node in onosIps: |
| 72 | iu = iu and main.ONOSbench.isup( node ) |
| 73 | |
| 74 | cli = main.TRUE |
| 75 | for node in range( 0, numNodes ): |
| 76 | cli = cli and main.CLIs[node].startOnosCli( onosIps[node] ) |
| 77 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 78 | # Check if all nodes are discovered correctly using |
| 79 | # 'nodes' command in Onos Cli |
| 80 | na = main.TRUE |
| 81 | try: |
| 82 | nodeCmdJson = json.loads( main.CLIs[0].nodes() ) |
| 83 | for node in nodeCmdJson: |
| 84 | if node['state'] != 'ACTIVE': |
| 85 | main.log.warn( str( node['id'] ) + |
| 86 | ' Node is not in ACTIVE state.' ) |
| 87 | na = main.FALSE |
| 88 | if na != main.FALSE: |
| 89 | main.log.info( 'All nodes discovered successfully' ) |
| 90 | except Exception: |
| 91 | main.log.error( 'nodes command did not execute properly' ) |
| 92 | return main.FALSE |
| 93 | |
| 94 | 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] | 95 | return main.TRUE |
| 96 | else: |
| 97 | return main.FALSE |
| 98 | |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 99 | def installOnosFromTar( wgetAddr, nodeIps ): |
| 100 | """ |
| 101 | Install Onos directly from tar.gz file. |
| 102 | Due to the nature of the specific steps required |
| 103 | to startup Onos in this fashion, all commands |
| 104 | required to start Onos from tar.gz will be |
| 105 | grouped in this method. |
| 106 | |
| 107 | 1) wget latest onos tar.gz on onos node |
| 108 | 2) untar package |
| 109 | 3) specify onos-config cluster |
| 110 | 4) start onos via onos-service |
| 111 | 5) form onos cluster using onos-form-cluster |
| 112 | 6) check for successful startup |
| 113 | |
| 114 | Specify the download link for the tar.gz. |
| 115 | Provide a list of nodeIps |
| 116 | |
| 117 | Ex) wgetAddr = 'https://mytargzdownload.com/file.tar.gz' |
| 118 | nodeIps = ['10.0.0.1', '10.0.0.2'] |
| 119 | """ |
| 120 | if isinstance( nodeIps, ( int, basestring ) ): |
| 121 | main.log.error( 'Please pass in a list of string nodes' ) |
| 122 | return main.FALSE |
| 123 | |
andrew@onlab.us | 15eddb9 | 2015-06-04 20:38:57 -0400 | [diff] [blame^] | 124 | # Obtain filename from provided address |
| 125 | # assumes that filename is separated by '/' character |
| 126 | f_name = '' |
| 127 | addr = str( wgetAddr ).split('/') |
| 128 | for phrase in addr: |
| 129 | if 'tar.gz' in phrase: |
| 130 | f_name = str( phrase ) |
| 131 | main.log.info( 'Using ' + f_name + ' as file' ) |
| 132 | |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 133 | clusterCount = len( nodeIps ) |
| 134 | |
| 135 | main.log.info( 'Initiating Onos installation sequence ' + |
| 136 | 'using tar.gz ... This may take a few minutes' ) |
| 137 | |
| 138 | for node in range( 0, clusterCount ): |
andrew@onlab.us | 15eddb9 | 2015-06-04 20:38:57 -0400 | [diff] [blame^] | 139 | # Use the wgetAddr to download a new tar.gz from server |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 140 | try: |
| 141 | main.ONOSnode[node].handle.sendline( 'wget ' + wgetAddr ) |
| 142 | main.ONOSnode[node].handle.expect( 'saved' ) |
| 143 | main.ONOSnode[node].handle.expect( '\$' ) |
| 144 | main.log.info( 'Successfully downloaded tar.gz ' + |
| 145 | 'on node: ' + str( main.ONOSips[node] ) ) |
| 146 | except Exception: |
| 147 | # NOTE: Additional exception may be appropriate |
| 148 | main.log.error( 'Uncaught exception while ' + |
| 149 | 'downloading Onos tar.gz: ' + |
| 150 | main.ONOSnode[node].handle.before ) |
| 151 | return main.FALSE |
| 152 | |
andrew@onlab.us | 15eddb9 | 2015-06-04 20:38:57 -0400 | [diff] [blame^] | 153 | for node in range( 0, clusterCount ): |
| 154 | # Untar files on all nodes, then enter the |
| 155 | # newly created directory |
| 156 | try: |
| 157 | main.ONOSnode[node].handle.sendline( 'tar zxvf ' + f_name ) |
| 158 | # Verbose output of tar will contain some onos returns |
| 159 | main.ONOSnode[node].handle.expect( 'onos' ) |
| 160 | main.ONOSnode[node].handle.expect( '\$' ) |
| 161 | # NOTE: Making an assumption here: |
| 162 | # the directory created by tar file has a name that |
| 163 | # starts with 'onos-' followed by version number |
| 164 | # '1.2.0'. If this is NOT true, this method must |
| 165 | # be changed to enter the correct directory. |
| 166 | # The directory name is currently dynamic |
| 167 | # and depends on the day at which you downloaded |
| 168 | # the tar file |
| 169 | # Enter onos- wildcard to disregard its version / date |
| 170 | # suffix |
| 171 | main.ONOSnode[node].handle.sendline( 'cd onos-*' ) |
| 172 | main.ONOSnode[node].handle.expect( '\$' ) |
| 173 | |
| 174 | main.ONOSnode[node].handle.sendline( 'pwd' ) |
| 175 | main.ONOSnode[node].handle.expect( 'pwd' ) |
| 176 | main.ONOSnode[node].handle.expect( '\$' ) |
| 177 | pwd = main.ONOSnode[node].handle.before |
| 178 | if 'onos' in str(pwd): |
| 179 | main.log.info( 'tar zxvf ' + f_name + ' successful ' + |
| 180 | 'on node ' + str( main.ONOSips[node] ) ) |
| 181 | |
| 182 | except Exception: |
| 183 | main.log.error( 'Uncaught exception while executing ' + |
| 184 | 'tar zxvf of ' + f_name + ': ' + |
| 185 | main.ONOSnode[node].handle.before + |
| 186 | main.ONOSnode[node].handle.after) |
| 187 | return main.FALSE |
| 188 | |
| 189 | for node in range( 0, clusterCount ): |
| 190 | try: |
| 191 | main.ONOSnode[node].handle.sendline( 'bin/onos-service '+ |
| 192 | 'server &' ) |
| 193 | # Send some extra characters to run the process |
| 194 | main.ONOSnode[node].handle.sendline( '' ) |
| 195 | main.ONOSnode[node].handle.sendline( '' ) |
| 196 | main.ONOSnode[node].handle.expect( '\$' ) |
| 197 | except Exception: |
| 198 | main.log.error( 'Uncaught exception while executing ' + |
| 199 | 'onos-service server command ' + |
| 200 | str( main.ONOSnode[node].handle.before ) ) |
| 201 | return main.FALSE |
| 202 | |
| 203 | # TODO: Check for startup (isup) |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 204 | return main.TRUE |
| 205 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 206 | def addAndStartOnosNode( nodeIps ): |
| 207 | """ |
| 208 | A scale-out scenario that adds specified list of |
| 209 | nodes and starts those instances. |
| 210 | |
| 211 | Ex) nodeIps = ['10.0.0.2', '10.0.0.3', 10.0.0.4'] |
| 212 | """ |
| 213 | main.log.info( 'addAndStartOnosNode implement me!' ) |