Exemplo n.º 1
0
 def get_peer_name(name):
     if name.startswith(VETH0_PREFIX):
         return name.replace(VETH0_PREFIX, VETH1_PREFIX)
     elif name.startswith(VETH1_PREFIX):
         return name.replace(VETH1_PREFIX, VETH0_PREFIX)
     else:
         tools.fail("%s is not a valid VethFixture veth endpoint" % name)
Exemplo n.º 2
0
 def assert_no_ping(self, dst_ip):
     try:
         self._ping_destination(dst_ip)
         tools.fail("destination ip %(dst_ip)s is replying to ping"
                    "from namespace %(ns)s, but it shouldn't" %
                    {'ns': self.namespace.namespace, 'dst_ip': dst_ip})
     except RuntimeError:
         pass
Exemplo n.º 3
0
 def assert_no_ping(self, dst_ip):
     try:
         self._ping_destination(dst_ip)
         tools.fail("destination ip %(dst_ip)s is replying to ping"
                    "from namespace %(ns)s, but it shouldn't" %
                    {'ns': self.namespace.namespace, 'dst_ip': dst_ip})
     except RuntimeError:
         pass
Exemplo n.º 4
0
 def get(cls, bridge, namespace=None):
     """Deduce PortFixture class from bridge type and instantiate it."""
     if isinstance(bridge, ovs_lib.OVSBridge):
         return OVSPortFixture(bridge, namespace)
     if isinstance(bridge, bridge_lib.BridgeDevice):
         return LinuxBridgePortFixture(bridge, namespace)
     if isinstance(bridge, VethBridge):
         return VethPortFixture(bridge, namespace)
     tools.fail("Unexpected bridge type: %s" % type(bridge))
Exemplo n.º 5
0
 def get(cls, bridge, namespace=None, mac=None, port_id=None):
     """Deduce PortFixture class from bridge type and instantiate it."""
     if isinstance(bridge, ovs_lib.OVSBridge):
         return OVSPortFixture(bridge, namespace, mac, port_id)
     if isinstance(bridge, bridge_lib.BridgeDevice):
         return LinuxBridgePortFixture(bridge, namespace)
     if isinstance(bridge, VethBridge):
         return VethPortFixture(bridge, namespace)
     tools.fail('Unexpected bridge type: %s' % type(bridge))
Exemplo n.º 6
0
def assert_no_arping(src_namespace, dst_ip, source=None, timeout=1, count=1):
    try:
        assert_arping(src_namespace, dst_ip, source, timeout, count)
    except RuntimeError:
        pass
    else:
        tools.fail("destination ip %(destination)s is replying to arp from "
                   "namespace %(ns)s, but it shouldn't" %
                   {'ns': src_namespace, 'destination': dst_ip})
Exemplo n.º 7
0
def assert_no_arping(src_namespace, dst_ip, source=None, timeout=1, count=1):
    try:
        assert_arping(src_namespace, dst_ip, source, timeout, count)
    except RuntimeError:
        pass
    else:
        tools.fail("destination ip %(destination)s is replying to arp from "
                   "namespace %(ns)s, but it shouldn't" %
                   {'ns': src_namespace, 'destination': dst_ip})
Exemplo n.º 8
0
 def wrapper(*args, **kwargs):
     try:
         return wrapped(*args, **kwargs)
     except (testtools.TestCase.skipException, unittest.case.SkipTest) as e:
         if base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'):
             tools.fail(
                 '%s cannot be skipped because OS_FAIL_ON_MISSING_DEPS '
                 'is enabled, skip reason: %s' % (wrapped.__name__, e))
         raise
Exemplo n.º 9
0
 def wrapper(*args, **kwargs):
     try:
         return wrapped(*args, **kwargs)
     except (testtools.TestCase.skipException, unittest.case.SkipTest) as e:
         if base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'):
             tools.fail(
                 '%s cannot be skipped because OS_FAIL_ON_MISSING_DEPS '
                 'is enabled, skip reason: %s' % (wrapped.__name__, e))
         raise
Exemplo n.º 10
0
def assert_no_ping(src_namespace, dst_ip, timeout=1, count=1):
    try:
        assert_ping(src_namespace, dst_ip, timeout, count)
    except RuntimeError:
        pass
    else:
        tools.fail(
            "destination ip %(destination)s is replying to ping from "
            "namespace %(ns)s, but it shouldn't" % {"ns": src_namespace, "destination": dst_ip}
        )
Exemplo n.º 11
0
    def _setUp(self):
        # NOTE(cbrandily): Ensure we will not delete a directory existing
        # before test run during cleanup.
        if os.path.exists(self.directory):
            tools.fail('%s already exists' % self.directory)

        create_cmd = ['mkdir', '-p', self.directory]
        delete_cmd = ['rm', '-r', self.directory]
        utils.execute(create_cmd, run_as_root=True)
        self.addCleanup(utils.execute, delete_cmd, run_as_root=True)
