1
# Copyright 2013 Cloudbase Solutions SRL
2
# Copyright 2013 Pedro Navarro Perez
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Unit Tests for hyperv neutron rpc
24
from oslo_context import context as oslo_context
26
from neutron.agent import rpc as agent_rpc
27
from neutron.common import topics
28
from neutron.plugins.hyperv import agent_notifier_api as ana
29
from neutron.plugins.hyperv.common import constants
30
from neutron.tests import base
33
class rpcHyperVApiTestCase(base.BaseTestCase):
35
def _test_hyperv_neutron_api(
36
self, rpcapi, topic, method, rpc_method, **kwargs):
37
ctxt = oslo_context.RequestContext('fake_user', 'fake_project')
38
expected_retval = 'foo' if rpc_method == 'call' else None
39
expected_version = kwargs.pop('version', None)
40
fanout = kwargs.pop('fanout', False)
42
with contextlib.nested(
43
mock.patch.object(rpcapi.client, rpc_method),
44
mock.patch.object(rpcapi.client, 'prepare'),
46
rpc_mock, prepare_mock
48
prepare_mock.return_value = rpcapi.client
49
rpc_mock.return_value = expected_retval
50
retval = getattr(rpcapi, method)(ctxt, **kwargs)
52
self.assertEqual(retval, expected_retval)
56
prepare_args['version'] = expected_version
58
prepare_args['fanout'] = True
60
prepare_args['topic'] = topic
61
prepare_mock.assert_called_once_with(**prepare_args)
63
rpc_mock.assert_called_once_with(ctxt, method, **kwargs)
65
def test_delete_network(self):
66
rpcapi = ana.AgentNotifierApi(topics.AGENT)
67
self._test_hyperv_neutron_api(
69
topics.get_topic_name(
73
'network_delete', rpc_method='cast', fanout=True,
74
network_id='fake_request_spec')
76
def test_port_update(self):
77
rpcapi = ana.AgentNotifierApi(topics.AGENT)
78
self._test_hyperv_neutron_api(
80
topics.get_topic_name(
84
'port_update', rpc_method='cast', fanout=True,
86
network_type='fake_network_type',
87
segmentation_id='fake_segmentation_id',
88
physical_network='fake_physical_network')
90
def test_port_delete(self):
91
rpcapi = ana.AgentNotifierApi(topics.AGENT)
92
self._test_hyperv_neutron_api(
94
topics.get_topic_name(
98
'port_delete', rpc_method='cast', fanout=True,
101
def test_tunnel_update(self):
102
rpcapi = ana.AgentNotifierApi(topics.AGENT)
103
self._test_hyperv_neutron_api(
105
topics.get_topic_name(
109
'tunnel_update', rpc_method='cast', fanout=True,
110
tunnel_ip='fake_ip', tunnel_id='fake_id')
112
def test_device_details(self):
113
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
114
self._test_hyperv_neutron_api(
116
'get_device_details', rpc_method='call',
117
device='fake_device',
118
agent_id='fake_agent_id',
121
def test_devices_details_list(self):
122
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
123
self._test_hyperv_neutron_api(
125
'get_devices_details_list', rpc_method='call',
126
devices=['fake_device1', 'fake_device2'],
127
agent_id='fake_agent_id', host='fake_host',
130
def test_update_device_down(self):
131
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
132
self._test_hyperv_neutron_api(
134
'update_device_down', rpc_method='call',
135
device='fake_device',
136
agent_id='fake_agent_id',
139
def test_tunnel_sync(self):
140
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
141
self._test_hyperv_neutron_api(
143
'tunnel_sync', rpc_method='call',
144
tunnel_ip='fake_tunnel_ip',