Exemplo n.º 1
0
    def test_process_deleted_networks(
        self, tenant_id="test_tenant", network_name="test_network",
        interface_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc'):

        LOG.debug("test_delete_vlan_bridge - START")
        new_network = (
            self._linuxbridge_plugin.create_network(tenant_id, network_name))
        new_port = self._linuxbridge_plugin.create_port(
            tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
        self._linuxbridge_plugin.plug_interface(
            tenant_id, new_network[lconst.NET_ID],
            new_port[lconst.PORT_ID], interface_id)
        bridge_name = self.br_name_prefix + new_network[lconst.NET_ID][0:11]
        vlan_bindings = {}
        vlan_bindings[new_network[lconst.NET_ID]] = (
            cdb.get_vlan_binding(new_network[lconst.NET_ID]))
        vlan_id = vlan_bindings[new_network[lconst.NET_ID]][lconst.VLANID]
        vlan_subinterface = self.physical_interface + '.' + str(vlan_id)

        self._linuxbridge_quantum_agent.linux_br.ensure_vlan_bridge(
            new_network[lconst.NET_ID], str(vlan_id))
        self.tearDownUnplugInterface(tenant_id, new_network[lconst.NET_ID],
                                     new_port[lconst.PORT_ID])
        vlan_bindings = {}
        self._linuxbridge_quantum_agent.process_deleted_networks(vlan_bindings)

        self.assertEquals(self.device_exists(vlan_subinterface), False)
        self.assertEquals(self.device_exists(bridge_name), False)
        LOG.debug("test_delete_vlan_bridge - END")
    def test_ensure_vlan_bridge(
                  self, tenant_id="test_tenant", network_name="test_network",
                  interface_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc'):

        LOG.debug("test_ensure_vlan_bridge - START")
        new_network =\
               self._linuxbridge_plugin.create_network(tenant_id, network_name)
        new_port = self._linuxbridge_plugin.create_port(
                         tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
        self._linuxbridge_plugin.plug_interface(
                         tenant_id, new_network[lconst.NET_ID],
                         new_port[lconst.PORT_ID], interface_id)
        bridge_name = self.br_name_prefix + new_network[lconst.NET_ID][0:11]
        vlan_bind = cdb.get_vlan_binding(new_network[lconst.NET_ID])
        vlan_id = vlan_bind[lconst.VLANID]
        vlan_subinterface = self.physical_interface + '.' + str(vlan_id)

        self._linuxbridge_quantum_agent.linux_br.ensure_vlan_bridge(
                         new_network[lconst.NET_ID], str(vlan_id))
        list_quantum_bridges = self._linuxbridge_quantum_agent.linux_br.\
                                    get_all_quantum_bridges()
        self.assertTrue(bridge_name in list_quantum_bridges)
        list_interface = self._linuxbridge_quantum_agent.linux_br.\
                              get_interfaces_on_bridge(bridge_name)
        self.assertTrue(vlan_subinterface in list_interface)

        for interface in list_interface:
            self._linuxbridge_quantum_agent.linux_br.remove_interface(
                                               bridge_name, interface)
            self.delete_device(interface)
        self.delete_bridge(bridge_name)
        self.tearDownUnplugInterface(tenant_id, new_network[lconst.NET_ID],
                                     new_port[lconst.PORT_ID])

        LOG.debug("test_ensure_vlan_bridge -END")
Exemplo n.º 3
0
 def delete_network(self, context, id):
     vlan_binding = cdb.get_vlan_binding(id)
     result = super(LinuxBridgePluginV2, self).delete_network(context, id)
     cdb.release_vlanid(vlan_binding["vlan_id"])
     if self.rpc:
         self.notifier.network_delete(self.context, id)
     return result
Exemplo n.º 4
0
 def update_port(self, context, id, port):
     if self.rpc:
         original_port = super(LinuxBridgePluginV2, self).get_port(context, id)
     port = super(LinuxBridgePluginV2, self).update_port(context, id, port)
     if self.rpc:
         if original_port["admin_state_up"] != port["admin_state_up"]:
             vlan_binding = cdb.get_vlan_binding(port["network_id"])
             self.notifier.port_update(self.context, port, vlan_binding["vlan_id"])
     return port
Exemplo n.º 5
0
 def get_vlan_binding(self, network_id):
     """Get a vlan binding"""
     vlan = []
     try:
         for vlan_bind in l2network_db.get_vlan_binding(network_id):
             LOG.debug("Getting vlan binding for vlan: %s" %
                       vlan_bind.vlan_id)
             vlan_dict = {}
             vlan_dict["vlan-id"] = str(vlan_bind.vlan_id)
             vlan_dict["net-id"] = str(vlan_bind.network_id)
             vlan.append(vlan_dict)
     except Exception, exc:
         LOG.error("Failed to get vlan binding: %s" % str(exc))
Exemplo n.º 6
0
    def test_process_unplugged_tap_interface(self, tenant_id="test_tenant",
                                             network_name="test_network",
                                             interface_id='fe701ddf-26a2-'
                                                          '42ea-b9e6-'
                                                          '7313d1c522cc',
                                             mac_address='fe:16:3e:51:60:dd'):

        LOG.debug("test_process_unplugged_tap_interface - START")
        new_network = (
            self._linuxbridge_plugin.create_network(tenant_id, network_name))
        new_port = self._linuxbridge_plugin.create_port(
            tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
        self._linuxbridge_plugin.plug_interface(
            tenant_id, new_network[lconst.NET_ID],
            new_port[lconst.PORT_ID], interface_id)
        bridge_name = self.br_name_prefix + new_network[lconst.NET_ID][0:11]
        self.create_bridge(bridge_name)
        device_name = self.tap_name_prefix + interface_id[0:11]
        self.create_device(device_name, mac_address)

        vlan_bind = cdb.get_vlan_binding(new_network[lconst.NET_ID])
        vlan_id = vlan_bind[lconst.VLANID]

        self._linuxbridge_quantum_agent.process_port_binding(
            new_port[lconst.PORT_ID], new_network[lconst.NET_ID],
            interface_id, str(vlan_id))
        list_interface = (self._linuxbridge_quantum_agent.linux_br.
                          get_interfaces_on_bridge(bridge_name))
        self._linuxbridge_plugin.unplug_interface(tenant_id,
                                                  new_network[lconst.NET_ID],
                                                  new_port[lconst.PORT_ID])
        plugged_interface = []
        self._linuxbridge_quantum_agent.process_unplugged_interfaces(
            plugged_interface)
        list_interface = (self._linuxbridge_quantum_agent.linux_br.
                          get_interfaces_on_bridge(bridge_name))
        self.assertFalse(device_name in list_interface)
        for interface in list_interface:
            self._linuxbridge_quantum_agent.linux_br.remove_interface(
                bridge_name, interface)
            self.delete_device(interface)
        self.delete_device(device_name)
        self.delete_bridge(bridge_name)
        self.tearDownNetworkPort(tenant_id, new_network[lconst.NET_ID],
                                 new_port[lconst.PORT_ID])

        LOG.debug("test_test_process_unplugged_tap_interface -END")
Exemplo n.º 7
0
    def test_remove_interface(self,
                              tenant_id="test_tenant",
                              network_name="test_network",
                              interface_id='fe701ddf-26a2-42ea-'
                              'b9e6-7313d1c522cc',
                              mac_address='fe:16:3e:51:60:dd'):

        LOG.debug("test_remove_interface - START")
        new_network = (self._linuxbridge_plugin.create_network(
            tenant_id, network_name))
        new_port = self._linuxbridge_plugin.create_port(
            tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
        self._linuxbridge_plugin.plug_interface(tenant_id,
                                                new_network[lconst.NET_ID],
                                                new_port[lconst.PORT_ID],
                                                interface_id)
        bridge_name = self.br_name_prefix + new_network[lconst.NET_ID][0:11]
        self.create_bridge(bridge_name)
        device_name = self.tap_name_prefix + interface_id[0:11]
        self.create_device(device_name, mac_address)

        vlan_bind = cdb.get_vlan_binding(new_network[lconst.NET_ID])
        vlan_id = vlan_bind[lconst.VLANID]

        self._linuxbridge_quantum_agent.process_port_binding(
            new_port[lconst.PORT_ID], new_network[lconst.NET_ID], interface_id,
            str(vlan_id))
        list_interface = (self._linuxbridge_quantum_agent.linux_br.
                          get_interfaces_on_bridge(bridge_name))

        self._linuxbridge_quantum_agent.linux_br.remove_interface(
            bridge_name, device_name)
        list_interface = (self._linuxbridge_quantum_agent.linux_br.
                          get_interfaces_on_bridge(bridge_name))
        self.assertFalse(device_name in list_interface)
        for interface in list_interface:
            self._linuxbridge_quantum_agent.linux_br.remove_interface(
                bridge_name, interface)
            self.delete_device(interface)
        self.delete_device(device_name)
        self.delete_bridge(bridge_name)
        self.tearDownUnplugInterface(tenant_id, new_network[lconst.NET_ID],
                                     new_port[lconst.PORT_ID])

        LOG.debug("test_remove_interface -END")
Exemplo n.º 8
0
 def get_device_details(self, context, **kwargs):
     """Agent requests device details"""
     agent_id = kwargs.get("agent_id")
     device = kwargs.get("device")
     LOG.debug("Device %s details requested from %s", device, agent_id)
     port = cdb.get_port_from_device(device[self.TAP_PREFIX_LEN :])
     if port:
         vlan_binding = cdb.get_vlan_binding(port["network_id"])
         entry = {
             "device": device,
             "vlan_id": vlan_binding["vlan_id"],
             "network_id": port["network_id"],
             "port_id": port["id"],
             "admin_state_up": port["admin_state_up"],
         }
         # Set the port status to UP
         cdb.set_port_status(port["id"], api_common.PORT_STATUS_UP)
     else:
         entry = {"device": device}
         LOG.debug("%s can not be found in database", device)
     return entry
Exemplo n.º 9
0
    def test_ensure_vlan_bridge(self,
                                tenant_id="test_tenant",
                                network_name="test_network",
                                interface_id='fe701ddf-26a2-42ea-'
                                'b9e6-7313d1c522cc'):

        LOG.debug("test_ensure_vlan_bridge - START")
        new_network = (self._linuxbridge_plugin.create_network(
            tenant_id, network_name))
        new_port = self._linuxbridge_plugin.create_port(
            tenant_id, new_network[lconst.NET_ID], lconst.PORT_UP)
        self._linuxbridge_plugin.plug_interface(tenant_id,
                                                new_network[lconst.NET_ID],
                                                new_port[lconst.PORT_ID],
                                                interface_id)
        bridge_name = self.br_name_prefix + new_network[lconst.NET_ID][0:11]
        vlan_bind = cdb.get_vlan_binding(new_network[lconst.NET_ID])
        vlan_id = vlan_bind[lconst.VLANID]
        vlan_subinterface = self.physical_interface + '.' + str(vlan_id)

        self._linuxbridge_quantum_agent.linux_br.ensure_vlan_bridge(
            new_network[lconst.NET_ID], str(vlan_id))
        list_quantum_bridges = (
            self._linuxbridge_quantum_agent.linux_br.get_all_quantum_bridges())
        self.assertTrue(bridge_name in list_quantum_bridges)
        list_interface = (self._linuxbridge_quantum_agent.linux_br.
                          get_interfaces_on_bridge(bridge_name))
        self.assertTrue(vlan_subinterface in list_interface)

        for interface in list_interface:
            self._linuxbridge_quantum_agent.linux_br.remove_interface(
                bridge_name, interface)
            self.delete_device(interface)
        self.delete_bridge(bridge_name)
        self.tearDownUnplugInterface(tenant_id, new_network[lconst.NET_ID],
                                     new_port[lconst.PORT_ID])

        LOG.debug("test_ensure_vlan_bridge -END")
Exemplo n.º 10
0
 def _release_vlan_for_tenant(self, tenant_id, net_id, **kwargs):
     """Release the ID"""
     vlan_binding = cdb.get_vlan_binding(net_id)
     return cdb.release_vlanid(vlan_binding[const.VLANID])
Exemplo n.º 11
0
 def delete_network(self, context, id):
     result = super(LinuxBridgePluginV2, self).delete_network(context, id)
     vlan_binding = cdb.get_vlan_binding(id)
     cdb.release_vlanid(vlan_binding['vlan_id'])
     return result
Exemplo n.º 12
0
 def _extend_network_dict(self, context, network):
     if self._check_provider_view_auth(context, network):
         vlan_binding = cdb.get_vlan_binding(network['id'])
         network['provider:vlan_id'] = vlan_binding['vlan_id']
Exemplo n.º 13
0
 def delete_network(self, context, id):
     vlan_binding = cdb.get_vlan_binding(id)
     cdb.release_vlanid(vlan_binding['vlan_id'])
     cdb.remove_vlan_binding(id)
     return super(LinuxBridgePluginV2, self).delete_network(context, id)
Exemplo n.º 14
0
 def _release_vlan_for_tenant(self, tenant_id, net_id, **kwargs):
     """Release the ID"""
     vlan_binding = cdb.get_vlan_binding(net_id)
     return cdb.release_vlanid(vlan_binding[const.VLANID])