示例#1
0
 def test_get_logical_switch_by_name(self):
     record_dict = self._get_logical_switch_dict()
     with self.ctx.session.begin(subtransactions=True):
         entry = self._create_logical_switch(record_dict, 'logical_switch2')
     record_dict['logical_switch_name'] = 'logical_switch2'
     result = lib.get_logical_switch_by_name(self.ctx, record_dict)
     self.assertEqual(entry, result)
示例#2
0
 def test_get_logical_switch_by_name(self):
     record_dict = self._get_logical_switch_dict()
     with self.ctx.session.begin(subtransactions=True):
         entry = self._create_logical_switch(record_dict,
                                             'logical_switch2')
     record_dict['logical_switch_name'] = 'logical_switch2'
     result = lib.get_logical_switch_by_name(self.ctx, record_dict)
     self.assertEqual(entry, result)
示例#3
0
 def _form_logical_switch_schema(self, context, network, ls_dict):
     logical_switch_uuid = None
     logical_switch = db.get_logical_switch_by_name(
         context, ls_dict)
     if logical_switch:
         logical_switch_uuid = logical_switch.get('uuid')
     logical_switch = self._get_dict(ovsdb_schema.LogicalSwitch(
         uuid=logical_switch_uuid,
         name=network['id'],
         key=network['provider:segmentation_id'],
         description=network['name']))
     return logical_switch
示例#4
0
 def _process_port_list(self,
                        context,
                        device,
                        gw_connection,
                        method,
                        gw_connection_ovsdb_set=None):
     port_dicts = []
     port_dict = {}
     logical_switch_uuid = None
     seg_id = gw_connection.get('segmentation_id', None)
     interfaces = self.service_plugin.get_l2gateway_interfaces_by_device_id(
         context, device['id'])
     LOG.debug("L2gwRpcDriver._process_port_list: ints=%s", interfaces)
     for interface in interfaces:
         interface_name = interface.get('interface_name')
         LOG.debug("L2gwRpcDriver._process_port_list: int_name=%s",
                   interface_name)
         physical_switch = db.get_physical_switch_by_name(
             context, device.get('device_name'))
         if not physical_switch:
             msg = _('The PHYSICAL SWITCH data not found in the server')
             raise Exception(msg)
         ovsdb_identifier = physical_switch.get('ovsdb_identifier')
         pp_dict = {
             'interface_name': interface_name,
             'ovsdb_identifier': ovsdb_identifier,
             'physical_switch_id': physical_switch.get('uuid'),
             'logical_switch_name': gw_connection.get('network_id')
         }
         logical_switch = db.get_logical_switch_by_name(context, pp_dict)
         if method == "DELETE":
             if not logical_switch:
                 msg = _('The LOGICAL SWITCH data not found in the server')
                 raise Exception(msg)
             if not (ovsdb_identifier in list(gw_connection_ovsdb_set)):
                 continue
         if logical_switch:
             logical_switch_uuid = logical_switch.get('uuid')
         ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict)
         if not ps_port:
             msg = _('The PHYSICAL PORT data not found in the server')
             raise Exception(msg)
         pp_dict['uuid'] = ps_port.get('uuid')
         pp_dict['name'] = ps_port.get('name')
         LOG.debug("L2gwRpcDriver._process_port_list: pp_dict.name=%s",
                   pp_dict['name'])
         port_dict = self._generate_port_list(context, method, seg_id,
                                              interface, pp_dict,
                                              logical_switch_uuid,
                                              gw_connection)
         port_dicts.append(port_dict)
     return ovsdb_identifier, logical_switch, port_dicts
示例#5
0
 def _process_port_list(self, context, device,
                        gw_connection, method,
                        gw_connection_ovsdb_set=None):
     port_dicts = []
     port_dict = {}
     logical_switch_uuid = None
     seg_id = gw_connection.get('segmentation_id', None)
     interfaces = self.service_plugin.get_l2gateway_interfaces_by_device_id(
         context, device['id'])
     LOG.debug("L2gwRpcDriver._process_port_list: ints=%s",
               interfaces)
     for interface in interfaces:
         interface_name = interface.get('interface_name')
         LOG.debug("L2gwRpcDriver._process_port_list: int_name=%s",
                   interface_name)
         physical_switch = db.get_physical_switch_by_name(
             context, device.get('device_name'))
         if not physical_switch:
             msg = _('The PHYSICAL SWITCH data not found in the server')
             raise Exception(msg)
         ovsdb_identifier = physical_switch.get('ovsdb_identifier')
         pp_dict = {'interface_name': interface_name,
                    'ovsdb_identifier': ovsdb_identifier,
                    'physical_switch_id': physical_switch.get('uuid'),
                    'logical_switch_name': gw_connection.get(
                        'network_id')}
         logical_switch = db.get_logical_switch_by_name(
             context, pp_dict)
         if method == "DELETE":
             if not logical_switch:
                 msg = _('The LOGICAL SWITCH data not found in the server')
                 raise Exception(msg)
             if not (ovsdb_identifier in list(gw_connection_ovsdb_set)):
                 continue
         if logical_switch:
             logical_switch_uuid = logical_switch.get('uuid')
         ps_port = db.get_physical_port_by_name_and_ps(context, pp_dict)
         if not ps_port:
             msg = _('The PHYSICAL PORT data not found in the server')
             raise Exception(msg)
         pp_dict['uuid'] = ps_port.get('uuid')
         pp_dict['name'] = ps_port.get('name')
         LOG.debug("L2gwRpcDriver._process_port_list: pp_dict.name=%s",
                   pp_dict['name'])
         port_dict = self._generate_port_list(
             context, method, seg_id, interface, pp_dict,
             logical_switch_uuid, gw_connection)
         port_dicts.append(port_dict)
     return ovsdb_identifier, logical_switch, port_dicts
