|
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
|
@@ -1947,26 +1948,34 @@ def setUp(self):
|
1947 | 1948 | self.host = host.Host("qemu:///system")
|
1948 | 1949 |
|
1949 | 1950 |
|
| 1951 | +@ddt.ddt |
1950 | 1952 | class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
1951 | 1953 | @mock.patch.object(os.path, 'exists', return_value=False)
|
1952 | 1954 | def test_kernel_parameter_missing(self, fake_exists):
|
1953 | 1955 | self.assertFalse(self.host._kernel_supports_amd_sev())
|
1954 | 1956 | fake_exists.assert_called_once_with(
|
1955 | 1957 | '/sys/module/kvm_amd/parameters/sev')
|
1956 | 1958 |
|
| 1959 | + @ddt.data( |
| 1960 | + ('0\n', False), |
| 1961 | + ('N\n', False), |
| 1962 | + ('1\n', True), |
| 1963 | + ('Y\n', True), |
| 1964 | + ) |
| 1965 | + @ddt.unpack |
1957 | 1966 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1958 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="0\n")) |
1959 |
| - def test_kernel_parameter_zero(self, fake_exists): |
1960 |
| - self.assertFalse(self.host._kernel_supports_amd_sev()) |
1961 |
| - fake_exists.assert_called_once_with( |
1962 |
| - '/sys/module/kvm_amd/parameters/sev') |
1963 |
| - |
1964 |
| - @mock.patch.object(os.path, 'exists', return_value=True) |
1965 |
| - @mock.patch('builtins.open', mock.mock_open(read_data="1\n")) |
1966 |
| - def test_kernel_parameter_one(self, fake_exists): |
1967 |
| - self.assertTrue(self.host._kernel_supports_amd_sev()) |
1968 |
| - fake_exists.assert_called_once_with( |
1969 |
| - '/sys/module/kvm_amd/parameters/sev') |
| 1967 | + def test_kernel_parameter( |
| 1968 | + self, sev_param_value, expected_support, mock_exists |
| 1969 | + ): |
| 1970 | + with mock.patch( |
| 1971 | + 'builtins.open', mock.mock_open(read_data=sev_param_value) |
| 1972 | + ): |
| 1973 | + self.assertIs( |
| 1974 | + expected_support, |
| 1975 | + self.host._kernel_supports_amd_sev() |
| 1976 | + ) |
| 1977 | + mock_exists.assert_called_once_with( |
| 1978 | + '/sys/module/kvm_amd/parameters/sev') |
1970 | 1979 |
|
1971 | 1980 | @mock.patch.object(os.path, 'exists', return_value=True)
|
1972 | 1981 | @mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
|
0 commit comments