Skip to content

Commit

Permalink
Merge "Remove fallback functions in agent/rpc"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 7, 2016
2 parents ea61c3e + a2f971c commit 2d03659
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 130 deletions.
85 changes: 15 additions & 70 deletions neutron/agent/rpc.py
Expand Up @@ -21,7 +21,6 @@
import oslo_messaging
from oslo_utils import uuidutils

from neutron._i18n import _LW
from neutron.common import constants as n_const
from neutron.common import rpc as n_rpc
from neutron.common import topics
Expand Down Expand Up @@ -111,21 +110,9 @@ def get_device_details(self, context, device, agent_id, host=None):
agent_id=agent_id, host=host)

def get_devices_details_list(self, context, devices, agent_id, host=None):
try:
cctxt = self.client.prepare(version='1.3')
res = cctxt.call(context, 'get_devices_details_list',
devices=devices, agent_id=agent_id, host=host)
except oslo_messaging.UnsupportedVersion:
# If the server has not been upgraded yet, a DVR-enabled agent
# may not work correctly, however it can function in 'degraded'
# mode, in that DVR routers may not be in the system yet, and
# it might be not necessary to retrieve info about the host.
LOG.warning(_LW('DVR functionality requires a server upgrade.'))
res = [
self.get_device_details(context, device, agent_id, host)
for device in devices
]
return res
cctxt = self.client.prepare(version='1.3')
return cctxt.call(context, 'get_devices_details_list',
devices=devices, agent_id=agent_id, host=host)

