Exemplo n.º 1
0
    def test_db_find_column_type_list(self):
        """Fixate output for vsctl/native ovsdb_interface.

        Makes sure that db_find search queries give the same result for both
        implementations.
        """
        bridge_name = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
        self.addCleanup(self.ovs.delete_bridge, bridge_name)
        br = self.ovs.add_bridge(bridge_name)
        port_name = utils.get_rand_name(prefix=net_helpers.PORT_PREFIX)
        br.add_port(port_name)
        self.ovs.set_db_attribute('Port', port_name, 'tag', 42)

        # wrap list/find in transaction so we get a single isolated snapshot
        with self.ovs.ovsdb.transaction(check_error=True) as txn:
            tags = txn.add(self.ovs.ovsdb.db_list('Port', columns=['tag']))
            len_0_list = txn.add(self.ovs.ovsdb.db_find(
                    'Port', ('tag', '!=', []), columns=['tag']))
            single_value = txn.add(self.ovs.ovsdb.db_find(
                    'Port', ('tag', '=', 42), columns=['tag']))

        # Make sure that there is data to query.
        # It should be, but let's be a little paranoid here as otherwise
        # the test has no sense
        tags_present = [t for t in tags.result if t['tag'] != []]
        self.assertTrue(tags_present)
        tags_42 = [t for t in tags_present if t['tag'] == 42]
        self.assertEqual(tags_42, single_value.result)
        self.assertItemsEqual(len_0_list.result, tags_present)
Exemplo n.º 2
0
 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or utils.get_rand_name(),
                   ip_cidrs or ["%s/24" % TEST_IP],
                   mac_address or
                   net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or utils.get_rand_name())
Exemplo n.º 3
0
 def create_ovs_vif_port(self, iface_id=None, mac=None,
                         iface_field='iface-id'):
     if iface_id is None:
         iface_id = utils.get_rand_name()
     if mac is None:
         mac = utils.get_rand_name()
     attrs = ('external_ids', {iface_field: iface_id, 'attached-mac': mac})
     port_name, ofport = self.create_ovs_port(attrs)
     return ovs_lib.VifPort(port_name, ofport, iface_id, mac, self.br)
Exemplo n.º 4
0
    def test_macvtap_exists(self):
        namespace = self.useFixture(net_helpers.NamespaceFixture())
        src_dev_name = utils.get_rand_name()
        src_dev = namespace.ip_wrapper.add_dummy(src_dev_name)
        self.addCleanup(self._safe_delete_device, src_dev)

        dev_name = utils.get_rand_name()
        device = namespace.ip_wrapper.add_macvtap(dev_name, src_dev_name)
        self.addCleanup(self._safe_delete_device, device)

        self._check_for_device_name(namespace.ip_wrapper, dev_name, True)
        device.link.delete()
        self._check_for_device_name(namespace.ip_wrapper, dev_name, False)
Exemplo n.º 5
0
    def _setUp(self):
        self.user = common_utils.get_rand_name(prefix='user')
        self.password = common_utils.get_rand_name(prefix='pass')
        self.vhost = common_utils.get_rand_name(prefix='vhost')

        self._execute('add_user', self.user, self.password)
        self.addCleanup(self._execute, 'delete_user', self.user)

        self._execute('add_vhost', self.vhost)
        self.addCleanup(self._execute, 'delete_vhost', self.vhost)

        self._execute('set_permissions', '-p', self.vhost, self.user,
                      '.*', '.*', '.*')
Exemplo n.º 6
0
    def create_network(self, tenant_id, name=None, external=False):
        resource_type = 'network'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external
        return self._create_resource(resource_type, spec)
Exemplo n.º 7
0
def create_resource(prefix, creation_func, *args, **kwargs):
    """Create a new resource that does not already exist.

    If prefix isn't 'max_length' in size, a random suffix is concatenated to
    ensure it is random. Otherwise, 'prefix' is used as is.

    :param prefix: The prefix for a randomly generated name
    :param creation_func: A function taking the name of the resource
           to be created as it's first argument.  An error is assumed
           to indicate a name collision.
    :param *args *kwargs: These will be passed to the create function.
    """

    # Don't generate a random name if prefix is already full-length.
    if len(prefix) == n_const.DEVICE_NAME_MAX_LEN:
        return creation_func(prefix, *args, **kwargs)

    while True:
        name = utils.get_rand_name(
            max_length=n_const.DEVICE_NAME_MAX_LEN,
            prefix=prefix)
        try:
            return creation_func(name, *args, **kwargs)
        except RuntimeError:
            pass
