blob: f3f90a92f0d1e55a020b004f3abb74903b7457e7 [file] [log] [blame]
andrew@onlab.us1bc346b2015-05-21 17:21:16 -04001
2"""
3Startup related methods for ONOS
4
5Guidelines:
6 * Group sequential functionalities together
andrew@onlab.usb3a48492015-06-04 18:50:10 -04007 * Methods should not be dependent on platform
andrew@onlab.us1bc346b2015-05-21 17:21:16 -04008 * Return main.TRUE on success or comprehensive error message
9 on failure (TBD)
andrew@onlab.usb3a48492015-06-04 18:50:10 -040010 * All methods should be consistent in expected behavior
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040011"""
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040012import time
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040013import json
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040014
15def __init__( self ):
16 self.ip = '127.0.0.1'
17
18def 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.us2bcfd8f2015-05-28 19:17:51 -040041def initOnosStartupSequence( cellName, appStr, benchIp, mnIp, onosIps ):
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040042 """
43 Startup sequence includes the following:
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040044 * 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.usb3a48492015-06-04 18:50:10 -040051
52 Also verifies that Onos is up and running by
53 'isup' driver function which executs
54 'onos-wait-for-start'
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040055 """
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040056
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040057 # 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.us1bc346b2015-05-21 17:21:16 -040061
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040062 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.usd2d36fc2015-05-29 14:27:54 -040078 # 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.us2bcfd8f2015-05-28 19:17:51 -040095 return main.TRUE
96 else:
97 return main.FALSE
98
andrew@onlab.usb3a48492015-06-04 18:50:10 -040099def 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.us15eddb92015-06-04 20:38:57 -0400124 # 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.usb3a48492015-06-04 18:50:10 -0400133 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.us15eddb92015-06-04 20:38:57 -0400139 # Use the wgetAddr to download a new tar.gz from server
andrew@onlab.usb3a48492015-06-04 18:50:10 -0400140 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.us15eddb92015-06-04 20:38:57 -0400153 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
andrew@onlab.us19b5e042015-06-05 13:14:02 -0400202
203 iu = main.TRUE
204 for node in nodeIps:
205 iu = iu and main.ONOSbench.isup( node )
andrew@onlab.us15eddb92015-06-04 20:38:57 -0400206
andrew@onlab.us19b5e042015-06-05 13:14:02 -0400207 if iu == main.TRUE:
208 return main.TRUE
209 else:
210 return main.FALSE
andrew@onlab.usb3a48492015-06-04 18:50:10 -0400211
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -0400212def addAndStartOnosNode( nodeIps ):
213 """
214 A scale-out scenario that adds specified list of
215 nodes and starts those instances.
216
217 Ex) nodeIps = ['10.0.0.2', '10.0.0.3', 10.0.0.4']
218 """
219 main.log.info( 'addAndStartOnosNode implement me!' )