def _update_gateway_route(self, agent_gateway_port, interface_name, tbl_index): ns_name = self.get_name() ipd = ip_lib.IPDevice(interface_name, namespace=ns_name) # If the 'fg-' device doesn't exist in the namespace then trying # to send advertisements or configure the default route will just # throw exceptions. Unsubscribe this external network so that # the next call will trigger the interface to be plugged. if not ipd.exists(): LOG.warning(_LW('DVR: FIP gateway port with interface ' 'name: %(device)s does not exist in the given ' 'namespace: %(ns)s'), {'device': interface_name, 'ns': ns_name}) msg = _('DVR: Gateway update route in FIP namespace failed, retry ' 'should be attempted on next call') raise n_exc.FloatingIpSetupException(msg) for fixed_ip in agent_gateway_port['fixed_ips']: ip_lib.send_ip_addr_adv_notif(ns_name, interface_name, fixed_ip['ip_address'], self.agent_conf.send_arp_for_ha) for subnet in agent_gateway_port['subnets']: gw_ip = subnet.get('gateway_ip') if gw_ip: is_gateway_not_in_subnet = not ipam_utils.check_subnet_ip( subnet.get('cidr'), gw_ip) if is_gateway_not_in_subnet: ipd.route.add_route(gw_ip, scope='link') self._add_default_gateway_for_fip(gw_ip, ipd, tbl_index) else: current_gateway = ipd.route.get_gateway() if current_gateway and current_gateway.get('gateway'): ipd.route.delete_gateway(current_gateway.get('gateway'))
def configure_fip_addresses(self, interface_name): try: return self.process_floating_ip_addresses(interface_name) except Exception: # TODO(salv-orlando): Less broad catching raise n_exc.FloatingIpSetupException('L3 agent failure to setup ' 'floating IPs')
def process_snat_dnat_for_fip(self): try: self.process_floating_ip_nat_rules() except Exception: # TODO(salv-orlando): Less broad catching raise n_exc.FloatingIpSetupException( 'L3 agent failure to setup NAT for floating IPs')
def _add_snat_rules(self, ex_gw_port, iptables_manager, interface_name): self.process_external_port_address_scope_routing(iptables_manager) if ex_gw_port: for ip_addr in ex_gw_port['fixed_ips']: ex_gw_ip = ip_addr['ip_address'] if netaddr.IPAddress(ex_gw_ip).version != 4: msg = 'WMF: only ipv4 is supported' raise n_exc.FloatingIpSetupException(msg) break # ex_gw_port should not be None in this case # NAT rules are added only if ex_gw_port has an IPv4 address if self._snat_enabled and self.agent_conf.routing_source_ip: LOG.debug('external_gateway_ip: %s', ex_gw_ip) LOG.debug('routing_source_ip: %s', self.agent_conf.routing_source_ip) self.routing_source_ip = self.agent_conf.routing_source_ip self.dmz_cidr = self.agent_conf.dmz_cidr if not netaddr.IPAddress(self.routing_source_ip).version == 4: msg = 'foo %s is not ipv4' % (self.routing_source_ip) raise n_exc.FloatingIpSetupException(msg) rules = self.external_gateway_nat_snat_rules( self.routing_source_ip, interface_name) for rule in rules: iptables_manager.ipv4['nat'].add_rule(*rule) rules = self.external_gateway_nat_fip_rules( ex_gw_ip, interface_name, self.dmz_cidr, self.routing_source_ip) for rule in rules: LOG.debug( 'foo self.external_gateway_nat_fip_rules rule: %s', str(rule)) iptables_manager.ipv4['nat'].add_rule(*rule) rules = self.external_gateway_mangle_rules(interface_name) for rule in rules: iptables_manager.ipv4['mangle'].add_rule(*rule)
def _associate_floatingip_to_port(self, context, floating_ip_address, port_id): compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone port = self._core_plugin.get_port(context, port_id) fixed_ip_address = None if len(port['fixed_ips']) > 0: fixed_ip = port['fixed_ips'][0] if 'ip_address' in fixed_ip: fixed_ip_address = fixed_ip['ip_address'] if fixed_ip_address: LOG.info('Found fixed ip %s for port %s' % (fixed_ip_address, port_id)) gceutils.assign_floatingip(compute, project, zone, fixed_ip_address, floating_ip_address) else: raise exceptions.FloatingIpSetupException( 'Unable to find fixed ip for port %s' % port_id)
def test_create_gateway_port_raises_exception(self, fip_desub, fip_delete, fip_create, device_exists, ip_wrapper): agent_gw_port = self._get_agent_gw_port() interface_name = self.fip_ns.get_ext_device_name(agent_gw_port['id']) device_exists.return_value = False msg = 'L3 agent failed to setup fip gateway in the namespace' self.fip_ns._update_gateway_port = mock.Mock( side_effect=n_exc.FloatingIpSetupException(msg)) self.assertRaises(n_exc.FloatingIpSetupException, self.fip_ns.create_or_update_gateway_port, agent_gw_port) self.assertTrue(fip_create.called) self.assertEqual(1, self.driver.plug.call_count) self.assertEqual(1, self.driver.init_l3.call_count) self.fip_ns._update_gateway_port.assert_called_once_with( agent_gw_port, interface_name) self.assertTrue(fip_desub.called) self.assertTrue(fip_delete.called) self.assertIsNone(self.fip_ns.agent_gateway_port)