test: fix test_host_ping.py to restore original host state (#8380)

Failures seen in #7344 were debugged and it was seen since one of the
host is in Alert state. VM deployment fails with affinity group.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2023-12-20 11:52:08 +05:30 committed by GitHub
parent ab70108f15
commit 64ecd00eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,9 +40,14 @@ class TestHostPing(cloudstackTestCase):
self.services = self.testClient.getParsedTestDataConfig() self.services = self.testClient.getParsedTestDataConfig()
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.pod = get_pod(self.apiclient, self.zone.id) self.pod = get_pod(self.apiclient, self.zone.id)
self.original_host_state_map = {}
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
for host_id in self.original_host_state_map:
state = self.original_host_state_map[host_id]
sql_query = "UPDATE host SET status = '" + state + "' WHERE uuid = '" + host_id + "'"
self.dbConnection.execute(sql_query)
super(TestHostPing, self).tearDown() super(TestHostPing, self).tearDown()
def checkHostStateInCloudstack(self, state, host_id): def checkHostStateInCloudstack(self, state, host_id):
@ -92,6 +97,7 @@ class TestHostPing(cloudstackTestCase):
self.logger.debug('Hypervisor = {}'.format(host.id)) self.logger.debug('Hypervisor = {}'.format(host.id))
hostToTest = listHost[0] hostToTest = listHost[0]
self.original_host_state_map[hostToTest.id] = hostToTest.state
sql_query = "UPDATE host SET status = 'Alert' WHERE uuid = '" + hostToTest.id + "'" sql_query = "UPDATE host SET status = 'Alert' WHERE uuid = '" + hostToTest.id + "'"
self.dbConnection.execute(sql_query) self.dbConnection.execute(sql_query)