Exemplo n.º 8
0
    def test_do_main_default_options(self):
        int_br = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.conf.set_override("ovs_integration_bridge", int_br.br_name)
        self.conf.set_override("ovs_all_ports", False)

        noskip = collections.defaultdict(list)
        skip = collections.defaultdict(list)
        # add two vifs, one skipped, and a non-vif port to int_br
        for collection in (noskip, skip):
            collection[int_br].append(
                self.useFixture(net_helpers.OVSPortFixture(int_br)).port.name)
        # set skippable vif to be skipped
        int_br.ovsdb.db_set(
            'Interface', skip[int_br][0],
            ('external_ids', {constants.SKIP_CLEANUP: "True"})
        ).execute(check_error=True)
        device_name = utils.get_rand_name()
        skip[int_br].append(device_name)
        int_br.add_port(device_name, ('type', 'internal'))
        # sanity check
        for collection in (noskip, skip):
            for bridge, ports in collection.items():
                port_list = bridge.get_port_name_list()
                for port in ports:
                    self.assertIn(port, port_list)
        ovs_cleanup.do_main(self.conf)
        ports = int_br.get_port_name_list()
        for vif in noskip[int_br]:
            self.assertNotIn(vif, ports)
        for port in skip[int_br]:
            self.assertIn(port, ports)
Exemplo n.º 9
0
    def create_security_group(self, tenant_id, name=None):
        resource_type = 'security_group'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}

        return self._create_resource(resource_type, spec)
Exemplo n.º 10
0
    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        device_mtu = 1450

        # Create a new OVS bridge
        ovs_bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.assertFalse(ovs_bridge.get_port_name_list())

        # Add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(
            net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(device_mtu - 1)
        ovs_bridge.add_port(lb_bridge_port.port.name)

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        device_name = utils.get_rand_name()
        mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=ovs_bridge.br_name,
                            namespace=namespace,
                            mtu=device_mtu)

        self.assertIn(device_name, ovs_bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
        self.assertEqual(
            device_mtu,
            ip_lib.IPDevice(device_name, namespace=namespace).link.mtu
        )
Exemplo n.º 11
0
 def test_bridge_lifecycle_baseovs(self):
     name = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
     self.addCleanup(self.ovs.delete_bridge, name)
     br = self.ovs.add_bridge(name)
     self.assertEqual(br.br_name, name)
     self.assertTrue(self.ovs.bridge_exists(name))
     self.ovs.delete_bridge(name)
     self.assertFalse(self.ovs.bridge_exists(name))
Exemplo n.º 12
0
 def test_db_add_to_new_object(self):
     ovsdb = self.ovs.ovsdb
     brname = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
     br = ovs_lib.OVSBridge(brname)  # doesn't create
     self.addCleanup(br.destroy)
     with ovsdb.transaction(check_error=True) as txn:
         txn.add(ovsdb.add_br(brname))
         txn.add(ovsdb.db_add('Bridge', brname, 'protocols', 'OpenFlow10'))
Exemplo n.º 13
0
    def test_set_link_alias(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        alias = utils.get_rand_name()

        device.link.set_alias(alias)

        self.assertEqual(alias, device.link.alias)
Exemplo n.º 14
0
    def test_set_mtu(self):
        device_name = utils.get_rand_name()
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self._test_mtu_set_after_action(
            device_name, self.bridge_name, namespace,
            functools.partial(
                self.interface.set_mtu,
                device_name=device_name, namespace=namespace))
Exemplo n.º 15
0
    def test_db_add_ref(self):
        ovsdb = self.ovs.ovsdb
        brname = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
        br = ovs_lib.OVSBridge(brname)  # doesn't create
        self.addCleanup(br.destroy)
        with ovsdb.transaction(check_error=True) as txn:
            br = txn.add(ovsdb.db_create('Bridge', name=brname))
            txn.add(ovsdb.db_add('Open_vSwitch', '.', 'bridges', br))

        self.assertIn(brname, self.ovs.get_bridges())
Exemplo n.º 16
0
    def create_router(self, tenant_id, name=None, ha=False,
                      external_network=None):
        resource_type = 'router'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
        if external_network:
            spec['external_gateway_info'] = {"network_id": external_network}

        return self._create_resource(resource_type, spec)
 def setUp(self):
     super(TestKeepalivedStateChange, self).setUp()
     self.conf_fixture = self.useFixture(fixture_config.Config())
     kd.register_l3_agent_keepalived_opts(self.conf_fixture)
     self.router_id = uuidutils.generate_uuid()
     self.conf_dir = self.get_default_temp_dir().path
     self.cidr = '169.254.128.1/24'
     self.interface_name = utils.get_rand_name()
     self.monitor = keepalived_state_change.MonitorDaemon(
         self.get_temp_file_path('monitor.pid'),
         self.router_id,
         1,
         2,
         utils.get_rand_name(),
         self.conf_dir,
         self.interface_name,
         self.cidr)
     mock.patch.object(self.monitor, 'notify_agent').start()
     self.line = '1: %s    inet %s' % (self.interface_name, self.cidr)
Exemplo n.º 18
0
 def setUp(self):
     super(OVSAgentTestFramework, self).setUp()
     agent_rpc = ('neutron.plugins.ml2.drivers.openvswitch.agent.'
                  'ovs_neutron_agent.OVSPluginApi')
     mock.patch(agent_rpc).start()
     mock.patch('neutron.agent.rpc.PluginReportStateAPI').start()
     self.br_int = utils.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                       prefix='br-int')
     self.br_tun = utils.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                       prefix='br-tun')
     self.br_phys = utils.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                        prefix='br-phys')
     patch_name_len = n_const.DEVICE_NAME_MAX_LEN - len("-patch-tun")
     self.patch_tun = "%s-patch-tun" % self.br_int[patch_name_len:]
     self.patch_int = "%s-patch-int" % self.br_tun[patch_name_len:]
     self.ovs = ovs_lib.BaseOVS()
     self.config = self._configure_agent()
     self.driver = interface.OVSInterfaceDriver(self.config)
     self.namespace = self.useFixture(net_helpers.NamespaceFixture()).name
