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 = [] |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 29 | runningNodes = self.getRunningNodes() |
| 30 | atomixNodes = [] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 31 | for ctrl in self.controllers: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 32 | controllers.append( "{%s:%s, %s - %s}" % ( ctrl.name, |
| 33 | ctrl.ipAddress, |
| 34 | "Configured" if ctrl in runningNodes else "Not Configured", |
| 35 | "Active" if ctrl.active else "Inactive" ) ) |
| 36 | for node in self.atomixNodes: |
| 37 | atomixNodes.append( "{%s:%s}" % ( node.name, node.ipAddress ) ) |
| 38 | return "%s[%s; Atomix Nodes:%s]" % ( self.name, ", ".join( controllers ), ", ".join( atomixNodes ) ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 39 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 40 | def __init__( self, ctrlList=[], name="Cluster", useDocker=False ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 41 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 42 | controllers : All the nodes |
| 43 | runningNodes : Node that are specifically running from the test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 44 | ie ) When the test is testing different number of nodes on each |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 45 | run. |
| 46 | numCtrls : number of runningNodes |
| 47 | maxCtrls : number of controllers |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 48 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 49 | self.controllers = ctrlList |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 50 | self.runningNodes = ctrlList |
| 51 | self.numCtrls = len( self.runningNodes ) |
| 52 | self.maxCtrls = len( self.controllers ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 53 | self.name = str( name ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 54 | self.atomixNodes = ctrlList |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 55 | self.iterator = iter( self.active() ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 56 | self.useDocker = useDocker |
| 57 | clusterParams = main.params.get( "CLUSTER", {} ) |
| 58 | self.dockerSkipBuild = clusterParams.get( "dockerSkipBuild", False ) |
| 59 | self.dockerBuildCmd = clusterParams.get( "dockerBuildCmd", None ) |
| 60 | self.dockerBuildTimeout = int( clusterParams.get( "dockerBuildTimeout", 600 ) ) |
| 61 | self.dockerFilePath = clusterParams.get( "dockerFilePath", None ) |
| 62 | self.dockerImageTag = clusterParams.get( "dockerImageTag", None ) |
| 63 | self.dockerOptions = clusterParams.get( "dockerOptions", "" ) |
| 64 | self.atomixImageTag = clusterParams.get( "atomixImageTag", None ) |
| 65 | self.atomixOptions = clusterParams.get( "atomixOptions", "" ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 66 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 67 | def fromNode( self, ctrlList ): |
| 68 | """ |
| 69 | Helper function to get a specific list of controllers |
| 70 | Required Arguments: |
| 71 | * ctrlList - The list of controllers to return. This can be either an index or a keyword |
| 72 | Index | Keyword | List returned |
| 73 | 0 | "all" | self.controllers |
| 74 | 1 | "running" | self.runningNodes |
| 75 | 2 | "active | self.active() |
| 76 | |
| 77 | Throws a ValueError exception if ctrlList value is not recognized |
| 78 | """ |
| 79 | # TODO: Add Atomix Nodes? |
| 80 | if isinstance( ctrlList, str ): |
| 81 | ctrlList = ctrlList.lower() |
| 82 | if ctrlList == 0 or ctrlList == "all": |
| 83 | return self.controllers |
| 84 | elif ctrlList == 1 or ctrlList == "running": |
| 85 | return self.runningNodes |
| 86 | elif ctrlList == 2 or ctrlList == "active": |
| 87 | return self.active() |
| 88 | else: |
| 89 | raise ValueError( "Unknown argument: {}".format( ctrlList ) ) |
| 90 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 91 | def getIps( self, activeOnly=False, allNode=False ): |
| 92 | """ |
| 93 | Description: |
| 94 | get the list of the ip. Default to get ips of running nodes. |
| 95 | Required: |
| 96 | * activeOnly - True for getting ips of active nodes |
| 97 | * allNode - True for getting ips of all nodes |
| 98 | Returns: |
| 99 | Retruns ips of active nodes if activeOnly is True. |
| 100 | Returns ips of all nodes if allNode is True. |
| 101 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 102 | ips = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 103 | if allNode: |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 104 | nodeList = self.controllers |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 105 | else: |
| 106 | if activeOnly: |
| 107 | nodeList = self.active() |
| 108 | else: |
| 109 | nodeList = self.runningNodes |
| 110 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 111 | for ctrl in nodeList: |
Jon Hall | d14a500 | 2021-03-30 16:45:30 -0700 | [diff] [blame] | 112 | ips.append( ctrl.ipAddress if 'localhost' not in ctrl.ipAddress else ctrl.address ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 113 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 114 | return ips |
| 115 | |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 116 | def clearActive( self ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 117 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 118 | Description: |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 119 | Sets the activeness of each cluster node to be False |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 120 | """ |
Jon Hall | ab61137 | 2018-02-21 15:26:05 -0800 | [diff] [blame] | 121 | for ctrl in self.controllers: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 122 | ctrl.active = False |
| 123 | |
| 124 | def getRunningPos( self ): |
| 125 | """ |
| 126 | Description: |
| 127 | get the position of the active running nodes. |
| 128 | Required: |
| 129 | Returns: |
| 130 | Retruns the list of the position of the active |
| 131 | running nodes. |
| 132 | """ |
| 133 | return [ ctrl.pos for ctrl in self.runningNodes |
| 134 | if ctrl.active ] |
| 135 | |
| 136 | def setRunningNode( self, numCtrls ): |
| 137 | """ |
| 138 | Description: |
| 139 | Set running nodes of n number of nodes. |
| 140 | It will create new list of runningNodes. |
| 141 | If numCtrls is a list, it will add the nodes of the |
| 142 | list. |
| 143 | Required: |
| 144 | * numCtrls - number of nodes to be set. |
| 145 | Returns: |
| 146 | """ |
| 147 | self.runningNodes = [] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 148 | for i in numCtrls if isinstance( numCtrls, list ) else range( numCtrls ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 149 | self.runningNodes.append( self.controllers[ i ] ) |
| 150 | self.numCtrls = len( numCtrls ) if isinstance( numCtrls, list ) else numCtrls |
| 151 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 152 | def setAtomixNodes( self, nodes ): |
| 153 | """ |
| 154 | Description: |
| 155 | Sets the list of Atomix nodes for the cluster |
| 156 | If nodes is a list, it will add the nodes of the list. |
| 157 | If nodes is an int, the function will set the Atomix nodes |
| 158 | to be the first n in the list of controllers. |
| 159 | Required: |
| 160 | * nodes - number of nodes to be set, or a list of nodes to set |
| 161 | Returns: |
| 162 | """ |
| 163 | self.atomixNodes = [] |
| 164 | for i in nodes if isinstance( nodes, list ) else range( nodes ): |
| 165 | self.atomixNodes.append( self.controllers[ i ] ) |
| 166 | |
| 167 | def getControllers( self, node=None ): |
| 168 | """ |
| 169 | Description: |
| 170 | Get the list of all controllers in a cluster or a controller at an index in the list |
| 171 | Optional Arguments: |
| 172 | * node - position of the node to get from the list of controllers. |
| 173 | Returns: |
| 174 | Return a list of controllers in the cluster if node is None |
| 175 | if not, it will return the controller at the given index. |
| 176 | """ |
| 177 | result = self.controllers |
| 178 | return result if node is None else result[ node % len( result ) ] |
| 179 | |
| 180 | def getRunningNodes( self, node=None ): |
| 181 | """ |
| 182 | Description: |
| 183 | Get the list of all controllers in a cluster that should be running or |
| 184 | a controller at an index in the list |
| 185 | Optional Arguments: |
| 186 | * node - position of the node to get from the list of controllers. |
| 187 | Returns: |
| 188 | Return a list of controllers in the cluster if node is None |
| 189 | if not, it will return the controller at the given index. |
| 190 | """ |
| 191 | result = self.runningNodes |
| 192 | return result if node is None else result[ node % len( result ) ] |
| 193 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 194 | def active( self, node=None ): |
| 195 | """ |
| 196 | Description: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 197 | Get the list of all active controllers in a cluster or |
| 198 | a controller at an index in the list |
| 199 | Optional Arguments: |
| 200 | * node - position of the node to get from the list of controllers. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 201 | Returns: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 202 | Return a list of controllers in the cluster if node is None |
| 203 | if not, it will return the controller at the given index. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 204 | """ |
| 205 | result = [ ctrl for ctrl in self.runningNodes |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 206 | if ctrl.active ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 207 | return result if node is None else result[ node % len( result ) ] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 208 | |
| 209 | def next( self ): |
| 210 | """ |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 211 | An iterator for the cluster's active controllers that |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 212 | resets when there are no more elements. |
| 213 | |
| 214 | Returns the next controller in the cluster |
| 215 | """ |
| 216 | try: |
Jon Hall | a1e8e51 | 2018-05-11 13:30:57 -0700 | [diff] [blame] | 217 | node = self.iterator.next() |
| 218 | assert node.active |
| 219 | return node |
| 220 | except ( StopIteration, AssertionError ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 221 | self.reset() |
| 222 | try: |
| 223 | return self.iterator.next() |
| 224 | except StopIteration: |
| 225 | raise RuntimeError( "There are no active nodes in the cluster" ) |
| 226 | |
| 227 | def reset( self ): |
| 228 | """ |
| 229 | Resets the cluster iterator. |
| 230 | |
| 231 | This should be used whenever a node's active state is changed |
| 232 | and is also used internally when the iterator has been exhausted. |
| 233 | """ |
| 234 | self.iterator = iter( self.active() ) |
| 235 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 236 | def createCell( self, cellName, cellApps, mininetIp, useSSH, onosIps, |
| 237 | atomixIps, installMax=False ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 238 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 239 | Description: |
| 240 | create a new cell |
| 241 | Required: |
| 242 | * cellName - The name of the cell. |
You Wang | 09b596b | 2018-01-10 10:42:38 -0800 | [diff] [blame] | 243 | * cellApps - The ONOS apps string. |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 244 | * mininetIp - Mininet IP address. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 245 | * useSSH - True for using ssh when creating a cell |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 246 | * onosIps - ip( s ) of the ONOS node( s ). |
| 247 | * atomixIps - ip( s ) of the Atomix node( s ). |
| 248 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 249 | Returns: |
| 250 | """ |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 251 | self.command( "createCellFile", |
| 252 | args=[ main.ONOSbench.ip_address, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 253 | cellName, |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 254 | mininetIp, |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 255 | cellApps, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 256 | onosIps, |
| 257 | atomixIps, |
Siddesh | 1349297 | 2021-03-12 21:09:32 +0000 | [diff] [blame] | 258 | main.ONOScell.nodeUser, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 259 | useSSH ], |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 260 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 261 | getFrom="all" if installMax else "running" ) |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 262 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 263 | def uninstallAtomix( self, uninstallMax ): |
| 264 | """ |
| 265 | Description: |
| 266 | uninstalling atomix |
| 267 | Required: |
| 268 | * uninstallMax - True for uninstalling max number of nodes |
| 269 | False for uninstalling the current running nodes. |
| 270 | Returns: |
| 271 | Returns main.TRUE if it successfully uninstalled. |
| 272 | """ |
| 273 | result = main.TRUE |
| 274 | uninstallResult = self.command( "atomixUninstall", |
| 275 | kwargs={ "nodeIp": "ipAddress" }, |
| 276 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 277 | getFrom="all" if uninstallMax else "running", |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 278 | funcFromCtrl=True ) |
| 279 | for uninstallR in uninstallResult: |
| 280 | result = result and uninstallR |
| 281 | return result |
| 282 | |
| 283 | def uninstallOnos( self, uninstallMax ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 284 | """ |
| 285 | Description: |
| 286 | uninstalling onos |
| 287 | Required: |
| 288 | * uninstallMax - True for uninstalling max number of nodes |
| 289 | False for uninstalling the current running nodes. |
| 290 | Returns: |
| 291 | Returns main.TRUE if it successfully uninstalled. |
| 292 | """ |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 293 | result = main.TRUE |
| 294 | uninstallResult = self.command( "onosUninstall", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 295 | kwargs={ "nodeIp": "ipAddress" }, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 296 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 297 | getFrom="all" if uninstallMax else "running", |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 298 | funcFromCtrl=True ) |
| 299 | for uninstallR in uninstallResult: |
| 300 | result = result and uninstallR |
| 301 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 302 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 303 | def applyCell( self, cellName, installMax=False ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 304 | """ |
| 305 | Description: |
| 306 | apply the cell with cellName. It will also verify the |
| 307 | cell. |
| 308 | Required: |
| 309 | * cellName - The name of the cell. |
| 310 | Returns: |
| 311 | Returns main.TRUE if it successfully set and verify cell. |
| 312 | """ |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 313 | result = main.TRUE |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 314 | setCellResult = self.command( "setCell", |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 315 | args=[ cellName ], |
| 316 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 317 | getFrom="all" ) |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 318 | for i in range( len( setCellResult ) ): |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 319 | result = result and setCellResult[ i ] |
| 320 | benchCellResult = main.ONOSbench.setCell( cellName ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 321 | result = result and benchCellResult |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 322 | if not self.useDocker: |
| 323 | verifyResult = self.command( "verifyCell", |
| 324 | specificDriver=1, |
| 325 | getFrom="all" ) |
| 326 | for i in range( len( verifyResult ) ): |
| 327 | result = result and verifyResult[ i ] |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 328 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 329 | |
| 330 | def checkService( self ): |
| 331 | """ |
| 332 | Description: |
| 333 | Checking if the onos service is up. If not, it will |
| 334 | start the onos service manually. |
| 335 | Required: |
| 336 | Returns: |
| 337 | Returns main.TRUE if it successfully checked |
| 338 | """ |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 339 | getFrom = "running" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 340 | onosIsUp = main.TRUE |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 341 | onosUp = self.command( "isup", |
| 342 | args=[ "ipAddress" ], |
| 343 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 344 | getFrom=getFrom, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 345 | funcFromCtrl=True ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 346 | ctrlList = self.fromNode( getFrom ) |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 347 | for i in range( len( onosUp ) ): |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 348 | ctrl = ctrlList[ i ] |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 349 | onosIsUp = onosIsUp and onosUp[ i ] |
| 350 | if onosUp[ i ] == main.TRUE: |
Jon Hall | 9655dcb | 2018-02-02 11:19:06 -0800 | [diff] [blame] | 351 | main.log.info( ctrl.name + " is up and ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 352 | else: |
Jon Hall | 9655dcb | 2018-02-02 11:19:06 -0800 | [diff] [blame] | 353 | main.log.warn( ctrl.name + " may not be up." ) |
| 354 | return onosIsUp |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 355 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 356 | def killAtomix( self, killMax, stopAtomix ): |
| 357 | """ |
| 358 | Description: |
| 359 | killing atomix. It will either kill the current runningnodes or |
| 360 | max number of the nodes. |
| 361 | Required: |
| 362 | * killRemoveMax - The boolean that will decide either to kill |
| 363 | only running nodes ( False ) or max number of nodes ( True ). |
| 364 | * stopAtomix - If wish to atomix onos before killing it. True for |
| 365 | enable stop, False for disable stop. |
| 366 | Returns: |
| 367 | Returns main.TRUE if successfully killing it. |
| 368 | """ |
| 369 | result = main.TRUE |
| 370 | killResult = self.command( "atomixKill", |
| 371 | args=[ "ipAddress" ], |
| 372 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 373 | getFrom="all" if killMax else "running", |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 374 | funcFromCtrl=True ) |
| 375 | for i in range( len( killResult ) ): |
| 376 | result = result and killResult[ i ] |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 377 | return result |
| 378 | |
| 379 | def killOnos( self, killMax, stopOnos ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 380 | """ |
| 381 | Description: |
| 382 | killing the onos. It will either kill the current runningnodes or |
| 383 | max number of the nodes. |
| 384 | Required: |
| 385 | * killRemoveMax - The boolean that will decide either to kill |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 386 | only running nodes ( False ) or max number of nodes ( True ). |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 387 | * stopOnos - If wish to stop onos before killing it. True for |
| 388 | enable stop , False for disable stop. |
| 389 | Returns: |
| 390 | Returns main.TRUE if successfully killing it. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 391 | """ |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 392 | getFrom = "all" if killMax else "running" |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 393 | result = main.TRUE |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 394 | killResult = self.command( "onosKill", |
| 395 | args=[ "ipAddress" ], |
| 396 | specificDriver=1, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 397 | getFrom=getFrom, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 398 | funcFromCtrl=True ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 399 | ctrlList = self.fromNode( getFrom ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 400 | for i in range( len( killResult ) ): |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 401 | result = result and killResult[ i ] |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 402 | ctrlList[ i ].active = False |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 403 | return result |
| 404 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 405 | def dockerStop( self, killMax, atomix=True ): |
| 406 | """ |
| 407 | Description: |
| 408 | killing the onos docker containers. It will either kill the |
| 409 | current runningnodes or max number of the nodes. |
| 410 | Required: |
| 411 | * killRemoveMax - The boolean that will decide either to kill |
| 412 | only running nodes ( False ) or max number of nodes ( True ). |
| 413 | Returns: |
| 414 | Returns main.TRUE if successfully killing it. |
| 415 | """ |
| 416 | getFrom = "all" if killMax else "running" |
| 417 | result = main.TRUE |
| 418 | stopResult = self.command( "dockerStop", |
| 419 | args=[ "name" ], |
| 420 | specificDriver=4, |
| 421 | getFrom=getFrom, |
| 422 | funcFromCtrl=True ) |
| 423 | ctrlList = self.fromNode( getFrom ) |
| 424 | for i in range( len( stopResult ) ): |
| 425 | result = result and stopResult[ i ] |
| 426 | ctrlList[ i ].active = False |
| 427 | atomixResult = main.TRUE |
| 428 | if atomix: |
| 429 | atomixResult = self.stopAtomixDocker( killMax ) |
| 430 | return result and atomixResult |
| 431 | |
| 432 | def dockerBuild( self, pull=True ): |
| 433 | """ |
| 434 | Description: |
| 435 | Build ONOS docker image |
| 436 | Optional: |
| 437 | * pull - Try to pull latest image before building |
| 438 | Returns: |
| 439 | Returns main.TRUE if successfully killing it. |
| 440 | """ |
| 441 | getFrom = "all" |
| 442 | result = main.TRUE |
| 443 | atomixResult = [] |
| 444 | buildResult = [] |
| 445 | if self.atomixImageTag: |
| 446 | atomixResult = self.command( "dockerPull", |
| 447 | args=[ self.atomixImageTag ], |
| 448 | specificDriver=4, |
| 449 | getFrom=getFrom, |
| 450 | funcFromCtrl=False ) |
| 451 | if not self.dockerImageTag: |
| 452 | main.log.error( "No image given, exiting test" ) |
| 453 | return main.FALSE |
| 454 | if pull and self.dockerImageTag: |
| 455 | buildResult = self.command( "dockerPull", |
| 456 | args=[ self.dockerImageTag ], |
| 457 | specificDriver=4, |
| 458 | getFrom=getFrom, |
| 459 | funcFromCtrl=False ) |
| 460 | for i in range( len( buildResult ) ): |
| 461 | result = result and buildResult[ i ] |
| 462 | if self.dockerSkipBuild: |
| 463 | return main.TRUE |
| 464 | if not result and self.dockerBuildCmd: |
| 465 | buildResult = self.command( "makeDocker", |
| 466 | args=[ self.dockerFilePath, self.dockerBuildCmd ], |
| 467 | kwargs={ "timeout": self.dockerBuildTimeout, |
| 468 | "prompt": "Successfully tagged %s" % self.dockerImageTag }, |
| 469 | specificDriver=4, |
| 470 | getFrom=getFrom, |
| 471 | funcFromCtrl=False ) |
| 472 | |
| 473 | elif not result: |
| 474 | buildResult = self.command( "dockerBuild", |
| 475 | args=[ self.dockerFilePath, self.dockerImageTag ], |
| 476 | kwargs={ "timeout": self.dockerBuildTimeout, |
| 477 | "pull": pull }, |
| 478 | specificDriver=4, |
| 479 | getFrom=getFrom, |
| 480 | funcFromCtrl=False ) |
| 481 | for i in range( len( atomixResult ) ): |
| 482 | result = result and atomixResult[ i ] |
| 483 | for i in range( len( buildResult ) ): |
| 484 | result = result and buildResult[ i ] |
| 485 | return result |
| 486 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 487 | def ssh( self ): |
| 488 | """ |
| 489 | Description: |
| 490 | set up ssh to the onos |
| 491 | Required: |
| 492 | Returns: |
| 493 | Returns main.TRUE if it successfully setup the ssh to |
| 494 | the onos. |
| 495 | """ |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 496 | result = main.TRUE |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 497 | if self.useDocker: |
| 498 | driver = 2 |
| 499 | kwargs = { "userName": "karafUser", |
| 500 | "userPWD": "karafPass" } |
| 501 | else: |
| 502 | driver = 1 |
| 503 | kwargs = { "node": "ipAddress" } |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 504 | sshResult = self.command( "onosSecureSSH", |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 505 | kwargs=kwargs, |
| 506 | specificDriver=driver, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 507 | getFrom="running", |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 508 | funcFromCtrl=True ) |
| 509 | for sshR in sshResult: |
| 510 | result = result and sshR |
| 511 | return result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 512 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 513 | def installAtomix( self, installParallel=True ): |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 514 | """ |
| 515 | Description: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 516 | Installing Atomix. |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 517 | Required: |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 518 | Returns: |
| 519 | Returns main.TRUE if it successfully installed |
| 520 | """ |
| 521 | result = main.TRUE |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 522 | if self.useDocker: |
| 523 | # We will do this as part of startDocker |
| 524 | return result |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 525 | threads = [] |
| 526 | i = 0 |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 527 | for ctrl in self.atomixNodes: |
| 528 | options = "-f" |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 529 | if installParallel: |
| 530 | t = main.Thread( target=ctrl.Bench.atomixInstall, |
| 531 | name="atomix-install-" + ctrl.name, |
| 532 | kwargs={ "node" : ctrl.ipAddress, |
| 533 | "options" : options } ) |
| 534 | threads.append( t ) |
| 535 | t.start() |
| 536 | else: |
| 537 | result = result and \ |
| 538 | main.ONOSbench.atomixInstall( node=ctrl.ipAddress, options=options ) |
| 539 | i += 1 |
| 540 | if installParallel: |
| 541 | for t in threads: |
| 542 | t.join() |
| 543 | result = result and t.result |
| 544 | return result |
| 545 | |
Jon Hall | 23bbe85 | 2021-03-26 10:47:23 -0700 | [diff] [blame] | 546 | def installOnos( self, installMax=True, installParallel=True, retries=5 ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 547 | """ |
| 548 | Description: |
| 549 | Installing onos. |
| 550 | Required: |
| 551 | * installMax - True for installing max number of nodes |
| 552 | False for installing current running nodes only. |
| 553 | Returns: |
| 554 | Returns main.TRUE if it successfully installed |
| 555 | """ |
| 556 | result = main.TRUE |
| 557 | threads = [] |
| 558 | i = 0 |
| 559 | for ctrl in self.controllers if installMax else self.runningNodes: |
| 560 | options = "-f" |
| 561 | if installMax and i >= self.numCtrls: |
| 562 | options = "-nf" |
Jon Hall | 23bbe85 | 2021-03-26 10:47:23 -0700 | [diff] [blame] | 563 | args = [ ctrl.Bench.onosInstall, main.FALSE ] |
| 564 | kwargs={ "node" : ctrl.ipAddress, |
| 565 | "options" : options } |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 566 | if installParallel: |
Jon Hall | 23bbe85 | 2021-03-26 10:47:23 -0700 | [diff] [blame] | 567 | t = main.Thread( target=utilities.retry, |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 568 | name="onos-install-" + ctrl.name, |
Jon Hall | 23bbe85 | 2021-03-26 10:47:23 -0700 | [diff] [blame] | 569 | args=args, |
| 570 | kwargs={ 'kwargs': kwargs, |
| 571 | 'attempts': retries } ) |
| 572 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 573 | threads.append( t ) |
| 574 | t.start() |
| 575 | else: |
| 576 | result = result and \ |
Jon Hall | 23bbe85 | 2021-03-26 10:47:23 -0700 | [diff] [blame] | 577 | utilities.retry( args=args, kwargs=kwargs, attempts=retries ) |
Jon Hall | a6771b3 | 2018-01-26 16:07:28 -0800 | [diff] [blame] | 578 | i += 1 |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 579 | if installParallel: |
| 580 | for t in threads: |
| 581 | t.join() |
| 582 | result = result and t.result |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 583 | return result |
| 584 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 585 | def startONOSDocker( self, installMax=True, installParallel=True ): |
| 586 | """ |
| 587 | Description: |
| 588 | Installing onos via docker containers. |
| 589 | Required: |
| 590 | * installMax - True for installing max number of nodes |
| 591 | False for installing current running nodes only. |
| 592 | Returns: |
| 593 | Returns main.TRUE if it successfully installed |
| 594 | """ |
| 595 | result = main.TRUE |
| 596 | threads = [] |
| 597 | for ctrl in self.controllers if installMax else self.runningNodes: |
| 598 | if installParallel: |
| 599 | t = main.Thread( target=ctrl.server.dockerRun, |
| 600 | name="onos-run-docker-" + ctrl.name, |
| 601 | args=[ self.dockerImageTag, ctrl.name ], |
| 602 | kwargs={ "options" : self.dockerOptions } ) |
| 603 | threads.append( t ) |
| 604 | t.start() |
| 605 | else: |
| 606 | result = result and \ |
| 607 | ctrl.server.dockerRun( self.dockerImageTag, |
| 608 | ctrl.name, |
| 609 | options=self.dockerOptions ) |
| 610 | if installParallel: |
| 611 | for t in threads: |
| 612 | t.join() |
| 613 | result = result and t.result |
| 614 | return result |
| 615 | |
Jon Hall | 214f88b | 2020-09-21 10:21:42 -0700 | [diff] [blame] | 616 | def startONOSDockerNode( self, node ): |
| 617 | """ |
| 618 | Description: |
| 619 | Installing onos via docker container on a specific node. |
| 620 | Required: |
| 621 | * node - the node to install ONOS on, given in index of runningNodes |
| 622 | Returns: |
| 623 | Returns main.TRUE if it successfully installed |
| 624 | """ |
| 625 | ctrl = self.runningNodes[ node ] |
| 626 | result = ctrl.server.dockerRun( self.dockerImageTag, |
| 627 | ctrl.name, |
| 628 | options=self.dockerOptions ) |
| 629 | return result |
| 630 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 631 | def startAtomixDocker( self, installParallel=True ): |
| 632 | """ |
| 633 | Description: |
| 634 | Installing atomix via docker containers. |
| 635 | Required: |
| 636 | * installParallel - True for installing atomix in parallel. |
| 637 | Returns: |
| 638 | Returns main.TRUE if it successfully installed |
| 639 | """ |
| 640 | result = main.TRUE |
| 641 | threads = [] |
| 642 | for ctrl in self.atomixNodes: |
| 643 | if installParallel: |
| 644 | t = main.Thread( target=ctrl.server.dockerRun, |
| 645 | name="atomix-run-docker-" + ctrl.name, |
| 646 | args=[ self.atomixImageTag, "atomix-" + ctrl.name ], |
| 647 | kwargs={ "options" : main.params['CLUSTER']['atomixOptions'], |
| 648 | "imageArgs": " --config /opt/atomix/conf/atomix.json --ignore-resources"} ) |
| 649 | threads.append( t ) |
| 650 | t.start() |
| 651 | else: |
| 652 | result = result and \ |
| 653 | ctrl.server.dockerRun( self.atomixImageTag, |
| 654 | "atomix-" + ctrl.name, |
| 655 | options=main.params['CLUSTER']['atomixOptions'] ) |
| 656 | if installParallel: |
| 657 | for t in threads: |
| 658 | t.join() |
| 659 | result = result and t.result |
| 660 | return result |
| 661 | |
| 662 | def stopAtomixDocker( self, killMax=True, installParallel=True ): |
| 663 | """ |
| 664 | Description: |
| 665 | Stoping all atomix containers |
| 666 | Required: |
| 667 | * killMax - True for stoping max number of nodes |
| 668 | False for stoping current running nodes only. |
| 669 | Returns: |
| 670 | Returns main.TRUE if it successfully stoped |
| 671 | """ |
| 672 | result = main.TRUE |
| 673 | threads = [] |
| 674 | for ctrl in self.controllers if killMax else self.atomixNodes: |
| 675 | if installParallel: |
| 676 | t = main.Thread( target=ctrl.server.dockerStop, |
| 677 | name="atomix-stop-docker-" + ctrl.name, |
| 678 | args=[ "atomix-" + ctrl.name ] ) |
| 679 | threads.append( t ) |
| 680 | t.start() |
| 681 | else: |
| 682 | result = result and \ |
| 683 | ctrl.server.dockerStop( "atomix-" + ctrl.name ) |
| 684 | if installParallel: |
| 685 | for t in threads: |
| 686 | t.join() |
| 687 | result = result and t.result |
| 688 | return result |
| 689 | |
| 690 | def genPartitions( self, path="/tmp/cluster.json" ): |
| 691 | """ |
| 692 | Description: |
| 693 | Create cluster config and move to each onos server |
| 694 | Required: |
| 695 | * installMax - True for installing max number of nodes |
| 696 | False for installing current running nodes only. |
| 697 | Returns: |
| 698 | Returns main.TRUE if it successfully installed |
| 699 | """ |
| 700 | result = main.TRUE |
| 701 | # move files to onos servers |
| 702 | for ctrl in self.atomixNodes: |
| 703 | localAtomixFile = ctrl.ip_address + "-atomix.json" |
| 704 | result = result and main.ONOSbench.generateAtomixConfig( ctrl.server.ip_address, path=localAtomixFile ) |
| 705 | result = result and main.ONOSbench.scp( ctrl.server, |
| 706 | localAtomixFile, |
| 707 | "/tmp/atomix.json", |
| 708 | direction="to" ) |
| 709 | for ctrl in self.controllers: |
| 710 | localOnosFile = ctrl.ip_address + "-cluster.json" |
| 711 | result = result and main.ONOSbench.generateOnosConfig( ctrl.server.ip_address, path=localOnosFile ) |
| 712 | result = result and main.ONOSbench.scp( ctrl.server, |
| 713 | localOnosFile, |
| 714 | path, |
| 715 | direction="to" ) |
| 716 | return result |
| 717 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 718 | def startCLIs( self ): |
| 719 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 720 | Description: |
| 721 | starting Onos using onosCli driver |
| 722 | Required: |
| 723 | Returns: |
| 724 | Returns main.TRUE if it successfully started. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 725 | """ |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 726 | getFrom = "running" |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 727 | result = main.TRUE |
| 728 | cliResults = self.command( "startOnosCli", |
| 729 | args=[ "ipAddress" ], |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 730 | kwargs= { "karafTimeout": "karafTimeout" }, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 731 | specificDriver=2, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 732 | getFrom=getFrom, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 733 | funcFromCtrl=True ) |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 734 | ctrlList = self.fromNode( getFrom ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 735 | for i in range( len( cliResults ) ): |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 736 | result = result and cliResults[ i ] |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 737 | ctrlList[ i ].active = True |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 738 | return result |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 739 | |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 740 | def nodesCheck( self ): |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 741 | """ |
| 742 | Description: |
| 743 | Checking if all the onos nodes are in READY state |
| 744 | Required: |
| 745 | Returns: |
| 746 | Returns True if it successfully checked |
| 747 | """ |
Siddesh | 1349297 | 2021-03-12 21:09:32 +0000 | [diff] [blame] | 748 | import time |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 749 | results = True |
| 750 | nodesOutput = self.command( "nodes", specificDriver=2 ) |
Siddesh | 5275062 | 2021-03-05 19:52:03 +0000 | [diff] [blame] | 751 | if None in nodesOutput: |
Siddesh | 1349297 | 2021-03-12 21:09:32 +0000 | [diff] [blame] | 752 | time.sleep(60) |
| 753 | nodesOutput = self.command( "nodes", specificDriver=2 ) |
| 754 | main.log.debug(nodesOutput) |
| 755 | if None in nodesOutput: |
| 756 | return False |
Siddesh | 5275062 | 2021-03-05 19:52:03 +0000 | [diff] [blame] | 757 | try: |
| 758 | self.command( "getAddress", specificDriver=2 ) |
| 759 | except ( ValueError, TypeError ): |
| 760 | main.log.error( "Error parsing summary output" ) |
| 761 | currentResult = False |
| 762 | return currentResult |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 763 | ips = sorted( self.getIps( activeOnly=True ) ) |
| 764 | for i in nodesOutput: |
| 765 | try: |
| 766 | current = json.loads( i ) |
| 767 | activeIps = [] |
| 768 | currentResult = False |
| 769 | for node in current: |
| 770 | if node[ 'state' ] == 'READY': |
| 771 | activeIps.append( node[ 'ip' ] ) |
| 772 | activeIps.sort() |
| 773 | if ips == activeIps: |
| 774 | currentResult = True |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 775 | else: |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 776 | main.log.warn( "Expected {} != found {}".format( ips, activeIps ) ) |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 777 | except ( ValueError, TypeError ): |
| 778 | main.log.error( "Error parsing nodes output" ) |
| 779 | main.log.warn( repr( i ) ) |
| 780 | currentResult = False |
| 781 | results = results and currentResult |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 782 | # Check to make sure all bundles are started |
| 783 | bundleOutput = self.command( "sendline", args=[ "bundle:list" ] ) |
| 784 | for i in bundleOutput: |
| 785 | if "START LEVEL 100" in i: |
| 786 | currentResult = True |
| 787 | else: |
| 788 | currentResult = False |
| 789 | main.log.warn( "Node's bundles not fully started" ) |
| 790 | main.log.debug( i ) |
| 791 | results = results and currentResult |
Devin Lim | 3ebd5e7 | 2017-11-14 10:38:00 -0800 | [diff] [blame] | 792 | return results |
| 793 | |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 794 | def appsCheck( self, apps ): |
| 795 | """ |
| 796 | Description: |
| 797 | Checking if all the applications are activated |
| 798 | Required: |
| 799 | apps: list of applications that are expected to be activated |
| 800 | Returns: |
| 801 | Returns True if it successfully checked |
| 802 | """ |
| 803 | results = True |
| 804 | for app in apps: |
| 805 | states = self.command( "appStatus", |
| 806 | args=[ app ], |
| 807 | specificDriver=2 ) |
| 808 | for i in range( len( states ) ): |
| 809 | ctrl = self.controllers[ i ] |
| 810 | if states[ i ] == "ACTIVE": |
| 811 | results = results and True |
| 812 | main.log.info( "{}: {} is activated".format( ctrl.name, app ) ) |
| 813 | else: |
| 814 | results = False |
| 815 | main.log.warn( "{}: {} is in {} state".format( ctrl.name, app, states[ i ] ) ) |
| 816 | return results |
| 817 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 818 | def attachToONOSDocker( self ): |
| 819 | """ |
| 820 | Description: |
| 821 | connect to onos docker using onosCli driver |
| 822 | Required: |
| 823 | Returns: |
| 824 | Returns main.TRUE if it successfully started. |
| 825 | """ |
| 826 | getFrom = "running" |
| 827 | result = main.TRUE |
| 828 | execResults = self.command( "dockerExec", |
| 829 | args=[ "name" ], |
| 830 | kwargs={ "dockerPrompt": "dockerPrompt" }, |
| 831 | specificDriver=2, |
| 832 | getFrom=getFrom, |
| 833 | funcFromCtrl=True ) |
| 834 | ctrlList = self.fromNode( getFrom ) |
| 835 | for i in range( len( execResults ) ): |
| 836 | result = result and execResults[ i ] |
| 837 | ctrlList[ i ].active = True |
| 838 | return result |
| 839 | |
| 840 | def prepareForCLI( self ): |
| 841 | """ |
| 842 | Description: |
| 843 | prepare docker to connect to the onos cli |
| 844 | Required: |
| 845 | Returns: |
| 846 | Returns main.TRUE if it successfully started. |
| 847 | """ |
| 848 | getFrom = "running" |
| 849 | for ctrl in self.getRunningNodes(): |
| 850 | ctrl.CLI.inDocker = True |
| 851 | result = main.TRUE |
| 852 | execResults = self.command( "prepareForCLI", |
| 853 | specificDriver=2, |
| 854 | getFrom=getFrom, |
| 855 | funcFromCtrl=True ) |
| 856 | ctrlList = self.fromNode( getFrom ) |
| 857 | for i in range( len( execResults ) ): |
| 858 | result = result and execResults[ i ] |
| 859 | ctrlList[ i ].active = True |
| 860 | return result |
| 861 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 862 | def printResult( self, results, activeList, logLevel="debug" ): |
| 863 | """ |
| 864 | Description: |
| 865 | Print the value of the list. |
| 866 | Required: |
| 867 | * results - list of the result |
| 868 | * activeList - list of the acitve nodes. |
| 869 | * logLevel - Type of log level you want it to be printed. |
| 870 | Returns: |
| 871 | """ |
| 872 | f = getattr( main.log, logLevel ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 873 | for i in range( len( results ) ): |
| 874 | f( activeList[ i ].name + "'s result : " + str( results[ i ] ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 875 | |
| 876 | def allTrueResultCheck( self, results, activeList ): |
| 877 | """ |
| 878 | Description: |
| 879 | check if all the result has main.TRUE. |
| 880 | Required: |
| 881 | * results - list of the result |
| 882 | * activeList - list of the acitve nodes. |
| 883 | Returns: |
| 884 | Returns True if all == main.TRUE else |
| 885 | returns False |
| 886 | """ |
| 887 | self.printResult( results, activeList ) |
| 888 | return all( result == main.TRUE for result in results ) |
| 889 | |
| 890 | def notEmptyResultCheck( self, results, activeList ): |
| 891 | """ |
| 892 | Description: |
| 893 | check if all the result has any contents |
| 894 | Required: |
| 895 | * results - list of the result |
| 896 | * activeList - list of the acitve nodes. |
| 897 | Returns: |
| 898 | Returns True if all the results has |
| 899 | something else returns False |
| 900 | """ |
| 901 | self.printResult( results, activeList ) |
| 902 | return all( result for result in results ) |
| 903 | |
| 904 | def identicalResultsCheck( self, results, activeList ): |
| 905 | """ |
| 906 | Description: |
| 907 | check if all the results has same output. |
| 908 | Required: |
| 909 | * results - list of the result |
| 910 | * activeList - list of the acitve nodes. |
| 911 | Returns: |
| 912 | Returns True if all the results has |
| 913 | same result else returns False |
| 914 | """ |
| 915 | self.printResult( results, activeList ) |
| 916 | resultOne = results[ 0 ] |
| 917 | return all( resultOne == result for result in results ) |
| 918 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 919 | def command( self, function, args=(), kwargs={}, returnBool=False, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 920 | specificDriver=0, contentCheck=False, getFrom="active", |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 921 | funcFromCtrl=False ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 922 | """ |
| 923 | Description: |
| 924 | execute some function of the active nodes. |
| 925 | Required: |
| 926 | * function - name of the function |
| 927 | * args - argument of the function |
| 928 | * kwargs - kwargs of the funciton |
| 929 | * returnBool - True if wish to check all the result has main.TRUE |
| 930 | * specificDriver - specific driver to execute the function. Since |
| 931 | some of the function can be used in different drivers, it is important |
| 932 | to specify which driver it will be executed from. |
| 933 | 0 - any type of driver |
| 934 | 1 - from bench |
| 935 | 2 - from cli |
| 936 | 3 - from rest |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 937 | 4 - from server |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 938 | * contentCheck - If this is True, it will check if the result has some |
| 939 | contents. |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 940 | * getFrom - from which nodes |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 941 | 2 or "active" - active nodes |
| 942 | 1 or "running" - current running nodes |
| 943 | 0 or "all" - all nodes |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 944 | * funcFromCtrl - specific function of the args/kwargs |
| 945 | from each controller from the list of the controllers |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 946 | Returns: |
| 947 | Returns results if not returnBool and not contentCheck |
| 948 | Returns checkTruthValue of the result if returnBool |
| 949 | Returns resultContent of the result if contentCheck |
| 950 | """ |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 951 | threads = [] |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 952 | drivers = [ None, "Bench", "CLI", "REST", "server" ] |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 953 | results = [] |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 954 | for ctrl in self.fromNode( getFrom ): |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 955 | funcArgs = [] |
| 956 | funcKwargs = {} |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 957 | try: |
| 958 | f = getattr( ( ctrl if not specificDriver else |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 959 | getattr( ctrl, drivers[ specificDriver ] ) ), function ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 960 | except AttributeError: |
| 961 | main.log.error( "Function " + function + " not found. Exiting the Test." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 962 | main.cleanAndExit() |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 963 | if funcFromCtrl: |
| 964 | if args: |
| 965 | try: |
| 966 | for i in range( len( args ) ): |
| 967 | funcArgs.append( getattr( ctrl, args[ i ] ) ) |
| 968 | except AttributeError: |
| 969 | main.log.error( "Argument " + str( args[ i ] ) + " for " + str( f ) + " not found. Exiting the Test." ) |
| 970 | main.cleanAndExit() |
| 971 | if kwargs: |
| 972 | try: |
| 973 | for k in kwargs: |
| 974 | funcKwargs.update( { k: getattr( ctrl, kwargs[ k ] ) } ) |
| 975 | except AttributeError as e: |
| 976 | main.log.exception("") |
| 977 | main.log.error( "Keyword Argument " + str( k ) + " for " + str( f ) + " not found. Exiting the Test." ) |
| 978 | main.log.debug( "Passed kwargs: %s; dir(ctrl): %s" % ( repr( kwargs ), dir( ctrl ) ) ) |
| 979 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 980 | t = main.Thread( target=f, |
| 981 | name=function + "-" + ctrl.name, |
Devin Lim | 40a1909 | 2017-08-15 14:54:22 -0700 | [diff] [blame] | 982 | args=funcArgs if funcFromCtrl else args, |
| 983 | kwargs=funcKwargs if funcFromCtrl else kwargs ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 984 | threads.append( t ) |
| 985 | t.start() |
| 986 | |
| 987 | for t in threads: |
| 988 | t.join() |
| 989 | results.append( t.result ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 990 | if returnBool: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 991 | return self.allTrueResultCheck( results, self.fromNode( getFrom ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 992 | elif contentCheck: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 993 | return self.notEmptyResultCheck( results, self.fromNode( getFrom ) ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 994 | return results |
| 995 | |
| 996 | def checkPartitionSize( self, segmentSize='64', units='M', multiplier='3' ): |
| 997 | # max segment size in bytes: 1024 * 1024 * 64 |
| 998 | # multiplier is somewhat arbitrary, but the idea is the logs would have |
| 999 | # been compacted before this many segments are written |
| 1000 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1001 | try: |
| 1002 | maxSize = float( segmentSize ) * float( multiplier ) |
| 1003 | ret = True |
| 1004 | for n in self.runningNodes: |
| 1005 | # Partition logs |
| 1006 | ret = ret and n.server.folderSize( "/opt/atomix/data/raft/partitions/*/*.log", |
| 1007 | size=maxSize, unit=units, ignoreRoot=False ) |
| 1008 | return ret |
| 1009 | except Exception as e: |
| 1010 | main.log.error( e ) |
| 1011 | main.log.error( repr( e ) ) |