Skip to content

Commit

Permalink
Merge pull request mininet#815 from teto/fix_controller
Browse files Browse the repository at this point in the history
fix "which" calls always returning true
  • Loading branch information
lantz authored Apr 16, 2019
2 parents cfb0a6d + a73e776 commit c5f23b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mininet/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from mininet.log import info, error, warn, debug
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
numCores, retry, mountCgroups, BaseString, decode,
encode, Python3 )
encode, Python3, which )
from mininet.moduledeps import moduleDeps, pathCheck, TUN
from mininet.link import Link, Intf, TCIntf, OVSIntf
from re import findall
Expand Down Expand Up @@ -1447,7 +1447,7 @@ def __repr__( self ):
@classmethod
def isAvailable( cls ):
"Is controller available?"
return quietRun( 'which controller' )
return which( 'controller' )


class OVSController( Controller ):
Expand All @@ -1459,9 +1459,9 @@ def __init__( self, name, **kwargs ):

@classmethod
def isAvailable( cls ):
return ( quietRun( 'which ovs-controller' ) or
quietRun( 'which test-controller' ) or
quietRun( 'which ovs-testcontroller' ) ).strip()
return (which( 'ovs-controller' ) or
which( 'test-controller' ) or
which( 'ovs-testcontroller' ))

class NOX( Controller ):
"Controller to run a NOX application."
Expand Down
5 changes: 5 additions & 0 deletions mininet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def quietRun( cmd, **kwargs ):
"Run a command and return merged stdout and stderr"
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]

def which(cmd, **kwargs ):
"Run a command and return merged stdout and stderr"
out, _, ret = errRun( ["which", cmd], stderr=STDOUT, **kwargs )
return out.rstrip() if ret == 0 else None

# pylint: enable=maybe-no-member

def isShellBuiltin( cmd ):
Expand Down

0 comments on commit c5f23b9

Please sign in to comment.