コード例 #1
0
 def __init__(self, conf, router):
     self.conf = conf
     self.id = router['id']
     self.router = router
     # TODO(cbrandily): deduplicate ns_name generation in metering/l3
     self.ns_name = NS_PREFIX + self.id
     self.iptables_manager = None
     self.snat_iptables_manager = None
     if self.router['distributed']:
         # If distributed routers then we need to apply the
         # metering agent label rules in the snat namespace as well.
         snat_ns_name = dvr_snat_ns.SnatNamespace.get_snat_ns_name(
             self.id)
         # Check for namespace existence before we assign the
         # snat_iptables_manager
         if ip_lib.IPWrapper().netns.exists(snat_ns_name):
             self.snat_iptables_manager = iptables_manager.IptablesManager(
                 namespace=snat_ns_name,
                 binary_name=WRAP_NAME,
                 state_less=True,
                 use_ipv6=ipv6_utils.is_enabled())
     # Check of namespace existence before we assign the iptables_manager
     # NOTE(Swami): If distributed routers, all external traffic on a
     # compute node will flow through the rfp interface in the router
     # namespace.
     ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name)
     if ip_wrapper.netns.exists(self.ns_name):
         self.iptables_manager = iptables_manager.IptablesManager(
             namespace=self.ns_name,
             binary_name=WRAP_NAME,
             state_less=True,
             use_ipv6=ipv6_utils.is_enabled())
     self.metering_labels = {}
コード例 #2
0
 def __init__(self, namespace=None):
     self.root_helper = cfg.CONF.AGENT.root_helper
     self.iptables = iptables_manager.IptablesManager(
         root_helper=self.root_helper, use_ipv6=ipv6_utils.is_enabled())
     # TODO(majopela, shihanzhang): refactor out ipset to a separate
     # driver composed over this one
     self.ipset = ipset_manager.IpsetManager(root_helper=self.root_helper)
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = {}
     self.pre_sg_members = None
     self.ipset_chains = {}
     self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
     self.defer_sg_rules = {}
     self.defer_sgs = {}
     self.available_local_zones = set(
         xrange(constants.MIN_VLAN_TAG, constants.MAX_VLAN_TAG))
     self.local_zone_map = {}
     self.namespace = namespace
