From e3e2a4747a089687d720d3bc5733e4ff4bb8f76a Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 15 Jan 2024 09:59:10 +0100 Subject: [PATCH 1/5] PR template enhanced --- PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 8293a22973a2..e02cc6518535 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -23,6 +23,7 @@ This PR... - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] build/CI +- [ ] test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity From f041490fa4576d658e8ddc700452ca007acbdcde Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Mon, 15 Jan 2024 09:55:48 +0100 Subject: [PATCH 2/5] assertion improvement on cluster DRS --- test/integration/smoke/test_cluster_drs.py | 55 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/test/integration/smoke/test_cluster_drs.py b/test/integration/smoke/test_cluster_drs.py index 4db6654aa73c..32b7115a037d 100644 --- a/test/integration/smoke/test_cluster_drs.py +++ b/test/integration/smoke/test_cluster_drs.py @@ -21,8 +21,10 @@ import logging import time +from collections.abc import Iterable from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackAPI import (migrateSystemVm, listRouters, listSystemVms) from marvin.lib.base import (Cluster, Configurations, Host, Network, NetworkOffering, ServiceOffering, VirtualMachine, Zone) from marvin.lib.common import (get_domain, get_zone, get_template) @@ -98,6 +100,41 @@ def setUpClass(cls): ) cls._cleanup.append(cls.network) + cls.migrateSvms(cls.cluster) + + @classmethod + def migrateSvms(cls, cluster): + """ + for testing the balanced algorithm we must make sure there is at least as more free memory on host[1] than on + host[0]. As a grude measure we migrate any and all system vms to host[0] before the testing commences + + :param cluster: the cluser to check + :return: None + """ + + systemVmIds = [] + cmds = listSystemVms.listSystemVmsCmd() + responseS = cls.apiclient.listSystemVms(cmds) + if isinstance(responseS, Iterable): + for svm in responseS: + if svm.hostid != cls.hosts[0].id: + systemVmIds.append(svm.id) + cmdv = listRouters.listRoutersCmd() + responseR = cls.apiclient.listRouters(cmdv) + if isinstance(responseR, Iterable): + for svm in responseR: + if svm.hostid != cls.hosts[0].id: + systemVmIds.append(svm.id) + numToMigrate = len(systemVmIds) + cls.logger.debug(f'system vms and routers to migrate -- {numToMigrate}') + cmdM = migrateSystemVm.migrateSystemVmCmd() + cmdM.hostId=cls.hosts[0].id + for id in systemVmIds: + cmdM.virtualmachineid=id + responseM = cls.apiclient.migrateSystemVm(cmdM) + cls.logger.debug(f'migrated {responseM}') + + @classmethod def tearDownClass(cls): super(TestClusterDRS, cls).tearDownClass() @@ -111,7 +148,6 @@ def setUp(self): def tearDown(self): super(TestClusterDRS, self).tearDown() - @classmethod def get_vm_host_id(cls, vm_id): list_vms = VirtualMachine.list(cls.apiclient, id=vm_id) vm = list_vms[0] @@ -188,8 +224,8 @@ def test_01_condensed_drs_algorithm(self): serviceofferingid=self.service_offering.id, templateid=self.template.id, zoneid=self.zone.id, networkids=self.network.id, hostid=self.hosts[1].id) - vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) self.cleanup.append(self.virtual_machine_2) + vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) self.assertNotEqual(vm_1_host_id, vm_2_host_id, msg="Both VMs should be on different hosts") self.wait_for_vm_start(self.virtual_machine_1) @@ -216,11 +252,13 @@ def test_01_condensed_drs_algorithm(self): @attr(tags=["advanced"], required_hardware="false") def test_02_balanced_drs_algorithm(self): - """ Verify DRS algorithm - balanced""" + """ + Verify DRS algorithm - balanced - # 1. Deploy vm-1 on host 1 - # 2. Deploy vm-2 on host 2 - # 3. Execute DRS to move all VMs on different hosts + # 1. Deploy vm-1 on host 1 + # 2. Deploy vm-2 on host 2 + # 3. Execute DRS to move all VMs on different hosts + """ self.logger.debug("=== Running test_02_balanced_drs_algorithm ===") # 1. Deploy vm-1 on host 1 @@ -240,8 +278,8 @@ def test_02_balanced_drs_algorithm(self): serviceofferingid=self.service_offering.id, templateid=self.template.id, zoneid=self.zone.id, networkids=self.network.id, hostid=self.hosts[0].id) - vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) self.cleanup.append(self.virtual_machine_2) + vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) self.assertEqual(vm_1_host_id, vm_2_host_id, msg="Both VMs should be on same hosts") self.wait_for_vm_start(self.virtual_machine_1) @@ -256,7 +294,8 @@ def test_02_balanced_drs_algorithm(self): migration["virtualmachineid"]: migration["destinationhostid"] for migration in migrations } - self.assertEqual(len(vm_to_dest_host_map), 1, msg="DRS plan should have 1 migrations") + # this is one if no svm is considered to be migrated, it might be higher + self.assertTrue(len(vm_to_dest_host_map) <= 1, msg="DRS plan should have 1 migrations") executed_plan = self.cluster.executeDrsPlan(self.apiclient, vm_to_dest_host_map) self.wait_for_plan_completion(executed_plan) From 86b9106fcbc6dac8209966d7e7e1eb4f776ae2f3 Mon Sep 17 00:00:00 2001 From: dahn Date: Thu, 6 Jun 2024 10:28:48 +0200 Subject: [PATCH 3/5] Update test/integration/smoke/test_cluster_drs.py --- test/integration/smoke/test_cluster_drs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/smoke/test_cluster_drs.py b/test/integration/smoke/test_cluster_drs.py index 32b7115a037d..7d3cb91a03b5 100644 --- a/test/integration/smoke/test_cluster_drs.py +++ b/test/integration/smoke/test_cluster_drs.py @@ -295,7 +295,7 @@ def test_02_balanced_drs_algorithm(self): } # this is one if no svm is considered to be migrated, it might be higher - self.assertTrue(len(vm_to_dest_host_map) <= 1, msg="DRS plan should have 1 migrations") + self.assertTrue(len(vm_to_dest_host_map) >= 1, msg="DRS plan should have at least 1 migrations") executed_plan = self.cluster.executeDrsPlan(self.apiclient, vm_to_dest_host_map) self.wait_for_plan_completion(executed_plan) From a45ca4f593aa2e1be6fd72bd95e1206e85206ce4 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Wed, 12 Jun 2024 16:34:29 +0530 Subject: [PATCH 4/5] Fix host id check for balanced drs e2e test --- test/integration/smoke/test_cluster_drs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/smoke/test_cluster_drs.py b/test/integration/smoke/test_cluster_drs.py index 7d3cb91a03b5..c74196f629f1 100644 --- a/test/integration/smoke/test_cluster_drs.py +++ b/test/integration/smoke/test_cluster_drs.py @@ -259,8 +259,8 @@ def test_02_balanced_drs_algorithm(self): # 2. Deploy vm-2 on host 2 # 3. Execute DRS to move all VMs on different hosts """ - self.logger.debug("=== Running test_02_balanced_drs_algorithm ===") + # 1. Deploy vm-1 on host 1 self.services["virtual_machine"]["name"] = "virtual-machine-1" self.services["virtual_machine"]["displayname"] = "virtual-machine-1" @@ -303,4 +303,6 @@ def test_02_balanced_drs_algorithm(self): vm_1_host_id = self.get_vm_host_id(self.virtual_machine_1.id) vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) - self.assertNotEqual(vm_1_host_id, vm_2_host_id, msg="Both VMs should be on different hosts") + self.assertTrue( + vm_1_host_id != self.virtual_machine_1.hostid or vm_2_host_id != self.virtual_machine_1.hostid, + msg="At least one VM should have been migrated to a different host") From bc4885a01c3827b68ebca9a329f5248c337e1dc6 Mon Sep 17 00:00:00 2001 From: Vishesh Date: Wed, 12 Jun 2024 17:54:25 +0530 Subject: [PATCH 5/5] Update test/integration/smoke/test_cluster_drs.py --- test/integration/smoke/test_cluster_drs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/smoke/test_cluster_drs.py b/test/integration/smoke/test_cluster_drs.py index c74196f629f1..8b4801849fd0 100644 --- a/test/integration/smoke/test_cluster_drs.py +++ b/test/integration/smoke/test_cluster_drs.py @@ -304,5 +304,5 @@ def test_02_balanced_drs_algorithm(self): vm_2_host_id = self.get_vm_host_id(self.virtual_machine_2.id) self.assertTrue( - vm_1_host_id != self.virtual_machine_1.hostid or vm_2_host_id != self.virtual_machine_1.hostid, + vm_1_host_id != self.virtual_machine_1.hostid or vm_2_host_id != self.virtual_machine_2.hostid, msg="At least one VM should have been migrated to a different host")