Skip to content

Commit

Permalink
Consolidate sriov agent and driver code
Browse files Browse the repository at this point in the history
In preparation for decomposing the built-in reference implementation,
this commits consolidates the sriov agent and driver code into a
coherent place for it's life in the new repository. I've also given
the unit tests a new home.

DocImpact
UpgradeImpact

Partially-Implements: blueprint reference-implementation-split
Partial-Bug: #1468433
Closes-Bug: #1427317

Change-Id: Ic8b5215de76e191030228bc28773cd6535e889d8
Signed-off-by: Kyle Mestery <mestery@mestery.com>
  • Loading branch information
mestery committed Jun 26, 2015
1 parent ab971d7 commit f242b17
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 91 deletions.
File renamed without changes.
Expand Up @@ -21,8 +21,9 @@
import six

from neutron.i18n import _LE, _LW
from neutron.plugins.sriovnicagent.common import exceptions as exc
from neutron.plugins.sriovnicagent import pci_lib
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.agent import pci_lib

LOG = logging.getLogger(__name__)

Expand Down
Expand Up @@ -19,7 +19,8 @@

from neutron.agent.linux import ip_lib
from neutron.i18n import _LE, _LW
from neutron.plugins.sriovnicagent.common import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
import exceptions as exc

LOG = logging.getLogger(__name__)

Expand Down
Expand Up @@ -34,9 +34,10 @@
from neutron import context
from neutron.i18n import _LE, _LI
from neutron.openstack.common import loopingcall
from neutron.plugins.sriovnicagent.common import config # noqa
from neutron.plugins.sriovnicagent.common import exceptions as exc
from neutron.plugins.sriovnicagent import eswitch_manager as esm
from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config # noqa
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.agent import eswitch_manager as esm


LOG = logging.getLogger(__name__)
Expand Down
Expand Up @@ -22,7 +22,8 @@
from neutron.i18n import _LE, _LW
from neutron.plugins.common import constants as p_const
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers.mech_sriov import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.mech_driver \
import exceptions as exc


LOG = log.getLogger(__name__)
Expand Down
Expand Up @@ -17,8 +17,9 @@
from oslo_config import cfg

from neutron.common import utils as q_utils
from neutron.plugins.sriovnicagent.common import config
from neutron.plugins.sriovnicagent import sriov_nic_agent as agent
from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config
from neutron.plugins.ml2.drivers.mech_sriov.agent \
import sriov_nic_agent as agent
from neutron.tests import base


Expand Down
Expand Up @@ -20,8 +20,9 @@
import testtools


from neutron.plugins.sriovnicagent.common import exceptions as exc
from neutron.plugins.sriovnicagent import eswitch_manager as esm
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.agent import eswitch_manager as esm
from neutron.tests import base


Expand All @@ -32,23 +33,25 @@ class TestCreateESwitchManager(base.BaseTestCase):

def test_create_eswitch_mgr_fail(self):
device_mappings = {'physnet1': 'p6p1'}
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.scan_vf_devices",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.scan_vf_devices",
side_effect=exc.InvalidDeviceError(
dev_name="p6p1", reason="device" " not found")),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):

with testtools.ExpectedException(exc.InvalidDeviceError):
esm.ESwitchManager(device_mappings, None)

def test_create_eswitch_mgr_ok(self):
device_mappings = {'physnet1': 'p6p1'}
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.scan_vf_devices",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.scan_vf_devices",
return_value=self.SCANNED_DEVICES),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):

esm.ESwitchManager(device_mappings, None)

Expand All @@ -66,49 +69,52 @@ class TestESwitchManagerApi(base.BaseTestCase):
def setUp(self):
super(TestESwitchManagerApi, self).setUp()
device_mappings = {'physnet1': 'p6p1'}
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.scan_vf_devices",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.scan_vf_devices",
return_value=self.SCANNED_DEVICES),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):
self.eswitch_mgr = esm.ESwitchManager(device_mappings, None)

def test_get_assigned_devices(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_assigned_devices",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_assigned_devices",
return_value=[self.ASSIGNED_MAC]):
result = self.eswitch_mgr.get_assigned_devices()
self.assertEqual(set([self.ASSIGNED_MAC]), result)

def test_get_device_status_true(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_device_state", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_device_state",
return_value=True):
result = self.eswitch_mgr.get_device_state(self.ASSIGNED_MAC,
self.PCI_SLOT)
self.assertTrue(result)

def test_get_device_status_false(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_device_state",
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_device_state",
return_value=False):
result = self.eswitch_mgr.get_device_state(self.ASSIGNED_MAC,
self.PCI_SLOT)
self.assertFalse(result)

