# See the License for the specific language governing permissions and
# limitations under the License.
+from oslo import messaging
+
from neutron.common import constants
from neutron.common import rpc as n_rpc
from neutron.common import topics
LOG = logging.getLogger(__name__)
-class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
+class DhcpAgentNotifyAPI(object):
"""API for plugin to notify DHCP agent."""
- BASE_RPC_API_VERSION = '1.0'
# It seems dhcp agent does not support bulk operation
VALID_RESOURCES = ['network', 'subnet', 'port']
VALID_METHOD_NAMES = ['network.create.end',
'port.delete.end']
def __init__(self, topic=topics.DHCP_AGENT, plugin=None):
- super(DhcpAgentNotifyAPI, self).__init__(
- topic=topic, default_version=self.BASE_RPC_API_VERSION)
self._plugin = plugin
+ target = messaging.Target(topic=topic, version='1.0')
+ self.client = n_rpc.get_client(target)
@property
def plugin(self):
def _cast_message(self, context, method, payload, host,
topic=topics.DHCP_AGENT):
"""Cast the payload to the dhcp agent running on the host."""
- self.cast(
- context, self.make_msg(method,
- payload=payload),
- topic='%s.%s' % (topic, host))
+ cctxt = self.client.prepare(topic=topic, server=host)
+ cctxt.cast(context, method, payload=payload)
def _fanout_message(self, context, method, payload):
"""Fanout the payload to all dhcp agents."""
- self.fanout_cast(
- context, self.make_msg(method,
- payload=payload),
- topic=topics.DHCP_AGENT)
+ cctxt = self.client.prepare(fanout=True)
+ cctxt.cast(context, method, payload=payload)
def network_removed_from_agent(self, context, network_id, host):
self._cast_message(context, 'network_delete_end',
for resource, attrs in attributes.RESOURCE_ATTRIBUTE_MAP.iteritems():
self.saved_attr_map[resource] = attrs.copy()
super(OvsDhcpAgentNotifierTestCase, self).setUp(self.plugin_str)
- # the notifier is used to get access to make_msg() method only
self.dhcp_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
self.dhcp_notifier_cast = mock.patch(
'neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.'
- 'DhcpAgentNotifyAPI.cast').start()
+ 'DhcpAgentNotifyAPI._cast_message').start()
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
self.adminContext = context.get_admin_context()
self._add_network_to_dhcp_agent(hosta_id,
network_id)
self.dhcp_notifier_cast.assert_called_with(
- mock.ANY,
- self.dhcp_notifier.make_msg(
- 'network_create_end',
- payload={'network': {'id': network_id}}),
- topic='dhcp_agent.' + DHCP_HOSTA)
+ mock.ANY, 'network_create_end',
+ {'network': {'id': network_id}}, DHCP_HOSTA)
notifications = fake_notifier.NOTIFICATIONS
expected_event_type = 'dhcp_agent.network.add'
self._assert_notify(notifications, expected_event_type)
self._remove_network_from_dhcp_agent(hosta_id,
network_id)
self.dhcp_notifier_cast.assert_called_with(
- mock.ANY,
- self.dhcp_notifier.make_msg(
- 'network_delete_end',
- payload={'network_id': network_id}),
- topic='dhcp_agent.' + DHCP_HOSTA)
+ mock.ANY, 'network_delete_end',
+ {'network_id': network_id}, DHCP_HOSTA)
notifications = fake_notifier.NOTIFICATIONS
expected_event_type = 'dhcp_agent.network.remove'
self._assert_notify(notifications, expected_event_type)
self._disable_agent(hosta_id, admin_state_up=False)
self.dhcp_notifier_cast.assert_called_with(
- mock.ANY, self.dhcp_notifier.make_msg(
- 'agent_updated',
- payload={'admin_state_up': False}),
- topic='dhcp_agent.' + DHCP_HOSTA)
+ mock.ANY, 'agent_updated',
+ {'admin_state_up': False}, DHCP_HOSTA)
def _network_port_create(
self, hosts, gateway=attributes.ATTR_NOT_SPECIFIED, owner=None):
expected_calls = [
mock.call(
mock.ANY,
- self.dhcp_notifier.make_msg(
- 'network_create_end',
- payload={'network': {'id': net['network']['id']}}),
- topic='dhcp_agent.' + host),
+ 'network_create_end',
+ {'network': {'id': net['network']['id']}},
+ host),
mock.call(
mock.ANY,
- self.dhcp_notifier.make_msg(
- 'port_create_end',
- payload={'port': port['port']}),
- topic='dhcp_agent.' + host)]
+ 'port_create_end',
+ {'port': port['port']},
+ host, 'dhcp_agent')]
host_calls[host] = expected_calls
return host_calls