|
5 | 5 | from ocp_resources.deployment import Deployment |
6 | 6 | from ocp_resources.pod_disruption_budget import PodDisruptionBudget |
7 | 7 | from ocp_resources.resource import Resource, ResourceEditor |
| 8 | +from ocp_resources.virtual_machine_instance_migration import VirtualMachineInstanceMigration |
8 | 9 | from ocp_utilities.infra import get_pods_by_name_prefix |
9 | 10 |
|
10 | 11 | from tests.virt.node.descheduler.constants import ( |
11 | 12 | DESCHEDULER_LABEL_KEY, |
12 | 13 | DESCHEDULER_LABEL_VALUE, |
13 | 14 | DESCHEDULER_TEST_LABEL, |
14 | | - RUNNING_PING_PROCESS_NAME_IN_VM, |
15 | 15 | ) |
16 | 16 | from tests.virt.node.descheduler.utils import ( |
17 | 17 | calculate_vm_deployment, |
18 | 18 | create_kube_descheduler, |
19 | 19 | deploy_vms, |
20 | | - start_vms_with_process, |
21 | 20 | vm_nodes, |
22 | 21 | vms_per_nodes, |
23 | 22 | wait_vmi_failover, |
24 | 23 | ) |
25 | | -from tests.virt.utils import build_node_affinity_dict, get_non_terminated_pods, start_stress_on_vm |
26 | | -from utilities.constants import TIMEOUT_5SEC |
| 24 | +from tests.virt.utils import ( |
| 25 | + build_node_affinity_dict, |
| 26 | + get_boot_time_for_multiple_vms, |
| 27 | + get_non_terminated_pods, |
| 28 | + start_stress_on_vm, |
| 29 | +) |
| 30 | +from utilities.constants import TIMEOUT_5MIN, TIMEOUT_5SEC |
27 | 31 | from utilities.infra import wait_for_pods_deletion |
28 | 32 | from utilities.virt import ( |
29 | 33 | node_mgmt_console, |
| 34 | + wait_for_migration_finished, |
30 | 35 | wait_for_node_schedulable_status, |
31 | 36 | ) |
32 | 37 |
|
@@ -57,7 +62,7 @@ def descheduler_kubevirt_relieve_and_migrate_profile( |
57 | 62 | ): |
58 | 63 | with create_kube_descheduler( |
59 | 64 | admin_client=admin_client, |
60 | | - profiles=["DevKubeVirtRelieveAndMigrate"], |
| 65 | + profiles=["KubeVirtRelieveAndMigrate"], |
61 | 66 | profile_customizations={ |
62 | 67 | "devActualUtilizationProfile": "PrometheusCPUCombined", |
63 | 68 | }, |
@@ -124,14 +129,10 @@ def vms_orig_nodes_before_node_drain(deployed_vms_for_descheduler_test): |
124 | 129 |
|
125 | 130 |
|
126 | 131 | @pytest.fixture(scope="class") |
127 | | -def vms_started_process_for_node_drain( |
| 132 | +def vms_boot_time_before_node_drain( |
128 | 133 | deployed_vms_for_descheduler_test, |
129 | 134 | ): |
130 | | - return start_vms_with_process( |
131 | | - vms=deployed_vms_for_descheduler_test, |
132 | | - process_name=RUNNING_PING_PROCESS_NAME_IN_VM, |
133 | | - args=LOCALHOST, |
134 | | - ) |
| 135 | + yield get_boot_time_for_multiple_vms(vm_list=deployed_vms_for_descheduler_test) |
135 | 136 |
|
136 | 137 |
|
137 | 138 | @pytest.fixture(scope="class") |
@@ -161,6 +162,13 @@ def drain_uncordon_node( |
161 | 162 | wait_vmi_failover(vm=vm, orig_node=vms_orig_nodes_before_node_drain[vm.name]) |
162 | 163 |
|
163 | 164 |
|
| 165 | +@pytest.fixture() |
| 166 | +def all_existing_migrations_completed(admin_client, namespace): |
| 167 | + # Descheduler may trigger multiple migrations, need to wait when all succeeded |
| 168 | + for migration in VirtualMachineInstanceMigration.get(dyn_client=admin_client, namespace=namespace): |
| 169 | + wait_for_migration_finished(namespace=namespace.name, migration=migration, timeout=TIMEOUT_5MIN) |
| 170 | + |
| 171 | + |
164 | 172 | @pytest.fixture(scope="class") |
165 | 173 | def node_with_min_memory_labeled_for_descheduler_test(node_with_least_available_memory): |
166 | 174 | with ResourceEditor(patches={node_with_least_available_memory: {"metadata": {"labels": DESCHEDULER_TEST_LABEL}}}): |
@@ -237,14 +245,10 @@ def deployed_vms_on_labeled_node( |
237 | 245 |
|
238 | 246 |
|
239 | 247 | @pytest.fixture(scope="class") |
240 | | -def vms_started_process_for_utilization_imbalance( |
| 248 | +def vms_boot_time_before_utilization_imbalance( |
241 | 249 | deployed_vms_for_utilization_imbalance, |
242 | 250 | ): |
243 | | - return start_vms_with_process( |
244 | | - vms=deployed_vms_for_utilization_imbalance, |
245 | | - process_name=RUNNING_PING_PROCESS_NAME_IN_VM, |
246 | | - args=LOCALHOST, |
247 | | - ) |
| 251 | + yield get_boot_time_for_multiple_vms(vm_list=deployed_vms_for_utilization_imbalance) |
248 | 252 |
|
249 | 253 |
|
250 | 254 | @pytest.fixture(scope="class") |
@@ -317,6 +321,7 @@ def node_to_run_stress(schedulable_nodes, deployed_vms_for_descheduler_test): |
317 | 321 | vm_per_node_counters = vms_per_nodes(vms=vm_nodes(vms=deployed_vms_for_descheduler_test)) |
318 | 322 | for node in schedulable_nodes: |
319 | 323 | if vm_per_node_counters[node.name] > 0: |
| 324 | + LOGGER.info(f"Node to run stress: {node.name}") |
320 | 325 | return node |
321 | 326 |
|
322 | 327 | raise ValueError("No suitable node to run stress") |
|
0 commit comments