Exemplo n.º 12
0
 def get(cls, bridge, namespace=None, mac=None, port_id=None,
         hybrid_plug=False):
     """Deduce PortFixture class from bridge type and instantiate it."""
     if isinstance(bridge, ovs_lib.OVSBridge):
         return OVSPortFixture(bridge, namespace, mac, port_id, hybrid_plug)
     if isinstance(bridge, bridge_lib.BridgeDevice):
         return LinuxBridgePortFixture(bridge, namespace, mac, port_id)
     if isinstance(bridge, VethBridge):
         return VethPortFixture(bridge, namespace)
     tools.fail('Unexpected bridge type: %s' % type(bridge))
Exemplo n.º 13
0
    def _setUp(self):
        # NOTE(cbrandily): Ensure we will not delete a directory existing
        # before test run during cleanup.
        if os.path.exists(self.directory):
            tools.fail('%s already exists' % self.directory)

        create_cmd = ['mkdir', '-p', self.directory]
        delete_cmd = ['rm', '-r', self.directory]
        utils.execute(create_cmd, run_as_root=True)
        self.addCleanup(utils.execute, delete_cmd, run_as_root=True)
Exemplo n.º 14
0
 def test_arp_spoof_blocks_request(self):
     # this will prevent the source from sending an ARP
     # request with its own address
     self._setup_arp_spoof_for_port(self.src_p.name, ["192.168.0.3"])
     self.src_p.addr.add("%s/24" % self.src_addr)
     self.dst_p.addr.add("%s/24" % self.dst_addr)
     ns_ip_wrapper = ip_lib.IPWrapper(self.src_namespace)
     try:
         ns_ip_wrapper.netns.execute(["arping", "-I", self.src_p.name, "-c1", self.dst_addr])
         tools.fail("arping should have failed. The arp request should " "have been blocked.")
     except RuntimeError:
         pass
Exemplo n.º 15
0
def increment_ip_cidr(ip_cidr, offset=1):
    """Increment ip_cidr offset times.

    example: increment_ip_cidr("1.2.3.4/24", 2) ==> "1.2.3.6/24"
    """
    net0 = netaddr.IPNetwork(ip_cidr)
    net = netaddr.IPNetwork(ip_cidr)
    net.value += offset
    if not net0.network < net.ip < net0[-1]:
        tools.fail(
            'Incorrect ip_cidr,offset tuple (%s,%s): "incremented" ip_cidr is '
            'outside ip_cidr' % (ip_cidr, offset))
    return str(net)
Exemplo n.º 16
0
def increment_ip_cidr(ip_cidr, offset=1):
    """Increment ip_cidr offset times.

    example: increment_ip_cidr("1.2.3.4/24", 2) ==> "1.2.3.6/24"
    """
    net0 = netaddr.IPNetwork(ip_cidr)
    net = netaddr.IPNetwork(ip_cidr)
    net.value += offset
    if not net0.network < net.ip < net0.broadcast:
        tools.fail(
            'Incorrect ip_cidr,offset tuple (%s,%s): "incremented" ip_cidr is ' "outside ip_cidr" % (ip_cidr, offset)
        )
    return str(net)
Exemplo n.º 17
0
 def test_arp_spoof_blocks_request(self):
     # this will prevent the source from sending an ARP
     # request with its own address
     self._setup_arp_spoof_for_port(self.src_p.name, ['192.168.0.3'])
     self.src_p.addr.add('%s/24' % self.src_addr)
     self.dst_p.addr.add('%s/24' % self.dst_addr)
     ns_ip_wrapper = ip_lib.IPWrapper(self.src_namespace)
     try:
         ns_ip_wrapper.netns.execute(['arping', '-I', self.src_p.name,
                                      '-c1', self.dst_addr])
         tools.fail("arping should have failed. The arp request should "
                    "have been blocked.")
     except RuntimeError:
         pass
Exemplo n.º 18
0
 def allocate_port(self):
     try:
         return self.unallocated_ports.pop()
     except KeyError:
         tools.fail('All FakeBridge ports (%s) are already allocated.' %
                    len(self.ports))
Exemplo n.º 19
0
def set_namespace_gateway(port_dev, gateway_ip):
    """Set gateway for the namespace associated to the port."""
    if not port_dev.namespace:
        tools.fail("tests should not change test machine gateway")
    port_dev.route.add_gateway(gateway_ip)
Exemplo n.º 20
0
 def allocate_port(self):
     try:
         return self.unallocated_ports.pop()
     except KeyError:
         tools.fail("All FakeBridge ports (%s) are already allocated." % len(self.ports))
Exemplo n.º 21
0
def set_namespace_gateway(port_dev, gateway_ip):
    """Set gateway for the namespace associated to the port."""
    if not port_dev.namespace:
        tools.fail('tests should not change test machine gateway')
    port_dev.route.add_gateway(gateway_ip)