|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import logging |
2 | 4 |
|
3 | 5 | from lib.commands import SSHCommandFailed |
4 | | -from lib.common import strtobool, wait_for, wait_for_not |
| 6 | +from lib.common import GiB, strtobool, wait_for, wait_for_not |
| 7 | +from lib.host import Host |
5 | 8 | from lib.sr import SR |
6 | 9 | from lib.vdi import VDI |
| 10 | +from lib.vm import VM |
7 | 11 |
|
8 | | -from typing import TYPE_CHECKING, Literal |
9 | | - |
10 | | -if TYPE_CHECKING: |
11 | | - from lib.host import Host |
12 | | - from lib.vm import VM |
| 12 | +from typing import Literal |
13 | 13 |
|
| 14 | +RANDSTREAM_1GIB_CHECKSUM = '65280014' |
14 | 15 |
|
15 | 16 | def try_to_create_sr_with_missing_device(sr_type, label, host): |
16 | 17 | try: |
@@ -42,21 +43,51 @@ def cold_migration_then_come_back(vm, prov_host, dest_host, dest_sr): |
42 | 43 | vm.wait_for_os_booted() |
43 | 44 | vm.shutdown(verify=True) |
44 | 45 |
|
45 | | -def live_storage_migration_then_come_back(vm, prov_host, dest_host, dest_sr): |
| 46 | + if vdi_name is not None: |
| 47 | + vm.destroy_vdi_by_name(vdi_name) |
| 48 | + |
| 49 | +def live_storage_migration_then_come_back(vm: VM, prov_host: Host, dest_host: Host, dest_sr: SR): |
46 | 50 | prov_sr = vm.get_sr() |
| 51 | + vdi_name = None |
| 52 | + |
| 53 | + if not vm.is_windows: |
| 54 | + vdi = prov_sr.create_vdi(virtual_size=1 * GiB) |
| 55 | + vdi_name = vdi.name() |
| 56 | + vm.connect_vdi(vdi, 'xvdb') |
| 57 | + |
47 | 58 | # start VM |
48 | 59 | vm.start(on=prov_host.uuid) |
49 | | - vm.wait_for_os_booted() |
| 60 | + if vm.is_windows: |
| 61 | + vm.wait_for_os_booted() |
| 62 | + else: |
| 63 | + vm.wait_for_vm_running_and_ssh_up() |
| 64 | + install_randstream(vm) |
| 65 | + logging.info("Generate /dev/xvdb content") |
| 66 | + vm.ssh("randstream generate -v /dev/xvdb") |
| 67 | + logging.info("Validate /dev/xvdb") |
| 68 | + vm.ssh(f"randstream validate -v --expected-checksum {RANDSTREAM_1GIB_CHECKSUM} /dev/xvdb") |
| 69 | + |
50 | 70 | # Move the VM to another host of the pool |
51 | 71 | vm.migrate(dest_host, dest_sr) |
52 | 72 | wait_for(lambda: vm.all_vdis_on_sr(dest_sr), "Wait for all VDIs on destination SR") |
53 | 73 | wait_for(lambda: vm.is_running_on_host(dest_host), "Wait for VM to be running on destination host") |
| 74 | + if not vm.is_windows: |
| 75 | + logging.info("Validate /dev/xvdb") |
| 76 | + vm.ssh(f"randstream validate -v --expected-checksum {RANDSTREAM_1GIB_CHECKSUM} /dev/xvdb") |
| 77 | + |
54 | 78 | # Migrate it back to the provenance SR |
55 | 79 | vm.migrate(prov_host, prov_sr) |
56 | 80 | wait_for(lambda: vm.all_vdis_on_sr(prov_sr), "Wait for all VDIs back on provenance SR") |
57 | 81 | wait_for(lambda: vm.is_running_on_host(prov_host), "Wait for VM to be running on provenance host") |
| 82 | + if not vm.is_windows: |
| 83 | + logging.info("Validate /dev/xvdb") |
| 84 | + vm.ssh(f"randstream validate -v --expected-checksum {RANDSTREAM_1GIB_CHECKSUM} /dev/xvdb") |
| 85 | + |
58 | 86 | vm.shutdown(verify=True) |
59 | 87 |
|
| 88 | + if vdi_name is not None: |
| 89 | + vm.destroy_vdi_by_name(vdi_name) |
| 90 | + |
60 | 91 | def vdi_is_open(vdi): |
61 | 92 | sr = vdi.sr |
62 | 93 |
|
|
0 commit comments