|
15 | 15 | Df, |
16 | 16 | Dmesg, |
17 | 17 | Fio, |
| 18 | + Free, |
18 | 19 | HibernationSetup, |
19 | 20 | Hwclock, |
20 | 21 | Iperf3, |
@@ -49,6 +50,60 @@ def is_distro_supported(node: Node) -> None: |
49 | 50 | ) |
50 | 51 |
|
51 | 52 |
|
| 53 | +def check_hibernation_disk_requirements(node: Node) -> None: |
| 54 | + """ |
| 55 | + Check if the VM has sufficient disk space for hibernation. |
| 56 | + Hibernation requires disk space based on RAM size using the formula: |
| 57 | + - 2 × RAM if RAM ≤ 8 GB |
| 58 | + - 1.5 × RAM if 8 < RAM ≤ 64 GB |
| 59 | + - RAM if 64 < RAM ≤ 256 GB |
| 60 | + - Not supported if RAM > 256 GB |
| 61 | + """ |
| 62 | + free_tool = node.tools[Free] |
| 63 | + df_tool = node.tools[Df] |
| 64 | + |
| 65 | + # Get total memory in KB |
| 66 | + total_memory_kb = free_tool._get_field_bytes_kib("Mem", "total") |
| 67 | + total_memory_gb = total_memory_kb / (1024 * 1024) # Convert KB to GB |
| 68 | + |
| 69 | + # Skip hibernation check for VMs with > 256 GB RAM |
| 70 | + if total_memory_gb > 256: |
| 71 | + raise SkippedException( |
| 72 | + f"Hibernation is not supported for VMs with RAM > 256 GB. " |
| 73 | + f"Current RAM: {total_memory_gb:.2f} GB" |
| 74 | + ) |
| 75 | + |
| 76 | + # Calculate required swap space based on RAM size |
| 77 | + if total_memory_gb <= 8: |
| 78 | + required_space_gb = 2 * total_memory_gb |
| 79 | + formula = "2*RAM" |
| 80 | + elif total_memory_gb <= 64: |
| 81 | + required_space_gb = 1.5 * total_memory_gb |
| 82 | + formula = "1.5*RAM" |
| 83 | + else: |
| 84 | + required_space_gb = total_memory_gb |
| 85 | + formula = "RAM" |
| 86 | + |
| 87 | + # Add 20% buffer for filesystem overhead, defragmentation, and safety margin |
| 88 | + required_space_with_buffer = required_space_gb * 1.2 |
| 89 | + |
| 90 | + root_partition = df_tool.get_partition_by_mountpoint("/", force_run=True) |
| 91 | + assert root_partition is not None, "Unable to determine root partition disk space" |
| 92 | + |
| 93 | + # available_blocks is in 1K blocks, convert to GB |
| 94 | + available_space_gb = root_partition.available_blocks / 1024 / 1024 |
| 95 | + |
| 96 | + if available_space_gb < required_space_with_buffer: |
| 97 | + raise LisaException( |
| 98 | + f"Insufficient disk space for hibernation. " |
| 99 | + f"Memory size: {total_memory_gb:.2f} GB, " |
| 100 | + f"Available space: {available_space_gb:.2f} GB, " |
| 101 | + f"Required space: {required_space_gb:.2f} GB ({formula}), " |
| 102 | + f"Recommended (20% buffer): {required_space_with_buffer:.2f} GB. " |
| 103 | + f"Please increase 'osdisk_size_in_gb'." |
| 104 | + ) |
| 105 | + |
| 106 | + |
52 | 107 | def _prepare_hibernation_environment(node: Node) -> None: |
53 | 108 | """ |
54 | 109 | Prepare the hibernation environment by handling OS-specific requirements. |
@@ -167,6 +222,11 @@ def verify_hibernation_by_tool( |
167 | 222 |
|
168 | 223 | hibernation_setup_tool = node.tools[HibernationSetup] |
169 | 224 |
|
| 225 | + # Verify disk space again before hibernation setup to |
| 226 | + # ensure sufficient space after any package installations |
| 227 | + # or system changes |
| 228 | + check_hibernation_disk_requirements(node) |
| 229 | + |
170 | 230 | # Get initial counts before hibernation |
171 | 231 | entry_before_hibernation = hibernation_setup_tool.check_entry() |
172 | 232 | exit_before_hibernation = hibernation_setup_tool.check_exit() |
|
0 commit comments