Exemplo n.º 19
0
 def test_bridge_lifecycle_ovsbridge(self):
     name = utils.get_rand_name(prefix=net_helpers.BR_PREFIX)
     br = ovs_lib.OVSBridge(name)
     self.assertEqual(br.br_name, name)
     # Make sure that instantiating an OVSBridge does not actually create
     self.assertFalse(self.ovs.bridge_exists(name))
     self.addCleanup(self.ovs.delete_bridge, name)
     br.create()
     self.assertTrue(self.ovs.bridge_exists(name))
     br.destroy()
     self.assertFalse(self.ovs.bridge_exists(name))
Exemplo n.º 20
0
 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': net.get_random_mac(
                 'fa:16:3e:00:00:00'.split(':')),
             'fixed_ips': [{
                 'ip_address': '10.%d.%d.%d' % (
                      random.randint(3, 254),
                      random.randint(3, 254),
                      random.randint(3, 254))}],
             'vif_name': utils.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
Exemplo n.º 21
0
    def test_veth_exists(self):
        namespace1 = self.useFixture(net_helpers.NamespaceFixture())
        namespace2 = self.useFixture(net_helpers.NamespaceFixture())
        dev_name1 = utils.get_rand_name()
        dev_name2 = utils.get_rand_name()

        device1, device2 = namespace1.ip_wrapper.add_veth(
            dev_name1, dev_name2, namespace2.name)
        self.addCleanup(self._safe_delete_device, device1)
        self.addCleanup(self._safe_delete_device, device2)

        self._check_for_device_name(namespace1.ip_wrapper, dev_name1, True)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name2, True)
        self._check_for_device_name(namespace1.ip_wrapper, dev_name2, False)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name1, False)

        # As it is veth pair, remove of device1 should be enough to remove
        # both devices
        device1.link.delete()
        self._check_for_device_name(namespace1.ip_wrapper, dev_name1, False)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name2, False)
