|
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
|
@@ -1844,26 +1845,34 @@ def setUp(self):
|
1844 | 1845 | self.host = host.Host("qemu:///system")
|
1845 | 1846 |
|
1846 | 1847 |
|
| 1848 | +@ddt.ddt |
1847 | 1849 | class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
1848 | 1850 | @mock.patch.object(os.path, 'exists', return_value=False)
|
1849 | 1851 | def test_kernel_parameter_missing(self, fake_exists):
|
1850 | 1852 | self.assertFalse(self.host._kernel_supports_amd_sev())
|
1851 | 1853 | fake_exists.assert_called_once_with(
|
1852 | 1854 | '/sys/module/kvm_amd/parameters/sev')
|
1853 | 1855 |
|
| 1856 | + @ddt.data( |
| 1857 | + ('0\n', False), |
| 1858 | + ('N\n', False), |
| 1859 | + ('1\n', True), |
| 1860 | + ('Y\n', True), |
| 1861 | + ) |
| 1862 | + @ddt.unpack |
1854 | 1863 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1855 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="0\n")) |
1856 |
| - def test_kernel_parameter_zero(self, fake_exists): |
1857 |
| - self.assertFalse(self.host._kernel_supports_amd_sev()) |
1858 |
| - fake_exists.assert_called_once_with( |
1859 |
| - '/sys/module/kvm_amd/parameters/sev') |
1860 |
| - |
1861 |
| - @mock.patch.object(os.path, 'exists', return_value=True) |
1862 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="1\n")) |
1863 |
| - def test_kernel_parameter_one(self, fake_exists): |
1864 |
| - self.assertTrue(self.host._kernel_supports_amd_sev()) |
1865 |
| - fake_exists.assert_called_once_with( |
1866 |
| - '/sys/module/kvm_amd/parameters/sev') |
| 1864 | + def test_kernel_parameter( |
| 1865 | + self, sev_param_value, expected_support, mock_exists |
| 1866 | + ): |
| 1867 | + with mock.patch( |
| 1868 | + 'builtins.open', mock.mock_open(read_data=sev_param_value) |
| 1869 | + ): |
| 1870 | + self.assertIs( |
| 1871 | + expected_support, |
| 1872 | + self.host._kernel_supports_amd_sev() |
| 1873 | + ) |
| 1874 | + mock_exists.assert_called_once_with( |
| 1875 | + '/sys/module/kvm_amd/parameters/sev') |
1867 | 1876 |
|
1868 | 1877 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1869 | 1878 | @mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
|
0 commit comments