|
59 | 59 |
|
60 | 60 | pcie_check_result_no = [] |
61 | 61 |
|
62 | | -pcie_check_result_pass = [{'bus': '00', 'dev': '01', 'fn': '0', 'id': '1f10', 'name': 'PCI A', 'result': 'Passed'}, |
| 62 | +pcie_check_result_pass = \ |
| 63 | +""" |
| 64 | +[{'bus': '00', 'dev': '01', 'fn': '0', 'id': '1f10', 'name': 'PCI A', 'result': 'Passed'}, |
63 | 65 | {'bus': '00', 'dev': '02', 'fn': '0', 'id': '1f11', 'name': 'PCI B', 'result': 'Passed'}, |
64 | 66 | {'bus': '00', 'dev': '03', 'fn': '0', 'id': '1f12', 'name': 'PCI C', 'result': 'Passed'}] |
| 67 | +""" |
65 | 68 |
|
66 | | - |
67 | | -pcie_check_result_fail = [{'bus': '00', 'dev': '01', 'fn': '0', 'id': '1f10', 'name': 'PCI A', 'result': 'Passed'}, |
| 69 | +pcie_check_result_fail = \ |
| 70 | +""" |
| 71 | +[{'bus': '00', 'dev': '01', 'fn': '0', 'id': '1f10', 'name': 'PCI A', 'result': 'Passed'}, |
68 | 72 | {'bus': '00', 'dev': '02', 'fn': '0', 'id': '1f11', 'name': 'PCI B', 'result': 'Passed'}, |
69 | 73 | {'bus': '00', 'dev': '03', 'fn': '0', 'id': '1f12', 'name': 'PCI C', 'result': 'Failed'}] |
70 | | - |
71 | | - |
72 | | -TEST_PLATFORM_PCIE_YAML_FILE = \ |
73 | | -""" |
74 | | -- bus: '00' |
75 | | - dev: '01' |
76 | | - fn: '0' |
77 | | - id: '9170' |
78 | | - name: 'PCI A' |
79 | 74 | """ |
80 | 75 |
|
81 | 76 | class TestDaemonPcied(object): |
@@ -148,125 +143,6 @@ def test_run(self): |
148 | 143 | daemon_pcied.run() |
149 | 144 | assert daemon_pcied.check_pcie_devices.call_count == 1 |
150 | 145 |
|
151 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
152 | | - def test_check_pcie_devices_yaml_file_open_error(self): |
153 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
154 | | - pcied.platform_pcieutil.get_pcie_check = mock.MagicMock() |
155 | | - |
156 | | - daemon_pcied.check_pcie_devices() |
157 | | - |
158 | | - assert pcied.platform_pcieutil.get_pcie_check.called |
159 | | - |
160 | | - |
161 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
162 | | - def test_check_pcie_devices_result_fail(self): |
163 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
164 | | - pcied.platform_pcieutil.get_pcie_check = mock.MagicMock(return_value=pcie_check_result_fail) |
165 | | - |
166 | | - daemon_pcied.check_pcie_devices() |
167 | | - |
168 | | - assert pcied.platform_pcieutil.get_pcie_check.called |
169 | | - |
170 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
171 | | - def test_check_pcie_devices_result_pass(self): |
172 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
173 | | - pcied.platform_pcieutil.get_pcie_check = mock.MagicMock(return_value=pcie_check_result_pass) |
174 | | - |
175 | | - daemon_pcied.check_pcie_devices() |
176 | | - |
177 | | - assert pcied.platform_pcieutil.get_pcie_check.called |
178 | | - |
179 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
180 | | - def test_check_pcie_devices_result_none(self): |
181 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
182 | | - pcied.platform_pcieutil.get_pcie_check = mock.MagicMock(return_value=None) |
183 | | - |
184 | | - daemon_pcied.check_pcie_devices() |
185 | | - |
186 | | - assert pcied.platform_pcieutil.get_pcie_check.called |
187 | | - |
188 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
189 | | - def test_check_pcie_devices_load_yaml_happy(self): |
190 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
191 | | - |
192 | | - with mock.patch('builtins.open', new_callable=mock.mock_open, read_data=TEST_PLATFORM_PCIE_YAML_FILE) as mock_fd: |
193 | | - |
194 | | - class MockOutput: |
195 | | - def decode(self, encodingType): |
196 | | - return self |
197 | | - def rstrip(self): |
198 | | - return "9170" |
199 | | - |
200 | | - mock_output = MockOutput() |
201 | | - with mock.patch('subprocess.check_output', mock.MagicMock()) as mock_check_output: |
202 | | - mock_check_output.return_value = mock_output |
203 | | - |
204 | | - daemon_pcied.check_pcie_devices() |
205 | | - |
206 | | - assert mock_check_output.called |
207 | | - |
208 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
209 | | - def test_check_pcie_devices_load_yaml_mismatch(self): |
210 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
211 | | - |
212 | | - with mock.patch('builtins.open', new_callable=mock.mock_open, read_data=TEST_PLATFORM_PCIE_YAML_FILE) as mock_fd: |
213 | | - |
214 | | - class MockOutput: |
215 | | - def decode(self, encodingType): |
216 | | - return self |
217 | | - def rstrip(self): |
218 | | - return "0123" |
219 | | - |
220 | | - mock_output = MockOutput() |
221 | | - with mock.patch('subprocess.check_output', mock.MagicMock()) as mock_check_output: |
222 | | - mock_check_output.return_value = mock_output |
223 | | - |
224 | | - daemon_pcied.check_pcie_devices() |
225 | | - |
226 | | - assert mock_check_output.called |
227 | | - |
228 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
229 | | - def test_check_pcie_devices_load_yaml_missing_device(self): |
230 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
231 | | - |
232 | | - with mock.patch('builtins.open', new_callable=mock.mock_open, read_data=TEST_PLATFORM_PCIE_YAML_FILE) as mock_fd: |
233 | | - |
234 | | - class MockOutput: |
235 | | - def decode(self, encodingType): |
236 | | - return self |
237 | | - def rstrip(self): |
238 | | - return "ffff" |
239 | | - |
240 | | - mock_output = MockOutput() |
241 | | - with mock.patch('subprocess.check_output', mock.MagicMock()) as mock_check_output: |
242 | | - mock_check_output.return_value = mock_output |
243 | | - |
244 | | - daemon_pcied.check_pcie_devices() |
245 | | - |
246 | | - assert mock_check_output.called |
247 | | - |
248 | | - @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
249 | | - def test_check_pcie_devices_load_yaml_invalid_device(self): |
250 | | - daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
251 | | - |
252 | | - with mock.patch('builtins.open', new_callable=mock.mock_open, read_data=TEST_PLATFORM_PCIE_YAML_FILE) as mock_fd: |
253 | | - |
254 | | - class MockOutput: |
255 | | - def decode(self, encodingType): |
256 | | - return self |
257 | | - def rstrip(self): |
258 | | - return "No devices selected" |
259 | | - |
260 | | - mock_output = MockOutput() |
261 | | - with mock.patch('subprocess.check_output', mock.MagicMock()) as mock_check_output: |
262 | | - mock_check_output.return_value = mock_output |
263 | | - |
264 | | - daemon_pcied.check_pcie_devices() |
265 | | - |
266 | | - assert mock_check_output.called |
267 | | - |
268 | | - |
269 | | - |
270 | 146 | @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) |
271 | 147 | def test_check_pcie_devices(self): |
272 | 148 | daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) |
|
0 commit comments