Ejemplo n.º 1
0
 def lsn_port_metadata_setup(self, context, lsn_id, subnet):
     """Connect subnet to specified LSN."""
     data = {
         "mac_address": const.METADATA_MAC,
         "ip_address": subnet['cidr'],
         "subnet_id": subnet['id']
     }
     network_id = subnet['network_id']
     tenant_id = subnet['tenant_id']
     lswitch_port_id = None
     try:
         lswitch_port_id = nsxlib.create_lport(self.cluster, network_id,
                                               tenant_id,
                                               const.METADATA_PORT_ID,
                                               const.METADATA_PORT_NAME,
                                               const.METADATA_DEVICE_ID,
                                               True)['uuid']
         lsn_port_id = self.lsn_port_create(self.cluster, lsn_id, data)
     except (n_exc.NotFound, p_exc.NvpPluginException,
             nsxlib.NvpApiClient.NvpApiException):
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=lswitch_port_id)
     else:
         try:
             lsn_api.lsn_port_plug_network(self.cluster, lsn_id,
                                           lsn_port_id, lswitch_port_id)
         except p_exc.LsnConfigurationConflict:
             self.lsn_port_delete(self.cluster, lsn_id, lsn_port_id)
             nsxlib.delete_port(self.cluster, network_id, lswitch_port_id)
             raise p_exc.PortConfigurationError(net_id=network_id,
                                                lsn_id=lsn_id,
                                                port_id=lsn_port_id)
Ejemplo n.º 2
0
 def lsn_port_dhcp_setup(self,
                         context,
                         network_id,
                         port_id,
                         port_data,
                         subnet_config=None):
     """Connect network to LSN via specified port and port_data."""
     try:
         lsn_id = None
         lswitch_port_id = nsxlib.get_port_by_neutron_tag(
             self.cluster, network_id, port_id)['uuid']
         lsn_id = self.lsn_get(context, network_id)
         lsn_port_id = self.lsn_port_create(context, lsn_id, port_data)
     except (n_exc.NotFound, p_exc.NvpPluginException):
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=port_id)
     else:
         try:
             lsn_api.lsn_port_plug_network(self.cluster, lsn_id,
                                           lsn_port_id, lswitch_port_id)
         except p_exc.LsnConfigurationConflict:
             self.lsn_port_delete(context, lsn_id, lsn_port_id)
             raise p_exc.PortConfigurationError(net_id=network_id,
                                                lsn_id=lsn_id,
                                                port_id=port_id)
         if subnet_config:
             self.lsn_port_dhcp_configure(context, lsn_id, lsn_port_id,
                                          subnet_config)
         else:
             return (lsn_id, lsn_port_id)
Ejemplo n.º 3
0
 def lsn_port_update(self,
                     context,
                     network_id,
                     subnet_id,
                     dhcp=None,
                     meta=None):
     """Update the specified configuration for the LSN port."""
     if not dhcp and not meta:
         return
     try:
         lsn_id, lsn_port_id = self.lsn_port_get(context,
                                                 network_id,
                                                 subnet_id,
                                                 raise_on_err=False)
         if dhcp and lsn_id and lsn_port_id:
             lsn_api.lsn_port_host_entries_update(self.cluster, lsn_id,
                                                  lsn_port_id, DHCP_CONF,
                                                  dhcp)
         if meta and lsn_id and lsn_port_id:
             lsn_api.lsn_port_host_entries_update(self.cluster, lsn_id,
                                                  lsn_port_id, META_CONF,
                                                  meta)
     except nsxlib.NvpApiClient.NvpApiException:
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=lsn_port_id)
Ejemplo n.º 4
0
 def test_subnet_create_raise_port_config_error(self):
     with mock.patch.object(nvp.db_base_plugin_v2.NeutronDbPluginV2,
                            'delete_port') as d:
         self._test_subnet_create(True,
                                  exc=n_exc.Conflict,
                                  exc_obj=p_exc.PortConfigurationError(
                                      lsn_id='foo_lsn_id',
                                      net_id='foo_net_id',
                                      port_id='foo_port_id'))
         d.assert_called_once_with(self.plugin, mock.ANY, 'foo_port_id')
Ejemplo n.º 5
0
 def _lsn_port_host_conf(self, context, network_id, subnet_id, data, hdlr):
     lsn_id = None
     lsn_port_id = None
     try:
         lsn_id, lsn_port_id = self.lsn_port_get(context, network_id,
                                                 subnet_id)
         hdlr(self.cluster, lsn_id, lsn_port_id, data)
     except (n_exc.NotFound, nsxlib.NvpApiClient.NvpApiException):
         LOG.error(_('Error while configuring LSN ' 'port %s'), lsn_port_id)
         raise p_exc.PortConfigurationError(net_id=network_id,
                                            lsn_id=lsn_id,
                                            port_id=lsn_port_id)
Ejemplo n.º 6
0
 def _test_handle_port_metadata_access(self, is_delete, raise_exc=False):
     port = {
         'id': 'foo_port_id',
         'device_owner': 'foo_device_id',
         'network_id': 'foo_network_id',
         'device_id': 'foo_device_id',
         'tenant_id': 'foo_tenant_id',
         'fixed_ips': [{
             'subnet_id': 'foo_subnet_id',
             'ip_address': '1.2.3.4'
         }]
     }
     meta = {
         'instance_id': port['device_id'],
         'tenant_id': port['tenant_id'],
         'ip_address': port['fixed_ips'][0]['ip_address']
     }
     self.plugin.get_network.return_value = {'router:external': False}
     if is_delete:
         mock_func = self.plugin.lsn_manager.lsn_port_meta_host_remove
     else:
         mock_func = self.plugin.lsn_manager.lsn_port_meta_host_add
     if raise_exc:
         mock_func.side_effect = p_exc.PortConfigurationError(
             lsn_id='foo_lsn_id', net_id='foo_net_id', port_id=None)
         with mock.patch.object(nvp.db_base_plugin_v2.NeutronDbPluginV2,
                                'delete_port') as d:
             self.assertRaises(p_exc.PortConfigurationError,
                               nvp.handle_port_metadata_access,
                               self.plugin,
                               mock.ANY,
                               port,
                               is_delete=is_delete)
             if not is_delete:
                 d.assert_called_once_with(mock.ANY, mock.ANY, port['id'])
             else:
                 self.assertFalse(d.call_count)
     else:
         nvp.handle_port_metadata_access(self.plugin,
                                         mock.ANY,
                                         port,
                                         is_delete=is_delete)
     mock_func.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, meta)
Ejemplo n.º 7
0
 def test_handle_create_dhcp_owner_port_raise_port_config_error(self):
     config_error = p_exc.PortConfigurationError(lsn_id='foo_lsn_id',
                                                 net_id='foo_net_id',
                                                 port_id='foo_port_id')
     self._test_handle_create_dhcp_owner_port(exc=config_error)