Beispiel #1
0
def _teardownBridge(iface):
    """Down and delete an ethernet bridge.

  Args:
    iface: The name of the bridge.
  """
    u.captureCall(['ifconfig', iface, 'down'])
    u.captureCall(['brctl', 'delbr', iface])
Beispiel #2
0
def _setupBridge(iface, ip, mask):
    """Create and up an ethernet bridge.

  Args:
    iface: The name of the bridge.
    gateway: The IP address to listen on.
    mask: The subnet mask of the gateway.
  """
    u.captureCall(['brctl', 'addbr', iface])
    u.captureCall(['ifconfig', iface, ip, 'netmask', mask, 'up'])
Beispiel #3
0
def _listBridges():
    """Return a generator containing all network bridges.

  Yields:
    A list of network bridges that exist on the host system.
  """
    out = u.captureCall(['brctl', 'show'])
    lines = out.strip().split('\n')
    for line in lines[1:]:
        net = line.split()[0]
        if net.startswith('debmarshal-'):
            yield net
    def testPassStderr(self):
        mock_p = self.mox.CreateMock(subprocess.Popen)
        self.mox.StubOutWithMock(subprocess, 'Popen', use_mock_anything=True)

        subprocess.Popen(['ls'],
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr='foo').AndReturn(mock_p)
        mock_p.communicate(None).AndReturn(('bar', 'baz'))
        mock_p.returncode = 0

        self.mox.ReplayAll()

        self.assertEqual(utils.captureCall(['ls'], stderr='foo'), 'bar')
Beispiel #5
0
  def testPassStderr(self):
    mock_p = self.mox.CreateMock(subprocess.Popen)
    self.mox.StubOutWithMock(subprocess, 'Popen', use_mock_anything=True)

    subprocess.Popen(['ls'],
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE,
                     stderr='foo').AndReturn(
        mock_p)
    mock_p.communicate(None).AndReturn(('bar', 'baz'))
    mock_p.returncode = 0

    self.mox.ReplayAll()

    self.assertEqual(utils.captureCall(['ls'], stderr='foo'),
                     'bar')
Beispiel #6
0
def _findUnusedNetwork(host_count):
    """Find an IP address network for a new debmarshal network.

  This picks a gateway IP address by simply incrementing the subnet
  until one is found that is not currently being used.

  To prevent races, this function should be called by a function that
  has taken out the debmarshal-netlist lock exclusively.

  Currently IP addresses are allocated in /24 blocks from
  169.254.0.0/16. Although this is sort of a violation of RFC 3927,
  these addresses are still link-local, so it's not a misuse of the
  block.

  This does mean that debmarshal currently has an effective limit of
  256 test suites running simultaneously. But that also means that
  you'd be running at least 256 VMs simultaneously, which would
  require some pretty impressive hardware.

  Args:
    host_count: How many hosts will be attached to this network.

  Returns:
    A network to use of the form (gateway, netmask)

  Raises:
    debmarshal.errors.NoAvailableIPs: Raised if no suitable subnet
      could be found.
  """
    # TODO(ebroder): Include the netmask of the existing networks when
    #   calculating available IP address space
    net_gateways = set()
    for net in _listBridges():
        # ifdata is part of moreutils (http://kitenet.net/~joey/code/moreutils/)
        net_gateways.add(u.captureCall(['ifdata', '-pa', net]).strip())

    for i in xrange(256):
        # TODO(ebroder): Allow for configuring which subnet to allocate IP
        #   addresses out of
        net = '169.254.%d.1' % i
        if net not in net_gateways:
            # TODO(ebroder): Adjust the size of the network based on the
            #   number of hosts that need to fit in it
            return (net, '255.255.255.0')

    raise errors.NoAvailableIPs('No unused subnet could be found.')