Skip to content

Commit

Permalink
Test UEFI var are kept upon live migration
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Reis <benjamin.reis@vates.tech>
  • Loading branch information
benjamreis committed Dec 6, 2024
1 parent 1ad468b commit 4355ce2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ def local_sr_on_hostB1(hostB1):
logging.info(">> local SR on hostB1 present : %s" % sr.uuid)
yield sr

@pytest.fixture(scope='session')
def existing_shared_sr(host):
sr = host.pool.first_shared_sr()
assert sr is not None, "A shared SR on the pool is required"
yield sr

@pytest.fixture(scope='session')
def sr_disk(pytestconfig, host):
disks = pytestconfig.getoption("sr_disk")
Expand Down
6 changes: 0 additions & 6 deletions tests/misc/test_basic_without_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
# the local SR or shared SR: the test will adapt itself.
# Note however that an existing VM will be left on a different SR after the tests.

@pytest.fixture(scope='session')
def existing_shared_sr(host):
sr = host.pool.first_shared_sr()
assert sr is not None, "A shared SR on the pool is required"
return sr

@pytest.mark.multi_vms # run them on a variety of VMs
@pytest.mark.big_vm # and also on a really big VM ideally
def test_vm_start_stop(imported_vm):
Expand Down
16 changes: 15 additions & 1 deletion tests/uefi_sb/test_uefistored_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from lib.common import wait_for

from .utils import _test_key_exchanges, boot_and_check_no_sb_errors, boot_and_check_sb_failed, \
boot_and_check_sb_succeeded, generate_keys, revert_vm_state, sign_efi_bins, VM_SECURE_BOOT_FAILED
boot_and_check_sb_succeeded, generate_keys, revert_vm_state, sign_efi_bins, VM_SECURE_BOOT_FAILED, \
_test_uefi_var_migrate

# These tests check the behaviour of XAPI and uefistored as they are in XCP-ng 8.2
# For XCP-ng 8.3 or later, see test_varstored_sb.py
Expand Down Expand Up @@ -217,3 +218,16 @@ def test_key_exchanges(self, uefi_vm):
vm = uefi_vm

_test_key_exchanges(vm)

@pytest.mark.small_vm
@pytest.mark.usefixtures("host_less_than_8_3", "existing_shared_sr")
@pytest.mark.usefixtures("pool_without_uefi_certs")
class TestUEFIVarMigrate:
@pytest.fixture(autouse=True)
def setup_and_cleanup(self, uefi_vm_and_snapshot):
vm, snapshot = uefi_vm_and_snapshot
yield
revert_vm_state(vm, snapshot)

def test_uefi_var_migrate(self, host, hostA2, uefi_vm):
_test_uefi_var_migrate(uefi_vm, host, hostA2)
14 changes: 13 additions & 1 deletion tests/uefi_sb/test_varstored_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from .utils import _test_key_exchanges, boot_and_check_no_sb_errors, boot_and_check_sb_failed, \
boot_and_check_sb_succeeded, generate_keys, revert_vm_state, sign_efi_bins
boot_and_check_sb_succeeded, generate_keys, revert_vm_state, sign_efi_bins, _test_uefi_var_migrate

# These tests check the behaviour of XAPI and varstored as they are in XCP-ng 8.3
# For XCP-ng 8.2, see test_uefistored_sb.py
Expand Down Expand Up @@ -153,3 +153,15 @@ def test_key_exchanges(self, uefi_vm):
vm.set_uefi_setup_mode()

_test_key_exchanges(vm)

@pytest.mark.small_vm
@pytest.mark.usefixtures("host_at_least_8_3", "existing_shared_sr")
class TestUEFIVarMigrate:
@pytest.fixture(autouse=True)
def setup_and_cleanup(self, uefi_vm_and_snapshot):
vm, snapshot = uefi_vm_and_snapshot
yield
revert_vm_state(vm, snapshot)

def test_uefi_var_migrate(self, host, hostA2, uefi_vm):
_test_uefi_var_migrate(uefi_vm, host, hostA2)
27 changes: 27 additions & 0 deletions tests/uefi_sb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,30 @@ def check_vm_cert_md5sum(vm, key, reference_file):
assert res.returncode == 0, f"Cert {key} must be present"
reference_md5 = get_md5sum_from_auth(reference_file)
assert hashlib.md5(res.stdout).hexdigest() == reference_md5

def _test_uefi_var_migrate(vm, source_host, dest_host):
shared_sr = source_host.pool.first_shared_sr()
vm.start(on=source_host.uuid)
vm.wait_for_os_booted()

res = vm.host.ssh(['varstore-ls', vm.uuid], simple_output=False)
reference = {}
for line in res.stdout.splitlines():
splitted_line = line.split(' ')
assert len(splitted_line) == 2
guid, name = splitted_line[0], splitted_line[1]
returned_res = vm.host.ssh(['varstore-get', vm.uuid, guid, name],
simple_output=False, decode=False)
md5 = hashlib.md5(returned_res.stdout).hexdigest()
reference[(guid, name)] = md5

vm.migrate(dest_host, shared_sr)
vm.reboot(verify=True)

# Check UEFI var kept upon live migration
for key, value in reference.items():
guid, name = key[0], key[1]
returned_res = vm.host.ssh(['varstore-get', vm.uuid, guid, name],
simple_output=False, decode=False)
md5 = hashlib.md5(returned_res.stdout).hexdigest()
assert md5 == value

0 comments on commit 4355ce2

Please sign in to comment.