Exemplo n.º 22
0
    def test_veth_exists(self):
        namespace1 = self.useFixture(net_helpers.NamespaceFixture())
        namespace2 = self.useFixture(net_helpers.NamespaceFixture())
        dev_name1 = utils.get_rand_name()
        dev_name2 = utils.get_rand_name()

        device1, device2 = namespace1.ip_wrapper.add_veth(
            dev_name1, dev_name2, namespace2.name)
        self.addCleanup(self._safe_delete_device, device1)
        self.addCleanup(self._safe_delete_device, device2)

        self._check_for_device_name(namespace1.ip_wrapper, dev_name1, True)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name2, True)
        self._check_for_device_name(namespace1.ip_wrapper, dev_name2, False)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name1, False)

        # As it is veth pair, remove of device1 should be enough to remove
        # both devices
        device1.link.delete()
        self._check_for_device_name(namespace1.ip_wrapper, dev_name1, False)
        self._check_for_device_name(namespace2.ip_wrapper, dev_name2, False)
Exemplo n.º 23
0
    def _flush_neigh(self, version, ip_to_flush, ips_expected):
        attr = self.generate_device_details(
            ip_cidrs=['%s/24' % TEST_IP, 'fd00::1/64'],
            namespace=utils.get_rand_name(20, 'ns-'))
        device = self.manage_device(attr)
        for test_ip, nud_state in TEST_IP_NUD_STATES:
            mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
            device.neigh.add(test_ip, mac_address, nud_state)

        device.neigh.flush(version, ip_to_flush)
        ips = {e['dst'] for e in device.neigh.dump(version)}
        self.assertEqual(ips_expected, ips)
Exemplo n.º 24
0
    def test_get_device_mac_too_long_name(self):
        name = utils.get_rand_name(
            max_length=constants.DEVICE_NAME_MAX_LEN + 5)
        attr = self.generate_device_details(name=name)
        device = self.manage_device(attr)

        mac_address = ip_lib.get_device_mac(attr.name,
                                            namespace=attr.namespace)

        self.assertEqual(attr.mac_address, mac_address)

        device.link.delete()
Exemplo n.º 25
0
    def test_get_device_mac_too_long_name(self):
        name = utils.get_rand_name(max_length=constants.DEVICE_NAME_MAX_LEN +
                                   5)
        attr = self.generate_device_details(name=name)
        device = self.manage_device(attr)

        mac_address = ip_lib.get_device_mac(attr.name,
                                            namespace=attr.namespace)

        self.assertEqual(attr.mac_address, mac_address)

        device.link.delete()
Exemplo n.º 26
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = common_utils.get_rand_name(LB_DEVICE_NAME_MAX_LEN,
                                               PORT_PREFIX)

        if self.hybrid_plug:
            self.hybrid_plug_port(port_name)
        else:
            self.plug_port(port_name)
Exemplo n.º 27
0
    def create_router(self,
                      tenant_id,
                      name=None,
                      ha=False,
                      external_network=None):
        resource_type = 'router'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
        if external_network:
            spec['external_gateway_info'] = {"network_id": external_network}

        return self._create_resource(resource_type, spec)