示例#6
0
    def delete_port_mac(self, context, port):
        """Process the deleted port and trigger the RPC

        to delete from the gateway.

        When the ML2 plugin invokes this call, the argument port is
        a single port dict, whereas the L2gateway service plugin
        sends it as a list of port dicts.
        """
        ls_dict = {}
        mac_list = []
        logical_switches = []
        ovsdb_identifier = None
        if isinstance(port, list):
            from_l2gw_plugin = True
            network_id = port[0].get('network_id')
            ovsdb_identifier = port[0].get('ovsdb_identifier')
            lg_dict = {'logical_switch_name': network_id,
                       'ovsdb_identifier': ovsdb_identifier}
            logical_switch = db.get_logical_switch_by_name(
                context, lg_dict)
            logical_switches.append(logical_switch)
            port_list = port
        else:
            from_l2gw_plugin = False
            network_id = port.get('network_id')
            logical_switches = (
                db.get_all_logical_switches_by_name(
                    context, network_id))
            l2gateway_connections = self.get_l2_gateway_connections(
                context, filters={'network_id': [network_id]})
            if not l2gateway_connections:
                return
            port_list = [port]
        for port_dict in port_list:
            if port_dict['device_owner']:
                if logical_switches:
                    for logical_switch in logical_switches:
                        logical_switch_uuid = logical_switch.get('uuid')
                        mac = port_dict.get("mac_address")
                        if port_dict.get('ovsdb_identifier', None):
                            ovsdb_identifier = port_dict.get(
                                'ovsdb_identifier')
                        else:
                            ovsdb_identifier = logical_switch.get(
                                'ovsdb_identifier')
                        record_dict = {'mac': mac,
                                       'logical_switch_uuid':
                                       logical_switch_uuid,
                                       'ovsdb_identifier': ovsdb_identifier}
                        rec_dict = {'logical_switch_id': logical_switch_uuid,
                                    'ovsdb_identifier': ovsdb_identifier}
                        if len(db.get_all_vlan_bindings_by_logical_switch(
                               context, rec_dict)) > 1:
                            if from_l2gw_plugin:
                                ls = logical_switch.get('name')
                                l2gateway_connections = (
                                    self.get_l2_gateway_connections(
                                        context, filters={'network_id': [ls]}))
                                if len(l2gateway_connections) > 1:
                                    continue
                        ucast_mac_remote = (
                            db.get_ucast_mac_remote_by_mac_and_ls(
                                context, record_dict))
                        del_count = 0
                        if not ucast_mac_remote:
                            LOG.debug("delete_port_mac: MAC %s does"
                                      " not exist", mac)
                            # It is possible that this MAC is present
                            # in the pending_ucast_mac_remote table.
                            # Delete this MAC as it was not inserted
                            # into the OVSDB server earlier.
                            del_count = db.delete_pending_ucast_mac_remote(
                                context, 'insert',
                                ovsdb_identifier,
                                logical_switch_uuid,
                                mac)
                        if not del_count:
                            mac_list = ls_dict.get(logical_switch_uuid, [])
                            mac_list.append(mac)
                            ls_dict[logical_switch_uuid] = mac_list
                else:
                    LOG.debug("delete_port_mac:Logical Switch %s "
                              "does not exist ", port_dict.get('network_id'))
                    return
        for logical_switch_uuid, mac_list in ls_dict.items():
            try:
                if mac_list:
                    self.agent_rpc.delete_vif_from_gateway(context,
                                                           ovsdb_identifier,
                                                           logical_switch_uuid,
                                                           mac_list)
            except messaging.MessagingTimeout:
                # If RPC is timed out, then the RabbitMQ
                # will retry the operation.
                LOG.exception(_LE("Communication error with "
                                  "the L2 gateway agent"))
            except Exception as ex:
                # The remote OVSDB server may be down.
                # We need to retry this operation later.
                LOG.debug("Exception occurred %s", str(ex))
                db.add_pending_ucast_mac_remote(
                    context, 'delete', ovsdb_identifier,
                    logical_switch_uuid,
                    None,
                    mac_list)