def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _(
                "enable_nvgre_support is set to True, but provider "
                "tunnel IP is not configured. Check neutron.conf "
                "config file."
            )
            LOG.error(err_msg)
            raise utils.HyperVException(msg=err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context, CONF.NVGRE.provider_tunnel_ip, constants.TYPE_NVGRE)

        # setup Hyper-V Agent Lookup Record update consumer
        topic = hyperv_agent_notifier.get_topic_name(self.topic, constants.LOOKUP, constants.UPDATE)
        self.connection.create_consumer(topic, self.endpoints, fanout=True)

        # the created consumer is the last connection server.
        # need to start it in order for it to consume.
        self.connection.servers[-1].start()
Esempio n. 2
0
    def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _('enable_nvgre_support is set to True, but provider '
                        'tunnel IP is not configured. Check neutron.conf '
                        'config file.')
            LOG.error(err_msg)
            raise utils.HyperVException(msg=err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(
            list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context,
                                      CONF.NVGRE.provider_tunnel_ip,
                                      constants.TYPE_NVGRE)

        # setup Hyper-V Agent Lookup Record update consumer
        topic = hyperv_agent_notifier.get_topic_name(self.topic,
                                                     constants.LOOKUP,
                                                     constants.UPDATE)
        self.connection.create_consumer(topic, self.endpoints, fanout=True)

        # the created consumer is the last connection server.
        # need to start it in order for it to consume.
        self.connection.servers[-1].start()
    def test_lookup_update(self):
        expected_topic = hyperv_agent_notifier.get_topic_name(
            constants.AGENT_TOPIC, constants.LOOKUP, constants.UPDATE)

        self.notifier.lookup_update(mock.sentinel.context,
                                    mock.sentinel.lookup_ip,
                                    mock.sentinel.lookup_details)

        self.notifier._client.prepare.assert_called_once_with(
            topic=expected_topic, fanout=True)
        prepared_client = self.notifier._client.prepare.return_value
        prepared_client.cast.assert_called_once_with(
            mock.sentinel.context, 'lookup_update',
            lookup_ip=mock.sentinel.lookup_ip,
            lookup_details=mock.sentinel.lookup_details)
    def test_tunnel_update(self):
        expected_topic = hyperv_agent_notifier.get_topic_name(
            constants.AGENT_TOPIC, constants.TUNNEL, constants.UPDATE)

        self.notifier.tunnel_update(mock.sentinel.context,
                                    mock.sentinel.tunnel_ip,
                                    constants.TYPE_NVGRE)

        self.notifier._client.prepare.assert_called_once_with(
            topic=expected_topic, fanout=True)
        prepared_client = self.notifier._client.prepare.return_value
        prepared_client.cast.assert_called_once_with(
            mock.sentinel.context, 'tunnel_update',
            tunnel_ip=mock.sentinel.tunnel_ip,
            tunnel_type=constants.TYPE_NVGRE)
    def test_lookup_update(self):
        expected_topic = hyperv_agent_notifier.get_topic_name(
            constants.AGENT_TOPIC, constants.LOOKUP, constants.UPDATE)

        self.notifier.lookup_update(mock.sentinel.context,
                                    mock.sentinel.lookup_ip,
                                    mock.sentinel.lookup_details)

        self.notifier._client.prepare.assert_called_once_with(
            topic=expected_topic, fanout=True)
        prepared_client = self.notifier._client.prepare.return_value
        prepared_client.cast.assert_called_once_with(
            mock.sentinel.context,
            'lookup_update',
            lookup_ip=mock.sentinel.lookup_ip,
            lookup_details=mock.sentinel.lookup_details)
    def test_tunnel_update(self):
        expected_topic = hyperv_agent_notifier.get_topic_name(
            constants.AGENT_TOPIC, constants.TUNNEL, constants.UPDATE)

        self.notifier.tunnel_update(mock.sentinel.context,
                                    mock.sentinel.tunnel_ip,
                                    constants.TYPE_NVGRE)

        self.notifier._client.prepare.assert_called_once_with(
            topic=expected_topic, fanout=True)
        prepared_client = self.notifier._client.prepare.return_value
        prepared_client.cast.assert_called_once_with(
            mock.sentinel.context,
            'tunnel_update',
            tunnel_ip=mock.sentinel.tunnel_ip,
            tunnel_type=constants.TYPE_NVGRE)
    def test_init_nvgre_enabled(self, mock_hyperv_nvgre_ops):
        self.config(enable_support=True, group='NVGRE')
        self.config(provider_tunnel_ip=mock.sentinel.tunneling_ip,
                    group='NVGRE')
        self.agent._init_nvgre()
        mock_hyperv_nvgre_ops.assert_called_once_with(
            list(self.agent._physical_network_mappings.values()))

        self.assertTrue(self.agent._nvgre_enabled)
        self.agent._nvgre_ops.init_notifier.assert_called_once_with(
            self.agent.context, self.agent.client)
        expected_topic = hyperv_agent_notifier.get_topic_name(
            self.agent.topic, constants.LOOKUP, constants.UPDATE)
        self.agent.connection.create_consumer.assert_called_once_with(
            expected_topic, self.agent.endpoints, fanout=True)
        self.agent.connection.servers[-1].start.assert_called_once_with()
    def test_init_nvgre_enabled(self, mock_hyperv_nvgre_ops):
        self.config(enable_support=True, group='NVGRE')
        self.config(provider_tunnel_ip=mock.sentinel.tunneling_ip,
                    group='NVGRE')
        self.agent._init_nvgre()
        mock_hyperv_nvgre_ops.assert_called_once_with(
            list(self.agent._physical_network_mappings.values()))

        self.assertTrue(self.agent._nvgre_enabled)
        self.agent._nvgre_ops.init_notifier.assert_called_once_with(
            self.agent.context, self.agent.client)
        expected_topic = hyperv_agent_notifier.get_topic_name(
            self.agent.topic, constants.LOOKUP, constants.UPDATE)
        self.agent.connection.create_consumer.assert_called_once_with(
            expected_topic, self.agent.endpoints, fanout=True)
        self.agent.connection.servers[-1].start.assert_called_once_with()