Exemplo n.º 28
0
    def test_set_link_name(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        ip_wrapper = ip_lib.IPWrapper(namespace=device.namespace)
        original_name = device.name
        new_name = utils.get_rand_name()

        # device has to be DOWN to rename it
        device.link.set_down()
        device.link.set_name(new_name)

        self.assertEqual(new_name, device.name)
        self._check_for_device_name(ip_wrapper, new_name, True)
        self._check_for_device_name(ip_wrapper, original_name, False)
Exemplo n.º 29
0
 def test_network_lifecycle(self):
     net = self.client.create_network(name=utils.get_rand_name())
     listed_networks = {x.id: x.name for x in self.client.get_networks()}
     self.assertIn(net.id, listed_networks)
     self.assertEqual(listed_networks[net.id], net.name,
                      'Listed network name is not as expected.')
     updated_name = 'new %s' % net.name
     updated_net = self.client.update_network(net.id, name=updated_name)
     self.assertEqual(updated_name, updated_net.name,
                      'Updated network name is not as expected.')
     self.client.delete_network(net.id)
     with testtools.ExpectedException(self.client.NotFound,
                                      msg='Network was not deleted'):
         self.client.get_network(net.id)
Exemplo n.º 30
0
    def test_plug_succeeds(self):
        device_name = utils.get_rand_name()
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self.assertFalse(self.bridge.get_port_name_list())
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=self.bridge.br_name,
                            namespace=namespace)
        self.assertIn(device_name, self.bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
Exemplo n.º 31
0
    def test_plug_succeeds(self):
        device_name = utils.get_rand_name()
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self.assertFalse(self.bridge.get_port_name_list())
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=self.bridge.br_name,
                            namespace=namespace)
        self.assertIn(device_name, self.bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
Exemplo n.º 32
0
 def test_network_lifecycle(self):
     net = self.client.create_network(name=utils.get_rand_name())
     listed_networks = {x.id: x.name for x in self.client.get_networks()}
     self.assertIn(net.id, listed_networks)
     self.assertEqual(listed_networks[net.id], net.name,
                      'Listed network name is not as expected.')
     updated_name = 'new %s' % net.name
     updated_net = self.client.update_network(net.id, name=updated_name)
     self.assertEqual(updated_name, updated_net.name,
                      'Updated network name is not as expected.')
     self.client.delete_network(net.id)
     with testtools.ExpectedException(self.client.NotFound,
                                      msg='Network was not deleted'):
         self.client.get_network(net.id)
Exemplo n.º 33
0
    def test_set_link_name(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        ip_wrapper = ip_lib.IPWrapper(namespace=device.namespace)
        original_name = device.name
        new_name = utils.get_rand_name()

        # device has to be DOWN to rename it
        device.link.set_down()
        device.link.set_name(new_name)

        self.assertEqual(new_name, device.name)
        self._check_for_device_name(ip_wrapper, new_name, True)
        self._check_for_device_name(ip_wrapper, original_name, False)
Exemplo n.º 34
0
    def create_router(self, tenant_id, name=None, ha=False,
                      external_network=None, external_subnet=None):
        LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2))
        resource_type = 'router'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name, 'ha': ha}
        if external_network:
            spec['external_gateway_info'] = {"network_id": external_network}
            if external_subnet:
                spec['external_gateway_info']['external_fixed_ips'] = (
                    [{"subnet_id": external_subnet}])

        return self._create_resource(resource_type, spec)
Exemplo n.º 35
0
    def _setUp(self):
        super(OVSPortFixture, self)._setUp()

        # because in some tests this port can be used to providing connection
        # between linuxbridge agents and vlan_id can be also added to this
        # device name it has to be max LB_DEVICE_NAME_MAX_LEN long
        port_name = common_utils.get_rand_name(
            LB_DEVICE_NAME_MAX_LEN,
            PORT_PREFIX
        )

        if self.hybrid_plug:
            self.hybrid_plug_port(port_name)
        else:
            self.plug_port(port_name)
Exemplo n.º 36
0
 def test_ipv6_lla_create_and_get(self):
     lla_address = "fe80::f816:3eff:fe66:73bf/64"
     global_address = "2001::1/64"
     device_name = utils.get_rand_name()
     namespace = self.useFixture(net_helpers.NamespaceFixture())
     namespace.ip_wrapper.add_dummy(device_name)
     self.interface.add_ipv6_addr(
         device_name, lla_address, namespace.name, 'link')
     self.interface.add_ipv6_addr(
         device_name, global_address, namespace.name, 'global')
     existing_addresses = [
         a['cidr'] for a in self.interface.get_ipv6_llas(
             device_name, namespace.name)]
     self.assertIn(lla_address, existing_addresses)
     self.assertNotIn(global_address, existing_addresses)
Exemplo n.º 37
0
 def _create_test_port_dict(self):
     return {
         'id':
         uuidutils.generate_uuid(),
         'mac_address':
         net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
         'fixed_ips': [{
             'ip_address':
             '10.%d.%d.%d' % (random.randint(3, 254), random.randint(
                 3, 254), random.randint(3, 254))
         }],
         'vif_name':
         utils.get_rand_name(self.driver.DEV_NAME_LEN,
                             self.driver.DEV_NAME_PREFIX)
     }
