diff options
| author | Kaifeng Wang <kaifeng.w@gmail.com> | 2020-08-03 14:13:33 +0800 |
|---|---|---|
| committer | Kaifeng Wang <kaifeng.w@gmail.com> | 2020-08-04 23:32:37 +0800 |
| commit | b424fbfa35d4014839ef84400bd9fcb63a2ed7f6 (patch) | |
| tree | 688bc32e8ce78798a1d1dda168dc2b7e84149566 /ironic_python_agent/tests | |
| parent | a9ed390f08c0dd8263a0050a12b36efc36c70c48 (diff) | |
| download | ironic-python-agent-b424fbfa35d4014839ef84400bd9fcb63a2ed7f6.tar.gz | |
Extends pci devices metrics
Collects PCI class, revision, and bus information for the pci-devices
collector, these metrics as well as vendor id and device id are
components which can be used to construct device information like
lspci output, which is how cyborg agent collects accelerator devices.
Accelerator device based scheduling is possible after ironic has such
information in place.
Change-Id: I6c37c554f37dd5f1d21c8fd4fad2a4f44a3c75d7
Story: 2007971
Task: 40474
Diffstat (limited to 'ironic_python_agent/tests')
| -rw-r--r-- | ironic_python_agent/tests/unit/test_inspector.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index 4c464185..c1fe2fc2 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -361,14 +361,21 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest): self.data = {} self.failures = utils.AccumulatedFailures() + @mock.patch.object(os.path, 'isfile', autospec=True) @mock.patch.object(os.path, 'isdir', autospec=True) - def test_success(self, mock_isdir, mock_listdir): + def test_success(self, mock_isdir, mock_isfile, mock_listdir): subdirs = ['foo', 'bar'] mock_listdir.return_value = subdirs + mock_isfile.return_value = True mock_isdir.return_value = True - reads = ['0x1234', '0x5678', '0x9876', '0x5432'] - expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678'}, - {'vendor_id': '9876', 'product_id': '5432'}] + reads = ['0x1234', '0x5678', '0x060000', '0x01', + '0x9876', '0x5432', '0x030000', '0x00'] + expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678', + 'class': '060000', 'revision': '01', + 'bus': 'foo'}, + {'vendor_id': '9876', 'product_id': '5432', + 'class': '030000', 'revision': '00', + 'bus': 'bar'}] mock_open = mock.mock_open() with mock.patch('builtins.open', mock_open): @@ -376,7 +383,7 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest): mock_read.side_effect = reads inspector.collect_pci_devices_info(self.data, self.failures) - self.assertEqual(2 * len(subdirs), mock_open.call_count) + self.assertEqual(4 * len(subdirs), mock_open.call_count) self.assertListEqual(expected_pci_devices, self.data['pci_devices']) def test_wrong_path(self, mock_listdir): @@ -387,14 +394,18 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest): self.assertNotIn('pci_devices', self.data) self.assertEqual(1, len(self.failures._failures)) + @mock.patch.object(os.path, 'isfile', autospec=True) @mock.patch.object(os.path, 'isdir', autospec=True) - def test_bad_pci_device_info(self, mock_isdir, mock_listdir): + def test_bad_pci_device_info(self, mock_isdir, mock_isfile, mock_listdir): subdirs = ['foo', 'bar', 'baz'] mock_listdir.return_value = subdirs + mock_isfile.return_value = False mock_isdir.return_value = True - reads = ['0x1234', '0x5678', '0x9876', IOError, IndexError, - '0x5432'] - expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678'}] + reads = ['0x1234', '0x5678', '0x060000', '0x9876', + IOError, IndexError] + expected_pci_devices = [{'vendor_id': '1234', 'product_id': '5678', + 'class': '060000', 'revision': None, + 'bus': 'foo'}] mock_open = mock.mock_open() with mock.patch('builtins.open', mock_open): @@ -403,8 +414,8 @@ class TestCollectPciDevicesInfo(base.IronicAgentTest): inspector.collect_pci_devices_info(self.data, self.failures) # note(sborkows): due to throwing IOError, the corresponding mock_open - # will not be called, so there are 5 mock_open calls in total - self.assertEqual(5, mock_open.call_count) + # will not be called, so there are 6 mock_open calls in total + self.assertEqual(6, mock_open.call_count) self.assertListEqual(expected_pci_devices, self.data['pci_devices']) |
