def posix(): from posix import uname p = ('posix_'+uname()[0]+'_'+uname()[4]).replace(' ','_') if globals().has_key(p): return globals()[p]() raise RuntimeError("unsupported posix platform %s" % p)
def test_uname(self): # just like cpython, a simple smoke test uname = posix.uname() self.assertRaises(TypeError, lambda: posix.uname(1)) self.assertIsNotNone(uname.sysname) self.assertIsNotNone(uname.nodename) self.assertIsNotNone(uname.release) self.assertIsNotNone(uname.version) self.assertIsNotNone(uname.machine)
def __init__(self,platform): unix_tools.PiUnixEnvironment.__init__(self,platform,'usr/pi','Library/Eigenlabs',python='/usr/pi/bin/python') os_major=uname()[2].split('.')[0] self.Append(LIBS=Split('dl m pthread')) self.Replace(MACOSXSDK='/Developer/SDKs/MacOSX10.4u.sdk') self.Append(CCFLAGS=Split('-isysroot ${MACOSXSDK} -mmacosx-version-min=10.4 -arch i386 -DDEBUG_DATA_ATOMICITY_DISABLED')) self.Append(LINKFLAGS=Split('-isysroot ${MACOSXSDK} -mmacosx-version-min=10.4 -arch i386 -framework Accelerate')) self.Append(CCFLAGS=Split('-ggdb -Werror -Wall -Wno-long-double -O3 -fmessage-length=0 -falign-loops=16 -msse3')) self.Replace(IS_MACOSX=os_major) self.Replace(PI_MODLINKFLAGS='$LINKFLAGS -bundle') self.Replace(PI_DLLENVNAME='DYLD_LIBRARY_PATH') self.Append(SHLINKFLAGS='-Wl,-install_name,@executable_path/${SHLIBPREFIX}${SHLIBNAME}${SHLIBSUFFIX}') self.Replace(PI_PLATFORMTYPE='macosx') self.Replace(APPRUNDIR=join('#tmp','app')) self.Replace(APPSTAGEDIR=join('$STAGEDIR','Applications','Eigenlabs','$PI_RELEASE')) self.Replace(APPINSTALLDIR=join('/','Applications','Eigenlabs','$PI_RELEASE')) self.Replace(APPSTAGEDIR_PRIV=join('$RELEASESTAGEDIR','Applications')) self.Replace(APPINSTALLDIR_PRIV=join('/','$INSTALLDIR','Applications')) self.Replace(CXX='g++-4.0') self.Replace(CC='gcc-4.0') self.Alias('target-default','#tmp/app')
def __init__(self): self.values = {} self.errors = 0 # Try to resolve the vendor and version information # for the distro we're running on vendor = None version = None for r in [ self.__redhatStyleRelease, self.__debianStyleRelease, self.__lsbStyleRelease ]: vendor, version = r() if vendor and version: break self.values["vendor"] = vendor or "Unknown vendor" self.values["version"] = version or "Unknown version" self.values["name"], nodename, release, version, self.values[ "arch"] = posix.uname() for k in self.values.keys(): if not self.values[k]: self.errors += 1
def EnableAll(): "Enable all known Ethernet interfaces" ostype = posix.uname()[0] if ostype == 'Linux': return ipmap = gen.getIFAddrs() for eth in ipmap.keys(): os.system('sudo ifconfig %s up' % eth)
def _InitDefaults(self): # Default value; user may unset it. # $ echo -n "$IFS" | python -c 'import sys;print repr(sys.stdin.read())' # ' \t\n' SetGlobalString(self, 'IFS', split.DEFAULT_IFS) SetGlobalString(self, 'PWD', posix.getcwd()) # NOTE: Should we put these in a namespace for Oil? SetGlobalString(self, 'UID', str(posix.getuid())) SetGlobalString(self, 'EUID', str(posix.geteuid())) SetGlobalString(self, 'HOSTNAME', str(libc.gethostname())) # In bash, this looks like 'linux-gnu', 'linux-musl', etc. Scripts test # for 'darwin' and 'freebsd' too. They generally don't like at 'gnu' or # 'musl'. We don't have that info, so just make it 'linux'. SetGlobalString(self, 'OSTYPE', str(posix.uname()[0].lower())) # For getopts builtin SetGlobalString(self, 'OPTIND', '1') # For xtrace SetGlobalString(self, 'PS4', '+ ') # bash-completion uses this. Value copied from bash. It doesn't integrate # with 'readline' yet. SetGlobalString(self, 'COMP_WORDBREAKS', util.READLINE_DELIMS)
def __init__(self, ipAddr,context): if not ipAddr.isalpha(): raise EnvironmentError, "control-rad.py: Expected host name, got address" self.shell = session.LocalShell() self.ostype = posix.uname()[0] ipm = ipsetup.IPManager() # 22726 - Radius Access Response needs to be received by the MSW on the same interface on # on which the request was sent. Radius Request messages will be sent on the management # interface. self.network = context['userConfig.radius_eth_iface'] self.ipAddr = socket.gethostbyname(ipAddr) if self.network == '-1': raise OSError, 'IP address %s not found in ipsetup.py' % self.ipAddr if self.ostype == 'Linux': self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ipAddr, self.network)) elif self.ostype == 'SunOS': self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \ % (self.network,self.ipAddr)) else: raise NotImplementedError,'Endpoint resource not implemented for %s' %self.ostype
def __init__(self, ipAddr, context): if not ipAddr.isalpha(): raise EnvironmentError, "control-rad.py: Expected host name, got address" self.shell = session.LocalShell() self.ostype = posix.uname()[0] ipm = ipsetup.IPManager() # 22726 - Radius Access Response needs to be received by the MSW on the same interface on # on which the request was sent. Radius Request messages will be sent on the management # interface. self.network = context['userConfig.radius_eth_iface'] self.ipAddr = socket.gethostbyname(ipAddr) if self.network == '-1': raise OSError, 'IP address %s not found in ipsetup.py' % self.ipAddr if self.ostype == 'Linux': self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ipAddr, self.network)) elif self.ostype == 'SunOS': self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \ % (self.network,self.ipAddr)) else: raise NotImplementedError, 'Endpoint resource not implemented for %s' % self.ostype
def ShowAppVersion(app_name): # type: (str) -> None """For Oil and OPy.""" loader = GetResourceLoader() f = loader.open('oil-version.txt') version = f.readline().strip() f.close() try: f = loader.open('release-date.txt') except IOError: release_date = '-' # in dev tree else: release_date = f.readline().strip() finally: f.close() try: f = loader.open('pyc-version.txt') except IOError: pyc_version = '-' # in dev tree else: pyc_version = f.readline().strip() finally: f.close() # node is like 'hostname' # release is the kernel version system, unused_node, unused_release, platform_version, machine = posix.uname( ) # The platform.py module has a big regex that parses sys.version, but we # don't want to depend on regular expressions. So we will do our own parsing # here. version_line, py_compiler = sys.version.splitlines() # Pick off the first part of '2.7.12 (default, ...)' py_version = version_line.split()[0] assert py_compiler.startswith('['), py_compiler assert py_compiler.endswith(']'), py_compiler py_compiler = py_compiler[1:-1] # We removed sys.executable from sysmodule.c. py_impl = 'CPython' if hasattr(sys, 'executable') else 'OVM' # What C functions do these come from? print('%s version %s' % (app_name, version)) print('Release Date: %s' % release_date) print('Arch: %s' % machine) print('OS: %s' % system) print('Platform: %s' % platform_version) print('Compiler: %s' % py_compiler) print('Interpreter: %s' % py_impl) print('Interpreter version: %s' % py_version) print('Bytecode: %s' % pyc_version)
def __init__(self, platform): unix_tools.PiUnixEnvironment.__init__( self, platform, 'usr/local/pi', 'Library/Eigenlabs', python='/usr/local/pi/bin/python') os_major = uname()[2].split('.')[0] self.Append(LIBS=Split('dl m pthread')) if platform == 'macosx-x86-64': self.Append(CXXFLAGS=Split( '-std=c++11 -Wno-c++11-narrowing -Wno-inconsistent-missing-override' )) self.Append(CCFLAGS=Split( '-arch x86_64 -DDEBUG_DATA_ATOMICITY_DISABLED -DPI_PREFIX=\\"$PI_PREFIX\\" -mmacosx-version-min=10.6' )) self.Append(LINKFLAGS=Split( '-arch x86_64 -framework Accelerate -Wl,-rpath,@executable_path/ -mmacosx-version-min=10.6' )) else: self.Append(CXXFLAGS=Split( '-std=c++11 -Wno-c++11-narrowing -Wno-inconsistent-missing-override' )) self.Append(CCFLAGS=Split( '-arch i386 -DDEBUG_DATA_ATOMICITY_DISABLED -DPI_PREFIX=\\"$PI_PREFIX\\" -mmacosx-version-min=10.6' )) self.Append(LINKFLAGS=Split( '-arch i386 -framework Accelerate -Wl,-rpath,@executable_path/ -mmacosx-version-min=10.6' )) self.Append(CCFLAGS=Split( '-ggdb -Werror -Wall -Wno-empty-body -Wno-deprecated-declarations -Wno-format -Wno-unused-function -Wno-unused-private-field -Wno-c++11-extensions -Os -fmessage-length=0 -msse3' )) self.Replace(PI_DLLENVNAME='DYLD_LIBRARY_PATH') self.Replace(IS_MACOSX=os_major) self.Replace(PI_MODLINKFLAGS=[ '$LINKFLAGS', '-bundle', '-Wl,-rpath,@loader_path/' ]) self.Append(SHLINKFLAGS=[ '-Wl,-install_name,@rpath/${SHLIBPREFIX}${SHLIBNAME}${SHLIBSUFFIX}', '-Wl,-rpath,@loader_path/' ]) self.Replace(PI_PLATFORMTYPE='macosx') self.Replace(APPRUNDIR=join('#tmp', 'app')) self.Replace(APPSTAGEDIR=join('$STAGEDIR', 'Applications', 'Eigenlabs', '$PI_RELEASE')) self.Replace(APPINSTALLDIR=join('/', 'Applications', 'Eigenlabs', '$PI_RELEASE')) self.Replace(APPSTAGEDIR_PRIV=join('$RELEASESTAGEDIR', 'Applications')) self.Replace( APPINSTALLDIR_PRIV=join('/', '$INSTALLDIR', 'Applications')) self.Alias('target-default', '#tmp/app')
def MakeAlias(ip, dev): ostype = posix.uname()[0] if ostype == 'Linux': dev = 'eth%s' % dev add = 'sudo ip addr add %s/24 dev %s > /dev/null 2>&1' % (ip, dev) if ostype == 'SunOS': dev = 'e1000g%s' % dev add = 'sudo ifconfig %s addif %s/24 > /dev/null 2>&1' % (dev, ip) print "adding %s to %s device %s" % (ip, ostype, dev) os.system(add)
def SetUp(self, context, result): """ Set up the resource. Create a generic endpoint object. Resolve the address prior to creating the gen. """ self.log = logging.getLogger('nextestlog') self.shell = session.LocalShell() self.ostype = posix.uname()[0] ipm = ipsetup.IPManager() self.network = ipm.getNetwork(self.ipaddr) self.log.debug('NETWORK ---------%s' % self.network) self.ipAddr = socket.gethostbyname(self.ipaddr) if self.network == '-1': raise OSError, 'IP address %s not found in ipsetup.py' % self.ipaddr # Ticket 14783 changes if self.network == '0': port = context['userConfig.eth_pub_iface'] else: port = context['userConfig.eth_pri_iface'] if self.ostype == 'Linux': self.ethport = "eth%s" % port self.shell.assertCommand('sudo ip addr add %s/16 dev %s > /dev/null 2>&1' \ % (self.ipAddr, self.ethport)) elif self.ostype == 'SunOS': self.ethport = "e1000g%s" % port self.shell.assertCommand( 'sudo ifconfig %s addif %s/16 up > /dev/null 2>&1' \ % (self.ethport,self.ipAddr)) else: raise NotImplementedError, 'Endpoint resource not implemented for %s' % self.ostype self.log.debug('Creating endpoint resource: property: %s, ip: %s, mask: %s eth: %s' % \ (self.property, self.ipaddr, self.mask, self.ethport)) #Create a generic endpoint object. if len(self.mask) == 0: self.mask = None if len(self.ethport) == 0: self.ethport = None try: ip = socket.gethostbyname(self.ipaddr) except socket.gaierror, exc: errno, errstr = exc result.Annotate({ 'Endpoint name': self.property, 'Endpoint address': self.ipaddr, 'Exception': str(exc) }) result.Fail('Could not resolve endpoint IP address')
def SetUp(self, context, result): """ Set up the resource. Create a generic endpoint object. Resolve the address prior to creating the gen. """ self.log = logging.getLogger('nextestlog') self.shell = session.LocalShell() self.ostype = posix.uname()[0] ipm = ipsetup.IPManager() self.network = ipm.getNetwork(self.ipaddr) self.log.debug('NETWORK ---------%s' %self.network) self.ipAddr = socket.gethostbyname(self.ipaddr) if self.network == '-1': raise OSError, 'IP address %s not found in ipsetup.py' % self.ipaddr # Ticket 14783 changes if self.network == '0': port = context['userConfig.eth_pub_iface'] else: port = context['userConfig.eth_pri_iface'] if self.ostype == 'Linux': self.ethport = "eth%s" % port self.shell.assertCommand('sudo ip addr add %s/16 dev %s > /dev/null 2>&1' \ % (self.ipAddr, self.ethport)) elif self.ostype == 'SunOS': self.ethport = "e1000g%s" % port self.shell.assertCommand( 'sudo ifconfig %s addif %s/16 up > /dev/null 2>&1' \ % (self.ethport,self.ipAddr)) else: raise NotImplementedError,'Endpoint resource not implemented for %s' %self.ostype self.log.debug('Creating endpoint resource: property: %s, ip: %s, mask: %s eth: %s' % \ (self.property, self.ipaddr, self.mask, self.ethport)) #Create a generic endpoint object. if len(self.mask) == 0: self.mask = None if len(self.ethport) == 0: self.ethport = None try: ip = socket.gethostbyname(self.ipaddr) except socket.gaierror, exc: errno, errstr = exc result.Annotate({'Endpoint name' : self.property, 'Endpoint address' : self.ipaddr, 'Exception' : str(exc)}) result.Fail('Could not resolve endpoint IP address')
def CleanUp(self, result): #get os type ostype = posix.uname()[0] if ostype == 'Linux': # Removing the IP addresses # 38969: Remove the new nat device # 54804: Remove new nat device prv_nat1 for ipAddr in range(0, 4): self.shell.assertCommand('sudo ip addr delete %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ExtAddresses[ipAddr], self.If[ipAddr])) # We are flushing the chains assuming that this class is only one # which adds nat rules. self.shell.assertCommand('sudo iptables -t nat -F POSTROUTING') elif ostype == 'SunOS': # Removing the IP addresses for ipAddr in 0, 1: self.shell.assertCommand( 'sudo ifconfig e1000g%s removeif %s/16 up > /dev/null 2>&1' \ % (self.If[ipAddr],self.ExtAddresses[ipAddr])) # Remove nat configuration in /etc/opt/ipf/ipnat.conf fileName = '/etc/opt/ipf/ipnat.conf' try: natFile = open(fileName, 'r') natFileLines = natFile.readlines() natFile.close() except: #file does not exist, nothing to do return natFileLinesCleaned = [ x for x in natFileLines if x not in self.solNatNewLines ] self.shell.assertCommand('sudo chmod 777 %s' % fileName) natFile = open(fileName, 'w') natFile.writelines(natFileLinesCleaned) natFile.close() self.shell.assertCommand('sudo chmod 644 %s' % fileName) self.shell.assertCommand('sudo /etc/init.d/ipfboot stop') self.shell.assertCommand('sudo /etc/init.d/ipfboot start') else: raise NotImplementedError, 'Nat resource not implemented for %s' % ostype self.shell.disconnect()
def CleanUp(self, result): #get os type ostype = posix.uname()[0] if ostype == 'Linux': # Removing the IP addresses # 38969: Remove the new nat device # 54804: Remove new nat device prv_nat1 for ipAddr in range(0,4): self.shell.assertCommand('sudo ip addr delete %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ExtAddresses[ipAddr], self.If[ipAddr])) # We are flushing the chains assuming that this class is only one # which adds nat rules. self.shell.assertCommand('sudo iptables -t nat -F POSTROUTING') elif ostype == 'SunOS': # Removing the IP addresses for ipAddr in 0,1: self.shell.assertCommand( 'sudo ifconfig e1000g%s removeif %s/16 up > /dev/null 2>&1' \ % (self.If[ipAddr],self.ExtAddresses[ipAddr])) # Remove nat configuration in /etc/opt/ipf/ipnat.conf fileName = '/etc/opt/ipf/ipnat.conf' try: natFile = open(fileName,'r') natFileLines = natFile.readlines() natFile.close() except: #file does not exist, nothing to do return natFileLinesCleaned = [x for x in natFileLines if x not in self.solNatNewLines] self.shell.assertCommand('sudo chmod 777 %s' % fileName) natFile = open(fileName,'w') natFile.writelines(natFileLinesCleaned) natFile.close() self.shell.assertCommand('sudo chmod 644 %s' % fileName) self.shell.assertCommand('sudo /etc/init.d/ipfboot stop') self.shell.assertCommand('sudo /etc/init.d/ipfboot start') else: raise NotImplementedError,'Nat resource not implemented for %s' %ostype self.shell.disconnect()
def __init__(self, platform): unix_tools.PiUnixEnvironment.__init__(self, platform, 'usr/pi', 'Library/Eigenlabs', python='/usr/pi/bin/python') os_major = uname()[2].split('.')[0] self.Append(LIBS=Split('dl m pthread')) self.Append(CCFLAGS=Split( '-arch i386 -DDEBUG_DATA_ATOMICITY_DISABLED -DPI_PREFIX=\\"$PI_PREFIX\\" -mmacosx-version-min=10.6' )) self.Append(LINKFLAGS=Split( '-arch i386 -framework Accelerate -Wl,-rpath,@executable_path/ -no_compact_linkedit -mmacosx-version-min=10.6' )) self.Replace(CXX='g++-4.2') self.Replace(CC='gcc-4.2') self.Append(CCFLAGS=Split( '-ggdb -Werror -Wall -Wno-deprecated-declarations -Wno-format -O4 -fmessage-length=0 -falign-loops=16 -msse3' )) self.Replace(PI_DLLENVNAME='DYLD_LIBRARY_PATH') self.Replace(IS_MACOSX=os_major) self.Replace(PI_MODLINKFLAGS=[ '$LINKFLAGS', '-bundle', '-Wl,-rpath,@loader_path/' ]) self.Append(SHLINKFLAGS=[ '-Wl,-install_name,@rpath/${SHLIBPREFIX}${SHLIBNAME}${SHLIBSUFFIX}', '-Wl,-rpath,@loader_path/' ]) self.Replace(PI_PLATFORMTYPE='macosx') self.Replace(APPRUNDIR=join('#tmp', 'app')) self.Replace(APPSTAGEDIR=join('$STAGEDIR', 'Applications', 'Eigenlabs', '$PI_RELEASE')) self.Replace(APPINSTALLDIR=join('/', 'Applications', 'Eigenlabs', '$PI_RELEASE')) self.Replace(APPSTAGEDIR_PRIV=join('$RELEASESTAGEDIR', 'Applications')) self.Replace( APPINSTALLDIR_PRIV=join('/', '$INSTALLDIR', 'Applications')) self.Alias('target-default', '#tmp/app')
def SetUp(self, context, result): """ Set up the LocalServer resource. """ self.log = logging.getLogger('nextestlog') cmd = self.startcommand # 22519 - Verify whether its a SER resource and if so, add the ip address to the # public interface if cmd.__contains__("run_ser"): shell = LocalShell() ostype = posix.uname()[0] ser_ip = socket.gethostbyname('sipproxy') interface = context['userConfig.eth_pub_iface'] ipCmd = "" ipAddCmd = "" if ostype == 'Linux': ipCmd = 'sudo ip addr show | grep %s' %ser_ip ipAddCmd = 'sudo ip addr add %s/24 dev eth%s > /dev/null 2>&1' %(ser_ip,interface) elif ostype == 'SunOS': ipCmd = 'sudo ifconfig -a | grep %s' %ser_ip ipAddCmd = 'sudo ifconfig addif e1000g%s %s/24 up > /dev/null 2>&1' %(interface,ser_ip) # Find if the ip already exists resultString = shell.filter(ipCmd) if not resultString.__contains__(ser_ip): shell.assertCommand(ipAddCmd) # Find if the ip has been successfully added resultString = shell.filter(ipCmd) if not resultString.__contains__(ser_ip): raise OSError, 'IP address %s could not be added to interface %s' %(ser_ip,interface) else: self.log.debug('control.LocalServer: SER IP address %s added to interface %s' %(ser_ip,interface)) else: self.log.debug('control.LocalServer: SER IP address %s already added' %ser_ip) self.log.debug('control.LocalServer: Starting %s, command: %s' % (self.property, cmd)) os.system(cmd) shell.disconnect()
def SetUp(self, context, result): """ Set up the gnuGatekeeper resource. """ self.log = logging.getLogger('nextestlog') self.ipAddr = socket.gethostbyname(self.gkname) if self.gkname == 'gatekeeper1': interface = context['userConfig.eth_pub_iface'] else: interface = context['userConfig.eth_pri_iface'] ipCmd = "" ipAddCmd = "" shell = LocalShell() ostype = posix.uname()[0] if ostype == 'Linux': ipCmd = 'sudo ip addr show | grep %s' %self.ipAddr ipAddCmd = 'sudo ip addr add %s/24 dev eth%s > /dev/null 2>&1' %(self.ipAddr,interface) elif ostype == 'SunOS': ipCmd = 'sudo ifconfig -a | grep %s' %self.ipAddr ipAddCmd = 'sudo ifconfig addif e1000g%s %s/24 up > /dev/null 2>&1' %(interface,self.ipAddr) # Find if the ip already exists resultString = shell.filter(ipCmd) if not resultString.__contains__(self.ipAddr): shell.assertCommand(ipAddCmd) # Find if the ip has been successfully added resultString = shell.filter(ipCmd) if not resultString.__contains__(self.ipAddr): raise OSError, 'GK IP address %s could not be added to interface %s' %(self.ipAddr,interface) else: self.log.debug('control.LocalServer: GK IP address %s added to interface %s' %(self.ipAddr,interface)) else: self.log.debug('control.LocalServer: GK IP address %s already added' %self.ipAddr) if self.gkname == 'gatekeeper2': context[self.gkname] = gatekeeper.gnuGk(self.gkname,switch='prv_rsa') else: context[self.gkname] = gatekeeper.gnuGk(self.gkname) self.gnuGKObj = context[self.gkname] self.gnuGKObj.addr = self.ipAddr
def __init__(self, platform): unix_tools.PiUnixEnvironment.__init__( self, platform, "usr/pi", "Library/Eigenlabs", python="/usr/pi/bin/python" ) os_major = uname()[2].split(".")[0] self.Append(LIBS=Split("dl m pthread")) self.Append( CCFLAGS=Split( '-arch i386 -DDEBUG_DATA_ATOMICITY_DISABLED -DPI_PREFIX=\\"$PI_PREFIX\\" -mmacosx-version-min=10.6' ) ) self.Append( LINKFLAGS=Split("-arch i386 -framework Accelerate -Wl,-rpath,@executable_path/ -mmacosx-version-min=10.6") ) self.Append( CCFLAGS=Split( "-ggdb -Werror -Wall -Wno-deprecated-declarations -Wno-format -Wno-unused-function -Wno-unused-private-field -Wno-c++11-extensions -Os -fmessage-length=0 -msse3" ) ) self.Replace(PI_DLLENVNAME="DYLD_LIBRARY_PATH") self.Replace(IS_MACOSX=os_major) self.Replace(PI_MODLINKFLAGS=["$LINKFLAGS", "-bundle", "-Wl,-rpath,@loader_path/"]) self.Append( SHLINKFLAGS=[ "-Wl,-install_name,@rpath/${SHLIBPREFIX}${SHLIBNAME}${SHLIBSUFFIX}", "-Wl,-rpath,@loader_path/", ] ) self.Replace(PI_PLATFORMTYPE="macosx") self.Replace(APPRUNDIR=join("#tmp", "app")) self.Replace(APPSTAGEDIR=join("$STAGEDIR", "Applications", "Eigenlabs", "$PI_RELEASE")) self.Replace(APPINSTALLDIR=join("/", "Applications", "Eigenlabs", "$PI_RELEASE")) self.Replace(APPSTAGEDIR_PRIV=join("$RELEASESTAGEDIR", "Applications")) self.Replace(APPINSTALLDIR_PRIV=join("/", "$INSTALLDIR", "Applications")) self.Alias("target-default", "#tmp/app")
def __init__(self): self.values = {} self.errors = 0 # Try to resolve the vendor and version information # for the distro we're running on vendor = None version = None for r in [self.__redhatStyleRelease, self.__debianStyleRelease, self.__lsbStyleRelease]: vendor, version = r() if vendor and version: break self.values["vendor"] = vendor or "Unknown vendor" self.values["version"] = version or "Unknown version" self.values["name"], nodename, release, version, self.values["arch"] = posix.uname() for k in self.values.keys(): if not self.values[k]: self.errors += 1
def __init__(self,platform): unix_tools.PiUnixEnvironment.__init__(self,platform,'usr/pi','Library/Eigenlabs',python='/usr/pi/bin/python') os_major=uname()[2].split('.')[0] self.Append(LIBS=Split('dl m pthread')) self.Append(CCFLAGS=Split('-arch i386 -DDEBUG_DATA_ATOMICITY_DISABLED -DPI_PREFIX=\\"$PI_PREFIX\\" -mmacosx-version-min=10.6')) self.Append(LINKFLAGS=Split('-arch i386 -framework Accelerate -Wl,-rpath,@executable_path/ -no_compact_linkedit -mmacosx-version-min=10.6')) self.Replace(CXX='g++-4.2') self.Replace(CC='gcc-4.2') self.Append(CCFLAGS=Split('-ggdb -Werror -Wall -Wno-deprecated-declarations -Wno-format -O4 -fmessage-length=0 -falign-loops=16 -msse3')) self.Replace(PI_DLLENVNAME='DYLD_LIBRARY_PATH') self.Replace(IS_MACOSX=os_major) self.Replace(PI_MODLINKFLAGS=['$LINKFLAGS','-bundle','-Wl,-rpath,@loader_path/']) self.Append(SHLINKFLAGS=['-Wl,-install_name,@rpath/${SHLIBPREFIX}${SHLIBNAME}${SHLIBSUFFIX}','-Wl,-rpath,@loader_path/']) self.Replace(PI_PLATFORMTYPE='macosx') self.Replace(APPRUNDIR=join('#tmp','app')) self.Replace(APPSTAGEDIR=join('$STAGEDIR','Applications','Eigenlabs','$PI_RELEASE')) self.Replace(APPINSTALLDIR=join('/','Applications','Eigenlabs','$PI_RELEASE')) self.Replace(APPSTAGEDIR_PRIV=join('$RELEASESTAGEDIR','Applications')) self.Replace(APPINSTALLDIR_PRIV=join('/','$INSTALLDIR','Applications')) self.Alias('target-default','#tmp/app')
print ' </ul>' print ' </li>' print '' print ' <li><a href="#output">Output</a>' print ' ' print ' <li ><a href="#changelog">Changelog</a>' print ' ' print ' </ul>' print '</div>' print '</div>' print '<div id="info">' import time print "<b>last update:</b> ", time.strftime("%d/%m/%y"), "<br>" import posix print "<b>host:</b> ", posix.uname()[1], "<br>" print "<b>OS:</b> ", posix.uname()[0], "<br>" print '</div>' print '<div id="content">' print '<p id="general"></p>' print '<H2 >General information</H2>' try: lastVersion = filter( lambda x: x.lower().find("version")!=-1 , chg)[0].split() versionNo = lastVersion[1] releasedOn = lastVersion[-1] print '<p>' print "<b>Version number:</b> %s <br>"%versionNo print "<b>Released on:</b> %s <br>"%releasedOn except:
print ' </ul>' print ' </li>' print '' print ' <li><a href="#output">Output</a>' print ' ' print ' <li ><a href="#changelog">Changelog</a>' print ' ' print ' </ul>' print '</div>' print '</div>' print '<div id="info">' import time print "<b>last update:</b> ", time.strftime("%d/%m/%y"), "<br>" import posix print "<b>host:</b> ", posix.uname()[1], "<br>" print "<b>OS:</b> ", posix.uname()[0], "<br>" print '</div>' print '<div id="content">' print '<p id="general"></p>' print '<H2 >General information</H2>' try: lastVersion = filter(lambda x: x.lower().find("version") != -1, chg)[0].split() versionNo = lastVersion[1] releasedOn = lastVersion[-1] print '<p>' print "<b>Version number:</b> %s <br>" % versionNo print "<b>Released on:</b> %s <br>" % releasedOn except: pass
class CallTest(Test): """ Run one or more calls and gather related data. """ arguments = [ qm.fields.TextField(name="testDocumentation", title="Test documentation", description=nexhelp.CallTestHelp.testDocumentation, verbatim="true", multiline="true", default_value="""Write test description here."""), qm.fields.TextField( name="testsource", title="Execution Code", description=nexhelp.CallTestHelp.testsource, verbatim="true", multiline="true", ), qm.fields.TextField(name="assertsource", title="Assertions", description=nexhelp.CallTestHelp.assertsource, verbatim="true", multiline="true", default_value="""clist = context['cdrlist'] test.assertEquals(len(clist), 1, 'One CDR expected, unexpected number or zero captured') test.assertEquals(clist[0]['15-call-error'],'', 'No call error')"""), qm.fields.EnumerationField(name="pkttrace", title="Packet Trace Enabled", description=nexhelp.CallTestHelp.pkttrace, enumerals=["ON", "OFF"], default_value="OFF"), qm.fields.EnumerationField(name="dbglog", title="Debug Log saving Enabled", description=nexhelp.CallTestHelp.dbglog, enumerals=["ON", "OFF"], default_value="ON"), # For SCM and redundancy testing qm.fields.EnumerationField(name="redundancy", title="Redundancy Configuration Enabled", description=nexhelp.CallTestHelp.redundant, enumerals=["ON", "OFF"], default_value="OFF"), qm.fields.EnumerationField(name="cdrcollect", title="CDR Collection Enabled", description=nexhelp.CallTestHelp.cdrcollect, enumerals=["ON", "OFF"], default_value="ON"), ] def Run(self, context, result): # Attach to the log file self.log = logging.getLogger('nextestlog') # Output a banner to mark the start of this call self.log.debug('CallTest: Run: ####') self.log.debug('CallTest: Run: ####') self.log.debug('CallTest: Run: #### Running CallTest %s' % context['qmtest.id']) self.log.debug('CallTest: Run: ####') self.log.debug('CallTest: Run: ####') #----------------------------------------------------------------------- # Kill any errant gen processes that may be running. Ideally, # we need to earn why gen processes errantly persist, but for now # we will just kill them. #----------------------------------------------------------------------- self.killErrantGenProcs() if not context.has_key('mswinfo'): raise CallTestError("CallTest requires a MSW resource") # 18524 - Create a MSWConfig object which is used for configuring certain # parameters of the MSW # 26333 - Pass on the SCM configuration information scmConf = context['nextest.scm_configuration'] context['nextest.mswconfig'] = MswConfig('mymsw', scmConf) # 22268 - Update the iServer version information context['nextest.mswconfig'].mswVersion = context['mswinfo'].iVersion # For SCM testing if (self.redundancy == "ON"): if not context.has_key('bkupinfo'): raise CallTestError("CallTest requires backup MSW resource") # If configured, start CDR collection: if (self.cdrcollect == "ON"): self.ccap = c = data.CDRCollector(context, 'CallTestCDR') c.start(context) # If configured, start producing a PCAP packet trace file: # Ticket-36712: Packet tracing is started if it is enabled either from # the testcase or the command line if (self.pkttrace == "ON") or (context['nextest.pkttrace'] != "OFF"): self.pcap = p = data.PktTraceCollector(context, 'pkttracecollector', '/tmp') p.start(context) # If configured, collect a debug log file: if (self.dbglog == "ON") and (context['nextest.dbglog'] != "OFF"): self.dbg = d = data.DbgLogCollector(context, 'dbglogcollector', '/var/log') d.start(context) # Ticket 13450 fix # Instantiate the errorlog watcher mswErrwatch = MswErrorWatch(context['mswinfo']) globalSpace = { 'context': context, 'result': result, 'test': self, 'myglobals': globals() } localSpace = {} self.runList = [] # Need a flag so that assertions are not run if test has problems testException = False # 36319 - Compare the pid of the gis process before and after the test # to find out if the script has restarted the iserver. # Check the Script Contents to see if it restarts iserver mswObj = session.SSH(['root@mymsw']) # 38957 - Added function names that restart iserver to the gis pid check src = self.testsource.lower() chk1 = src.__contains__('iserver all stop') or src.__contains__( 'ftest') or src.__contains__('checkiserver') chk2 = src.__contains__('checkscmstatus') or src.__contains__( 'restartscm') or src.__contains__('.initialize') if chk1 or chk2: gispid1 = '' else: gispid1 = mswObj.filter('pgrep -x gis') # 58122 - Added hung call check before the test case run if (context['nextest.hung_calls'] != 'OFF'): hungcalls1 = mswObj.getVPorts('Used VPORTS') # 36319 - Find the HVal value before running the test hVal2 = '' hVal1 = mswObj.filter('cli test passive | grep -i hval') self.log.debug('CallTest: hVal Value before running test is %s' % hVal1) try: exec self.testsource in globalSpace, localSpace self.log.info("CallTest: run: call test source done") except Exception, exc: testException = True if sys.exc_type is AssertionError: result.Annotate({"Assertion error": str(exc)}) result.Fail("Failed test assertion") elif sys.exc_type is gen.EndpointError: result.Annotate({'Endpoint error': str(exc)}) result.Fail('Call failed; an endpoint exception occurred') else: result.NoteException(cause="Exception executing source.") result.NoteException(cause=str(exc)) # At this point, we have handled the exception from the # test source. Before continuing, must tell any outstanding # generators to stop or the next test will hang. self._stopGens(context) # Stop commands created via runCommand for cmd in self.runList: print "stopping", cmd self.stopCommand(cmd) # Save all test data and annotate the result with the location if (self.cdrcollect == "ON"): c.saveResult(context, 'cdr.dat') result[Result.NEXTEST_CDR] = c.getRelResultFile() # Ticket-36712: Packet tracing is started if it is enabled either from # the testcase or the command line if (self.pkttrace == "ON") or (context['nextest.pkttrace'] != "OFF"): p.saveResult(context, 'pkttrace_g0_g1.pcap') result[Result.NEXTEST_NET] = p.getRelResultFile() ostype = posix.uname()[0] if ostype == 'Linux': # Change for S9 duplicate packet to maintain different behavior than s3. if (context['userConfig.automation'] == 's9'): context['pdmlPkts'] = pktInspect_s9.readCapture( p.getPdmlFile()) else: context['pdmlPkts'] = pktInspect.readCapture( p.getPdmlFile()) elif ostype == 'SunOS': self.log.info( 'CallTest.Run(): pdml files not supported on SunOS, don\'t run any tests using Packet Inspection Feature.' ) #print "pkttrace file saved" #sleep(20) if (self.dbglog == "ON") and (context['nextest.dbglog'] != "OFF"): d.saveResult(context, 'gisdbg.log') result[Result.NEXTEST_GIS] = d.getRelResultFile() mswObj = session.SSH(['root@mymsw']) # 36319 - Verify whether gis has restarted during the test if (gispid1 != ''): gispid2 = mswObj.filter('pgrep -x gis') if (gispid1 != gispid2): annotations = { 'Assertion': 'GIS has restarted during the test, pid changed %s:%s!!!!' % (gispid1, gispid2) } result.Fail('GIS has restarted', annotations) #self.assert_((gispid1==gispid2),'GIS has restarted!!!!') # 58122 - Verify there are no hung calls after the test case is run if (context['nextest.hung_calls'] != 'OFF'): hungcalls2 = mswObj.getVPorts('Used VPORTS') self.assert_((hungcalls1 == hungcalls2), 'VPORTS are not released and calls are hung!!!!') # Ticket 13450 fix # Collect the errorlog from MSW and verify mswErrwatch.watchMswErrors( result, (context['nextest.fail_on_msw_error'] == "ON")) # Execute the assertion code only if we didn't get a test exception if (not testException) and (self.assertsource is not None): try: exec self.assertsource in globalSpace, localSpace except AssertionError, theException: # put the '00' in so assertion appears first in list annotations = {'Assertion': str(theException)} result.Fail('Test assertion(s) false.', annotations)
def on_master(): return posix.uname().nodename.startswith("master")
def SetUp(self, context, result): """ Create NAT table rules to convert fixed internal addresses into fixed external addresses. """ #get nat addresses pubNat = socket.gethostbyname('pub_nat') prvNat = socket.gethostbyname('prv_nat') # 54804: Add new nat device prv_nat1 prvNat1 = socket.gethostbyname('prv_nat1') # 38969: Add a new NAT device pubNat1 pubNat1 = socket.gethostbyname('pub_nat1') #pubNat2 = socket.gethostbyname('pub_nat2') #prvNat2 = socket.gethostbyname('prv_nat2') if (len(pubNat) < 8) or (len(prvNat) < 8) or (len(pubNat1) < 8): raise EnvironmentError,'Check pub_nat/prv_nat addresses in /etc/hosts file' #self.intAddresses = { '192.168.0.100':'0', # '192.168.0.101':'0', # '192.168.1.100':'1', # '192.168.1.101':'1', # } # 38969: New NAT device pubNat1 # 54804: Add new nat device prv_nat1 self.ExtAddresses = [pubNat, prvNat, pubNat1, prvNat1] self.If = [context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface'],\ context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface']] self.shell = session.LocalShell() #get os type ostype = posix.uname()[0] if ostype == 'Linux': # Add the NAT endpoint addresses # 38969: Add the new nat device # 54804: Add new nat device prv_nat1 for ipAddr in range(0,4): self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ExtAddresses[ipAddr], self.If[ipAddr])) # Add NAT configuration # 38969: Set NAT rules for the new nat device commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.0.100/24 -j SNAT ' + \ '--to-source %s:20000-25000' % pubNat self.shell.assertCommand(commandLine) commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.2.100/24 -j SNAT ' + \ '--to-source %s:25001-29999' % pubNat1 self.shell.assertCommand(commandLine) # 43494: Modified the port range commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.1.100/24 -j SNAT ' + \ '--to-source %s:30000-35000' % prvNat self.shell.assertCommand(commandLine) # 43494: Add NAT rule for tcp commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.100/24 -j SNAT ' + \ '--to-source %s:35001-39999' % prvNat self.shell.assertCommand(commandLine) # 51005: Add NAT TCP rule for pubNat commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.0.100/24 -j SNAT ' + \ '--to-source %s:40000-45000' % pubNat self.shell.assertCommand(commandLine) #PR 137224 Add rules for new NAt device in nat_enhancements commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.3.100/24 -j SNAT ' + \ '--to-source %s:20000-25000' % prvNat1 self.shell.assertCommand(commandLine) elif ostype == 'SunOS': #Package installation should be done at the install time. #self.shell.assertCommand('cd /opt/nextest/etc') #self.shell.assertCommand('sudo pkgrm nsf') #self.shell.assertCommand('sudo pkgadd -d ipfilter_3.4.27_stock.pkg') # Add the NAT endpoint addresses for ipAddr in 0,1: self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \ % (self.If[ipAddr],self.ExtAddresses[ipAddr])) # Add nat configuration in /etc/opt/ipf/ipnat.conf fileName = '/etc/opt/ipf/ipnat.conf' try: natFile = open(fileName,'r') natFileLines = natFile.readlines() natFile.close() except: #file does not exist, we will create it later natFileLines = [] # Ticket 14783 changes self.solNatNewLines = [ 'map e1000g%s 192.168.0.0/16 -> %s/32 portmap udp 20001:30000\n' % (context['pub_eth_iface'],pubNat), 'map e1000g%s 192.168.1.0/16 -> %s/32 portmap udp 30001:40000\n' % (context['pri_eth_iface'],prvNat), ] natFileLinesCleaned = [x for x in natFileLines if x not in self.solNatNewLines] self.shell.assertCommand('sudo touch %s' % fileName) self.shell.assertCommand('sudo chmod 777 %s' % fileName) natFile = open(fileName,'w') natFile.writelines(natFileLinesCleaned) natFile.writelines(self.solNatNewLines) natFile.close() self.shell.assertCommand('sudo chmod 644 %s' % fileName) self.shell.assertCommand('sudo /etc/init.d/ipfboot stop') self.shell.assertCommand('sudo /etc/init.d/ipfboot start') else: raise NotImplementedError,'Nat resource not implemented for %s' %ostype context[self.property] = 'created'
def SetUp(self, context, result): """ Create NAT table rules to convert fixed internal addresses into fixed external addresses. """ #get nat addresses pubNat = socket.gethostbyname('pub_nat') prvNat = socket.gethostbyname('prv_nat') # 54804: Add new nat device prv_nat1 prvNat1 = socket.gethostbyname('prv_nat1') # 38969: Add a new NAT device pubNat1 pubNat1 = socket.gethostbyname('pub_nat1') #pubNat2 = socket.gethostbyname('pub_nat2') #prvNat2 = socket.gethostbyname('prv_nat2') if (len(pubNat) < 8) or (len(prvNat) < 8) or (len(pubNat1) < 8): raise EnvironmentError, 'Check pub_nat/prv_nat addresses in /etc/hosts file' #self.intAddresses = { '192.168.0.100':'0', # '192.168.0.101':'0', # '192.168.1.100':'1', # '192.168.1.101':'1', # } # 38969: New NAT device pubNat1 # 54804: Add new nat device prv_nat1 self.ExtAddresses = [pubNat, prvNat, pubNat1, prvNat1] self.If = [context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface'],\ context['userConfig.eth_pub_iface'],context['userConfig.eth_pri_iface']] self.shell = session.LocalShell() #get os type ostype = posix.uname()[0] if ostype == 'Linux': # Add the NAT endpoint addresses # 38969: Add the new nat device # 54804: Add new nat device prv_nat1 for ipAddr in range(0, 4): self.shell.assertCommand('sudo ip addr add %s/16 dev eth%s > /dev/null 2>&1' \ % (self.ExtAddresses[ipAddr], self.If[ipAddr])) # Add NAT configuration # 38969: Set NAT rules for the new nat device commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.0.100/24 -j SNAT ' + \ '--to-source %s:20000-25000' % pubNat self.shell.assertCommand(commandLine) commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.2.100/24 -j SNAT ' + \ '--to-source %s:25001-29999' % pubNat1 self.shell.assertCommand(commandLine) # 43494: Modified the port range commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.1.100/24 -j SNAT ' + \ '--to-source %s:30000-35000' % prvNat self.shell.assertCommand(commandLine) # 43494: Add NAT rule for tcp commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.100/24 -j SNAT ' + \ '--to-source %s:35001-39999' % prvNat self.shell.assertCommand(commandLine) # 51005: Add NAT TCP rule for pubNat commandLine = 'sudo iptables -t nat -A POSTROUTING -p tcp -s 192.168.0.100/24 -j SNAT ' + \ '--to-source %s:40000-45000' % pubNat self.shell.assertCommand(commandLine) #PR 137224 Add rules for new NAt device in nat_enhancements commandLine = 'sudo iptables -t nat -A POSTROUTING -p udp -s 192.168.3.100/24 -j SNAT ' + \ '--to-source %s:20000-25000' % prvNat1 self.shell.assertCommand(commandLine) elif ostype == 'SunOS': #Package installation should be done at the install time. #self.shell.assertCommand('cd /opt/nextest/etc') #self.shell.assertCommand('sudo pkgrm nsf') #self.shell.assertCommand('sudo pkgadd -d ipfilter_3.4.27_stock.pkg') # Add the NAT endpoint addresses for ipAddr in 0, 1: self.shell.assertCommand( 'sudo ifconfig e1000g%s addif %s/16 up > /dev/null 2>&1' \ % (self.If[ipAddr],self.ExtAddresses[ipAddr])) # Add nat configuration in /etc/opt/ipf/ipnat.conf fileName = '/etc/opt/ipf/ipnat.conf' try: natFile = open(fileName, 'r') natFileLines = natFile.readlines() natFile.close() except: #file does not exist, we will create it later natFileLines = [] # Ticket 14783 changes self.solNatNewLines = [ 'map e1000g%s 192.168.0.0/16 -> %s/32 portmap udp 20001:30000\n' % (context['pub_eth_iface'], pubNat), 'map e1000g%s 192.168.1.0/16 -> %s/32 portmap udp 30001:40000\n' % (context['pri_eth_iface'], prvNat), ] natFileLinesCleaned = [ x for x in natFileLines if x not in self.solNatNewLines ] self.shell.assertCommand('sudo touch %s' % fileName) self.shell.assertCommand('sudo chmod 777 %s' % fileName) natFile = open(fileName, 'w') natFile.writelines(natFileLinesCleaned) natFile.writelines(self.solNatNewLines) natFile.close() self.shell.assertCommand('sudo chmod 644 %s' % fileName) self.shell.assertCommand('sudo /etc/init.d/ipfboot stop') self.shell.assertCommand('sudo /etc/init.d/ipfboot start') else: raise NotImplementedError, 'Nat resource not implemented for %s' % ostype context[self.property] = 'created'
def get_host_name(): """Return the name of this computer.""" return posix.uname()[1]
#!/usr/bin/env python # # Get Ethernet interface names and primary addresses import os import posix import re import sys LINUX = 'Linux' SOLARIS = 'SunOS' ostype = posix.uname()[0] def parseSolaris(text): import string ADDRESS = 'inet' INTERFACE = 'e1000g' t = string.join(text) text = t.split() state = INTERFACE output = '' while text != []: if state == INTERFACE: if text[0].startswith(INTERFACE): ifname = text[0] ifname = ifname.strip(':') output = string.join([output, ifname]) state = ADDRESS if state == ADDRESS: if text[0] == ADDRESS:
from types import * from warnings import * import logging # 54705: Added These two classes to get userConfig values without passing context dictionary from qm.test.context import Context from qm.test.readUserConfig import UserConfig # global variables used by tests for persistent storage mediaport = 49200 # Portability switch LINUX = 'Linux' SOLARIS = 'SunOS' ostype = posix.uname()[0] class EndpointError(Exception): "An endpoint error occurred." class Endpoint(object): """ An IP endpoint with optional VOIP protocol generators. This class is responsible for managing the network configuration of an endpoint and for providing a bridge between the tests and the call generator implementations. Note that he system commands used to set up and tear down logical