Exemplo n.º 38
0
    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        # First, add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(1400)
        self.bridge.add_port(lb_bridge_port.port.name)

        device_name = utils.get_rand_name()
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        self._test_mtu_set_after_action(device_name, self.bridge_name,
                                        namespace)
Exemplo n.º 39
0
    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        # First, add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(
            net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(1400)
        self.bridge.add_port(lb_bridge_port.port.name)

        device_name = utils.get_rand_name()
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        self._test_mtu_set_after_action(
            device_name, self.bridge_name, namespace)
Exemplo n.º 40
0
    def create_network(self, tenant_id, name=None, external=False,
                       network_type=None, segmentation_id=None,
                       physical_network=None):
        resource_type = 'network'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external

        if segmentation_id is not None:
            spec['provider:segmentation_id'] = segmentation_id
        if network_type is not None:
            spec['provider:network_type'] = network_type
        if physical_network is not None:
            spec['provider:physical_network'] = physical_network

        return self._create_resource(resource_type, spec)
Exemplo n.º 41
0
    def create_network(self, tenant_id, name=None, external=False,
                       network_type=None, segmentation_id=None,
                       physical_network=None):
        resource_type = 'network'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external

        if segmentation_id is not None:
            spec['provider:segmentation_id'] = segmentation_id
        if network_type is not None:
            spec['provider:network_type'] = network_type
        if physical_network is not None:
            spec['provider:physical_network'] = physical_network

        return self._create_resource(resource_type, spec)
Exemplo n.º 42
0
    def setUp(self):
        super(IpsetBase, self).setUp()

        bridge = self.useFixture(net_helpers.VethBridgeFixture()).bridge
        self.source, self.destination = self.useFixture(
            machine_fixtures.PeerMachines(bridge)).machines

        self.ipset_name = utils.get_rand_name(MAX_IPSET_NAME_LENGTH, 'set-')
        self.icmp_accept_rule = (
            '-p icmp -m set --match-set %s src -j ACCEPT' % self.ipset_name)
        self.ipset = self._create_ipset_manager_and_set(
            ip_lib.IPWrapper(self.destination.namespace), self.ipset_name)
        self.addCleanup(self.ipset._destroy, self.ipset_name)
        self.dst_iptables = iptables_manager.IptablesManager(
            namespace=self.destination.namespace)

        self._add_iptables_ipset_rules()
        self.addCleanup(self._remove_iptables_ipset_rules)
Exemplo n.º 43
0
 def test_bridge_lifecycle_ovsbridge(self):
     name = six.text_type(utils.get_rand_name(prefix=net_helpers.BR_PREFIX))
     mac_table_size = 12345
     cfg.CONF.set_override('bridge_mac_table_size', mac_table_size)
     br = ovs_lib.OVSBridge(name)
     self.assertEqual(br.br_name, name)
     # Make sure that instantiating an OVSBridge does not actually create
     self.assertFalse(self.ovs.bridge_exists(name))
     self.addCleanup(self.ovs.delete_bridge, name)
     br.create()
     self.assertTrue(self.ovs.bridge_exists(name))
     br_other_config = self.ovs.ovsdb.db_find(
         'Bridge', ('name', '=', name),
         columns=['other_config']).execute()[0]['other_config']
     self.assertEqual(str(mac_table_size),
                      br_other_config['mac-table-size'])
     br.destroy()
     self.assertFalse(self.ovs.bridge_exists(name))
Exemplo n.º 44
0
    def setUp(self):
        super(IpsetBase, self).setUp()

        bridge = self.useFixture(net_helpers.VethBridgeFixture()).bridge
        self.source, self.destination = self.useFixture(
            machine_fixtures.PeerMachines(bridge)).machines

        self.ipset_name = utils.get_rand_name(MAX_IPSET_NAME_LENGTH, 'set-')
        self.icmp_accept_rule = ('-p icmp -m set --match-set %s src -j ACCEPT'
                                 % self.ipset_name)
        self.ipset = self._create_ipset_manager_and_set(
            ip_lib.IPWrapper(self.destination.namespace), self.ipset_name)
        self.addCleanup(self.ipset._destroy, self.ipset_name)
        self.dst_iptables = iptables_manager.IptablesManager(
            namespace=self.destination.namespace)

        self._add_iptables_ipset_rules()
        self.addCleanup(self._remove_iptables_ipset_rules)
