Beispiel #1
0
 def test_lsn_port_host_conf_lsn_port_not_found(self):
     with mock.patch.object(self.manager,
                            'lsn_port_get',
                            side_effect=p_exc.LsnPortNotFound(
                                lsn_id=self.lsn_id,
                                entity='subnet',
                                entity_id=self.sub_id)):
         self.assertRaises(p_exc.PortConfigurationError,
                           self.manager._lsn_port_host_conf, mock.ANY,
                           self.net_id, self.sub_id, mock.ANY, mock.Mock())
Beispiel #2
0
def lsn_port_get_for_subnet(context, subnet_id, raise_on_err=True):
    """Return Logical Service Node Port information given its subnet id."""
    with context.session.begin(subtransactions=True):
        try:
            return (context.session.query(LsnPort).filter_by(
                sub_id=subnet_id).one())
        except (orm.exc.NoResultFound, d_exc.DBError):
            if raise_on_err:
                raise p_exc.LsnPortNotFound(lsn_id=None,
                                            entity='subnet',
                                            entity_id=subnet_id)
Beispiel #3
0
def lsn_port_get_for_mac(context, mac_address, raise_on_err=True):
    """Return Logical Service Node Port information given its mac address."""
    with context.session.begin(subtransactions=True):
        try:
            return (context.session.query(LsnPort).filter_by(
                mac_addr=mac_address).one())
        except (orm.exc.NoResultFound, d_exc.DBError):
            if raise_on_err:
                raise p_exc.LsnPortNotFound(lsn_id=None,
                                            entity='mac',
                                            entity_id=mac_address)
Beispiel #4
0
 def _test_subnet_update_lsn_port_not_found(self, dhcp_port):
     subnet = {
         'id': 'foo_subnet_id',
         'enable_dhcp': True,
         'network_id': 'foo_network_id',
         'tenant_id': 'foo_tenant_id'
     }
     self.lsn_manager.lsn_port_get.side_effect = (p_exc.LsnPortNotFound(
         lsn_id='foo_lsn_id', entity='subnet', entity_id=subnet['id']))
     self.notifier.plugin.get_ports.return_value = dhcp_port
     count = 0 if dhcp_port is None else 1
     with mock.patch.object(nvp, 'handle_port_dhcp_access') as h:
         self.notifier.notify(mock.ANY, {'subnet': subnet},
                              'subnet.update.end')
         self.assertEqual(count, h.call_count)
         if not dhcp_port:
             self._test_subnet_create(enable_dhcp=True,
                                      exc=None,
                                      call_notify=False)
Beispiel #5
0
 def lsn_port_get_by_mac(self, context, network_id, mac, raise_on_err=True):
     """Retrieve LSN and LSN port given network and mac address."""
     lsn_id = self.lsn_get(context, network_id, raise_on_err=raise_on_err)
     if lsn_id:
         try:
             lsn_port_id = lsn_api.lsn_port_by_mac_get(
                 self.cluster, lsn_id, mac)
         except (n_exc.NotFound, nvplib.NvpApiClient.NvpApiException):
             logger = raise_on_err and LOG.error or LOG.warn
             logger(_('Unable to find Logical Service Node Port for '
                      'LSN %(lsn_id)s and mac address %(mac)s')
                    % {'lsn_id': lsn_id, 'mac': mac})
             if raise_on_err:
                 raise p_exc.LsnPortNotFound(lsn_id=lsn_id,
                                             entity='MAC',
                                             entity_id=mac)
             return (lsn_id, None)
         else:
             return (lsn_id, lsn_port_id)
     else:
         return (None, None)
Beispiel #6
0
 def lsn_port_get(self, context, network_id, subnet_id, raise_on_err=True):
     """Retrieve LSN and LSN port for the network and the subnet."""
     lsn_id = self.lsn_get(context, network_id, raise_on_err=raise_on_err)
     if lsn_id:
         try:
             lsn_port_id = lsn_api.lsn_port_by_subnet_get(
                 self.cluster, lsn_id, subnet_id)
         except (n_exc.NotFound, nvplib.NvpApiClient.NvpApiException):
             logger = raise_on_err and LOG.error or LOG.warn
             logger(_('Unable to find Logical Service Node Port for '
                      'LSN %(lsn_id)s and subnet %(subnet_id)s')
                    % {'lsn_id': lsn_id, 'subnet_id': subnet_id})
             if raise_on_err:
                 raise p_exc.LsnPortNotFound(lsn_id=lsn_id,
                                             entity='subnet',
                                             entity_id=subnet_id)
             return (lsn_id, None)
         else:
             return (lsn_id, lsn_port_id)
     else:
         return (None, None)