Committed by
Gerrit Code Review
Various minor fixes and improvements
- enable parameters for onos cli commands (e.g. onos:apps -a) - don't depend on onos1's name - reduce dependencies on unnecessary variables - enable running if karaf isn't installed elsewhere - make NAT an option Change-Id: I3e8abd51aa8d3f5c7afab1c6b86e50707de20ef6
Showing
1 changed file
with
28 additions
and
16 deletions
... | @@ -74,7 +74,7 @@ def defaultUser(): | ... | @@ -74,7 +74,7 @@ def defaultUser(): |
74 | return user | 74 | return user |
75 | 75 | ||
76 | # Module vars, initialized below | 76 | # Module vars, initialized below |
77 | -HOME = ONOS_ROOT = KARAF_ROOT = ONOS_HOME = ONOS_USER = None | 77 | +HOME = ONOS_ROOT = ONOS_USER = None |
78 | ONOS_APPS = ONOS_WEB_USER = ONOS_WEB_PASS = ONOS_TAR = None | 78 | ONOS_APPS = ONOS_WEB_USER = ONOS_WEB_PASS = ONOS_TAR = None |
79 | 79 | ||
80 | def initONOSEnv(): | 80 | def initONOSEnv(): |
... | @@ -84,20 +84,16 @@ def initONOSEnv(): | ... | @@ -84,20 +84,16 @@ def initONOSEnv(): |
84 | nodes: list of ONOS nodes | 84 | nodes: list of ONOS nodes |
85 | returns: ONOS environment variable dict""" | 85 | returns: ONOS environment variable dict""" |
86 | # pylint: disable=global-statement | 86 | # pylint: disable=global-statement |
87 | - global HOME, ONOS_ROOT, KARAF_ROOT, ONOS_HOME, ONOS_USER | 87 | + global HOME, ONOS_ROOT, ONOS_USER |
88 | global ONOS_APPS, ONOS_WEB_USER, ONOS_WEB_PASS | 88 | global ONOS_APPS, ONOS_WEB_USER, ONOS_WEB_PASS |
89 | env = {} | 89 | env = {} |
90 | def sd( var, val ): | 90 | def sd( var, val ): |
91 | "Set default value for environment variable" | 91 | "Set default value for environment variable" |
92 | env[ var ] = environ.setdefault( var, val ) | 92 | env[ var ] = environ.setdefault( var, val ) |
93 | return env[ var ] | 93 | return env[ var ] |
94 | + assert environ[ 'HOME' ] | ||
94 | HOME = sd( 'HOME', environ[ 'HOME' ] ) | 95 | HOME = sd( 'HOME', environ[ 'HOME' ] ) |
95 | - assert HOME | ||
96 | ONOS_ROOT = sd( 'ONOS_ROOT', join( HOME, 'onos' ) ) | 96 | ONOS_ROOT = sd( 'ONOS_ROOT', join( HOME, 'onos' ) ) |
97 | - KARAF_ROOT = sd( 'KARAF_ROOT', | ||
98 | - glob( join( HOME, | ||
99 | - 'Applications/apache-karaf-*' ) )[ -1 ] ) | ||
100 | - ONOS_HOME = sd( 'ONOS_HOME', dirname( KARAF_ROOT ) ) | ||
101 | environ[ 'ONOS_USER' ] = defaultUser() | 97 | environ[ 'ONOS_USER' ] = defaultUser() |
102 | ONOS_USER = sd( 'ONOS_USER', defaultUser() ) | 98 | ONOS_USER = sd( 'ONOS_USER', defaultUser() ) |
103 | ONOS_APPS = sd( 'ONOS_APPS', | 99 | ONOS_APPS = sd( 'ONOS_APPS', |
... | @@ -194,14 +190,11 @@ def RenamedTopo( topo, *args, **kwargs ): | ... | @@ -194,14 +190,11 @@ def RenamedTopo( topo, *args, **kwargs ): |
194 | class ONOSNode( Controller ): | 190 | class ONOSNode( Controller ): |
195 | "ONOS cluster node" | 191 | "ONOS cluster node" |
196 | 192 | ||
197 | - # Default karaf client location | ||
198 | - client = '/tmp/onos1/karaf/bin/client' | ||
199 | - | ||
200 | def __init__( self, name, **kwargs ): | 193 | def __init__( self, name, **kwargs ): |
201 | kwargs.update( inNamespace=True ) | 194 | kwargs.update( inNamespace=True ) |
202 | Controller.__init__( self, name, **kwargs ) | 195 | Controller.__init__( self, name, **kwargs ) |
203 | self.dir = '/tmp/%s' % self.name | 196 | self.dir = '/tmp/%s' % self.name |
204 | - # Satisfy pylint | 197 | + self.client = self.dir + '/karaf/bin/client' |
205 | self.ONOS_HOME = '/tmp' | 198 | self.ONOS_HOME = '/tmp' |
206 | 199 | ||
207 | # pylint: disable=arguments-differ | 200 | # pylint: disable=arguments-differ |
... | @@ -224,6 +217,7 @@ class ONOSNode( Controller ): | ... | @@ -224,6 +217,7 @@ class ONOSNode( Controller ): |
224 | service = join( self.ONOS_HOME, 'bin/onos-service' ) | 217 | service = join( self.ONOS_HOME, 'bin/onos-service' ) |
225 | self.ucmd( service, 'server 1>../onos.log 2>../onos.log' | 218 | self.ucmd( service, 'server 1>../onos.log 2>../onos.log' |
226 | ' & echo $! > onos.pid; ln -s `pwd`/onos.pid ..' ) | 219 | ' & echo $! > onos.pid; ln -s `pwd`/onos.pid ..' ) |
220 | + self.onosPid = int( self.cmd( 'cat onos.pid' ).strip() ) | ||
227 | 221 | ||
228 | # pylint: enable=arguments-differ | 222 | # pylint: enable=arguments-differ |
229 | 223 | ||
... | @@ -232,6 +226,16 @@ class ONOSNode( Controller ): | ... | @@ -232,6 +226,16 @@ class ONOSNode( Controller ): |
232 | self.cmd( 'pkill -HUP -f karaf.jar && wait' ) | 226 | self.cmd( 'pkill -HUP -f karaf.jar && wait' ) |
233 | self.cmd( 'rm -rf', self.dir ) | 227 | self.cmd( 'rm -rf', self.dir ) |
234 | 228 | ||
229 | + def isRunning( self ): | ||
230 | + "Is our ONOS process still running?" | ||
231 | + cmd = 'ps -p %d >/dev/null 2>&1 && echo "running" || echo "not running"' | ||
232 | + return self.cmd( cmd % self.onosPid ) == 'running' | ||
233 | + | ||
234 | + def sanityCheck( self ): | ||
235 | + "Check whether we've quit or are running out of memory" | ||
236 | + if not self.isRunning(): | ||
237 | + raise Exception( 'ONOS node %s has died' % self.name ) | ||
238 | + | ||
235 | def waitStarted( self ): | 239 | def waitStarted( self ): |
236 | "Wait until we've really started" | 240 | "Wait until we've really started" |
237 | info( '(checking: karaf' ) | 241 | info( '(checking: karaf' ) |
... | @@ -281,6 +285,7 @@ class ONOSCluster( Controller ): | ... | @@ -281,6 +285,7 @@ class ONOSCluster( Controller ): |
281 | args = list( args ) | 285 | args = list( args ) |
282 | name = args.pop( 0 ) | 286 | name = args.pop( 0 ) |
283 | topo = kwargs.pop( 'topo', None ) | 287 | topo = kwargs.pop( 'topo', None ) |
288 | + nat = kwargs.pop( 'nat', 'nat0' ) | ||
284 | # Default: single switch with 1 ONOS node | 289 | # Default: single switch with 1 ONOS node |
285 | if not topo: | 290 | if not topo: |
286 | topo = SingleSwitchTopo | 291 | topo = SingleSwitchTopo |
... | @@ -297,13 +302,13 @@ class ONOSCluster( Controller ): | ... | @@ -297,13 +302,13 @@ class ONOSCluster( Controller ): |
297 | self.net = Mininet( topo=topo, ipBase=self.ipBase, | 302 | self.net = Mininet( topo=topo, ipBase=self.ipBase, |
298 | host=ONOSNode, switch=LinuxBridge, | 303 | host=ONOSNode, switch=LinuxBridge, |
299 | controller=None ) | 304 | controller=None ) |
300 | - self.net.addNAT().configDefault() | 305 | + if nat: |
306 | + self.net.addNAT( nat ).configDefault() | ||
301 | updateNodeIPs( self.env, self.nodes() ) | 307 | updateNodeIPs( self.env, self.nodes() ) |
302 | self._remoteControllers = [] | 308 | self._remoteControllers = [] |
303 | 309 | ||
304 | def start( self ): | 310 | def start( self ): |
305 | "Start up ONOS cluster" | 311 | "Start up ONOS cluster" |
306 | - killprocs( 'karaf.jar' ) | ||
307 | info( '*** ONOS_APPS = %s\n' % ONOS_APPS ) | 312 | info( '*** ONOS_APPS = %s\n' % ONOS_APPS ) |
308 | self.net.start() | 313 | self.net.start() |
309 | for node in self.nodes(): | 314 | for node in self.nodes(): |
... | @@ -402,6 +407,10 @@ class ONOSCLI( OldCLI ): | ... | @@ -402,6 +407,10 @@ class ONOSCLI( OldCLI ): |
402 | net = MininetFacade( net, cnet=c0.net ) | 407 | net = MininetFacade( net, cnet=c0.net ) |
403 | OldCLI.__init__( self, net, **kwargs ) | 408 | OldCLI.__init__( self, net, **kwargs ) |
404 | 409 | ||
410 | + def onos1( self ): | ||
411 | + "Helper function: return default ONOS node" | ||
412 | + return self.mn.controllers[ 0 ].net.hosts[ 0 ] | ||
413 | + | ||
405 | def do_onos( self, line ): | 414 | def do_onos( self, line ): |
406 | "Send command to ONOS CLI" | 415 | "Send command to ONOS CLI" |
407 | c0 = self.mn.controllers[ 0 ] | 416 | c0 = self.mn.controllers[ 0 ] |
... | @@ -409,7 +418,10 @@ class ONOSCLI( OldCLI ): | ... | @@ -409,7 +418,10 @@ class ONOSCLI( OldCLI ): |
409 | # cmdLoop strips off command name 'onos' | 418 | # cmdLoop strips off command name 'onos' |
410 | if line.startswith( ':' ): | 419 | if line.startswith( ':' ): |
411 | line = 'onos' + line | 420 | line = 'onos' + line |
412 | - cmd = 'onos1 client -h onos1 ' + line | 421 | + onos1 = self.onos1().name |
422 | + if line: | ||
423 | + line = '"%s"' % line | ||
424 | + cmd = '%s client -h %s %s' % ( onos1, onos1, line ) | ||
413 | quietRun( 'stty -echo' ) | 425 | quietRun( 'stty -echo' ) |
414 | self.default( cmd ) | 426 | self.default( cmd ) |
415 | quietRun( 'stty echo' ) | 427 | quietRun( 'stty echo' ) |
... | @@ -423,8 +435,8 @@ class ONOSCLI( OldCLI ): | ... | @@ -423,8 +435,8 @@ class ONOSCLI( OldCLI ): |
423 | self.do_onos( ':balance-masters' ) | 435 | self.do_onos( ':balance-masters' ) |
424 | 436 | ||
425 | def do_log( self, line ): | 437 | def do_log( self, line ): |
426 | - "Run tail -f /tmp/onos1/log on onos1; press control-C to stop" | 438 | + "Run tail -f /tmp/onos1/log; press control-C to stop" |
427 | - self.default( 'onos1 tail -f /tmp/onos1/log' ) | 439 | + self.default( self.onos1().name, 'tail -f /tmp/%s/log' % self.onos1() ) |
428 | 440 | ||
429 | 441 | ||
430 | ### Exports for bin/mn | 442 | ### Exports for bin/mn | ... | ... |
-
Please register or login to post a comment