def test_get_device_status_mismatch(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_device_state", return_value=True):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"LOG.warning") as log_mock:
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_device_state",
return_value=True):
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.LOG.warning") as log_mock:
result = self.eswitch_mgr.get_device_state(self.WRONG_MAC,
self.PCI_SLOT)
log_mock.assert_called_with('device pci mismatch: '
Expand All @@ -118,22 +124,22 @@ def test_get_device_status_mismatch(self):
self.assertFalse(result)

def test_set_device_status(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.set_device_state"):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.set_device_state"):
self.eswitch_mgr.set_device_state(self.ASSIGNED_MAC,
self.PCI_SLOT, True)

def test_set_device_status_mismatch(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.set_device_state"):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"LOG.warning") as log_mock:
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.set_device_state"):
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.LOG.warning") as log_mock:
self.eswitch_mgr.set_device_state(self.WRONG_MAC,
self.PCI_SLOT, True)
log_mock.assert_called_with('device pci mismatch: '
Expand All @@ -142,8 +148,8 @@ def test_set_device_status_mismatch(self):
'device_mac': self.WRONG_MAC})

def _mock_device_exists(self, pci_slot, mac_address, expected_result):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC):
result = self.eswitch_mgr.device_exists(mac_address,
pci_slot)
Expand All @@ -160,11 +166,11 @@ def test_device_exists_false(self):
False)

def test_device_exists_mismatch(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"EmbSwitch.get_pci_device",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.EmbSwitch.get_pci_device",
return_value=self.ASSIGNED_MAC):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"LOG.warning") as log_mock:
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.LOG.warning") as log_mock:
result = self.eswitch_mgr.device_exists(self.WRONG_MAC,
self.PCI_SLOT)
log_mock.assert_called_with('device pci mismatch: '
Expand All @@ -187,73 +193,76 @@ class TestEmbSwitch(base.BaseTestCase):
def setUp(self):
super(TestEmbSwitch, self).setUp()
exclude_devices = set()
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.scan_vf_devices",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.scan_vf_devices",
return_value=self.SCANNED_DEVICES):
self.emb_switch = esm.EmbSwitch(self.PHYS_NET, self.DEV_NAME,
exclude_devices)

def test_get_assigned_devices(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.get_assigned_macs",
return_value=[self.ASSIGNED_MAC]),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):
result = self.emb_switch.get_assigned_devices()
self.assertEqual([self.ASSIGNED_MAC], result)

def test_get_assigned_devices_empty(self):
with mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf",
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=False):
result = self.emb_switch.get_assigned_devices()
self.assertFalse(result)

def test_get_device_state_ok(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.get_vf_state",
return_value=False):
result = self.emb_switch.get_device_state(self.PCI_SLOT)
self.assertFalse(result)

def test_get_device_state_fail(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.get_vf_state",
return_value=False):
self.assertRaises(exc.InvalidPciSlotError,
self.emb_switch.get_device_state,
self.WRONG_PCI_SLOT)

def test_set_device_state_ok(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.set_vf_state"):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib.LOG."
"warning") as log_mock:
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"pci_lib.LOG.warning") as log_mock:
self.emb_switch.set_device_state(self.PCI_SLOT, True)
self.assertEqual(0, log_mock.call_count)

def test_set_device_state_fail(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.set_vf_state"):
self.assertRaises(exc.InvalidPciSlotError,
self.emb_switch.set_device_state,
self.WRONG_PCI_SLOT, True)

def test_get_pci_device(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.get_assigned_macs",
return_value=[self.ASSIGNED_MAC]),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):
result = self.emb_switch.get_pci_device(self.PCI_SLOT)
self.assertEqual(self.ASSIGNED_MAC, result)

def test_get_pci_device_fail(self):
with mock.patch("neutron.plugins.sriovnicagent.pci_lib."
with mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent.pci_lib."
"PciDeviceIPWrapper.get_assigned_macs",
return_value=[self.ASSIGNED_MAC]),\
mock.patch("neutron.plugins.sriovnicagent.eswitch_manager."
"PciOsWrapper.is_assigned_vf", return_value=True):
mock.patch("neutron.plugins.ml2.drivers.mech_sriov.agent."
"eswitch_manager.PciOsWrapper.is_assigned_vf",
return_value=True):
result = self.emb_switch.get_pci_device(self.WRONG_PCI_SLOT)
self.assertIsNone(result)

Expand Down
Expand Up @@ -16,8 +16,9 @@

import mock

from neutron.plugins.sriovnicagent.common import exceptions as exc
from neutron.plugins.sriovnicagent import pci_lib
from neutron.plugins.ml2.drivers.mech_sriov.agent.common \
import exceptions as exc
from neutron.plugins.ml2.drivers.mech_sriov.agent import pci_lib
from neutron.tests import base


Expand Down
Expand Up @@ -17,8 +17,8 @@
import mock
from oslo_config import cfg

from neutron.plugins.sriovnicagent.common import config # noqa
from neutron.plugins.sriovnicagent import sriov_nic_agent
from neutron.plugins.ml2.drivers.mech_sriov.agent.common import config # noqa
from neutron.plugins.ml2.drivers.mech_sriov.agent import sriov_nic_agent
from neutron.tests import base

DEVICE_MAC = '11:22:33:44:55:66'
Expand Down

0 comments on commit f242b17

Please sign in to comment.