Exemplo n.º 45
0
 def create_segment(self,
                    project_id,
                    network,
                    name,
                    network_type=None,
                    segmentation_id=None,
                    physical_network=None):
     resource_type = 'segment'
     name = name or utils.get_rand_name(prefix=resource_type)
     spec = {
         'project_id': project_id,
         'name': name,
         'network_id': network,
         'network_type': network_type,
         'physical_network': physical_network,
         'segmentation_id': segmentation_id
     }
     return self._create_resource(resource_type, spec)
Exemplo n.º 46
0
    def create_subnet(self, tenant_id, network_id,
                      cidr, gateway_ip=None, name=None, enable_dhcp=True,
                      ipv6_address_mode='slaac', ipv6_ra_mode='slaac'):
        resource_type = 'subnet'

        name = name or utils.get_rand_name(prefix=resource_type)
        ip_version = netaddr.IPNetwork(cidr).version
        spec = {'tenant_id': tenant_id, 'network_id': network_id, 'name': name,
                'cidr': cidr, 'enable_dhcp': enable_dhcp,
                'ip_version': ip_version}
        if ip_version == constants.IP_VERSION_6:
            spec['ipv6_address_mode'] = ipv6_address_mode
            spec['ipv6_ra_mode'] = ipv6_ra_mode

        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Exemplo n.º 47
0
    def create_subnet(self, tenant_id, network_id,
                      cidr, gateway_ip=None, name=None, enable_dhcp=True,
                      ipv6_address_mode='slaac', ipv6_ra_mode='slaac'):
        resource_type = 'subnet'

        name = name or utils.get_rand_name(prefix=resource_type)
        ip_version = netaddr.IPNetwork(cidr).version
        spec = {'tenant_id': tenant_id, 'network_id': network_id, 'name': name,
                'cidr': cidr, 'enable_dhcp': enable_dhcp,
                'ip_version': ip_version}
        if ip_version == constants.IP_VERSION_6:
            spec['ipv6_address_mode'] = ipv6_address_mode
            spec['ipv6_ra_mode'] = ipv6_ra_mode

        if gateway_ip:
            spec['gateway_ip'] = gateway_ip

        return self._create_resource(resource_type, spec)
Exemplo n.º 48
0
def create_patch_ports(source, destination):
    """Hook up two OVS bridges.

    The result is two patch ports, each end connected to a bridge.
    The two patch port names will start with 'patch-', followed by identical
    four characters. For example patch-xyzw-fedora, and patch-xyzw-ubuntu,
    where fedora and ubuntu are random strings.

    :param source: Instance of OVSBridge
    :param destination: Instance of OVSBridge
    """
    common = common_utils.get_rand_name(max_length=4, prefix='')
    prefix = '%s-%s-' % (PATCH_PREFIX, common)

    source_name = common_utils.get_rand_device_name(prefix=prefix)
    destination_name = common_utils.get_rand_device_name(prefix=prefix)

    source.add_patch_port(source_name, destination_name)
    destination.add_patch_port(destination_name, source_name)
Exemplo n.º 49
0
    def create_network(self, tenant_id, name=None, external=False,
                       network_type=None, segmentation_id=None,
                       physical_network=None, mtu=None):
        LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2))
        resource_type = 'network'

        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {'tenant_id': tenant_id, 'name': name}
        spec['router:external'] = external

        if segmentation_id is not None:
            spec['provider:segmentation_id'] = segmentation_id
        if network_type is not None:
            spec['provider:network_type'] = network_type
        if physical_network is not None:
            spec['provider:physical_network'] = physical_network
        if mtu is not None:
            spec['mtu'] = mtu

        return self._create_resource(resource_type, spec)
Exemplo n.º 50
0
    def create_subnetpool(self,
                          project_id,
                          name=None,
                          min_prefixlen=8,
                          max_prefixlen=24,
                          default_prefixlen=24,
                          prefixes=None):
        resource_type = 'subnetpool'
        name = name or utils.get_rand_name(prefix=resource_type)
        spec = {
            'project_id': project_id,
            'name': name,
            'min_prefixlen': min_prefixlen,
            'max_prefixlen': max_prefixlen,
            'default_prefixlen': default_prefixlen,
            'is_default': False,
            'shared': False,
            'prefixes': prefixes
        }

        return self._create_resource(resource_type, spec)
