Skip to content

Commit 8b25fdf

Browse files
Paul Angusyadvr
authored andcommitted
tests: fix some Marvin smoketests (#2869)
Fixes intermittent failures: - Add a pause to avoid tests restarting before VRs recovering from HA have fully booted. - Add some pauses to allow services to restart and hosts to reconnect before continuing tests. - Adding a loop around this method because sometimes VRs are overloaded and just respond with exception, so it'll catch it and try 5 times with 30sec cooldown. If that fails as well it'll fail the test. - wait until host is up using explicit check
1 parent 55fb1c4 commit 8b25fdf

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

test/integration/smoke/test_deploy_virtio_scsi_vm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def setUpClass(cls):
9696
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
9797
cls.pod = get_pod(cls.apiclient, cls.zone.id)
9898
cls.services['mode'] = cls.zone.networktype
99+
cls.cleanup = []
99100
if cls.hypervisor.lower() not in ['kvm']:
100101
cls.hypervisorNotSupported = True
101102
return

test/integration/smoke/test_hostha_kvm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ def test_hostha_enable_ha_when_host_in_maintenance(self):
274274
Tests Enable HA when host is in Maintenance mode, should be Ineligible
275275
"""
276276
self.logger.debug("Starting test_hostha_enable_ha_when_host_in_maintenance")
277-
277+
self.logger.debug("Pausing to wait for VMs to have finished starting")
278+
time.sleep(300)
279+
278280
# Enable HA
279281
self.configureAndEnableHostHa()
282+
280283

281284
# Prepare for maintenance Host
282285
self.setHostToMaintanance(self.host.id)

test/integration/smoke/test_vm_life_cycle.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,16 +900,34 @@ def migrate_and_check(self, vm, src_host, dest_host, proto='tls'):
900900
vm_response = VirtualMachine.list(self.apiclient, id=vm.id)[0]
901901
self.assertEqual(vm_response.hostid, dest_host.id, "Check destination host ID of migrated VM")
902902

903+
def waitUntilHostInState(self, hostId, state="Up", interval=5, retries=20):
904+
while retries > -1:
905+
print("Waiting for host: %s to be %s. %s retries left." % (hostId, state, retries))
906+
time.sleep(interval)
907+
host = Host.list(
908+
self.apiclient,
909+
hostid=hostId,
910+
type='Routing'
911+
)[0]
912+
if host.state != state:
913+
if retries >= 0:
914+
retries = retries - 1
915+
continue
916+
else:
917+
print("Host %s now showing as %s" % (hostId, state))
918+
return
919+
903920
def unsecure_host(self, host):
904921
SshClient(host.ipaddress, port=22, user=self.hostConfig["username"], passwd=self.hostConfig["password"])\
905922
.execute("rm -f /etc/cloudstack/agent/cloud* && \
906923
sed -i 's/listen_tls.*/listen_tls=0/g' /etc/libvirt/libvirtd.conf && \
907924
sed -i 's/listen_tcp.*/listen_tcp=1/g' /etc/libvirt/libvirtd.conf && \
908925
sed -i '/.*_file=.*/d' /etc/libvirt/libvirtd.conf && \
909926
service libvirtd restart && \
927+
sleep 30 && \
910928
service cloudstack-agent restart")
911-
912-
time.sleep(10)
929+
print("Unsecuring Host: %s" % (host.name))
930+
self.waitUntilHostInState(hostId=host.id, state="Up")
913931
self.check_connection(host=host, secured='false')
914932
return host
915933

@@ -921,6 +939,8 @@ def secure_all_hosts(self):
921939
self.apiclient.provisionCertificate(cmd)
922940

923941
for host in self.hosts:
942+
print("Securing Host %s" % host.name)
943+
self.waitUntilHostInState(hostId=host.id, state="Up")
924944
self.check_connection(secured='true', host=host)
925945

926946
def deploy_vm(self, origin_host):
@@ -971,6 +991,7 @@ def test_01_secure_vm_migration(self):
971991
vm = self.deploy_vm(src_host)
972992
self.cleanup.append(vm)
973993

994+
self.debug("Securing Host(s)")
974995
dest_host = self.get_target_host(secured='true', virtualmachineid=vm.id)
975996
self.migrate_and_check(vm, src_host, dest_host)
976997

tools/marvin/marvin/lib/base.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -605,22 +605,34 @@ def create(cls, apiclient, services, templateid=None, accountid=None,
605605
return VirtualMachine(virtual_machine.__dict__, services)
606606

607607
# program ssh access over NAT via PF
608-
if mode.lower() == 'advanced':
609-
cls.access_ssh_over_nat(
610-
apiclient,
611-
services,
612-
virtual_machine,
613-
allow_egress=allow_egress,
614-
networkid=cmd.networkids[0] if cmd.networkids else None)
615-
elif mode.lower() == 'basic':
616-
if virtual_machine.publicip is not None:
617-
# EIP/ELB (netscaler) enabled zone
618-
vm_ssh_ip = virtual_machine.publicip
619-
else:
620-
# regular basic zone with security group
621-
vm_ssh_ip = virtual_machine.nic[0].ipaddress
622-
virtual_machine.ssh_ip = vm_ssh_ip
623-
virtual_machine.public_ip = vm_ssh_ip
608+
retries = 5
609+
interval = 30
610+
while retries > 0:
611+
time.sleep(interval)
612+
try:
613+
if mode.lower() == 'advanced':
614+
cls.access_ssh_over_nat(
615+
apiclient,
616+
services,
617+
virtual_machine,
618+
allow_egress=allow_egress,
619+
networkid=cmd.networkids[0] if cmd.networkids else None)
620+
elif mode.lower() == 'basic':
621+
if virtual_machine.publicip is not None:
622+
# EIP/ELB (netscaler) enabled zone
623+
vm_ssh_ip = virtual_machine.publicip
624+
else:
625+
# regular basic zone with security group
626+
vm_ssh_ip = virtual_machine.nic[0].ipaddress
627+
virtual_machine.ssh_ip = vm_ssh_ip
628+
virtual_machine.public_ip = vm_ssh_ip
629+
break
630+
except Exception as e:
631+
if retries >= 0:
632+
retries = retries - 1
633+
continue
634+
raise Exception(
635+
"The following exception appeared while programming ssh access - %s" % e)
624636

625637
return VirtualMachine(virtual_machine.__dict__, services)
626638

0 commit comments

Comments
 (0)