コード例 #3
0
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.root_helper = config.get_root_helper(self.conf)
        self.router_info = {}

        self._check_config_params()

        try:
            self.driver = importutils.import_object(self.conf.interface_driver,
                                                    self.conf)
        except Exception:
            msg = _("Error importing interface driver "
                    "'%s'") % self.conf.interface_driver
            LOG.error(msg)
            raise SystemExit(msg)

        self.context = context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True
        self.updated_routers = set()
        self.removed_routers = set()
        self.sync_progress = False

        self._delete_stale_namespaces = (self.conf.use_namespaces and
                                         self.conf.router_delete_namespaces)

        self.rpc_loop = loopingcall.FixedIntervalLoopingCall(self._rpc_loop)
        self.rpc_loop.start(interval=RPC_LOOP_INTERVAL)
        super(L3NATAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()
コード例 #4
0
 def __init__(self, namespace=None):
     self.root_helper = cfg.CONF.AGENT.root_helper
     self.iptables = iptables_manager.IptablesManager(
         root_helper=self.root_helper,
         use_ipv6=ipv6_utils.is_enabled())
     # TODO(majopela, shihanzhang): refactor out ipset to a separate
     # driver composed over this one
     self.ipset = ipset_manager.IpsetManager(root_helper=self.root_helper)
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = {}
     self.pre_sg_members = None
     self.ipset_chains = {}
     self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
     self.defer_sg_rules = {}
     self.defer_sgs = {}
     self.available_local_zones = set(xrange(constants.MIN_VLAN_TAG,
                                             constants.MAX_VLAN_TAG))
     self.local_zone_map = {}
     self.namespace = namespace
コード例 #5
0
 def __init__(self, namespace=None):
     self.iptables = iptables_manager.IptablesManager(
         use_ipv6=ipv6_utils.is_enabled(), namespace=namespace)
     # TODO(majopela, shihanzhang): refactor out ipset to a separate
     # driver composed over this one
     self.ipset = ipset_manager.IpsetManager(namespace=namespace)
     self.ipconntrack = ip_conntrack.IpConntrackManager(
         self.get_device_zone, namespace=namespace)
     self._populate_initial_zone_map()
     # list of port which has security group
     self.filtered_ports = {}
     self.unfiltered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     self._pre_defer_unfiltered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = collections.defaultdict(
         lambda: collections.defaultdict(list))
     self.pre_sg_members = None
     self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
     self._enabled_netfilter_for_bridges = False
     self.updated_rule_sg_ids = set()
     self.updated_sg_members = set()
     self.devices_with_udpated_sg_members = collections.defaultdict(list)
コード例 #6
0
 def __init__(self, namespace=None):
     self.iptables = iptables_manager.IptablesManager(
         use_ipv6=ipv6_utils.is_enabled(),
         namespace=namespace)
     # TODO(majopela, shihanzhang): refactor out ipset to a separate
     # driver composed over this one
     self.ipset = ipset_manager.IpsetManager(namespace=namespace)
     self.ipconntrack = ip_conntrack.IpConntrackManager(
         self.get_device_zone, namespace=namespace)
     self._populate_initial_zone_map()
     # list of port which has security group
     self.filtered_ports = {}
     self.unfiltered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     self._pre_defer_unfiltered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = collections.defaultdict(
         lambda: collections.defaultdict(list))
     self.pre_sg_members = None
     self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
     self._enabled_netfilter_for_bridges = False
     self.updated_rule_sg_ids = set()
     self.updated_sg_members = set()
     self.devices_with_udpated_sg_members = collections.defaultdict(list)
コード例 #7
0
ファイル: interface.py プロジェクト: whitepages/neutron
 def _validate_network_device_mtu(self):
     if (ipv6_utils.is_enabled() and
         self.conf.network_device_mtu < n_const.IPV6_MIN_MTU):
         LOG.error(_LE("IPv6 protocol requires a minimum MTU of "
                       "%(min_mtu)s, while the configured value is "
                       "%(current_mtu)s"), {'min_mtu': n_const.IPV6_MIN_MTU,
                       'current_mtu': self.conf.network_device_mtu})
         raise SystemExit(1)
コード例 #8
0
 def __init__(self):
     self.iptables = iptables_manager.IptablesManager(
         root_helper=cfg.CONF.AGENT.root_helper,
         use_ipv6=ipv6_utils.is_enabled())
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
コード例 #9
0
 def __init__(self):
     self.iptables = iptables_manager.IptablesManager(
         root_helper=cfg.CONF.AGENT.root_helper,
         use_ipv6=ipv6_utils.is_enabled())
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
コード例 #10
0
 def ds__init__(self, conf, router):
     self.conf = conf
     self.id = router['id']
     self.router = router
     self.ns_name = NS_PREFIX + self.id if conf.use_namespaces else None
     self.iptables_manager = iptables_manager.IptablesManager(
         namespace=self.ns_name,
         binary_name=WRAP_NAME,
         use_ipv6=ipv6_utils.is_enabled())
     self.metering_labels = {}
コード例 #11
0
ファイル: iptables_driver.py プロジェクト: klmitch/neutron
 def __init__(self, conf, router):
     self.conf = conf
     self.id = router["id"]
     self.router = router
     # TODO(cbrandily): deduplicate ns_name generation in metering/l3
     self.ns_name = NS_PREFIX + self.id
     self.iptables_manager = iptables_manager.IptablesManager(
         namespace=self.ns_name, binary_name=WRAP_NAME, state_less=True, use_ipv6=ipv6_utils.is_enabled()
     )
     self.metering_labels = {}
コード例 #12
0
ファイル: iptables_driver.py プロジェクト: Akanksha08/neutron
 def __init__(self, conf, router):
     self.conf = conf
     self.id = router['id']
     self.router = router
     self.ns_name = NS_PREFIX + self.id if conf.use_namespaces else None
     self.iptables_manager = iptables_manager.IptablesManager(
         namespace=self.ns_name,
         binary_name=WRAP_NAME,
         use_ipv6=ipv6_utils.is_enabled())
     self.metering_labels = {}
コード例 #13
0
 def __init__(self, conf, router):
     self.conf = conf
     self.id = router['id']
     self.router = router
     # TODO(cbrandily): deduplicate ns_name generation in metering/l3
     self.ns_name = NS_PREFIX + self.id
     self.iptables_manager = iptables_manager.IptablesManager(
         namespace=self.ns_name,
         binary_name=WRAP_NAME,
         use_ipv6=ipv6_utils.is_enabled())
     self.metering_labels = {}
コード例 #14
0
 def __init__(self, conf, router):
     self.conf = conf
     self.id = router["id"]
     self.router = router
     self.root_helper = config.get_root_helper(self.conf)
     self.ns_name = NS_PREFIX + self.id if conf.use_namespaces else None
     self.iptables_manager = iptables_manager.IptablesManager(
         root_helper=self.root_helper,
         namespace=self.ns_name,
         binary_name=WRAP_NAME,
         use_ipv6=ipv6_utils.is_enabled(),
     )
     self.metering_labels = {}
コード例 #15
0
 def __init__(self):
     self.iptables = iptables_manager.IptablesManager(
         root_helper=cfg.CONF.AGENT.root_helper,
         use_ipv6=ipv6_utils.is_enabled())
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = {}
     self.pre_sg_members = None
コード例 #16
0
ファイル: iptables_firewall.py プロジェクト: dlq84/neutron
 def __init__(self):
     self.iptables = iptables_manager.IptablesManager(
         root_helper=cfg.CONF.AGENT.root_helper,
         use_ipv6=ipv6_utils.is_enabled())
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = {}
     self.pre_sg_members = None
コード例 #17
0
 def __init__(self):
     self.iptables = iptables_manager.IptablesManager(
         use_ipv6=ipv6_utils.is_enabled())
     # TODO(majopela, shihanzhang): refactor out ipset to a separate
     # driver composed over this one
     self.ipset = ipset_manager.IpsetManager()
     # list of port which has security group
     self.filtered_ports = {}
     self._add_fallback_chain_v4v6()
     self._defer_apply = False
     self._pre_defer_filtered_ports = None
     # List of security group rules for ports residing on this host
     self.sg_rules = {}
     self.pre_sg_rules = None
     # List of security group member ips for ports residing on this host
     self.sg_members = {}
     self.pre_sg_members = None
     self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
コード例 #18
0
ファイル: l3_agent.py プロジェクト: codybum/OpenStackInAction
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.root_helper = config.get_root_helper(self.conf)
        self.router_info = {}

        self._check_config_params()

        try:
            self.driver = importutils.import_object(
                self.conf.interface_driver,
                self.conf
            )
        except Exception:
            msg = _("Error importing interface driver "
                    "'%s'") % self.conf.interface_driver
            LOG.error(msg)
            raise SystemExit(msg)

        self.context = context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True
        self.updated_routers = set()
        self.removed_routers = set()
        self.sync_progress = False

        self._delete_stale_namespaces = (self.conf.use_namespaces and
                                         self.conf.router_delete_namespaces)

        self.rpc_loop = loopingcall.FixedIntervalLoopingCall(
            self._rpc_loop)
        self.rpc_loop.start(interval=RPC_LOOP_INTERVAL)
        super(L3NATAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()
コード例 #19
0
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(
            config=self.conf, resource_type='router')

        self.driver = common_utils.load_interface_driver(self.conf)

        self._context = n_context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True
        self.sync_routers_chunk_size = SYNC_ROUTERS_MAX_CHUNK_SIZE

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        while True:
            try:
                self.neutron_service_plugins = (
                    self.plugin_rpc.get_service_plugin_list(self.context))
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(
                        _LW('l3-agent cannot check service plugins '
                            'enabled at the neutron server when '
                            'startup due to RPC error. It happens '
                            'when the server does not support this '
                            'RPC API. If the error is '
                            'UnsupportedVersion you can ignore this '
                            'warning. Detail message: %s'), e)
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(
                        _LW('l3-agent cannot contact neutron server '
                            'to retrieve service plugins enabled. '
                            'Check connectivity to neutron server. '
                            'Retrying... '
                            'Detailed message: %(msg)s.'), {'msg': e})
                    continue
            break

        self.init_extension_manager(self.plugin_rpc)

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf, self.driver, self.metadata_driver)

        self._queue = queue.RouterProcessingQueue()
        super(L3NATAgent, self).__init__(host=self.conf.host)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()

        self.pd = pd.PrefixDelegation(self.context, self.process_monitor,
                                      self.driver,
                                      self.plugin_rpc.process_prefix_update,
                                      self.create_pd_router_update, self.conf)
コード例 #20
0
 def test_disabled(self):
     self.mock_read.return_value = "1"
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
コード例 #21
0
ファイル: agent.py プロジェクト: brandonlogan/neutron
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(
            config=self.conf,
            resource_type='router')

        self.driver = common_utils.load_interface_driver(self.conf)

        self._context = n_context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True
        self.sync_routers_chunk_size = SYNC_ROUTERS_MAX_CHUNK_SIZE

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        while True:
            try:
                self.neutron_service_plugins = (
                    self.plugin_rpc.get_service_plugin_list(self.context))
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(_LW('l3-agent cannot check service plugins '
                                    'enabled at the neutron server when '
                                    'startup due to RPC error. It happens '
                                    'when the server does not support this '
                                    'RPC API. If the error is '
                                    'UnsupportedVersion you can ignore this '
                                    'warning. Detail message: %s'), e)
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(_LW('l3-agent cannot contact neutron server '
                                    'to retrieve service plugins enabled. '
                                    'Check connectivity to neutron server. '
                                    'Retrying... '
                                    'Detailed message: %(msg)s.'), {'msg': e})
                    continue
            break

        self.init_extension_manager(self.plugin_rpc)

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf,
            self.driver,
            self.metadata_driver)

        self._queue = queue.RouterProcessingQueue()
        super(L3NATAgent, self).__init__(host=self.conf.host)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()

        self.pd = pd.PrefixDelegation(self.context, self.process_monitor,
                                      self.driver,
                                      self.plugin_rpc.process_prefix_update,
                                      self.create_pd_router_update,
                                      self.conf)
コード例 #22
0
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(
            config=self.conf, resource_type='router')

        try:
            self.driver = importutils.import_object(self.conf.interface_driver,
                                                    self.conf)
        except Exception:
            LOG.error(_LE("Error importing interface driver "
                          "'%s'"), self.conf.interface_driver)
            raise SystemExit(1)

        self.context = n_context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        retry_count = 5
        while True:
            retry_count = retry_count - 1
            try:
                self.neutron_service_plugins = (
                    self.plugin_rpc.get_service_plugin_list(self.context))
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(
                        _LW('l3-agent cannot check service plugins '
                            'enabled at the neutron server when '
                            'startup due to RPC error. It happens '
                            'when the server does not support this '
                            'RPC API. If the error is '
                            'UnsupportedVersion you can ignore this '
                            'warning. Detail message: %s'), e)
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    if retry_count > 0:
                        ctx.reraise = False
                        LOG.warning(
                            _LW('l3-agent cannot check service '
                                'plugins enabled on the neutron '
                                'server. Retrying. '
                                'Detail message: %s'), e)
                        continue
            break

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf, self.driver, self.conf.use_namespaces,
            self.metadata_driver)

        self._queue = queue.RouterProcessingQueue()
        super(L3NATAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()
コード例 #23
0
ファイル: test_ipv6_utils.py プロジェクト: 21atlas/neutron
 def test_disabled(self):
     self.useFixture(tools.OpenFixture(self.proc_path, '1'))
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
コード例 #24
0
 def test_memoize(self):
     mo = self.useFixture(tools.OpenFixture(self.proc_path, '0')).mock_open
     ipv6_utils.is_enabled()
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
     mo.assert_called_once_with(self.proc_path, 'r')
コード例 #25
0
ファイル: test_ha_router.py プロジェクト: zainubwahid/neutron
class L3HATestCase(framework.L3AgentTestFramework):
    def test_ha_router_update_floatingip_statuses(self):
        self._test_update_floatingip_statuses(
            self.generate_router_info(enable_ha=True))

    def test_keepalived_state_change_notification(self):
        enqueue_mock = mock.patch.object(self.agent,
                                         'enqueue_state_change').start()
        router_info = self.generate_router_info(enable_ha=True)
        router = self.manage_router(self.agent, router_info)
        common_utils.wait_until_true(lambda: router.ha_state == 'master')

        self.fail_ha_router(router)
        common_utils.wait_until_true(lambda: router.ha_state == 'backup')

        common_utils.wait_until_true(lambda: enqueue_mock.call_count == 3)
        calls = [args[0] for args in enqueue_mock.call_args_list]
        self.assertEqual((router.router_id, 'backup'), calls[0])
        self.assertEqual((router.router_id, 'master'), calls[1])
        self.assertEqual((router.router_id, 'backup'), calls[2])

    def _expected_rpc_report(self, expected):
        calls = (args[0][1] for args in
                 self.agent.plugin_rpc.update_ha_routers_states.call_args_list)

        # Get the last state reported for each router
        actual_router_states = {}
        for call in calls:
            for router_id, state in six.iteritems(call):
                actual_router_states[router_id] = state

        return actual_router_states == expected

    def test_keepalived_state_change_bulk_rpc(self):
        router_info = self.generate_router_info(enable_ha=True)
        router1 = self.manage_router(self.agent, router_info)
        self.fail_ha_router(router1)
        router_info = self.generate_router_info(enable_ha=True)
        router2 = self.manage_router(self.agent, router_info)

        common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
        common_utils.wait_until_true(lambda: router2.ha_state == 'master')
        common_utils.wait_until_true(
            lambda: self._expected_rpc_report({
                router1.router_id: 'standby',
                router2.router_id: 'active'
            }))

    def test_ha_router_lifecycle(self):
        self._router_lifecycle(enable_ha=True)

    def test_conntrack_disassociate_fip_ha_router(self):
        self._test_conntrack_disassociate_fip(ha=True)

    def test_ipv6_ha_router_lifecycle(self):
        self._router_lifecycle(enable_ha=True, ip_version=6)

    def test_ipv6_ha_router_lifecycle_with_no_gw_subnet(self):
        self.agent.conf.set_override('ipv6_gateway', 'fe80::f816:3eff:fe2e:1')
        self._router_lifecycle(enable_ha=True,
                               ip_version=6,
                               v6_ext_gw_with_sub=False)

    def test_ipv6_ha_router_lifecycle_with_no_gw_subnet_for_router_advts(self):
        # Verify that router gw interface is configured to receive Router
        # Advts from upstream router when no external gateway is configured.
        self._router_lifecycle(enable_ha=True,
                               dual_stack=True,
                               v6_ext_gw_with_sub=False)

    @testtools.skipUnless(ipv6_utils.is_enabled(), "IPv6 is not enabled")
    def test_ipv6_router_advts_after_router_state_change(self):
        # Schedule router to l3 agent, and then add router gateway. Verify
        # that router gw interface is configured to receive Router Advts.
        router_info = l3_test_common.prepare_router_data(enable_snat=True,
                                                         enable_ha=True,
                                                         dual_stack=True,
                                                         enable_gw=False)
        router = self.manage_router(self.agent, router_info)
        common_utils.wait_until_true(lambda: router.ha_state == 'master')
        _ext_dev_name, ex_port = l3_test_common.prepare_ext_gw_test(
            mock.Mock(), router)
        router_info['gw_port'] = ex_port
        router.process(self.agent)
        self._assert_ipv6_accept_ra(router)

    def test_keepalived_configuration(self):
        router_info = self.generate_router_info(enable_ha=True)
        router = self.manage_router(self.agent, router_info)
        expected = self.get_expected_keepalive_configuration(router)

        self.assertEqual(expected,
                         router.keepalived_manager.get_conf_on_disk())

        # Add a new FIP and change the GW IP address
        router.router = copy.deepcopy(router.router)
        existing_fip = '19.4.4.2'
        new_fip = '19.4.4.3'
        self._add_fip(router, new_fip)
        subnet_id = framework._uuid()
        fixed_ips = [{
            'ip_address': '19.4.4.10',
            'prefixlen': 24,
            'subnet_id': subnet_id
        }]
        subnets = [{
            'id': subnet_id,
            'cidr': '19.4.4.0/24',
            'gateway_ip': '19.4.4.5'
        }]
        router.router['gw_port']['subnets'] = subnets
        router.router['gw_port']['fixed_ips'] = fixed_ips

        router.process(self.agent)

        # Get the updated configuration and assert that both FIPs are in,
        # and that the GW IP address was updated.
        new_config = router.keepalived_manager.config.get_config_str()
        old_gw = '0.0.0.0/0 via 19.4.4.1'
        new_gw = '0.0.0.0/0 via 19.4.4.5'
        old_external_device_ip = '19.4.4.4'
        new_external_device_ip = '19.4.4.10'
        self.assertIn(existing_fip, new_config)
        self.assertIn(new_fip, new_config)
        self.assertNotIn(old_gw, new_config)
        self.assertIn(new_gw, new_config)
        external_port = router.get_ex_gw_port()
        external_device_name = router.get_external_device_name(
            external_port['id'])
        self.assertNotIn(
            '%s/24 dev %s' % (old_external_device_ip, external_device_name),
            new_config)
        self.assertIn(
            '%s/24 dev %s' % (new_external_device_ip, external_device_name),
            new_config)

    def test_ha_router_conf_on_restarted_agent(self):
        router_info = self.generate_router_info(enable_ha=True)
        router1 = self.manage_router(self.agent, router_info)
        self._add_fip(router1, '192.168.111.12')
        restarted_agent = neutron_l3_agent.L3NATAgentWithStateReport(
            self.agent.host, self.agent.conf)
        self.manage_router(restarted_agent, router1.router)
        common_utils.wait_until_true(
            lambda: self.floating_ips_configured(router1))
        self.assertIn(
            router1._get_primary_vip(),
            self._get_addresses_on_device(router1.ns_name,
                                          router1.get_ha_device_name()))

    def test_ha_router_ipv6_radvd_status(self):
        router_info = self.generate_router_info(ip_version=6, enable_ha=True)
        router1 = self.manage_router(self.agent, router_info)
        common_utils.wait_until_true(lambda: router1.ha_state == 'master')
        common_utils.wait_until_true(lambda: router1.radvd.enabled)

        def _check_lla_status(router, expected):
            internal_devices = router.router[constants.INTERFACE_KEY]
            for device in internal_devices:
                lladdr = ip_lib.get_ipv6_lladdr(device['mac_address'])
                exists = ip_lib.device_exists_with_ips_and_mac(
                    router.get_internal_device_name(device['id']), [lladdr],
                    device['mac_address'], router.ns_name)
                self.assertEqual(expected, exists)

        _check_lla_status(router1, True)

        device_name = router1.get_ha_device_name()
        ha_device = ip_lib.IPDevice(device_name, namespace=router1.ns_name)
        ha_device.link.set_down()

        common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
        common_utils.wait_until_true(lambda: not router1.radvd.enabled,
                                     timeout=10)
        _check_lla_status(router1, False)

    def test_ha_router_process_ipv6_subnets_to_existing_port(self):
        router_info = self.generate_router_info(enable_ha=True, ip_version=6)
        router = self.manage_router(self.agent, router_info)

        def verify_ip_in_keepalived_config(router, iface):
            config = router.keepalived_manager.config.get_config_str()
            ip_cidrs = common_utils.fixed_ip_cidrs(iface['fixed_ips'])
            for ip_addr in ip_cidrs:
                self.assertIn(ip_addr, config)

        interface_id = router.router[constants.INTERFACE_KEY][0]['id']
        slaac = constants.IPV6_SLAAC
        slaac_mode = {'ra_mode': slaac, 'address_mode': slaac}

        # Add a second IPv6 subnet to the router internal interface.
        self._add_internal_interface_by_subnet(router.router,
                                               count=1,
                                               ip_version=6,
                                               ipv6_subnet_modes=[slaac_mode],
                                               interface_id=interface_id)
        router.process(self.agent)
        common_utils.wait_until_true(lambda: router.ha_state == 'master')

        # Verify that router internal interface is present and is configured
        # with IP address from both the subnets.
        internal_iface = router.router[constants.INTERFACE_KEY][0]
        self.assertEqual(2, len(internal_iface['fixed_ips']))
        self._assert_internal_devices(router)

        # Verify that keepalived config is properly updated.
        verify_ip_in_keepalived_config(router, internal_iface)

        # Remove one subnet from the router internal iface
        interfaces = copy.deepcopy(
            router.router.get(constants.INTERFACE_KEY, []))
        fixed_ips, subnets = [], []
        fixed_ips.append(interfaces[0]['fixed_ips'][0])
        subnets.append(interfaces[0]['subnets'][0])
        interfaces[0].update({'fixed_ips': fixed_ips, 'subnets': subnets})
        router.router[constants.INTERFACE_KEY] = interfaces
        router.process(self.agent)

        # Verify that router internal interface has a single ipaddress
        internal_iface = router.router[constants.INTERFACE_KEY][0]
        self.assertEqual(1, len(internal_iface['fixed_ips']))
        self._assert_internal_devices(router)

        # Verify that keepalived config is properly updated.
        verify_ip_in_keepalived_config(router, internal_iface)

    def test_delete_external_gateway_on_standby_router(self):
        router_info = self.generate_router_info(enable_ha=True)
        router = self.manage_router(self.agent, router_info)

        self.fail_ha_router(router)
        common_utils.wait_until_true(lambda: router.ha_state == 'backup')

        # The purpose of the test is to simply make sure no exception is raised
        port = router.get_ex_gw_port()
        interface_name = router.get_external_device_name(port['id'])
        router.external_gateway_removed(port, interface_name)

    def test_removing_floatingip_immediately(self):
        router_info = self.generate_router_info(enable_ha=True)
        router = self.manage_router(self.agent, router_info)
        ex_gw_port = router.get_ex_gw_port()
        interface_name = router.get_external_device_interface_name(ex_gw_port)
        common_utils.wait_until_true(lambda: router.ha_state == 'master')
        self._add_fip(router, '172.168.1.20', fixed_address='10.0.0.3')
        router.process(self.agent)
        router.router[constants.FLOATINGIP_KEY] = []
        # The purpose of the test is to simply make sure no exception is raised
        # Because router.process will consume the FloatingIpSetupException,
        # call the configure_fip_addresses directly here
        router.configure_fip_addresses(interface_name)

    def test_ha_port_status_update(self):
        router_info = self.generate_router_info(enable_ha=True)
        router_info[constants.HA_INTERFACE_KEY]['status'] = (
            constants.PORT_STATUS_DOWN)
        router1 = self.manage_router(self.agent, router_info)
        common_utils.wait_until_true(lambda: router1.ha_state == 'backup')

        router1.router[constants.HA_INTERFACE_KEY]['status'] = (
            constants.PORT_STATUS_ACTIVE)
        self.agent._process_updated_router(router1.router)
        common_utils.wait_until_true(lambda: router1.ha_state == 'master')
コード例 #26
0
 def test_enabled(self):
     self.mock_read.return_value = "0"
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
コード例 #27
0
 def test_disabled_non_exists(self):
     self.mock_exists.return_value = False
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
     self.assertFalse(self.mock_read.called)
コード例 #28
0
 def test_memoize(self):
     self.mock_read.return_value = "0"
     ipv6_utils.is_enabled()
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
     self.mock_read.assert_called_once_with()
コード例 #29
0
 def test_disabled(self):
     self.mock_read.return_value = "1"
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
コード例 #30
0
 def test_enabled(self):
     self.mock_read.return_value = "0"
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
コード例 #31
0
ファイル: test_ipv6_utils.py プロジェクト: 21atlas/neutron
 def test_enabled(self):
     self.useFixture(tools.OpenFixture(self.proc_path, '0'))
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
コード例 #32
0
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(
            config=self.conf,
            resource_type='router')
        self.conf.interface_driver = const.INF_DR
        self.driver = common_utils.load_interface_driver(self.conf)
        self.context = n_context.get_admin_context_without_session()
        self.plugin_rpc = l3_agent.L3PluginApi(topics.L3PLUGIN, host)
        self.ftnt_rpc = FortinetL3PluginApi(const.FTNT_AGENT, host)
        self.task_manager = tasks.TaskManager()
        self.task_manager.start()
        self.fortigates = []
        self.fortigate = fortigate.Fortigate()
        self.api_client = self.fortigate.get_apiclient()
        self.initialize_fortigate()
        self.router = l3_fortinet.FortinetL3ServicePlugin(
            fortigate=self.fortigate)
        self.fullsync = True
        self.test = True

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        retry_count = 5
        while True:
            retry_count = retry_count - 1
            try:
                self.neutron_service_plugins = (
                    self.plugin_rpc.get_service_plugin_list(self.context))
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(_LW('l3-agent cannot check service plugins '
                                    'enabled at the neutron server when '
                                    'startup due to RPC error. It happens '
                                    'when the server does not support this '
                                    'RPC API. If the error is '
                                    'UnsupportedVersion you can ignore this '
                                    'warning. Detail message: %s'), e)
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    if retry_count > 0:
                        ctx.reraise = False
                        LOG.warning(_LW('l3-agent cannot check service '
                                        'plugins enabled on the neutron '
                                        'server. Retrying. '
                                        'Detail message: %s'), e)
                        continue
            break

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf,
            self.driver,
            self.fortigate,
            self.conf.use_namespaces,
            self.metadata_driver)

        self._queue = queue.RouterProcessingQueue()
        super(FortinetAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()
        if self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR:
            self.pd = None
        else:
            self.pd = pd.PrefixDelegation(
                self.context, self.process_monitor, self.driver,
                self.plugin_rpc.process_prefix_update,
                self.create_pd_router_update, self.conf)
コード例 #33
0
 def test_disabled_non_exists(self):
     self.mock_exists.return_value = False
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
     self.assertFalse(self.mock_read.called)
コード例 #34
0
ファイル: agent.py プロジェクト: kkxue/neutron
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(
            config=self.conf,
            resource_type='router')

        try:
            self.driver = importutils.import_object(
                self.conf.interface_driver,
                self.conf
            )
        except Exception:
            LOG.error(_LE("Error importing interface driver "
                          "'%s'"), self.conf.interface_driver)
            raise SystemExit(1)

        self.context = n_context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        retry_count = 5
        while True:
            retry_count = retry_count - 1
            try:
                self.neutron_service_plugins = (
                    self.plugin_rpc.get_service_plugin_list(self.context))
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(_LW('l3-agent cannot check service plugins '
                                    'enabled at the neutron server when '
                                    'startup due to RPC error. It happens '
                                    'when the server does not support this '
                                    'RPC API. If the error is '
                                    'UnsupportedVersion you can ignore this '
                                    'warning. Detail message: %s'), e)
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    if retry_count > 0:
                        ctx.reraise = False
                        LOG.warning(_LW('l3-agent cannot check service '
                                        'plugins enabled on the neutron '
                                        'server. Retrying. '
                                        'Detail message: %s'), e)
                        continue
            break

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf,
            self.driver,
            self.conf.use_namespaces,
            self.metadata_driver)

        self._queue = queue.RouterProcessingQueue()
        super(L3NATAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()
コード例 #35
0
ファイル: test_ipv6_utils.py プロジェクト: 21atlas/neutron
 def test_memoize(self):
     mo = self.useFixture(tools.OpenFixture(self.proc_path, '0')).mock_open
     ipv6_utils.is_enabled()
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
     mo.assert_called_once_with(self.proc_path, 'r')
コード例 #36
0
 def test_enabled(self):
     self.useFixture(tools.OpenFixture(self.proc_path, '0'))
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
コード例 #37
0
 def test_memoize(self):
     self.mock_read.return_value = "0"
     ipv6_utils.is_enabled()
     enabled = ipv6_utils.is_enabled()
     self.assertTrue(enabled)
     self.mock_read.assert_called_once_with()
コード例 #38
0
ファイル: agent.py プロジェクト: akash1808/neutron
    def __init__(self, host, conf=None):
        if conf:
            self.conf = conf
        else:
            self.conf = cfg.CONF
        self.router_info = {}

        self._check_config_params()

        self.process_monitor = external_process.ProcessMonitor(config=self.conf, resource_type="router")

        self.driver = common_utils.load_interface_driver(self.conf)

        self.context = n_context.get_admin_context_without_session()
        self.plugin_rpc = L3PluginApi(topics.L3PLUGIN, host)
        self.fullsync = True

        # Get the list of service plugins from Neutron Server
        # This is the first place where we contact neutron-server on startup
        # so retry in case its not ready to respond.
        retry_count = 5
        while True:
            retry_count = retry_count - 1
            try:
                self.neutron_service_plugins = self.plugin_rpc.get_service_plugin_list(self.context)
            except oslo_messaging.RemoteError as e:
                with excutils.save_and_reraise_exception() as ctx:
                    ctx.reraise = False
                    LOG.warning(
                        _LW(
                            "l3-agent cannot check service plugins "
                            "enabled at the neutron server when "
                            "startup due to RPC error. It happens "
                            "when the server does not support this "
                            "RPC API. If the error is "
                            "UnsupportedVersion you can ignore this "
                            "warning. Detail message: %s"
                        ),
                        e,
                    )
                self.neutron_service_plugins = None
            except oslo_messaging.MessagingTimeout as e:
                with excutils.save_and_reraise_exception() as ctx:
                    if retry_count > 0:
                        ctx.reraise = False
                        LOG.warning(
                            _LW(
                                "l3-agent cannot check service "
                                "plugins enabled on the neutron "
                                "server. Retrying. "
                                "Detail message: %s"
                            ),
                            e,
                        )
                        continue
            break

        self.metadata_driver = None
        if self.conf.enable_metadata_proxy:
            self.metadata_driver = metadata_driver.MetadataDriver(self)

        self.namespaces_manager = namespace_manager.NamespaceManager(
            self.conf, self.driver, self.conf.use_namespaces, self.metadata_driver
        )

        self._queue = queue.RouterProcessingQueue()
        super(L3NATAgent, self).__init__(conf=self.conf)

        self.target_ex_net_id = None
        self.use_ipv6 = ipv6_utils.is_enabled()

        self.pd = pd.PrefixDelegation(
            self.context,
            self.process_monitor,
            self.driver,
            self.plugin_rpc.process_prefix_update,
            self.create_pd_router_update,
            self.conf,
        )
コード例 #39
0
 def test_disabled(self):
     self.useFixture(tools.OpenFixture(self.proc_path, '1'))
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
コード例 #40
0
 def test_disabled_non_exists(self):
     mo = self.useFixture(tools.OpenFixture(self.proc_path, '1')).mock_open
     self.mock_exists.return_value = False
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
     self.assertFalse(mo.called)
コード例 #41
0
ファイル: test_ipv6_utils.py プロジェクト: 21atlas/neutron
 def test_disabled_non_exists(self):
     mo = self.useFixture(tools.OpenFixture(self.proc_path, '1')).mock_open
     self.mock_exists.return_value = False
     enabled = ipv6_utils.is_enabled()
     self.assertFalse(enabled)
     self.assertFalse(mo.called)