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