|
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
|
@@ -1928,26 +1929,34 @@ def setUp(self):
|
1928 | 1929 | self.host = host.Host("qemu:///system")
|
1929 | 1930 |
|
1930 | 1931 |
|
| 1932 | +@ddt.ddt |
1931 | 1933 | class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
1932 | 1934 | @mock.patch.object(os.path, 'exists', return_value=False)
|
1933 | 1935 | def test_kernel_parameter_missing(self, fake_exists):
|
1934 | 1936 | self.assertFalse(self.host._kernel_supports_amd_sev())
|
1935 | 1937 | fake_exists.assert_called_once_with(
|
1936 | 1938 | '/sys/module/kvm_amd/parameters/sev')
|
1937 | 1939 |
|
| 1940 | + @ddt.data( |
| 1941 | + ('0\n', False), |
| 1942 | + ('N\n', False), |
| 1943 | + ('1\n', True), |
| 1944 | + ('Y\n', True), |
| 1945 | + ) |
| 1946 | + @ddt.unpack |
1938 | 1947 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1939 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="0\n")) |
1940 |
| - def test_kernel_parameter_zero(self, fake_exists): |
1941 |
| - self.assertFalse(self.host._kernel_supports_amd_sev()) |
1942 |
| - fake_exists.assert_called_once_with( |
1943 |
| - '/sys/module/kvm_amd/parameters/sev') |
1944 |
| - |
1945 |
| - @mock.patch.object(os.path, 'exists', return_value=True) |
1946 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="1\n")) |
1947 |
| - def test_kernel_parameter_one(self, fake_exists): |
1948 |
| - self.assertTrue(self.host._kernel_supports_amd_sev()) |
1949 |
| - fake_exists.assert_called_once_with( |
1950 |
| - '/sys/module/kvm_amd/parameters/sev') |
| 1948 | + def test_kernel_parameter( |
| 1949 | + self, sev_param_value, expected_support, mock_exists |
| 1950 | + ): |
| 1951 | + with mock.patch( |
| 1952 | + 'builtins.open', mock.mock_open(read_data=sev_param_value) |
| 1953 | + ): |
| 1954 | + self.assertIs( |
| 1955 | + expected_support, |
| 1956 | + self.host._kernel_supports_amd_sev() |
| 1957 | + ) |
| 1958 | + mock_exists.assert_called_once_with( |
| 1959 | + '/sys/module/kvm_amd/parameters/sev') |
1951 | 1960 |
|
1952 | 1961 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1953 | 1962 | @mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
|
0 commit comments