Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2017 Open Networking Foundation ( ONF ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 21 | import json |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 22 | class Cluster(): |
| 23 | |
| 24 | def __str__( self ): |
| 25 | return self.name |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 26 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 27 | def __repr__( self ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 28 | controllers = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 29 | runningNodes = [] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 30 | for ctrl in self.controllers: |
| 31 | controllers.append( str( ctrl ) ) |
| 32 | return "%s[%s]" % ( self.name, ", ".join( controllers ) ) |
| 33 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 34 | def __init__( self, ctrlList=[], name="Cluster" ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 35 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 36 | controllers : All the nodes |
| 37 | runningNodes : Node that are specifically running from the test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 38 | ie ) When the test is testing different number of nodes on each |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 39 | run. |
| 40 | numCtrls : number of runningNodes |
| 41 | maxCtrls : number of controllers |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 42 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 43 | self.controllers = ctrlList |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 44 | self.runningNodes = ctrlList |
| 45 | self.numCtrls = len( self.runningNodes ) |
| 46 | self.maxCtrls = len( self.controllers ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 47 | self.name = str( name ) |
| 48 | self.iterator = iter( self.active() ) |
| 49 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 50 | def getIps( self, activeOnly=False, allNode=False ): |
| 51 | """ |
| 52 | Description: |
| 53 | get the list of the ip. Default to get ips of running nodes. |
| 54 | Required: |
| 55 | * activeOnly - True for getting ips of active nodes |
| 56 | * allNode - True for getting ips of all nodes |
| 57 | Returns: |
| 58 | Retruns ips of active nodes if activeOnly is True. |
| 59 | Returns ips of all nodes if allNode is True. |
| 60 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 61 | ips = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 62 | if allNode: |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 63 | nodeList = self.controllers |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 64 | else: |
| 65 | if activeOnly: |
| 66 | nodeList = self.active() |
| 67 | else: |
| 68 | nodeList = self.runningNodes |
| 69 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 70 | for ctrl in nodeList: |
| 71 | ips.append( ctrl.ipAddress ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 72 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 73 | return ips |
| 74 | |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 75 | def clearActive( self ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 76 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 77 | Description: |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 78 | Sets the activeness of each cluster node to be False |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 79 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 80 | for ctrl in self.controllers: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 81 | ctrl.active = False |
| 82 | |
| 83 | def getRunningPos( self ): |
| 84 | """ |
| 85 | Description: |
| 86 | get the position of the active running nodes. |
| 87 | Required: |
| 88 | Returns: |
| 89 | Retruns the list of the position of the active |
| 90 | running nodes. |
| 91 | """ |
| 92 | return [ ctrl.pos for ctrl in self.runningNodes |
| 93 | if ctrl.active ] |
| 94 | |
| 95 | def setRunningNode( self, numCtrls ): |
| 96 | """ |
| 97 | Description: |
| 98 | Set running nodes of n number of nodes. |
| 99 | It will create new list of runningNodes. |
| 100 | If numCtrls is a list, it will add the nodes of the |
| 101 | list. |
| 102 | Required: |
| 103 | * numCtrls - number of nodes to be set. |
| 104 | Returns: |
| 105 | """ |
| 106 | self.runningNodes = [] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 107 | for i in numCtrls if isinstance( numCtrls, list ) else range( numCtrls ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 108 | self.runningNodes.append( self.controllers[ i ] ) |
| 109 | self.numCtrls = len( numCtrls ) if isinstance( numCtrls, list ) else numCtrls |
| 110 | |
| 111 | def active( self, node=None ): |
| 112 | """ |
| 113 | Description: |
| 114 | get the list/controller of the active controller. |
| 115 | Required: |
| 116 | * node - position of the node to get from the active controller. |
| 117 | Returns: |
| 118 | Return a list of active controllers in the cluster if node is None |
| 119 | if not, it will return the nth controller. |
| 120 | """ |
| 121 | result = [ ctrl for ctrl in self.runningNodes |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 122 | if ctrl.active ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 123 | return result if node is None else result[ node % len( result ) ] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 124 | |
| 125 | def next( self ): |
| 126 | """ |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 127 | An iterator for the cluster's active controllers that |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 128 | resets when there are no more elements. |
| 129 | |
| 130 | Returns the next controller in the cluster |
| 131 | """ |
| 132 | try: |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 133 | node = self.iterator.next() |
| 134 | assert node.active |
| 135 | return node |
| 136 | except ( StopIteration, AssertionError ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 137 | self.reset() |
| 138 | try: |
| 139 | return self.iterator.next() |
| 140 | except StopIteration: |
| 141 | raise RuntimeError( "There are no active nodes in the cluster" ) |
| 142 | |
| 143 | def reset( self ): |
| 144 | """ |
| 145 | Resets the cluster iterator. |
| 146 | |
| 147 | This should be used whenever a node's active state is changed |
| 148 | and is also used internally when the iterator has been exhausted. |
| 149 | """ |
| 150 | self.iterator = iter( self.active() ) |
| 151 | |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 152 | def createCell( self, cellName, cellApps, mininetIp, useSSH, ips, installMax=False ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 153 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 154 | Description: |
| 155 | create a new cell |
| 156 | Required: |
| 157 | * cellName - The name of the cell. |
You Wang | 09b596b | 2018-01-10 10:42:38 -0800 | [diff] [blame] | 158 | * cellApps - The ONOS apps string. |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 159 | * mininetIp - Mininet IP address. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 160 | * useSSH - True for using ssh when creating a cell |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 161 | * ips - ip( s ) of the node( s ). |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 162 | Returns: |
| 163 | """ |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 164 | self.command( "createCellFile", |
| 165 | args=[ main.ONOSbench.ip_address, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 166 | cellName, |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 167 | mininetIp, |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 168 | cellApps, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 169 | ips, |
| 170 | main.ONOScell.karafUser, |
| 171 | useSSH ], |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 172 | specificDriver=1, |
| 173 | getFrom=0 if installMax else 1 ) |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 174 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 175 | def uninstallAtomix( self, uninstallMax ): |
| 176 | """ |
| 177 | Description: |
| 178 | uninstalling atomix |
| 179 | Required: |
| 180 | * uninstallMax - True for uninstalling max number of nodes |
| 181 | False for uninstalling the current running nodes. |
| 182 | Returns: |
| 183 | Returns main.TRUE if it successfully uninstalled. |
| 184 | """ |
| 185 | result = main.TRUE |
| 186 | uninstallResult = self.command( "atomixUninstall", |
| 187 | kwargs={ "nodeIp": "ipAddress" }, |
| 188 | specificDriver=1, |
| 189 | getFrom=0 if uninstallMax else 1, |
| 190 | funcFromCtrl=True ) |
| 191 | for uninstallR in uninstallResult: |
| 192 | result = result and uninstallR |
| 193 | return result |
| 194 | |
| 195 | def uninstallOnos( self, uninstallMax ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 196 | """ |
| 197 | Description: |
| 198 | uninstalling onos |
| 199 | Required: |
| 200 | * uninstallMax - True for uninstalling max number of nodes |
| 201 | False for uninstalling the current running nodes. |
| 202 | Returns: |
| 203 | Returns main.TRUE if it successfully uninstalled. |
| 204 | """ |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 205 | result = main.TRUE |
| 206 | uninstallResult = self.command( "onosUninstall", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 207 | kwargs={ "nodeIp": "ipAddress" }, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 208 | specificDriver=1, |
| 209 | getFrom=0 if uninstallMax else 1, |
| 210 | funcFromCtrl=True ) |
| 211 | for uninstallR in uninstallResult: |
| 212 | result = result and uninstallR |
| 213 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 214 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 215 | def applyCell( self, cellName, installMax=False ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 216 | """ |
| 217 | Description: |
| 218 | apply the cell with cellName. It will also verify the |
| 219 | cell. |
| 220 | Required: |
| 221 | * cellName - The name of the cell. |
| 222 | Returns: |
| 223 | Returns main.TRUE if it successfully set and verify cell. |
| 224 | """ |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 225 | setCellResult = self.command( "setCell", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 226 | args=[ cellName ], |
| 227 | specificDriver=1, |
| 228 | getFrom=0 if installMax else 1 ) |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 229 | verifyResult = self.command( "verifyCell", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 230 | specificDriver=1, |
| 231 | getFrom=0 if installMax else 1 ) |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 232 | result = main.TRUE |
| 233 | for i in range( len( setCellResult ) ): |
| 234 | result = result and setCellResult[ i ] and verifyResult[ i ] |
| 235 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 236 | |
| 237 | def checkService( self ): |
| 238 | """ |
| 239 | Description: |
| 240 | Checking if the onos service is up. If not, it will |
| 241 | start the onos service manually. |
| 242 | Required: |
| 243 | Returns: |
| 244 | Returns main.TRUE if it successfully checked |
| 245 | """ |
| 246 | stopResult = main.TRUE |
| 247 | startResult = main.TRUE |
| 248 | onosIsUp = main.TRUE |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 249 | onosUp = self.command( "isup", |
| 250 | args=[ "ipAddress" ], |
| 251 | specificDriver=1, |
| 252 | getFrom=1, |
| 253 | funcFromCtrl=True ) |
| 254 | for i in range( len( onosUp ) ): |
| 255 | ctrl = self.controllers[ i ] |
| 256 | onosIsUp = onosIsUp and onosUp[ i ] |
| 257 | if onosUp[ i ] == main.TRUE: |
Jon Hall | 9655dcb | 2018-02-02 11:19:06 -0800 | [diff] [blame] | 258 | main.log.info( ctrl.name + " is up and ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 259 | else: |
Jon Hall | 9655dcb | 2018-02-02 11:19:06 -0800 | [diff] [blame] | 260 | main.log.warn( ctrl.name + " may not be up." ) |
| 261 | return onosIsUp |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 262 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 263 | def killAtomix( self, killMax, stopAtomix ): |
| 264 | """ |
| 265 | Description: |
| 266 | killing atomix. It will either kill the current runningnodes or |
| 267 | max number of the nodes. |
| 268 | Required: |
| 269 | * killRemoveMax - The boolean that will decide either to kill |
| 270 | only running nodes ( False ) or max number of nodes ( True ). |
| 271 | * stopAtomix - If wish to atomix onos before killing it. True for |
| 272 | enable stop, False for disable stop. |
| 273 | Returns: |
| 274 | Returns main.TRUE if successfully killing it. |
| 275 | """ |
| 276 | result = main.TRUE |
| 277 | killResult = self.command( "atomixKill", |
| 278 | args=[ "ipAddress" ], |
| 279 | specificDriver=1, |
| 280 | getFrom=0 if killMax else 1, |
| 281 | funcFromCtrl=True ) |
| 282 | for i in range( len( killResult ) ): |
| 283 | result = result and killResult[ i ] |
| 284 | self.controllers[ i ].active = False |
| 285 | return result |
| 286 | |
| 287 | def killOnos( self, killMax, stopOnos ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 288 | """ |
| 289 | Description: |
| 290 | killing the onos. It will either kill the current runningnodes or |
| 291 | max number of the nodes. |
| 292 | Required: |
| 293 | * killRemoveMax - The boolean that will decide either to kill |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 294 | only running nodes ( False ) or max number of nodes ( True ). |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 295 | * stopOnos - If wish to stop onos before killing it. True for |
| 296 | enable stop , False for disable stop. |
| 297 | Returns: |
| 298 | Returns main.TRUE if successfully killing it. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 299 | """ |
| 300 | result = main.TRUE |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 301 | killResult = self.command( "onosKill", |
| 302 | args=[ "ipAddress" ], |
| 303 | specificDriver=1, |
| 304 | getFrom=0 if killMax else 1, |
| 305 | funcFromCtrl=True ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 306 | for i in range( len( killResult ) ): |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 307 | result = result and killResult[ i ] |
| 308 | self.controllers[ i ].active = False |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 309 | return result |
| 310 | |
| 311 | def ssh( self ): |
| 312 | """ |
| 313 | Description: |
| 314 | set up ssh to the onos |
| 315 | Required: |
| 316 | Returns: |
| 317 | Returns main.TRUE if it successfully setup the ssh to |
| 318 | the onos. |
| 319 | """ |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 320 | result = main.TRUE |
| 321 | sshResult = self.command( "onosSecureSSH", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 322 | kwargs={ "node": "ipAddress" }, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 323 | specificDriver=1, |
| 324 | getFrom=1, |
| 325 | funcFromCtrl=True ) |
| 326 | for sshR in sshResult: |
| 327 | result = result and sshR |
| 328 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 329 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 330 | def installAtomix( self, installMax=True, installParallel=True ): |
| 331 | """ |
| 332 | Description: |
| 333 | Installing onos. |
| 334 | Required: |
| 335 | * installMax - True for installing max number of nodes |
| 336 | False for installing current running nodes only. |
| 337 | Returns: |
| 338 | Returns main.TRUE if it successfully installed |
| 339 | """ |
| 340 | result = main.TRUE |
| 341 | threads = [] |
| 342 | i = 0 |
| 343 | for ctrl in self.controllers if installMax else self.runningNodes: |
| 344 | options = "" |
| 345 | if installMax and i >= self.numCtrls: |
| 346 | # TODO: is installMax supported here? |
| 347 | pass |
| 348 | if installParallel: |
| 349 | t = main.Thread( target=ctrl.Bench.atomixInstall, |
| 350 | name="atomix-install-" + ctrl.name, |
| 351 | kwargs={ "node" : ctrl.ipAddress, |
| 352 | "options" : options } ) |
| 353 | threads.append( t ) |
| 354 | t.start() |
| 355 | else: |
| 356 | result = result and \ |
| 357 | main.ONOSbench.atomixInstall( node=ctrl.ipAddress, options=options ) |
| 358 | i += 1 |
| 359 | if installParallel: |
| 360 | for t in threads: |
| 361 | t.join() |
| 362 | result = result and t.result |
| 363 | return result |
| 364 | |
| 365 | def installOnos( self, installMax=True, installParallel=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 366 | """ |
| 367 | Description: |
| 368 | Installing onos. |
| 369 | Required: |
| 370 | * installMax - True for installing max number of nodes |
| 371 | False for installing current running nodes only. |
| 372 | Returns: |
| 373 | Returns main.TRUE if it successfully installed |
| 374 | """ |
| 375 | result = main.TRUE |
| 376 | threads = [] |
| 377 | i = 0 |
| 378 | for ctrl in self.controllers if installMax else self.runningNodes: |
| 379 | options = "-f" |
| 380 | if installMax and i >= self.numCtrls: |
| 381 | options = "-nf" |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 382 | if installParallel: |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 383 | t = main.Thread( target=ctrl.Bench.onosInstall, |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 384 | name="onos-install-" + ctrl.name, |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 385 | kwargs={ "node" : ctrl.ipAddress, |
| 386 | "options" : options } ) |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 387 | threads.append( t ) |
| 388 | t.start() |
| 389 | else: |
| 390 | result = result and \ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 391 | main.ONOSbench.onosInstall( node=ctrl.ipAddress, options=options ) |
Jon Hall | a6771b3 | 2018-01-26 16:07:28 -0800 | [diff] [blame] | 392 | i += 1 |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 393 | if installParallel: |
| 394 | for t in threads: |
| 395 | t.join() |
| 396 | result = result and t.result |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 397 | return result |
| 398 | |
| 399 | def startCLIs( self ): |
| 400 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 401 | Description: |
| 402 | starting Onos using onosCli driver |
| 403 | Required: |
| 404 | Returns: |
| 405 | Returns main.TRUE if it successfully started. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 406 | """ |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 407 | result = main.TRUE |
| 408 | cliResults = self.command( "startOnosCli", |
| 409 | args=[ "ipAddress" ], |
| 410 | specificDriver=2, |
| 411 | getFrom=1, |
| 412 | funcFromCtrl=True ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 413 | for i in range( len( cliResults ) ): |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 414 | result = result and cliResults[ i ] |
| 415 | self.controllers[ i ].active = True |
| 416 | return result |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 417 | |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 418 | def nodesCheck( self ): |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 419 | """ |
| 420 | Description: |
| 421 | Checking if all the onos nodes are in READY state |
| 422 | Required: |
| 423 | Returns: |
| 424 | Returns True if it successfully checked |
| 425 | """ |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 426 | results = True |
| 427 | nodesOutput = self.command( "nodes", specificDriver=2 ) |
| 428 | ips = sorted( self.getIps( activeOnly=True ) ) |
| 429 | for i in nodesOutput: |
| 430 | try: |
| 431 | current = json.loads( i ) |
| 432 | activeIps = [] |
| 433 | currentResult = False |
| 434 | for node in current: |
| 435 | if node[ 'state' ] == 'READY': |
| 436 | activeIps.append( node[ 'ip' ] ) |
| 437 | activeIps.sort() |
| 438 | if ips == activeIps: |
| 439 | currentResult = True |
| 440 | except ( ValueError, TypeError ): |
| 441 | main.log.error( "Error parsing nodes output" ) |
| 442 | main.log.warn( repr( i ) ) |
| 443 | currentResult = False |
| 444 | results = results and currentResult |
| 445 | return results |
| 446 | |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 447 | def appsCheck( self, apps ): |
| 448 | """ |
| 449 | Description: |
| 450 | Checking if all the applications are activated |
| 451 | Required: |
| 452 | apps: list of applications that are expected to be activated |
| 453 | Returns: |
| 454 | Returns True if it successfully checked |
| 455 | """ |
| 456 | results = True |
| 457 | for app in apps: |
| 458 | states = self.command( "appStatus", |
| 459 | args=[ app ], |
| 460 | specificDriver=2 ) |
| 461 | for i in range( len( states ) ): |
| 462 | ctrl = self.controllers[ i ] |
| 463 | if states[ i ] == "ACTIVE": |
| 464 | results = results and True |
| 465 | main.log.info( "{}: {} is activated".format( ctrl.name, app ) ) |
| 466 | else: |
| 467 | results = False |
| 468 | main.log.warn( "{}: {} is in {} state".format( ctrl.name, app, states[ i ] ) ) |
| 469 | return results |
| 470 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 471 | def printResult( self, results, activeList, logLevel="debug" ): |
| 472 | """ |
| 473 | Description: |
| 474 | Print the value of the list. |
| 475 | Required: |
| 476 | * results - list of the result |
| 477 | * activeList - list of the acitve nodes. |
| 478 | * logLevel - Type of log level you want it to be printed. |
| 479 | Returns: |
| 480 | """ |
| 481 | f = getattr( main.log, logLevel ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 482 | for i in range( len( results ) ): |
| 483 | f( activeList[ i ].name + "'s result : " + str( results[ i ] ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 484 | |
| 485 | def allTrueResultCheck( self, results, activeList ): |
| 486 | """ |
| 487 | Description: |
| 488 | check if all the result has main.TRUE. |
| 489 | Required: |
| 490 | * results - list of the result |
| 491 | * activeList - list of the acitve nodes. |
| 492 | Returns: |
| 493 | Returns True if all == main.TRUE else |
| 494 | returns False |
| 495 | """ |
| 496 | self.printResult( results, activeList ) |
| 497 | return all( result == main.TRUE for result in results ) |
| 498 | |
| 499 | def notEmptyResultCheck( self, results, activeList ): |
| 500 | """ |
| 501 | Description: |
| 502 | check if all the result has any contents |
| 503 | Required: |
| 504 | * results - list of the result |
| 505 | * activeList - list of the acitve nodes. |
| 506 | Returns: |
| 507 | Returns True if all the results has |
| 508 | something else returns False |
| 509 | """ |
| 510 | self.printResult( results, activeList ) |
| 511 | return all( result for result in results ) |
| 512 | |
| 513 | def identicalResultsCheck( self, results, activeList ): |
| 514 | """ |
| 515 | Description: |
| 516 | check if all the results has same output. |
| 517 | Required: |
| 518 | * results - list of the result |
| 519 | * activeList - list of the acitve nodes. |
| 520 | Returns: |
| 521 | Returns True if all the results has |
| 522 | same result else returns False |
| 523 | """ |
| 524 | self.printResult( results, activeList ) |
| 525 | resultOne = results[ 0 ] |
| 526 | return all( resultOne == result for result in results ) |
| 527 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 528 | def command( self, function, args=(), kwargs={}, returnBool=False, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 529 | specificDriver=0, contentCheck=False, getFrom=2, |
| 530 | funcFromCtrl=False ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 531 | """ |
| 532 | Description: |
| 533 | execute some function of the active nodes. |
| 534 | Required: |
| 535 | * function - name of the function |
| 536 | * args - argument of the function |
| 537 | * kwargs - kwargs of the funciton |
| 538 | * returnBool - True if wish to check all the result has main.TRUE |
| 539 | * specificDriver - specific driver to execute the function. Since |
| 540 | some of the function can be used in different drivers, it is important |
| 541 | to specify which driver it will be executed from. |
| 542 | 0 - any type of driver |
| 543 | 1 - from bench |
| 544 | 2 - from cli |
| 545 | 3 - from rest |
| 546 | * contentCheck - If this is True, it will check if the result has some |
| 547 | contents. |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 548 | * getFrom - from which nodes |
| 549 | 2 - active nodes |
| 550 | 1 - current running nodes |
| 551 | 0 - all nodes |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 552 | * funcFromCtrl - specific function of the args/kwargs |
| 553 | from each controller from the list of the controllers |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 554 | Returns: |
| 555 | Returns results if not returnBool and not contentCheck |
| 556 | Returns checkTruthValue of the result if returnBool |
| 557 | Returns resultContent of the result if contentCheck |
| 558 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 559 | threads = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 560 | drivers = [ None, "Bench", "CLI", "REST" ] |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 561 | fromNode = [ self.controllers, self.runningNodes, self.active() ] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 562 | results = [] |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 563 | for ctrl in fromNode[ getFrom ]: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 564 | try: |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 565 | funcArgs = [] |
| 566 | funcKwargs = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 567 | f = getattr( ( ctrl if not specificDriver else |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 568 | getattr( ctrl, drivers[ specificDriver ] ) ), function ) |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 569 | if funcFromCtrl: |
| 570 | if args: |
| 571 | for i in range( len( args ) ): |
| 572 | funcArgs.append( getattr( ctrl, args[ i ] ) ) |
| 573 | if kwargs: |
| 574 | for k in kwargs: |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 575 | funcKwargs.update( { k: getattr( ctrl, kwargs[ k ] ) } ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 576 | except AttributeError: |
| 577 | main.log.error( "Function " + function + " not found. Exiting the Test." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 578 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 579 | t = main.Thread( target=f, |
| 580 | name=function + "-" + ctrl.name, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 581 | args=funcArgs if funcFromCtrl else args, |
| 582 | kwargs=funcKwargs if funcFromCtrl else kwargs ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 583 | threads.append( t ) |
| 584 | t.start() |
| 585 | |
| 586 | for t in threads: |
| 587 | t.join() |
| 588 | results.append( t.result ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 589 | if returnBool: |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 590 | return self.allTrueResultCheck( results, fromNode[ getFrom ] ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 591 | elif contentCheck: |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 592 | return self.notEmptyResultCheck( results, fromNode[ getFrom ] ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 593 | return results |
| 594 | |
| 595 | def checkPartitionSize( self, segmentSize='64', units='M', multiplier='3' ): |
| 596 | # max segment size in bytes: 1024 * 1024 * 64 |
| 597 | # multiplier is somewhat arbitrary, but the idea is the logs would have |
| 598 | # been compacted before this many segments are written |
| 599 | |
| 600 | maxSize = float( segmentSize ) * float( multiplier ) |
| 601 | ret = True |
| 602 | for n in self.runningNodes: |
Jon Hall | 5d5876e | 2017-11-30 09:33:16 -0800 | [diff] [blame] | 603 | # Partition logs |
Jon Hall | d81e016 | 2018-08-13 12:06:13 -0700 | [diff] [blame] | 604 | ret = ret and n.server.folderSize( "/opt/atomix/data/raft/partitions/*/*.log", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 605 | size=maxSize, unit=units, ignoreRoot=False ) |
| 606 | return ret |