Пример #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 = base.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 = base.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)
Пример #2
0
 def generate_device_details(self, name=None, ip_cidr=None,
                             mac_address=None, namespace=None):
     return Device(name or base.get_rand_name(),
                   ip_cidr or '240.0.0.1/24',
                   mac_address or
                   utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or base.get_rand_name())
Пример #3
0
 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or base.get_rand_name(),
                   ip_cidrs or ["%s/24" % TEST_IP],
                   mac_address or
                   utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or base.get_rand_name())
Пример #4
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 = base.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 = base.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)
Пример #5
0
 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or base.get_rand_name(),
                   ip_cidrs or ['240.0.0.1/24'],
                   mac_address or
                   utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or base.get_rand_name())
Пример #6
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 = base.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 = base.get_rand_name(prefix=net_helpers.PORT_PREFIX)
        br.add_port(port_name)
        self.ovs.set_db_attribute('Port', port_name, 'tag', 42)
        tags = self.ovs.ovsdb.db_list('Port', columns=['tag']).execute()
        # 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 if t['tag'] != []]
        self.assertTrue(tags_present)
        tags_42 = [t for t in tags_present if t['tag'] == 42]
        single_value = self.ovs.ovsdb.db_find(
            'Port', ('tag', '=', 42), columns=['tag']).execute()
        self.assertEqual(tags_42, single_value)
        len_0_list = self.ovs.ovsdb.db_find(
            'Port', ('tag', '!=', []), columns=['tag']).execute()
        self.assertEqual(tags_present, len_0_list)
Пример #7
0
 def create_ovs_vif_port(self, iface_id=None, mac=None,
                         iface_field='iface-id'):
     if iface_id is None:
         iface_id = base.get_rand_name()
     if mac is None:
         mac = base.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)
Пример #8
0
 def create_ovs_vif_port(self, iface_id=None, mac=None,
                         iface_field='iface-id'):
     if iface_id is None:
         iface_id = base.get_rand_name()
     if mac is None:
         mac = base.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)
Пример #9
0
 def create_ovs_vif_port(self, iface_id=None, mac=None,
                         iface_field='iface-id'):
     if iface_id is None:
         iface_id = base.get_rand_name()
     if mac is None:
         mac = base.get_rand_name()
     attrs = {
         'external_ids:%s' % iface_field: iface_id,
         'external_ids:attached-mac': mac
     }
     port_name, ofport = self.create_ovs_port(*attrs.items())
     return ovs_lib.VifPort(port_name, ofport, iface_id, mac, self.br)
Пример #10
0
 def create_ovs_vif_port(self,
                         iface_id=None,
                         mac=None,
                         iface_field='iface-id'):
     if iface_id is None:
         iface_id = base.get_rand_name()
     if mac is None:
         mac = base.get_rand_name()
     attrs = {
         'external_ids:%s' % iface_field: iface_id,
         'external_ids:attached-mac': mac
     }
     port_name, ofport = self.create_ovs_port(*attrs.items())
     return ovs_lib.VifPort(port_name, ofport, iface_id, mac, self.br)
Пример #11
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 = base.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                      prefix='br-int')
     self.br_tun = base.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                      prefix='br-tun')
     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)
Пример #12
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 = base.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                      prefix='br-int')
     self.br_tun = base.get_rand_name(n_const.DEVICE_NAME_MAX_LEN,
                                      prefix='br-tun')
     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)
Пример #13
0
 def test_bridge_lifecycle_baseovs(self):
     name = base.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))
Пример #14
0
 def test_bridge_lifecycle_baseovs(self):
     name = base.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))
Пример #15
0
 def test_dummy_exists(self):
     namespace = self.useFixture(net_helpers.NamespaceFixture())
     dev_name = base.get_rand_name()
     device = namespace.ip_wrapper.add_dummy(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)
Пример #16
0
 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': utils.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': base.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
Пример #17
0
 def test_bridge_lifecycle_ovsbridge(self):
     name = base.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))
Пример #18
0
 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': utils.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': base.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
Пример #19
0
 def test_bridge_lifecycle_ovsbridge(self):
     name = base.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))
Пример #20
0
    def setUp(self):
        super(IpsetBase, self).setUp()

        self.src_ns, self.dst_ns = self.prepare_veth_pairs()
        self.ipset_name = base.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(self.dst_ns,
                                                        self.ipset_name)
        self.addCleanup(self.ipset._destroy, self.ipset_name)
        self.dst_iptables = iptables_manager.IptablesManager(
            namespace=self.dst_ns.namespace)

        self._add_iptables_ipset_rules()
        self.addCleanup(self._remove_iptables_ipset_rules)
        self.pinger = helpers.Pinger(self.src_ns)
Пример #21
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 = base.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)