|
16 | 16 |
|
17 | 17 | import os
|
18 | 18 |
|
| 19 | +import ddt |
19 | 20 | import eventlet
|
20 | 21 | from eventlet import greenthread
|
21 | 22 | from eventlet import tpool
|
@@ -1831,26 +1832,34 @@ def setUp(self):
|
1831 | 1832 | self.host = host.Host("qemu:///system")
|
1832 | 1833 |
|
1833 | 1834 |
|
| 1835 | +@ddt.ddt |
1834 | 1836 | class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
1835 | 1837 | @mock.patch.object(os.path, 'exists', return_value=False)
|
1836 | 1838 | def test_kernel_parameter_missing(self, fake_exists):
|
1837 | 1839 | self.assertFalse(self.host._kernel_supports_amd_sev())
|
1838 | 1840 | fake_exists.assert_called_once_with(
|
1839 | 1841 | '/sys/module/kvm_amd/parameters/sev')
|
1840 | 1842 |
|
| 1843 | + @ddt.data( |
| 1844 | + ('0\n', False), |
| 1845 | + ('N\n', False), |
| 1846 | + ('1\n', True), |
| 1847 | + ('Y\n', True), |
| 1848 | + ) |
| 1849 | + @ddt.unpack |
1841 | 1850 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1842 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="0\n")) |
1843 |
| - def test_kernel_parameter_zero(self, fake_exists): |
1844 |
| - self.assertFalse(self.host._kernel_supports_amd_sev()) |
1845 |
| - fake_exists.assert_called_once_with( |
1846 |
| - '/sys/module/kvm_amd/parameters/sev') |
1847 |
| - |
1848 |
| - @mock.patch.object(os.path, 'exists', return_value=True) |
1849 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="1\n")) |
1850 |
| - def test_kernel_parameter_one(self, fake_exists): |
1851 |
| - self.assertTrue(self.host._kernel_supports_amd_sev()) |
1852 |
| - fake_exists.assert_called_once_with( |
1853 |
| - '/sys/module/kvm_amd/parameters/sev') |
| 1851 | + def test_kernel_parameter( |
| 1852 | + self, sev_param_value, expected_support, mock_exists |
| 1853 | + ): |
| 1854 | + with mock.patch( |
| 1855 | + 'builtins.open', mock.mock_open(read_data=sev_param_value) |
| 1856 | + ): |
| 1857 | + self.assertIs( |
| 1858 | + expected_support, |
| 1859 | + self.host._kernel_supports_amd_sev() |
| 1860 | + ) |
| 1861 | + mock_exists.assert_called_once_with( |
| 1862 | + '/sys/module/kvm_amd/parameters/sev') |
1854 | 1863 |
|
1855 | 1864 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1856 | 1865 | @mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
|
0 commit comments