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