|
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
|
@@ -1821,26 +1822,34 @@ def setUp(self):
|
1821 | 1822 | self.host = host.Host("qemu:///system")
|
1822 | 1823 |
|
1823 | 1824 |
|
| 1825 | +@ddt.ddt |
1824 | 1826 | class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
1825 | 1827 | @mock.patch.object(os.path, 'exists', return_value=False)
|
1826 | 1828 | def test_kernel_parameter_missing(self, fake_exists):
|
1827 | 1829 | self.assertFalse(self.host._kernel_supports_amd_sev())
|
1828 | 1830 | fake_exists.assert_called_once_with(
|
1829 | 1831 | '/sys/module/kvm_amd/parameters/sev')
|
1830 | 1832 |
|
| 1833 | + @ddt.data( |
| 1834 | + ('0\n', False), |
| 1835 | + ('N\n', False), |
| 1836 | + ('1\n', True), |
| 1837 | + ('Y\n', True), |
| 1838 | + ) |
| 1839 | + @ddt.unpack |
1831 | 1840 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1832 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="0\n")) |
1833 |
| - def test_kernel_parameter_zero(self, fake_exists): |
1834 |
| - self.assertFalse(self.host._kernel_supports_amd_sev()) |
1835 |
| - fake_exists.assert_called_once_with( |
1836 |
| - '/sys/module/kvm_amd/parameters/sev') |
1837 |
| - |
1838 |
| - @mock.patch.object(os.path, 'exists', return_value=True) |
1839 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="1\n")) |
1840 |
| - def test_kernel_parameter_one(self, fake_exists): |
1841 |
| - self.assertTrue(self.host._kernel_supports_amd_sev()) |
1842 |
| - fake_exists.assert_called_once_with( |
1843 |
| - '/sys/module/kvm_amd/parameters/sev') |
| 1841 | + def test_kernel_parameter( |
| 1842 | + self, sev_param_value, expected_support, mock_exists |
| 1843 | + ): |
| 1844 | + with mock.patch( |
| 1845 | + 'builtins.open', mock.mock_open(read_data=sev_param_value) |
| 1846 | + ): |
| 1847 | + self.assertIs( |
| 1848 | + expected_support, |
| 1849 | + self.host._kernel_supports_amd_sev() |
| 1850 | + ) |
| 1851 | + mock_exists.assert_called_once_with( |
| 1852 | + '/sys/module/kvm_amd/parameters/sev') |
1844 | 1853 |
|
1845 | 1854 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1846 | 1855 | @mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
|
0 commit comments