Run onos as ONOS_USER rather than root (!)
Change-Id: Ibe87b89a71d12665eb932b40a843c691c4cfa584
Showing
1 changed file
with
22 additions
and
13 deletions
... | @@ -46,7 +46,7 @@ from mininet.net import Mininet | ... | @@ -46,7 +46,7 @@ from mininet.net import Mininet |
46 | from mininet.topo import SingleSwitchTopo, Topo | 46 | from mininet.topo import SingleSwitchTopo, Topo |
47 | from mininet.log import setLogLevel, info | 47 | from mininet.log import setLogLevel, info |
48 | from mininet.cli import CLI | 48 | from mininet.cli import CLI |
49 | -from mininet.util import quietRun, errRun, waitListening | 49 | +from mininet.util import quietRun, waitListening |
50 | from mininet.clean import killprocs | 50 | from mininet.clean import killprocs |
51 | from mininet.examples.controlnet import MininetFacade | 51 | from mininet.examples.controlnet import MininetFacade |
52 | 52 | ||
... | @@ -129,7 +129,7 @@ def updateNodeIPs( env, nodes ): | ... | @@ -129,7 +129,7 @@ def updateNodeIPs( env, nodes ): |
129 | 129 | ||
130 | tarDefaultPath = 'buck-out/gen/tools/package/onos-package/onos.tar.gz' | 130 | tarDefaultPath = 'buck-out/gen/tools/package/onos-package/onos.tar.gz' |
131 | 131 | ||
132 | -def unpackONOS( destDir='/tmp' ): | 132 | +def unpackONOS( destDir='/tmp', run=quietRun ): |
133 | "Unpack ONOS and return its location" | 133 | "Unpack ONOS and return its location" |
134 | global ONOS_TAR | 134 | global ONOS_TAR |
135 | environ.setdefault( 'ONOS_TAR', join( ONOS_ROOT, tarDefaultPath ) ) | 135 | environ.setdefault( 'ONOS_TAR', join( ONOS_ROOT, tarDefaultPath ) ) |
... | @@ -139,14 +139,16 @@ def unpackONOS( destDir='/tmp' ): | ... | @@ -139,14 +139,16 @@ def unpackONOS( destDir='/tmp' ): |
139 | raise Exception( 'Missing ONOS tarball %s - run buck build onos?' | 139 | raise Exception( 'Missing ONOS tarball %s - run buck build onos?' |
140 | % tarPath ) | 140 | % tarPath ) |
141 | info( '(unpacking %s)' % destDir) | 141 | info( '(unpacking %s)' % destDir) |
142 | - cmds = ( 'mkdir -p "%s" && cd "%s" && tar xvzf "%s"' | 142 | + cmds = ( 'mkdir -p "%s" && cd "%s" && tar xzf "%s"' |
143 | % ( destDir, destDir, tarPath) ) | 143 | % ( destDir, destDir, tarPath) ) |
144 | - out, _err, _code = errRun( cmds, shell=True, verbose=True ) | 144 | + run( cmds, shell=True, verbose=True ) |
145 | - first = out.split( '\n' )[ 0 ] | 145 | + # We can use quietRun for this usually |
146 | - assert '/' in first | 146 | + tarOutput = quietRun( 'tar tzf "%s" | head -1' % tarPath, shell=True) |
147 | - onosDir = join( destDir, dirname( first ) ) | 147 | + tarOutput = tarOutput.split()[ 0 ].strip() |
148 | + assert '/' in tarOutput | ||
149 | + onosDir = join( destDir, dirname( tarOutput ) ) | ||
148 | # Add symlink to log file | 150 | # Add symlink to log file |
149 | - quietRun( 'cd %s; ln -s onos*/apache* karaf;' | 151 | + run( 'cd %s; ln -s onos*/apache* karaf;' |
150 | 'ln -s karaf/data/log/karaf.log log' % destDir, | 152 | 'ln -s karaf/data/log/karaf.log log' % destDir, |
151 | shell=True ) | 153 | shell=True ) |
152 | return onosDir | 154 | return onosDir |
... | @@ -209,19 +211,19 @@ class ONOSNode( Controller ): | ... | @@ -209,19 +211,19 @@ class ONOSNode( Controller ): |
209 | env: environment var dict""" | 211 | env: environment var dict""" |
210 | env = dict( env ) | 212 | env = dict( env ) |
211 | self.cmd( 'rm -rf', self.dir ) | 213 | self.cmd( 'rm -rf', self.dir ) |
212 | - self.ONOS_HOME = unpackONOS( self.dir ) | 214 | + self.ONOS_HOME = unpackONOS( self.dir, run=self.ucmd ) |
213 | env.update( ONOS_HOME=self.ONOS_HOME ) | 215 | env.update( ONOS_HOME=self.ONOS_HOME ) |
214 | self.updateEnv( env ) | 216 | self.updateEnv( env ) |
215 | karafbin = glob( '%s/apache*/bin' % self.ONOS_HOME )[ 0 ] | 217 | karafbin = glob( '%s/apache*/bin' % self.ONOS_HOME )[ 0 ] |
216 | onosbin = join( ONOS_ROOT, 'tools/test/bin' ) | 218 | onosbin = join( ONOS_ROOT, 'tools/test/bin' ) |
217 | self.cmd( 'export PATH=%s:%s:$PATH' % ( onosbin, karafbin ) ) | 219 | self.cmd( 'export PATH=%s:%s:$PATH' % ( onosbin, karafbin ) ) |
218 | self.cmd( 'cd', self.ONOS_HOME ) | 220 | self.cmd( 'cd', self.ONOS_HOME ) |
219 | - self.cmd( 'mkdir -p config && ' | 221 | + self.ucmd( 'mkdir -p config && ' |
220 | 'onos-gen-partitions config/cluster.json' ) | 222 | 'onos-gen-partitions config/cluster.json' ) |
221 | info( '(starting %s)' % self ) | 223 | info( '(starting %s)' % self ) |
222 | service = join( self.ONOS_HOME, 'bin/onos-service' ) | 224 | service = join( self.ONOS_HOME, 'bin/onos-service' ) |
223 | - self.cmd( service, 'server 1>../onos.log 2>../onos.log &' ) | 225 | + self.ucmd( service, 'server 1>../onos.log 2>../onos.log' |
224 | - self.cmd( 'echo $! > onos.pid' ) | 226 | + ' & echo $! > onos.pid; ln -s `pwd`/onos.pid ..' ) |
225 | 227 | ||
226 | # pylint: enable=arguments-differ | 228 | # pylint: enable=arguments-differ |
227 | 229 | ||
... | @@ -234,7 +236,7 @@ class ONOSNode( Controller ): | ... | @@ -234,7 +236,7 @@ class ONOSNode( Controller ): |
234 | "Wait until we've really started" | 236 | "Wait until we've really started" |
235 | info( '(checking: karaf' ) | 237 | info( '(checking: karaf' ) |
236 | while True: | 238 | while True: |
237 | - status = self.cmd( 'karaf status' ).lower() | 239 | + status = self.ucmd( 'karaf status' ).lower() |
238 | if 'running' in status and 'not running' not in status: | 240 | if 'running' in status and 'not running' not in status: |
239 | break | 241 | break |
240 | info( '.' ) | 242 | info( '.' ) |
... | @@ -259,6 +261,13 @@ class ONOSNode( Controller ): | ... | @@ -259,6 +261,13 @@ class ONOSNode( Controller ): |
259 | for var, val in envDict.iteritems() ) | 261 | for var, val in envDict.iteritems() ) |
260 | self.cmd( cmd ) | 262 | self.cmd( cmd ) |
261 | 263 | ||
264 | + def ucmd( self, *args, **_kwargs ): | ||
265 | + "Run command as $ONOS_USER using sudo -E -u" | ||
266 | + if ONOS_USER != 'root': # don't bother with sudo | ||
267 | + args = [ "sudo -E -u $ONOS_USER PATH=$PATH " | ||
268 | + "bash -c '%s'" % ' '.join( args ) ] | ||
269 | + return self.cmd( *args ) | ||
270 | + | ||
262 | 271 | ||
263 | class ONOSCluster( Controller ): | 272 | class ONOSCluster( Controller ): |
264 | "ONOS Cluster" | 273 | "ONOS Cluster" | ... | ... |
-
Please register or login to post a comment