Exemplo n.º 51
0
    def create_subnet(self,
                      tenant_id,
                      network_id,
                      cidr=None,
                      gateway_ip=None,
                      name=None,
                      enable_dhcp=True,
                      ipv6_address_mode='slaac',
                      ipv6_ra_mode='slaac',
                      subnetpool_id=None,
                      ip_version=None,
                      host_routes=None):
        resource_type = 'subnet'

        name = name or utils.get_rand_name(prefix=resource_type)
        if cidr and not ip_version:
            ip_version = netaddr.IPNetwork(cidr).version
        spec = {
            'tenant_id': tenant_id,
            'network_id': network_id,
            'name': name,
            'enable_dhcp': enable_dhcp,
            'ip_version': ip_version
        }
        if ip_version == constants.IP_VERSION_6:
            spec['ipv6_address_mode'] = ipv6_address_mode
            spec['ipv6_ra_mode'] = ipv6_ra_mode

        if gateway_ip:
            spec['gateway_ip'] = gateway_ip
        if subnetpool_id:
            spec['subnetpool_id'] = subnetpool_id
        if cidr:
            spec['cidr'] = cidr
        if host_routes:
            spec['host_routes'] = host_routes

        return self._create_resource(resource_type, spec)
Exemplo n.º 52
0
def create_resource(prefix, creation_func, *args, **kwargs):
    """Create a new resource that does not already exist.

    If prefix isn't 'max_length' in size, a random suffix is concatenated to
    ensure it is random. Otherwise, 'prefix' is used as is.

    :param prefix: The prefix for a randomly generated name
    :param creation_func: A function taking the name of the resource
           to be created as it's first argument.  An error is assumed
           to indicate a name collision.
    :param *args *kwargs: These will be passed to the create function.
    """

    # Don't generate a random name if prefix is already full-length.
    if len(prefix) == n_const.DEVICE_NAME_MAX_LEN:
        return creation_func(prefix, *args, **kwargs)

    while True:
        name = utils.get_rand_name(max_length=n_const.DEVICE_NAME_MAX_LEN,
                                   prefix=prefix)
        try:
            return creation_func(name, *args, **kwargs)
        except RuntimeError:
            pass
Exemplo n.º 53
0
 def test_destroy_patch_ports_no_int_br(self):
     name = utils.get_rand_name(max_length=n_const.DEVICE_NAME_MAX_LEN)
     self.config.set_override('integration_bridge', name, "OVS")
     cleaner = destroy_patch_ports.PatchPortCleaner(self.config)
     cleaner.destroy_patch_ports()
Exemplo n.º 54
0
 def _generate_host(self):
     return utils.get_rand_name(prefix='host-')
Exemplo n.º 55
0
 def _generate_namespace_suffix(self):
     return utils.get_rand_name(prefix='test')
Exemplo n.º 56
0
 def _make_bridge(self):
     bridge = framework.get_ovs_bridge(utils.get_rand_name())
     bridge.create()
     self.addCleanup(bridge.destroy)
     return bridge
Exemplo n.º 57
0
 def _generate_temp_log_file(self, test_name):
     log_dir_path = os.path.join(fullstack_base.DEFAULT_LOG_DIR, test_name)
     if not os.path.exists(log_dir_path):
         os.mkdir(log_dir_path, 0o755)
     return '%s/%s.log' % (log_dir_path,
                           utils.get_rand_name(prefix="test-sg-"))
Exemplo n.º 58
0
 def _generate_namespace_suffix(self):
     LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2))
     return utils.get_rand_name(prefix='test')
Exemplo n.º 59
0
    def test_plug_multiple_calls_update_mtu(self):
        device_name = utils.get_rand_name()
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self._test_mtu_set_after_action(device_name, self.bridge_name,
                                        namespace)
Exemplo n.º 60
0
 def _generate_host(self):
     LOG.info('%s(): caller(): %s', log_utils.get_fname(1), log_utils.get_fname(2))
     return utils.get_rand_name(prefix='host-')