CLOUDSTACK-5959: Fixed cascading failures in portable IP test cases

This commit is contained in:
Gaurav Aradhye 2014-02-10 12:34:17 +05:30 committed by Girish Shilamkar
parent 306ffa0218
commit d44c850445
2 changed files with 117 additions and 39 deletions

View File

@ -15,14 +15,31 @@
# specific language governing permissions and limitations
# under the License.
""" Tests for Portable public IP Ranges feature
Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Portable+IP+Test+Execution
Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/portable+public+IP
"""
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.cloudstackException import cloudstackAPIException
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
from netaddr import *
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.integration.lib.utils import cleanup_resources
from marvin.integration.lib.base import (Account,
NetworkOffering,
ServiceOffering,
Network,
VirtualMachine,
PublicIPAddress,
FireWallRule,
NATRule,
PortablePublicIpRange,
StaticNATRule)
from marvin.integration.lib.common import (get_zone,
get_pod,
get_domain,
get_region,
get_template,
get_portable_ip_range_services,
is_public_ip_in_correct_state)
from netaddr import IPAddress
from marvin.sshClient import SshClient
from nose.plugins.attrib import attr
@ -739,7 +756,6 @@ class TestAssociatePublicIp(cloudstackTestCase):
self.debug("Associating ip address failed")
return
@unittest.skip("SSH failing to portable ip, need to investigate the issue")
@attr(tags=["advanced"])
def test_associate_ip_address_services_enable_disable(self):
""" Test enabling and disabling NAT, Firewall services on portable ip
@ -785,6 +801,12 @@ class TestAssociatePublicIp(cloudstackTestCase):
)
self.debug("created public ip address (portable): %s" % portableip.ipaddress.ipaddress)
ipInCorrectState = is_public_ip_in_correct_state(self.apiclient, portableip.ipaddress.id, state="allocated")
if not ipInCorrectState:
portableip.delete(self.apiclient)
self.fail("Portable IP not in allocated state even after 10 mins")
try:
# Open up firewall port for SSH
self.debug("Opening firewall on the portable public ip")
fw_rule = FireWallRule.create(
@ -804,6 +826,9 @@ class TestAssociatePublicIp(cloudstackTestCase):
self.services["natrule"],
portableip.ipaddress.id
)
except Exception as e:
portableip.delete(self.apiclient)
self.fail("Error: %s" % e)
try:
@ -1052,6 +1077,12 @@ class TestDisassociatePublicIp(cloudstackTestCase):
)
self.debug("created public ip address (portable): %s" % portableip.ipaddress.ipaddress)
ipInCorrectState = is_public_ip_in_correct_state(self.apiclient, portableip.ipaddress.id, state="allocated")
if not ipInCorrectState:
portableip.delete(self.apiclient)
self.fail("Portable IP not in allocated state even after 10 mins")
try:
# Open up firewall port for SSH
self.debug("Opening firewall on the portable public ip")
FireWallRule.create(
@ -1071,6 +1102,9 @@ class TestDisassociatePublicIp(cloudstackTestCase):
self.services["natrule"],
portableip.ipaddress.id
)
except Exception as e:
portableip.delete(self.apiclient)
self.fail("Error: %s" % e)
try:
self.debug("Disassociating portable ip: %s with id: %s" %
@ -1308,6 +1342,13 @@ class TestDeleteAccount(cloudstackTestCase):
)
self.debug("created public ip address (portable): %s" % portableip.ipaddress.ipaddress)
ipInCorrectState = is_public_ip_in_correct_state(self.apiclient, portableip.ipaddress.id, state="allocated")
if not ipInCorrectState:
portableip.delete(self.apiclient)
self.account.delete(self.apiclient)
self.fail("Portable IP not in allocated state even after 10 mins")
try:
# Open up firewall port for SSH
self.debug("Opening firewall on the portable public ip")
FireWallRule.create(
@ -1327,6 +1368,10 @@ class TestDeleteAccount(cloudstackTestCase):
self.services["natrule"],
portableip.ipaddress.id
)
except Exception as e:
portableip.delete(self.apiclient)
self.account.delete(self.apiclient)
self.fail("Error %s" % e)
self.debug("Deleting account: %s :" % self.account.name)
@ -1492,9 +1537,17 @@ class TestPortableIpTransferAcrossNetworks(cloudstackTestCase):
networkid=self.network1.id,
isportable=True
)
ipInCorrectState = is_public_ip_in_correct_state(self.apiclient, portableip.ipaddress.id, state="allocated")
if not ipInCorrectState:
portableip.delete(self.apiclient)
self.fail("Portable IP not in allocated state even after 10 mins")
self.debug("created public ip address (portable): %s" % portableip.ipaddress.ipaddress)
#Create NAT rule
self.debug("Creating NAT rule on the portable public ip")
try:
# Enable Static NAT for VM
StaticNATRule.enable(
self.apiclient,
@ -1502,9 +1555,10 @@ class TestPortableIpTransferAcrossNetworks(cloudstackTestCase):
self.virtual_machine2.id,
networkid=self.network2.id
)
# Open up firewall port for SSH
self.debug("Opening firewall on the portable public ip")
fw_rule = FireWallRule.create(
FireWallRule.create(
self.apiclient,
ipaddressid=portableip.ipaddress.id,
protocol=self.services["natrule"]["protocol"],
@ -1512,6 +1566,10 @@ class TestPortableIpTransferAcrossNetworks(cloudstackTestCase):
startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"]
)
except Exception as e:
portableip.delete(self.apiclient)
self.fail("Error: %s" % e)
static_nat_list = PublicIPAddress.list(
self.apiclient,
associatednetworkid=self.network2.id,

View File

@ -62,11 +62,14 @@ from marvin.integration.lib.base import (Configurations,
Template,
Resources,
PhysicalNetwork,
Host)
Host,
PublicIPAddress)
from marvin.integration.lib.utils import (get_process_status,
xsplit)
xsplit,
validateList)
from marvin.sshClient import SshClient
from marvin.codes import PASS
import random
#Import System modules
@ -907,3 +910,20 @@ def setNonContiguousVlanIds(apiclient, zoneid):
return None, None
return physical_network, vlan
def is_public_ip_in_correct_state(apiclient, ipaddressid, state):
""" Check if the given IP is in the correct state (given)
and return True/False accordingly"""
retriesCount = 10
while True:
portableips = PublicIPAddress.list(apiclient, id=ipaddressid)
assert validateList(portableips)[0] == PASS, "IPs list validation failed"
if str(portableips[0].state).lower() == state:
break
elif retriesCount == 0:
return False
else:
retriesCount -= 1
time.sleep(60)
continue
return True