pci: Remove get_pci_devices_filter() method
Continuing the cleanup of the PCI modules, this patch gets rid of the nova.pci.whitelist.get_pci_devices_filter() method which did nothing other than return a nova.pci.whitelist.PciHostDevicesWhiteList object. While at it, rename the PciHostDevicesWhiteList class to just Whitelist to save eyeballs. Change-Id: I403248c5343d5ac97d9ab7716e2c817fcc30a3b7
This commit is contained in:
parent
bc10ba2a69
commit
a00e425f57
|
@ -16,6 +16,7 @@
|
|||
|
||||
import collections
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
|
@ -28,6 +29,7 @@ from nova.pci import stats
|
|||
from nova.pci import whitelist
|
||||
from nova.virt import hardware
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -55,7 +57,7 @@ class PciDevTracker(object):
|
|||
self.stale = {}
|
||||
self.node_id = node_id
|
||||
self.stats = stats.PciDeviceStats()
|
||||
self.dev_filter = whitelist.get_pci_devices_filter()
|
||||
self.dev_filter = whitelist.Whitelist(CONF.pci_passthrough_whitelist)
|
||||
if node_id:
|
||||
self.pci_devs = list(
|
||||
objects.PciDeviceList.get_by_compute_node(context, node_id))
|
||||
|
|
|
@ -35,7 +35,7 @@ CONF.register_opts(pci_opts)
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PciHostDevicesWhiteList(object):
|
||||
class Whitelist(object):
|
||||
|
||||
"""White list class to decide assignable pci devices.
|
||||
|
||||
|
@ -84,7 +84,7 @@ class PciHostDevicesWhiteList(object):
|
|||
each dictionary specifies the pci device
|
||||
properties requirement.
|
||||
"""
|
||||
super(PciHostDevicesWhiteList, self).__init__()
|
||||
super(Whitelist, self).__init__()
|
||||
if whitelist_spec:
|
||||
self.specs = self._parse_white_list_from_config(whitelist_spec)
|
||||
else:
|
||||
|
@ -106,10 +106,6 @@ class PciHostDevicesWhiteList(object):
|
|||
return spec
|
||||
|
||||
|
||||
def get_pci_devices_filter():
|
||||
return PciHostDevicesWhiteList(CONF.pci_passthrough_whitelist)
|
||||
|
||||
|
||||
def get_pci_device_devspec(pci_dev):
|
||||
dev_filter = get_pci_devices_filter()
|
||||
dev_filter = Whitelist(CONF.pci_passthrough_whitelist)
|
||||
return dev_filter.get_devspec(pci_dev)
|
||||
|
|
|
@ -139,7 +139,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase):
|
|||
self.tracker = manager.PciDevTracker(self.fake_context, node_id=1)
|
||||
mock_get_cn.assert_called_once_with(self.fake_context, 1)
|
||||
|
||||
@mock.patch('nova.pci.whitelist.PciHostDevicesWhiteList.device_assignable',
|
||||
@mock.patch('nova.pci.whitelist.Whitelist.device_assignable',
|
||||
return_value=True)
|
||||
def test_update_devices_from_hypervisor_resources(self, _mock_dev_assign):
|
||||
fake_pci_devs = [copy.deepcopy(fake_pci), copy.deepcopy(fake_pci_2)]
|
||||
|
|
|
@ -13,14 +13,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
import six
|
||||
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.pci import stats
|
||||
from nova.pci import whitelist
|
||||
from nova import test
|
||||
from nova.tests.unit.pci import fakes
|
||||
fake_pci_1 = {
|
||||
|
@ -202,19 +199,15 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
|||
set([dev.vendor_id for dev in devs]))
|
||||
|
||||
|
||||
@mock.patch.object(whitelist, 'get_pci_devices_filter')
|
||||
class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PciDeviceStatsWithTagsTestCase, self).setUp()
|
||||
self.pci_stats = stats.PciDeviceStats()
|
||||
self._create_whitelist()
|
||||
|
||||
def _create_whitelist(self):
|
||||
white_list = ['{"vendor_id":"1137","product_id":"0071",'
|
||||
'"address":"*:0a:00.*","physical_network":"physnet1"}',
|
||||
'{"vendor_id":"1137","product_id":"0072"}']
|
||||
self.pci_wlist = whitelist.PciHostDevicesWhiteList(white_list)
|
||||
self.flags(pci_passthrough_whitelist=white_list)
|
||||
self.pci_stats = stats.PciDeviceStats()
|
||||
|
||||
def _create_pci_devices(self):
|
||||
self.pci_tagged_devices = []
|
||||
|
@ -267,13 +260,11 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
|
|||
self.assertEqual(self.pci_tagged_devices,
|
||||
self.pci_stats.pools[1]['devices'])
|
||||
|
||||
def test_add_devices(self, mock_get_dev_filter):
|
||||
mock_get_dev_filter.return_value = self.pci_wlist
|
||||
def test_add_devices(self):
|
||||
self._create_pci_devices()
|
||||
self._assertPools()
|
||||
|
||||
def test_consume_reqeusts(self, mock_get_dev_filter):
|
||||
mock_get_dev_filter.return_value = self.pci_wlist
|
||||
def test_consume_reqeusts(self):
|
||||
self._create_pci_devices()
|
||||
pci_requests = [objects.InstancePCIRequest(count=1,
|
||||
spec=[{'physical_network': 'physnet1'}]),
|
||||
|
@ -288,8 +279,7 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
|
|||
self._assertPoolContent(self.pci_stats.pools[1], '1137', '0071', 3,
|
||||
physical_network='physnet1')
|
||||
|
||||
def test_add_device_no_devspec(self, mock_get_dev_filter):
|
||||
mock_get_dev_filter.return_value = self.pci_wlist
|
||||
def test_add_device_no_devspec(self):
|
||||
self._create_pci_devices()
|
||||
pci_dev = {'compute_node_id': 1,
|
||||
'address': '0000:0c:00.1',
|
||||
|
@ -304,8 +294,7 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
|
|||
self.pci_stats._create_pool_keys_from_dev(pci_dev_obj))
|
||||
self._assertPools()
|
||||
|
||||
def test_remove_device_no_devspec(self, mock_get_dev_filter):
|
||||
mock_get_dev_filter.return_value = self.pci_wlist
|
||||
def test_remove_device_no_devspec(self):
|
||||
self._create_pci_devices()
|
||||
pci_dev = {'compute_node_id': 1,
|
||||
'address': '0000:0c:00.1',
|
||||
|
@ -320,8 +309,7 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase):
|
|||
self.pci_stats._create_pool_keys_from_dev(pci_dev_obj))
|
||||
self._assertPools()
|
||||
|
||||
def test_remove_device(self, mock_get_dev_filter):
|
||||
mock_get_dev_filter.return_value = self.pci_wlist
|
||||
def test_remove_device(self):
|
||||
self._create_pci_devices()
|
||||
dev1 = self.pci_untagged_devices.pop()
|
||||
self.pci_stats.remove_device(dev1)
|
||||
|
|
|
@ -27,46 +27,40 @@ dev_dict = {
|
|||
}
|
||||
|
||||
|
||||
class PciHostDevicesWhiteListTestCase(test.NoDBTestCase):
|
||||
class WhitelistTestCase(test.NoDBTestCase):
|
||||
def test_whitelist(self):
|
||||
white_list = '{"product_id":"0001", "vendor_id":"8086"}'
|
||||
parsed = whitelist.PciHostDevicesWhiteList([white_list])
|
||||
parsed = whitelist.Whitelist([white_list])
|
||||
self.assertEqual(1, len(parsed.specs))
|
||||
|
||||
def test_whitelist_list_format(self):
|
||||
white_list = '[{"product_id":"0001", "vendor_id":"8086"},'\
|
||||
'{"product_id":"0002", "vendor_id":"8086"}]'
|
||||
parsed = whitelist.PciHostDevicesWhiteList([white_list])
|
||||
parsed = whitelist.Whitelist([white_list])
|
||||
self.assertEqual(2, len(parsed.specs))
|
||||
|
||||
def test_whitelist_empty(self):
|
||||
parsed = whitelist.PciHostDevicesWhiteList()
|
||||
parsed = whitelist.Whitelist()
|
||||
self.assertFalse(parsed.device_assignable(dev_dict))
|
||||
|
||||
def test_whitelist_multiple(self):
|
||||
wl1 = '{"product_id":"0001", "vendor_id":"8086"}'
|
||||
wl2 = '{"product_id":"0002", "vendor_id":"8087"}'
|
||||
parsed = whitelist.PciHostDevicesWhiteList([wl1, wl2])
|
||||
parsed = whitelist.Whitelist([wl1, wl2])
|
||||
self.assertEqual(2, len(parsed.specs))
|
||||
|
||||
def test_device_assignable(self):
|
||||
white_list = '{"product_id":"0001", "vendor_id":"8086"}'
|
||||
parsed = whitelist.PciHostDevicesWhiteList([white_list])
|
||||
parsed = whitelist.Whitelist([white_list])
|
||||
self.assertTrue(parsed.device_assignable(dev_dict))
|
||||
|
||||
def test_device_assignable_multiple(self):
|
||||
white_list_1 = '{"product_id":"0001", "vendor_id":"8086"}'
|
||||
white_list_2 = '{"product_id":"0002", "vendor_id":"8087"}'
|
||||
parsed = whitelist.PciHostDevicesWhiteList(
|
||||
parsed = whitelist.Whitelist(
|
||||
[white_list_1, white_list_2])
|
||||
self.assertTrue(parsed.device_assignable(dev_dict))
|
||||
dev_dict1 = dev_dict.copy()
|
||||
dev_dict1['vendor_id'] = '8087'
|
||||
dev_dict1['product_id'] = '0002'
|
||||
self.assertTrue(parsed.device_assignable(dev_dict1))
|
||||
|
||||
def test_get_pci_devices_filter(self):
|
||||
white_list_1 = '{"product_id":"0001", "vendor_id":"8086"}'
|
||||
self.flags(pci_passthrough_whitelist=[white_list_1])
|
||||
pci_filter = whitelist.get_pci_devices_filter()
|
||||
self.assertTrue(pci_filter.device_assignable(dev_dict))
|
||||
|
|
Loading…
Reference in New Issue