Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3 | Copyright 2017 Open Networking Foundation (ONF) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 8 | |
| 9 | TestON is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 12 | (at your option) any later version. |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 13 | |
| 14 | TestON is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | |
| 23 | This driver is used to interact with an ONOS cluster. It should |
| 24 | handle creating the necessary components to interact with each specific ONOS nodes. |
| 25 | |
| 26 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 27 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 28 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 29 | |
| 30 | """ |
| 31 | import pexpect |
| 32 | import os |
| 33 | from drivers.common.clidriver import CLI |
| 34 | |
| 35 | # FIXME: Move this to it's own file? |
| 36 | class Controller(): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 37 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 38 | def __str__( self ): |
| 39 | return self.name |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 40 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 41 | def __repr__( self ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 42 | # TODO use repr() for components? |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 43 | return "%s<IP=%s, CLI=%s, REST=%s, Bench=%s >" % ( self.name, |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 44 | self.ipAddress, |
| 45 | self.CLI, |
| 46 | self.REST, |
| 47 | self.Bench ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 48 | |
| 49 | def __getattr__( self, name ): |
| 50 | """ |
| 51 | Called when an attribute lookup has not found the attribute |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 52 | in the usual places (i.e. it is not an instance attribute nor |
| 53 | is it found in the class tree for self). name is the attribute |
| 54 | name. This method should return the (computed) attribute value |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 55 | or raise an AttributeError exception. |
| 56 | |
| 57 | We will look into each of the node's component handles to try to find the attreibute, looking at REST first |
| 58 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 59 | usedDriver = False |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 60 | if hasattr( self.REST, name ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 61 | if not usedDriver: |
| 62 | usedDriver = True |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 63 | main.log.debug("Using Rest driver's attribute for '%s'" % (name)) |
| 64 | f = getattr( self.REST, name) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 65 | if hasattr( self.CLI, name ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 66 | if not usedDriver: |
| 67 | usedDriver = True |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 68 | main.log.debug("Using CLI driver's attribute for '%s'" % (name)) |
| 69 | f = getattr( self.CLI, name) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 70 | if hasattr( self.Bench, name ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 71 | if not usedDriver: |
| 72 | usedDriver = True |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 73 | main.log.debug("Using Bench driver's attribute for '%s'" % (name)) |
| 74 | f = getattr( self.Bench, name) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 75 | if usedDriver: |
| 76 | return f |
| 77 | raise AttributeError( "Could not find the attribute %s in %r or it's component handles" % ( name, self ) ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 78 | |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 79 | def __init__( self, name, ipAddress, CLI=None, REST=None, Bench=None, pos=None, userName=None, server=None ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 80 | # TODO: validate these arguments |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 81 | self.name = str( name ) |
| 82 | self.ipAddress = ipAddress |
| 83 | self.CLI = CLI |
| 84 | self.REST = REST |
| 85 | self.Bench = Bench |
| 86 | self.active = False |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 87 | self.pos = pos |
| 88 | self.ip_address = ipAddress |
| 89 | self.user_name = userName |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 90 | self.server = server |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 91 | |
| 92 | class OnosClusterDriver( CLI ): |
| 93 | |
| 94 | def __init__( self ): |
| 95 | """ |
| 96 | Initialize client |
| 97 | """ |
| 98 | self.name = None |
| 99 | self.home = None |
| 100 | self.handle = None |
| 101 | self.nodes = [] |
| 102 | super( OnosClusterDriver, self ).__init__() |
| 103 | |
| 104 | def checkOptions( self, var, defaultVar ): |
| 105 | if var is None or var == "": |
| 106 | return defaultVar |
| 107 | return var |
| 108 | |
| 109 | def connect( self, **connectargs ): |
| 110 | """ |
| 111 | Creates ssh handle for ONOS "bench". |
| 112 | NOTE: |
| 113 | The ip_address would come from the topo file using the host tag, the |
| 114 | value can be an environment variable as well as a "localhost" to get |
| 115 | the ip address needed to ssh to the "bench" |
| 116 | """ |
| 117 | try: |
| 118 | for key in connectargs: |
| 119 | vars( self )[ key ] = connectargs[ key ] |
| 120 | self.home = "~/onos" |
| 121 | for key in self.options: |
| 122 | if key == "home": |
| 123 | self.home = self.options[ 'home' ] |
| 124 | elif key == "karaf_username": |
| 125 | self.karafUser = self.options[ key ] |
| 126 | elif key == "karaf_password": |
| 127 | self.karafPass = self.options[ key ] |
| 128 | elif key == "cluster_name": |
| 129 | prefix = self.options[ key ] |
| 130 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 131 | self.home = self.checkOptions(self.home, "~/onos" ) |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 132 | self.karafUser = self.checkOptions(self.karafUser, self.user_name) |
| 133 | self.karafPass = self.checkOptions(self.karafPass, self.pwd ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 134 | prefix = self.checkOptions( prefix, "ONOS" ) |
| 135 | |
| 136 | self.name = self.options[ 'name' ] |
| 137 | |
| 138 | # The 'nodes' tag is optional and it is not required in .topo file |
| 139 | for key in self.options: |
| 140 | if key == "nodes": |
| 141 | # Maximum number of ONOS nodes to run, if there is any |
| 142 | self.maxNodes = int( self.options[ 'nodes' ] ) |
| 143 | break |
| 144 | self.maxNodes = None |
| 145 | |
| 146 | if self.maxNodes is None or self.maxNodes == "": |
| 147 | self.maxNodes = 100 |
| 148 | |
| 149 | # Grabs all OC environment variables based on max number of nodes |
| 150 | # TODO: Also support giving an ip range as a compononet option |
| 151 | self.onosIps = {} # Dictionary of all possible ONOS ip |
| 152 | |
| 153 | try: |
| 154 | if self.maxNodes: |
| 155 | for i in range( self.maxNodes ): |
| 156 | envString = "OC" + str( i + 1 ) |
| 157 | # If there is no more OC# then break the loop |
| 158 | if os.getenv( envString ): |
| 159 | self.onosIps[ envString ] = os.getenv( envString ) |
| 160 | else: |
| 161 | self.maxNodes = len( self.onosIps ) |
| 162 | main.log.info( self.name + |
| 163 | ": Created cluster data with " + |
| 164 | str( self.maxNodes ) + |
| 165 | " maximum number" + |
| 166 | " of nodes" ) |
| 167 | break |
| 168 | |
| 169 | if not self.onosIps: |
| 170 | main.log.info( "Could not read any environment variable" |
| 171 | + " please load a cell file with all" + |
| 172 | " onos IP" ) |
| 173 | self.maxNodes = None |
| 174 | else: |
| 175 | main.log.info( self.name + ": Found " + |
| 176 | str( self.onosIps.values() ) + |
| 177 | " ONOS IPs" ) |
| 178 | except KeyError: |
| 179 | main.log.info( "Invalid environment variable" ) |
| 180 | except Exception as inst: |
| 181 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 182 | |
| 183 | try: |
| 184 | if os.getenv( str( self.ip_address ) ) is not None: |
| 185 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 186 | else: |
| 187 | main.log.info( self.name + |
| 188 | ": Trying to connect to " + |
| 189 | self.ip_address ) |
| 190 | except KeyError: |
| 191 | main.log.info( "Invalid host name," + |
| 192 | " connecting to local host instead" ) |
| 193 | self.ip_address = 'localhost' |
| 194 | except Exception as inst: |
| 195 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 196 | |
| 197 | self.handle = super( OnosClusterDriver, self ).connect( |
| 198 | user_name=self.user_name, |
| 199 | ip_address=self.ip_address, |
| 200 | port=self.port, |
| 201 | pwd=self.pwd, |
| 202 | home=self.home ) |
| 203 | |
| 204 | if self.handle: |
| 205 | self.handle.sendline( "cd " + self.home ) |
| 206 | self.handle.expect( "\$" ) |
| 207 | self.createComponents( prefix=prefix ) |
| 208 | return self.handle |
| 209 | else: |
| 210 | main.log.info( "Failed to create ONOS handle" ) |
| 211 | return main.FALSE |
| 212 | except pexpect.EOF: |
| 213 | main.log.error( self.name + ": EOF exception found" ) |
| 214 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 215 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 216 | except Exception: |
| 217 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 218 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 219 | |
| 220 | def disconnect( self ): |
| 221 | """ |
| 222 | Called when Test is complete to disconnect the ONOS handle. |
| 223 | """ |
| 224 | response = main.TRUE |
| 225 | try: |
| 226 | if self.handle: |
| 227 | self.handle.sendline( "" ) |
| 228 | self.handle.expect( "\$" ) |
| 229 | self.handle.sendline( "exit" ) |
| 230 | self.handle.expect( "closed" ) |
| 231 | except pexpect.EOF: |
| 232 | main.log.error( self.name + ": EOF exception found" ) |
| 233 | main.log.error( self.name + ": " + self.handle.before ) |
| 234 | except ValueError: |
| 235 | main.log.exception( "Exception in disconnect of " + self.name ) |
| 236 | response = main.TRUE |
| 237 | except Exception: |
| 238 | main.log.exception( self.name + ": Connection failed to the host" ) |
| 239 | response = main.FALSE |
| 240 | return response |
| 241 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 242 | def setCliOptions( self, name, host ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 243 | """ |
| 244 | Parse the cluster options to create an ONOS cli component with the given name |
| 245 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 246 | main.componentDictionary[name] = main.componentDictionary[self.name].copy() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 247 | clihost = main.componentDictionary[ name ][ 'COMPONENTS' ].get( "diff_clihost", "" ) |
| 248 | if clihost == "True": |
| 249 | main.componentDictionary[ name ][ 'host' ] = host |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 250 | main.componentDictionary[name]['type'] = "OnosCliDriver" |
| 251 | main.componentDictionary[name]['connect_order'] = str( int( main.componentDictionary[name]['connect_order'] ) + 1 ) |
| 252 | main.log.debug( main.componentDictionary[name] ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 253 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 254 | def createCliComponent( self, name, host ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 255 | """ |
| 256 | Creates a new onos cli component. |
| 257 | |
| 258 | Arguments: |
| 259 | name - The string of the name of this component. The new component |
| 260 | will be assigned to main.<name> . |
| 261 | In addition, main.<name>.name = str( name ) |
| 262 | """ |
| 263 | try: |
| 264 | # look to see if this component already exists |
| 265 | getattr( main, name ) |
| 266 | except AttributeError: |
| 267 | # namespace is clear, creating component |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 268 | self.setCliOptions( name, host ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 269 | return main.componentInit( name ) |
| 270 | except pexpect.EOF: |
| 271 | main.log.error( self.name + ": EOF exception found" ) |
| 272 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 273 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 274 | except Exception: |
| 275 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 276 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 277 | else: |
| 278 | # namespace is not clear! |
| 279 | main.log.error( name + " component already exists!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 280 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 281 | |
| 282 | def setRestOptions( self, name, host ): |
| 283 | """ |
| 284 | Parse the cluster options to create an ONOS cli component with the given name |
| 285 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 286 | main.componentDictionary[name] = main.componentDictionary[self.name].copy() |
| 287 | main.log.debug( main.componentDictionary[name] ) |
| 288 | user = main.componentDictionary[name]['COMPONENTS'].get( "web_user", "onos" ) |
| 289 | main.componentDictionary[name]['user'] = self.checkOptions( user, "onos" ) |
| 290 | password = main.componentDictionary[name]['COMPONENTS'].get( "web_pass", "rocks" ) |
| 291 | main.componentDictionary[name]['pass'] = self.checkOptions( password, "rocks" ) |
| 292 | main.componentDictionary[name]['host'] = host |
| 293 | port = main.componentDictionary[name]['COMPONENTS'].get( "rest_port", "8181" ) |
| 294 | main.componentDictionary[name]['port'] = self.checkOptions( port, "8181" ) |
| 295 | main.componentDictionary[name]['type'] = "OnosRestDriver" |
| 296 | main.componentDictionary[name]['connect_order'] = str( int( main.componentDictionary[name]['connect_order'] ) + 1 ) |
| 297 | main.log.debug( main.componentDictionary[name] ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 298 | |
| 299 | def createRestComponent( self, name, ipAddress ): |
| 300 | """ |
| 301 | Creates a new onos rest component. |
| 302 | |
| 303 | Arguments: |
| 304 | name - The string of the name of this component. The new component |
| 305 | will be assigned to main.<name> . |
| 306 | In addition, main.<name>.name = str( name ) |
| 307 | """ |
| 308 | try: |
| 309 | # look to see if this component already exists |
| 310 | getattr( main, name ) |
| 311 | except AttributeError: |
| 312 | # namespace is clear, creating component |
| 313 | self.setRestOptions( name, ipAddress ) |
| 314 | return main.componentInit( name ) |
| 315 | except pexpect.EOF: |
| 316 | main.log.error( self.name + ": EOF exception found" ) |
| 317 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 318 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 319 | except Exception: |
| 320 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 321 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 322 | else: |
| 323 | # namespace is not clear! |
| 324 | main.log.error( name + " component already exists!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 325 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 326 | |
| 327 | def setBenchOptions( self, name ): |
| 328 | """ |
| 329 | Parse the cluster options to create an ONOS "bench" component with the given name |
| 330 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 331 | main.componentDictionary[name] = main.componentDictionary[self.name].copy() |
| 332 | main.componentDictionary[name]['type'] = "OnosDriver" |
| 333 | home = main.componentDictionary[name]['COMPONENTS'].get( "onos_home", None ) |
| 334 | main.componentDictionary[name]['home'] = self.checkOptions( home, None ) |
| 335 | main.componentDictionary[name]['connect_order'] = str( int( main.componentDictionary[name]['connect_order'] ) + 1 ) |
| 336 | main.log.debug( main.componentDictionary[name] ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 337 | |
| 338 | def createBenchComponent( self, name ): |
| 339 | """ |
| 340 | Creates a new onos "bench" component. |
| 341 | |
| 342 | Arguments: |
| 343 | name - The string of the name of this component. The new component |
| 344 | will be assigned to main.<name> . |
| 345 | In addition, main.<name>.name = str( name ) |
| 346 | """ |
| 347 | try: |
| 348 | # look to see if this component already exists |
| 349 | getattr( main, name ) |
| 350 | except AttributeError: |
| 351 | # namespace is clear, creating component |
| 352 | self.setBenchOptions( name ) |
| 353 | return main.componentInit( name ) |
| 354 | except pexpect.EOF: |
| 355 | main.log.error( self.name + ": EOF exception found" ) |
| 356 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 357 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 358 | except Exception: |
| 359 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 360 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 361 | else: |
| 362 | # namespace is not clear! |
| 363 | main.log.error( name + " component already exists!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 364 | main.cleanAndExit() |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 365 | |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 366 | def setServerOptions( self, name, ipAddress ): |
| 367 | """ |
| 368 | Parse the cluster options to create an ONOS "server" component with the given name |
| 369 | |
| 370 | Arguments: |
| 371 | name - The name of the server componet |
| 372 | ipAddress - The ip address of the server |
| 373 | """ |
| 374 | main.componentDictionary[name] = main.componentDictionary[self.name].copy() |
| 375 | main.componentDictionary[name]['type'] = "OnosDriver" |
| 376 | main.componentDictionary[name]['host'] = ipAddress |
| 377 | home = main.componentDictionary[name]['COMPONENTS'].get( "onos_home", None ) |
| 378 | main.componentDictionary[name]['home'] = self.checkOptions( home, None ) |
| 379 | main.componentDictionary[name]['connect_order'] = str( int( main.componentDictionary[name]['connect_order'] ) + 1 ) |
| 380 | main.log.debug( main.componentDictionary[name] ) |
| 381 | |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 382 | def createServerComponent( self, name, ipAddress ): |
| 383 | """ |
| 384 | Creates a new onos "server" component. This will be connected to the |
| 385 | node ONOS is running on. |
| 386 | |
| 387 | Arguments: |
| 388 | name - The string of the name of this component. The new component |
| 389 | will be assigned to main.<name> . |
| 390 | In addition, main.<name>.name = str( name ) |
| 391 | ipAddress - The ip address of the server |
| 392 | """ |
| 393 | try: |
| 394 | # look to see if this component already exists |
| 395 | getattr( main, name ) |
| 396 | except AttributeError: |
| 397 | # namespace is clear, creating component |
| 398 | self.setServerOptions( name, ipAddress ) |
| 399 | return main.componentInit( name ) |
| 400 | except pexpect.EOF: |
| 401 | main.log.error( self.name + ": EOF exception found" ) |
| 402 | main.log.error( self.name + ": " + self.handle.before ) |
| 403 | main.cleanAndExit() |
| 404 | except Exception: |
| 405 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 406 | main.cleanAndExit() |
| 407 | else: |
| 408 | # namespace is not clear! |
| 409 | main.log.error( name + " component already exists!" ) |
| 410 | main.cleanAndExit() |
| 411 | |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 412 | def createComponents( self, prefix='', createServer=True ): |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 413 | """ |
| 414 | Creates a CLI and REST component for each nodes in the cluster |
| 415 | """ |
| 416 | # TODO: This needs work to support starting two seperate clusters in one test |
| 417 | cliPrefix = prefix + "cli" |
| 418 | restPrefix = prefix + "rest" |
| 419 | benchPrefix = prefix + "bench" |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 420 | serverPrefix = prefix + "server" |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 421 | for i in xrange( 1, self.maxNodes + 1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 422 | cliName = cliPrefix + str( i ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 423 | restName = restPrefix + str( i ) |
| 424 | benchName = benchPrefix + str( i ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 425 | serverName = serverPrefix + str( i ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 426 | |
| 427 | # Unfortunately this means we need to have a cell set beofre running TestON, |
| 428 | # Even if it is just the entire possible cluster size |
| 429 | ip = self.onosIps[ 'OC' + str( i ) ] |
| 430 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 431 | cli = self.createCliComponent( cliName, ip ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 432 | rest = self.createRestComponent( restName, ip ) |
| 433 | bench = self.createBenchComponent( benchName ) |
Jon Hall | 4173b24 | 2017-09-12 17:04:38 -0700 | [diff] [blame] | 434 | server = self.createServerComponent( serverName, ip ) if createServer else None |
| 435 | self.nodes.append( Controller( prefix + str( i ), ip, cli, rest, bench, i - 1, self.user_name, server=server ) ) |