Merge "Reduce rpc calls in SR-IOV agent"
This commit is contained in:
commit
9d8e28f2ea
@ -254,20 +254,11 @@ class SriovNicSwitchAgent(object):
|
|||||||
device)
|
device)
|
||||||
except exc.SriovNicError:
|
except exc.SriovNicError:
|
||||||
LOG.warning(_LW("Failed to set device %s state"), device)
|
LOG.warning(_LW("Failed to set device %s state"), device)
|
||||||
return
|
return False
|
||||||
if admin_state_up:
|
|
||||||
# update plugin about port status
|
|
||||||
self.plugin_rpc.update_device_up(self.context,
|
|
||||||
device,
|
|
||||||
self.agent_id,
|
|
||||||
cfg.CONF.host)
|
|
||||||
else:
|
|
||||||
self.plugin_rpc.update_device_down(self.context,
|
|
||||||
device,
|
|
||||||
self.agent_id,
|
|
||||||
cfg.CONF.host)
|
|
||||||
else:
|
else:
|
||||||
LOG.info(_LI("No device with MAC %s defined on agent."), device)
|
LOG.info(_LI("No device with MAC %s defined on agent."), device)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def _update_network_ports(self, network_id, port_id, mac_pci_slot):
|
def _update_network_ports(self, network_id, port_id, mac_pci_slot):
|
||||||
self._clean_network_ports(mac_pci_slot)
|
self._clean_network_ports(mac_pci_slot)
|
||||||
@ -296,6 +287,8 @@ class SriovNicSwitchAgent(object):
|
|||||||
# resync is needed
|
# resync is needed
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
devices_up = set()
|
||||||
|
devices_down = set()
|
||||||
for device_details in devices_details_list:
|
for device_details in devices_details_list:
|
||||||
device = device_details['device']
|
device = device_details['device']
|
||||||
LOG.debug("Port with MAC address %s is added", device)
|
LOG.debug("Port with MAC address %s is added", device)
|
||||||
@ -306,10 +299,14 @@ class SriovNicSwitchAgent(object):
|
|||||||
port_id = device_details['port_id']
|
port_id = device_details['port_id']
|
||||||
profile = device_details['profile']
|
profile = device_details['profile']
|
||||||
spoofcheck = device_details.get('port_security_enabled', True)
|
spoofcheck = device_details.get('port_security_enabled', True)
|
||||||
self.treat_device(device,
|
if self.treat_device(device,
|
||||||
profile.get('pci_slot'),
|
profile.get('pci_slot'),
|
||||||
device_details['admin_state_up'],
|
device_details['admin_state_up'],
|
||||||
spoofcheck)
|
spoofcheck):
|
||||||
|
if device_details['admin_state_up']:
|
||||||
|
devices_up.add(device)
|
||||||
|
else:
|
||||||
|
devices_down.add(device)
|
||||||
self._update_network_ports(device_details['network_id'],
|
self._update_network_ports(device_details['network_id'],
|
||||||
port_id,
|
port_id,
|
||||||
(device, profile.get('pci_slot')))
|
(device, profile.get('pci_slot')))
|
||||||
@ -317,6 +314,11 @@ class SriovNicSwitchAgent(object):
|
|||||||
else:
|
else:
|
||||||
LOG.info(_LI("Device with MAC %s not defined on plugin"),
|
LOG.info(_LI("Device with MAC %s not defined on plugin"),
|
||||||
device)
|
device)
|
||||||
|
self.plugin_rpc.update_device_list(self.context,
|
||||||
|
devices_up,
|
||||||
|
devices_down,
|
||||||
|
self.agent_id,
|
||||||
|
self.conf.host)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def treat_devices_removed(self, devices):
|
def treat_devices_removed(self, devices):
|
||||||
|
@ -302,7 +302,108 @@ class TestSriovAgent(base.BaseTestCase):
|
|||||||
'aa:bb:cc:dd:ee:ff',
|
'aa:bb:cc:dd:ee:ff',
|
||||||
'1:2:3.0',
|
'1:2:3.0',
|
||||||
False)
|
False)
|
||||||
self.assertTrue(agent.plugin_rpc.update_device_up.called)
|
agent.plugin_rpc.update_device_list.assert_called_once_with(
|
||||||
|
mock.ANY,
|
||||||
|
set(['aa:bb:cc:dd:ee:ff']),
|
||||||
|
set(),
|
||||||
|
mock.ANY,
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
|
def test_treat_devices_added_updated_multiple_admin_state_up_true(self):
|
||||||
|
agent = self.agent
|
||||||
|
mock_details = [{'device': 'aa:bb:cc:dd:ee:ff',
|
||||||
|
'port_id': 'port123',
|
||||||
|
'network_id': 'net123',
|
||||||
|
'admin_state_up': True,
|
||||||
|
'network_type': 'vlan',
|
||||||
|
'segmentation_id': 100,
|
||||||
|
'profile': {'pci_slot': '1:2:3.0'},
|
||||||
|
'physical_network': 'physnet1',
|
||||||
|
'port_security_enabled': False},
|
||||||
|
{'device': '11:22:33:44:55:66',
|
||||||
|
'port_id': 'port321',
|
||||||
|
'network_id': 'net123',
|
||||||
|
'admin_state_up': True,
|
||||||
|
'network_type': 'vlan',
|
||||||
|
'segmentation_id': 100,
|
||||||
|
'profile': {'pci_slot': '1:2:3.0'},
|
||||||
|
'physical_network': 'physnet1',
|
||||||
|
'port_security_enabled': False}]
|
||||||
|
agent.plugin_rpc = mock.Mock()
|
||||||
|
agent.plugin_rpc.get_devices_details_list.return_value = mock_details
|
||||||
|
agent.eswitch_mgr = mock.Mock()
|
||||||
|
agent.eswitch_mgr.device_exists.return_value = True
|
||||||
|
agent.set_device_state = mock.Mock()
|
||||||
|
agent.set_device_spoofcheck = mock.Mock()
|
||||||
|
resync_needed = agent.treat_devices_added_updated(
|
||||||
|
set(['aa:bb:cc:dd:ee:ff',
|
||||||
|
'11:22:33:44:55:66']))
|
||||||
|
self.assertFalse(resync_needed)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0'),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0')]
|
||||||
|
agent.eswitch_mgr.device_exists.assert_has_calls(calls, any_order=True)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0', True),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0', True)]
|
||||||
|
agent.eswitch_mgr.set_device_state.assert_has_calls(calls,
|
||||||
|
any_order=True)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0', False),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0', False)]
|
||||||
|
agent.eswitch_mgr.set_device_spoofcheck.assert_has_calls(calls,
|
||||||
|
any_order=True)
|
||||||
|
agent.plugin_rpc.update_device_list.assert_called_once_with(
|
||||||
|
mock.ANY,
|
||||||
|
set(['aa:bb:cc:dd:ee:ff', '11:22:33:44:55:66']),
|
||||||
|
set(),
|
||||||
|
mock.ANY,
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
|
def test_treat_devices_added_updated_multiple_admin_states(self):
|
||||||
|
agent = self.agent
|
||||||
|
mock_details = [{'device': 'aa:bb:cc:dd:ee:ff',
|
||||||
|
'port_id': 'port123',
|
||||||
|
'network_id': 'net123',
|
||||||
|
'admin_state_up': True,
|
||||||
|
'network_type': 'vlan',
|
||||||
|
'segmentation_id': 100,
|
||||||
|
'profile': {'pci_slot': '1:2:3.0'},
|
||||||
|
'physical_network': 'physnet1',
|
||||||
|
'port_security_enabled': False},
|
||||||
|
{'device': '11:22:33:44:55:66',
|
||||||
|
'port_id': 'port321',
|
||||||
|
'network_id': 'net123',
|
||||||
|
'admin_state_up': False,
|
||||||
|
'network_type': 'vlan',
|
||||||
|
'segmentation_id': 100,
|
||||||
|
'profile': {'pci_slot': '1:2:3.0'},
|
||||||
|
'physical_network': 'physnet1',
|
||||||
|
'port_security_enabled': False}]
|
||||||
|
agent.plugin_rpc = mock.Mock()
|
||||||
|
agent.plugin_rpc.get_devices_details_list.return_value = mock_details
|
||||||
|
agent.eswitch_mgr = mock.Mock()
|
||||||
|
agent.eswitch_mgr.device_exists.return_value = True
|
||||||
|
agent.set_device_state = mock.Mock()
|
||||||
|
agent.set_device_spoofcheck = mock.Mock()
|
||||||
|
resync_needed = agent.treat_devices_added_updated(
|
||||||
|
set(['aa:bb:cc:dd:ee:ff',
|
||||||
|
'11:22:33:44:55:66']))
|
||||||
|
self.assertFalse(resync_needed)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0'),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0')]
|
||||||
|
agent.eswitch_mgr.device_exists.assert_has_calls(calls, any_order=True)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0', True),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0', False)]
|
||||||
|
agent.eswitch_mgr.set_device_state.assert_has_calls(calls,
|
||||||
|
any_order=True)
|
||||||
|
calls = [mock.call('aa:bb:cc:dd:ee:ff', '1:2:3.0', False),
|
||||||
|
mock.call('11:22:33:44:55:66', '1:2:3.0', False)]
|
||||||
|
agent.eswitch_mgr.set_device_spoofcheck.assert_has_calls(calls,
|
||||||
|
any_order=True)
|
||||||
|
agent.plugin_rpc.update_device_list.assert_called_once_with(
|
||||||
|
mock.ANY,
|
||||||
|
set(['aa:bb:cc:dd:ee:ff']),
|
||||||
|
set(['11:22:33:44:55:66']),
|
||||||
|
mock.ANY,
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
def test_treat_device_ip_link_state_not_supported(self):
|
def test_treat_device_ip_link_state_not_supported(self):
|
||||||
agent = self.agent
|
agent = self.agent
|
||||||
@ -313,9 +414,8 @@ class TestSriovAgent(base.BaseTestCase):
|
|||||||
exceptions.IpCommandOperationNotSupportedError(
|
exceptions.IpCommandOperationNotSupportedError(
|
||||||
dev_name='aa:bb:cc:dd:ee:ff'))
|
dev_name='aa:bb:cc:dd:ee:ff'))
|
||||||
|
|
||||||
agent.treat_device('aa:bb:cc:dd:ee:ff', '1:2:3:0',
|
self.assertTrue(agent.treat_device('aa:bb:cc:dd:ee:ff', '1:2:3:0',
|
||||||
admin_state_up=True)
|
admin_state_up=True))
|
||||||
self.assertTrue(agent.plugin_rpc.update_device_up.called)
|
|
||||||
|
|
||||||
def test_treat_device_set_device_state_exception(self):
|
def test_treat_device_set_device_state_exception(self):
|
||||||
agent = self.agent
|
agent = self.agent
|
||||||
@ -325,9 +425,8 @@ class TestSriovAgent(base.BaseTestCase):
|
|||||||
agent.eswitch_mgr.set_device_state.side_effect = (
|
agent.eswitch_mgr.set_device_state.side_effect = (
|
||||||
exceptions.SriovNicError())
|
exceptions.SriovNicError())
|
||||||
|
|
||||||
agent.treat_device('aa:bb:cc:dd:ee:ff', '1:2:3:0',
|
self.assertFalse(agent.treat_device('aa:bb:cc:dd:ee:ff', '1:2:3:0',
|
||||||
admin_state_up=True)
|
admin_state_up=True))
|
||||||
self.assertFalse(agent.plugin_rpc.update_device_up.called)
|
|
||||||
|
|
||||||
def test_treat_devices_added_updated_admin_state_up_false(self):
|
def test_treat_devices_added_updated_admin_state_up_false(self):
|
||||||
agent = self.agent
|
agent = self.agent
|
||||||
@ -342,11 +441,17 @@ class TestSriovAgent(base.BaseTestCase):
|
|||||||
agent.plugin_rpc = mock.Mock()
|
agent.plugin_rpc = mock.Mock()
|
||||||
agent.plugin_rpc.get_devices_details_list.return_value = [mock_details]
|
agent.plugin_rpc.get_devices_details_list.return_value = [mock_details]
|
||||||
agent.remove_port_binding = mock.Mock()
|
agent.remove_port_binding = mock.Mock()
|
||||||
|
agent.eswitch_mgr = mock.Mock()
|
||||||
|
agent.eswitch_mgr.device_exists.return_value = True
|
||||||
resync_needed = agent.treat_devices_added_updated(
|
resync_needed = agent.treat_devices_added_updated(
|
||||||
set(['aa:bb:cc:dd:ee:ff']))
|
set(['aa:bb:cc:dd:ee:ff']))
|
||||||
|
|
||||||
self.assertFalse(resync_needed)
|
self.assertFalse(resync_needed)
|
||||||
self.assertFalse(agent.plugin_rpc.update_device_up.called)
|
agent.plugin_rpc.update_device_list.assert_called_once_with(
|
||||||
|
mock.ANY,
|
||||||
|
set(),
|
||||||
|
set(['aa:bb:cc:dd:ee:ff']),
|
||||||
|
mock.ANY,
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
def test_update_and_clean_network_ports(self):
|
def test_update_and_clean_network_ports(self):
|
||||||
network_id1 = 'network_id1'
|
network_id1 = 'network_id1'
|
||||||
|
Loading…
Reference in New Issue
Block a user