def get_devices_details_list_and_failed_devices(self, context, devices,
agent_id, host=None):
Expand All @@ -135,17 +122,11 @@ def get_devices_details_list_and_failed_devices(self, context, devices,
retrieving the devices details, the device is put in a list of
failed devices.
"""
try:
cctxt = self.client.prepare(version='1.5')
res = cctxt.call(
context,
'get_devices_details_list_and_failed_devices',
devices=devices, agent_id=agent_id, host=host)
except oslo_messaging.UnsupportedVersion:
#TODO(rossella_s): Remove this failback logic in M
res = self._device_list_rpc_call_with_failed_dev(
self.get_device_details, context, agent_id, host, devices)
return res
cctxt = self.client.prepare(version='1.5')
return cctxt.call(
context,
'get_devices_details_list_and_failed_devices',
devices=devices, agent_id=agent_id, host=host)

def update_device_down(self, context, device, agent_id, host=None):
cctxt = self.client.prepare()
Expand All @@ -157,50 +138,14 @@ def update_device_up(self, context, device, agent_id, host=None):
return cctxt.call(context, 'update_device_up', device=device,
agent_id=agent_id, host=host)

def _device_list_rpc_call_with_failed_dev(self, rpc_call, context,
agent_id, host, devices):
succeeded_devices = []
failed_devices = []
for device in devices:
try:
rpc_device = rpc_call(context, device, agent_id, host)
except Exception:
failed_devices.append(device)
else:
# update_device_up doesn't return the device
succeeded_dev = rpc_device or device
succeeded_devices.append(succeeded_dev)
return {'devices': succeeded_devices, 'failed_devices': failed_devices}

def update_device_list(self, context, devices_up, devices_down,
agent_id, host):
try:
cctxt = self.client.prepare(version='1.5')
res = cctxt.call(context, 'update_device_list',
devices_up=devices_up, devices_down=devices_down,
agent_id=agent_id, host=host)
except oslo_messaging.UnsupportedVersion:
#TODO(rossella_s): Remove this failback logic in M
dev_up = self._device_list_rpc_call_with_failed_dev(
self.update_device_up, context, agent_id, host, devices_up)
dev_down = self._device_list_rpc_call_with_failed_dev(
self.update_device_down, context, agent_id, host, devices_down)

res = {'devices_up': dev_up.get('devices'),
'failed_devices_up': dev_up.get('failed_devices'),
'devices_down': dev_down.get('devices'),
'failed_devices_down': dev_down.get('failed_devices')}
return res
cctxt = self.client.prepare(version='1.5')
return cctxt.call(context, 'update_device_list',
devices_up=devices_up, devices_down=devices_down,
agent_id=agent_id, host=host)

def tunnel_sync(self, context, tunnel_ip, tunnel_type=None, host=None):
try:
cctxt = self.client.prepare(version='1.4')
res = cctxt.call(context, 'tunnel_sync', tunnel_ip=tunnel_ip,
tunnel_type=tunnel_type, host=host)
except oslo_messaging.UnsupportedVersion:
LOG.warning(_LW('Tunnel synchronization requires a '
'server upgrade.'))
cctxt = self.client.prepare()
res = cctxt.call(context, 'tunnel_sync', tunnel_ip=tunnel_ip,
tunnel_type=tunnel_type)
return res
cctxt = self.client.prepare(version='1.4')
return cctxt.call(context, 'tunnel_sync', tunnel_ip=tunnel_ip,
tunnel_type=tunnel_type, host=host)
16 changes: 0 additions & 16 deletions neutron/tests/unit/agent/test_rpc.py
Expand Up @@ -16,7 +16,6 @@
import datetime
import mock
from oslo_context import context as oslo_context
import oslo_messaging

from neutron.agent import rpc
from neutron.tests import base
Expand Down Expand Up @@ -45,21 +44,6 @@ def test_get_device_details(self):
def test_get_devices_details_list(self):
self._test_rpc_call('get_devices_details_list')

def test_devices_details_list_unsupported(self):
agent = rpc.PluginApi('fake_topic')
ctxt = oslo_context.RequestContext(user='fake_user',
tenant='fake_project')
expect_val_get_device_details = 'foo'
expect_val = [expect_val_get_device_details]
with mock.patch.object(agent.client, 'call') as mock_call, \
mock.patch.object(agent.client, 'prepare') as mock_prepare:
mock_prepare.return_value = agent.client
mock_call.side_effect = [oslo_messaging.UnsupportedVersion('1.2'),
expect_val_get_device_details]
func_obj = getattr(agent, 'get_devices_details_list')
actual_val = func_obj(ctxt, ['fake_device'], 'fake_agent_id')
self.assertEqual(actual_val, expect_val)

def test_update_device_down(self):
self._test_rpc_call('update_device_down')

Expand Down
44 changes: 0 additions & 44 deletions neutron/tests/unit/plugins/ml2/test_rpc.py
Expand Up @@ -24,7 +24,6 @@
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_context import context as oslo_context
import oslo_messaging
from sqlalchemy.orm import exc

from neutron.agent import rpc as agent_rpc
Expand Down Expand Up @@ -445,30 +444,6 @@ def test_update_device_list(self):
host='fake_host',
version='1.5')

def test_update_device_list_unsupported(self):
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
ctxt = oslo_context.RequestContext(user='fake_user',
tenant='fake_project')
devices_up = ['fake_device1', 'fake_device2']
devices_down = ['fake_device3', 'fake_device4']
expected_ret_val = {'devices_up': ['fake_device2'],
'failed_devices_up': ['fake_device1'],
'devices_down': [
{'device': 'fake_device3', 'exists': True}],
'failed_devices_down': ['fake_device4']}
rpcapi.update_device_up = mock.Mock(
side_effect=[Exception('fake_device1 fails'), None])
rpcapi.update_device_down = mock.Mock(
side_effect=[{'device': 'fake_device3', 'exists': True},
Exception('fake_device4 fails')])
with mock.patch.object(rpcapi.client, 'call'),\
mock.patch.object(rpcapi.client, 'prepare') as prepare_mock:
prepare_mock.side_effect = oslo_messaging.UnsupportedVersion(
'test')
res = rpcapi.update_device_list(ctxt, devices_up, devices_down,
'fake_agent_id', 'fake_host')
self.assertEqual(expected_ret_val, res)

def test_get_devices_details_list_and_failed_devices(self):
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
self._test_rpc_api(rpcapi, None,
Expand All @@ -487,22 +462,3 @@ def test_devices_details_list_and_failed_devices(self):
devices=['fake_device1', 'fake_device2'],
agent_id='fake_agent_id', host='fake_host',
version='1.5')

def test_get_devices_details_list_and_failed_devices_unsupported(self):
rpcapi = agent_rpc.PluginApi(topics.PLUGIN)
ctxt = oslo_context.RequestContext(user='fake_user',
tenant='fake_project')
devices = ['fake_device1', 'fake_device2']
dev2_details = {'device': 'fake_device2', 'network_id': 'net_id',
'port_id': 'port_id', 'admin_state_up': True}
expected_ret_val = {'devices': [dev2_details],
'failed_devices': ['fake_device1']}
rpcapi.get_device_details = mock.Mock(
side_effect=[Exception('fake_device1 fails'), dev2_details])
with mock.patch.object(rpcapi.client, 'call'),\
mock.patch.object(rpcapi.client, 'prepare') as prepare_mock:
prepare_mock.side_effect = oslo_messaging.UnsupportedVersion(
'test')
res = rpcapi.get_devices_details_list_and_failed_devices(
ctxt, devices, 'fake_agent_id', 'fake_host')
self.assertEqual(expected_ret_val, res)

0 comments on commit 2d03659

Please sign in to comment.