示例#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)
示例#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
示例#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
示例#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))
示例#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))
示例#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})
示例#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})
示例#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
示例#9
0
文件: base.py 项目: bgxavier/neutron
 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
示例#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}
        )
示例#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)
示例#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))
示例#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)
示例#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
示例#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)
示例#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)
示例#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
示例#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))
示例#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)
示例#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))
示例#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)