CLOUDSTACK-8002: test_high_availability.py - Skip test cases if enough hosts are not available

Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
Gaurav Aradhye 2014-12-02 16:15:52 +05:30 committed by SrikanteswaraRao Talluri
parent a6fd3190c0
commit d5370a95d2

View File

@ -18,19 +18,35 @@
""" P1 tests for high availability
"""
#Import Local Modules
import marvin
# Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.lib.utils import *
from marvin.lib.base import *
from marvin.lib.common import *
from marvin.sshClient import SshClient
import datetime
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import (prepareHostForMaintenance,
cancelHostMaintenance)
from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account,
Host,
VirtualMachine,
Network,
ServiceOffering,
NATRule,
LoadBalancerRule,
Snapshot,
Template,
PublicIPAddress)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
get_pod,
list_volumes,
list_snapshots,
list_templates,
wait_for_ssvms)
import time
class Services:
"""Test network offering Services
"""
@ -139,7 +155,7 @@ class TestHighAvailability(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
#Cleanup resources used
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@ -159,18 +175,22 @@ class TestHighAvailability(cloudstackTestCase):
def tearDown(self):
try:
#Clean up, terminate the created accounts, domains etc
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags = ["advanced", "advancedns", "multihost"], required_hardware="true")
@attr(
tags=[
"advanced",
"advancedns",
"multihost"],
required_hardware="true")
def test_01_host_maintenance_mode(self):
"""Test host maintenance mode
"""
# Validate the following
# 1. Create Vms. Acquire IP. Create port forwarding & load balancing
# rules for Vms.
@ -196,11 +216,9 @@ class TestHighAvailability(cloudstackTestCase):
True,
"List hosts should return valid host response"
)
self.assertGreaterEqual(
len(hosts),
2,
"There must be two hosts present in a cluster"
)
if len(hosts) < 2:
self.skipTest("There must be at least 2 hosts present in cluster")
self.debug("Checking HA with hosts: %s, %s" % (
hosts[0].name,
hosts[1].name
@ -265,7 +283,7 @@ class TestHighAvailability(cloudstackTestCase):
))
self.debug("Creating PF rule for IP address: %s" %
public_ip.ipaddress.ipaddress)
nat_rule = NATRule.create(
NATRule.create(
self.apiclient,
virtual_machine,
self.services["natrule"],
@ -287,10 +305,10 @@ class TestHighAvailability(cloudstackTestCase):
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % virtual_machine.id)
ssh = virtual_machine.get_ssh_client(
virtual_machine.get_ssh_client(
ipaddress=public_ip.ipaddress.ipaddress)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
self.fail("SSH Access failed for %s: %s" %
(virtual_machine.ipaddress, e)
)
@ -340,7 +358,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other\
failed while enabling maintenance"
)
second_host = vm.hostid
self.assertEqual(
@ -351,10 +370,10 @@ class TestHighAvailability(cloudstackTestCase):
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % virtual_machine.id)
ssh = virtual_machine.get_ssh_client(
virtual_machine.get_ssh_client(
ipaddress=public_ip.ipaddress.ipaddress)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
self.fail("SSH Access failed for %s: %s" %
(virtual_machine.ipaddress, e)
)
self.debug("Deploying VM in account: %s" % self.account.name)
@ -446,7 +465,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other failed\
while enabling maintenance"
)
# Poll and check the status of VMs
@ -486,7 +506,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other\
failed while enabling maintenance"
)
for vm in vms:
@ -535,10 +556,10 @@ class TestHighAvailability(cloudstackTestCase):
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % virtual_machine.id)
ssh = virtual_machine.get_ssh_client(
virtual_machine.get_ssh_client(
ipaddress=public_ip.ipaddress.ipaddress)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
self.fail("SSH Access failed for %s: %s" %
(virtual_machine.ipaddress, e)
)
@ -556,12 +577,16 @@ class TestHighAvailability(cloudstackTestCase):
)
return
@attr(tags = ["advanced", "advancedns", "multihost"], required_hardware="true")
@attr(
tags=[
"advanced",
"advancedns",
"multihost"],
required_hardware="true")
def test_02_host_maintenance_mode_with_activities(self):
"""Test host maintenance mode with activities
"""
# Validate the following
# 1. Create Vms. Acquire IP. Create port forwarding & load balancing
# rules for Vms.
@ -591,11 +616,9 @@ class TestHighAvailability(cloudstackTestCase):
True,
"List hosts should return valid host response"
)
self.assertGreaterEqual(
len(hosts),
2,
"There must be two hosts present in a cluster"
)
if len(hosts) < 2:
self.skipTest("There must be at least 2 hosts present in cluster")
self.debug("Checking HA with hosts: %s, %s" % (
hosts[0].name,
hosts[1].name
@ -660,7 +683,7 @@ class TestHighAvailability(cloudstackTestCase):
))
self.debug("Creating PF rule for IP address: %s" %
public_ip.ipaddress.ipaddress)
nat_rule = NATRule.create(
NATRule.create(
self.apiclient,
virtual_machine,
self.services["natrule"],
@ -682,10 +705,10 @@ class TestHighAvailability(cloudstackTestCase):
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % virtual_machine.id)
ssh = virtual_machine.get_ssh_client(
virtual_machine.get_ssh_client(
ipaddress=public_ip.ipaddress.ipaddress)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
self.fail("SSH Access failed for %s: %s" %
(virtual_machine.ipaddress, e)
)
# Get the Root disk of VM
@ -738,8 +761,7 @@ class TestHighAvailability(cloudstackTestCase):
templates = list_templates(
self.apiclient,
templatefilter=\
self.services["templates"]["templatefilter"],
templatefilter=self.services["templates"]["templatefilter"],
id=template.id
)
@ -801,7 +823,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other failed\
while enabling maintenance"
)
second_host = vm.hostid
self.assertEqual(
@ -812,10 +835,10 @@ class TestHighAvailability(cloudstackTestCase):
# Should be able to SSH VM
try:
self.debug("SSH into VM: %s" % virtual_machine.id)
ssh = virtual_machine.get_ssh_client(
virtual_machine.get_ssh_client(
ipaddress=public_ip.ipaddress.ipaddress)
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
self.fail("SSH Access failed for %s: %s" %
(virtual_machine.ipaddress, e)
)
self.debug("Deploying VM in account: %s" % self.account.name)
@ -907,8 +930,7 @@ class TestHighAvailability(cloudstackTestCase):
templates = list_templates(
self.apiclient,
templatefilter=\
self.services["templates"]["templatefilter"],
templatefilter=self.services["templates"]["templatefilter"],
id=template.id
)
@ -972,7 +994,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other failed\
while enabling maintenance"
)
# Poll and check the status of VMs
@ -1010,7 +1033,8 @@ class TestHighAvailability(cloudstackTestCase):
timeout = timeout - 1
else:
self.fail(
"VM migration from one-host-to-other failed while enabling maintenance"
"VM migration from one-host-to-other failed\
while enabling maintenance"
)
for vm in vms: