Ejemplo n.º 1
0
def tunnelX11(node, display=None):
    """Create an X11 tunnel from node:6000 to the root host
       display: display on root host (optional)
       returns: node $DISPLAY, Popen object for tunnel"""
    if display is None and 'DISPLAY' in environ:
        display = environ['DISPLAY']
    if display is None:
        error("Error: Cannot connect to display\n")
        return None, None
    host, screen = display.split(':')
    # Unix sockets should work
    if not host or host == 'unix':
        # GDM3 doesn't put credentials in .Xauthority,
        # so allow root to just connect
        quietRun('xhost +si:localuser:root')
        return display, None
    else:
        # Create a tunnel for the TCP connection
        port = 6000 + int(float(screen))
        connection = r'TCP\:%s\:%s' % (host, port)
        cmd = [
            "socat",
            "TCP-LISTEN:%d,fork,reuseaddr" % port,
            "EXEC:'vdlocalmnexec -a 1 socat STDIO %s'" % connection
        ]
    return 'localhost:' + screen, node.popen(cmd)
Ejemplo n.º 2
0
 def do_noecho(self, line):
     """Run an interactive command with echoing turned off.
        Usage: noecho [cmd args]"""
     if self.isatty():
         quietRun('stty -echo')
     self.default(line)
     if self.isatty():
         quietRun('stty echo')
Ejemplo n.º 3
0
 def setup( cls ):
     "Check dependencies and warn about firewalling"
     pathCheck( 'brctl', moduleName='bridge-utils' )
     # Disable Linux bridge firewalling so that traffic can flow!
     for table in 'arp', 'ip', 'ip6':
         cmd = 'sysctl net.bridge.bridge-nf-call-%stables' % table
         out = quietRun( cmd ).strip()
         if out.endswith( '1' ):
             warn( 'Warning: Linux bridge may not work with', out, '\n' )
Ejemplo n.º 4
0
 def waitForNode(self, node):
     "Wait for a node to finish, and print its output."
     # Pollers
     nodePoller = poll()
     nodePoller.register(node.stdout)
     bothPoller = poll()
     bothPoller.register(self.stdin, POLLIN)
     bothPoller.register(node.stdout, POLLIN)
     if self.isatty():
         # Buffer by character, so that interactive
         # commands sort of work
         quietRun('stty -icanon min 1')
     while True:
         try:
             bothPoller.poll()
             # XXX BL: this doesn't quite do what we want.
             if False and self.inputFile:
                 key = self.inputFile.read(1)
                 if key is not '':
                     node.write(key)
                 else:
                     self.inputFile = None
             if isReadable(self.inPoller):
                 key = self.stdin.read(1)
                 node.write(key)
             if isReadable(nodePoller):
                 data = node.monitor()
                 output(data)
             if not node.waiting:
                 break
         except KeyboardInterrupt:
             # There is an at least one race condition here, since
             # it's possible to interrupt ourselves after we've
             # read data but before it has been printed.
             node.sendInt()
         except select.error as e:
             # pylint: disable=unpacking-non-sequence
             errno_, errmsg = e.args
             # pylint: enable=unpacking-non-sequence
             if errno_ != errno.EINTR:
                 error("select.error: %d, %s" % (errno_, errmsg))
                 node.sendInt()
Ejemplo n.º 5
0
 def run(self):
     "Run our cmdloop(), catching KeyboardInterrupt"
     while True:
         try:
             # Make sure no nodes are still waiting
             for node in self.mn.values():
                 while node.waiting:
                     info('stopping', node, '\n')
                     node.sendInt()
                     node.waitOutput()
             if self.isatty():
                 quietRun('stty echo sane intr ^C')
             self.cmdloop()
             break
         except KeyboardInterrupt:
             # Output a message - unless it's also interrupted
             # pylint: disable=broad-except
             try:
                 output('\nInterrupt\n')
             except Exception:
                 pass
Ejemplo n.º 6
0
 def runCpuLimitTest(self, cpu, duration=5):
     """run CPU limit test with 'while true' processes.
     cpu: desired CPU fraction of each host
     duration: test duration in seconds (integer)
     returns a single list of measured CPU fractions as floats.
     """
     pct = cpu * 100
     info('*** Testing CPU %.0f%% bandwidth limit\n' % pct)
     hosts = self.hosts
     cores = int(quietRun('nproc'))
     # number of processes to run a while loop on per host
     num_procs = int(ceil(cores * cpu))
     pids = {}
     for h in hosts:
         pids[h] = []
         for _core in range(num_procs):
             h.cmd('while true; do a=1; done &')
             pids[h].append(h.cmd('echo $!').strip())
     outputs = {}
     time = {}
     # get the initial cpu time for each host
     for host in hosts:
         outputs[host] = []
         with open('/sys/fs/cgroup/cpuacct/%s/cpuacct.usage' % host,
                   'r') as f:
             time[host] = float(f.read())
     for _ in range(duration):
         sleep(1)
         for host in hosts:
             with open('/sys/fs/cgroup/cpuacct/%s/cpuacct.usage' % host,
                       'r') as f:
                 readTime = float(f.read())
             outputs[host].append(
                 ((readTime - time[host]) / 1000000000) / cores * 100)
             time[host] = readTime
     for h, pids in pids.items():
         for pid in pids:
             h.cmd('kill -9 %s' % pid)
     cpu_fractions = []
     for _host, outputs in outputs.items():
         for pct in outputs:
             cpu_fractions.append(pct)
     output('*** Results: %s\n' % cpu_fractions)
     return cpu_fractions
Ejemplo n.º 7
0
def lsmod():
    "Return output of lsmod."
    return quietRun('lsmod')
Ejemplo n.º 8
0
def modprobe(mod):
    """Return output of modprobe
       mod: module string"""
    return quietRun(['modprobe', mod])
Ejemplo n.º 9
0
def rmmod(mod):
    """Return output of lsmod.
       mod: module string"""
    return quietRun(['rmmod', mod])