Merge pull request #1221 from ekholabs/improve/test-internal-lb-CLOUDSTACK-9135

CLOUDSTACK-9135 - As a Developer I want the test_internal_lb.py to test Redundant VPCsThis PR refactors the existing tests and adds tests to cover internal LB with Redundant VPCs.

In order to make it possible I had to change the base.py, allowing multiple providers per service. This change requires the changes in the Java side which were dealt with PR #1215 .

* pr/1221:
  CLOUDSTACK-9135 - Makes test compliant with Redundant VPCs
  CLOUDSTACK-9135 - Makes possible to add multiple providers per service
  CLOUDSTACK-9135 - Moves test into smoke directory

Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
Remi Bergsma 2015-12-12 11:29:28 +01:00
commit 7fa62a5765
3 changed files with 132 additions and 34 deletions

View File

@ -128,7 +128,7 @@ class Services:
},
"egress_policy": "true",
},
"vpc_offering": {
"redundant_vpc_offering": {
"name": 'Redundant VPC off',
"displaytext": 'Redundant VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
@ -137,8 +137,8 @@ class Services:
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"Lb" : ["InternalLbVm", "VpcVirtualRouter"],
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
@ -146,7 +146,23 @@ class Services:
"serviceCapabilityList": {
"SourceNat": {
"RedundantRouter": 'true'
}
},
},
},
"vpc_offering": {
"name": "VPC off",
"displaytext": "VPC off",
"supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat,NetworkACL",
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"Lb" : ["InternalLbVm", "VpcVirtualRouter"],
"PortForwarding": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
},
"vpc": {
@ -286,9 +302,12 @@ class TestInternalLb(cloudstackTestCase):
%s" % (cls.account.name,
cls.account.id))
cls.cleanup = [cls.template, cls.account, cls.compute_offering]
cls._cleanup = [cls.template, cls.account, cls.compute_offering]
return
def setUp(self):
self.cleanup = []
def get_networkoffering_state(self, offering):
result = list_network_offerings(self.apiclient, id=offering.id)
if result:
@ -314,39 +333,34 @@ class TestInternalLb(cloudstackTestCase):
offering), "Enabled", "Failed to enable network offering")
self.logger.debug("Enabled network offering: %s" % offering.id)
self.cleanup.insert(0, offering)
return offering
except Exception as e:
self.fail("Failed to create and enable network offering: %s because of %s" % (
offering_name, e))
self.fail("Failed to create and enable network offering due to %s" % e)
def create_vpc(self, name, cidr):
print name, cidr
def create_vpc(self, vpc_offering):
self.logger.debug("Creating VPC using offering ==> ID %s / Name %s" % (vpc_offering.id, vpc_offering.name))
try:
vpcOffering = VpcOffering.list(self.apiclient, isdefault=True)
self.assert_(vpcOffering is not None and len(
vpcOffering) > 0, "No VPC offerings found")
self.services["vpc"] = {}
self.services["vpc"]["name"] = name
self.services["vpc"]["displaytext"] = name
self.services["vpc"]["cidr"] = cidr
vpc = VPC.create(
apiclient=self.apiclient,
services=self.services["vpc"],
networkDomain="vpc.internallb",
vpcofferingid=vpcOffering[0].id,
vpcofferingid=vpc_offering.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.domain.id
)
self.assertIsNotNone(vpc, "VPC creation failed")
self.logger.debug("Created VPC %s" % vpc.id)
self.cleanup.insert(0, vpc)
return vpc
except Exception as e:
self.fail("Failed to create VPC: %s due to %s" % (name, e))
self.fail("Failed to create VPC due to %s" % e)
def create_network_tier(self, name, vpcid, gateway, network_offering):
self.services["network"]["name"] = name
@ -367,10 +381,12 @@ class TestInternalLb(cloudstackTestCase):
netmask=self.services["network"]["netmask"],
aclid=default_acl.id
)
self.assertIsNotNone(network, "Network failed to create")
self.logger.debug(
"Created network %s in VPC %s" % (network.id, vpcid))
self.cleanup.insert(0, network)
return network
except Exception as e:
@ -393,6 +409,7 @@ class TestInternalLb(cloudstackTestCase):
self.assert_(vm.state == 'Running', "VM is not running")
self.logger.debug("Deployed VM id: %s in VPC %s" % (vm.id, vpc.id))
self.cleanup.insert(0, vm)
return vm
except Exception as e:
@ -565,8 +582,41 @@ class TestInternalLb(cloudstackTestCase):
@attr(tags=["smoke", "advanced"], required_hardware="true")
def test_01_internallb_roundrobin_1VPC_3VM_HTTP_port80(self):
"""Test create, assign, remove of an Internal LB with roundrobin http traffic to 3 vm's
"""
Test create, assign, remove of an Internal LB with roundrobin http traffic to 3 vm's in a Single VPC
"""
self.logger.debug("Starting test_01_internallb_roundrobin_1VPC_3VM_HTTP_port80")
self.logger.debug("Creating a VPC offering..")
vpc_offering = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"])
self.logger.debug("Enabling the VPC offering created")
vpc_offering.update(self.apiclient, state='Enabled')
self.cleanup.insert(0, vpc_offering)
self.execute_internallb_roundrobin_tests(vpc_offering)
@attr(tags=["smoke", "advanced"], required_hardware="true")
def test_02_internallb_roundrobin_1RVPC_3VM_HTTP_port80(self):
"""
Test create, assign, remove of an Internal LB with roundrobin http traffic to 3 vm's in a Redundant VPC
"""
self.logger.debug("Starting test_02_internallb_roundrobin_1RVPC_3VM_HTTP_port80")
self.logger.debug("Creating a Redundant VPC offering..")
redundant_vpc_offering = VpcOffering.create(
self.apiclient,
self.services["redundant_vpc_offering"])
self.logger.debug("Enabling the Redundant VPC offering created")
redundant_vpc_offering.update(self.apiclient, state='Enabled')
self.cleanup.insert(0, redundant_vpc_offering)
self.execute_internallb_roundrobin_tests(redundant_vpc_offering)
def execute_internallb_roundrobin_tests(self, vpc_offering):
max_http_requests = 30
algorithm = "roundrobin"
public_lb_port = 80
@ -582,7 +632,7 @@ class TestInternalLb(cloudstackTestCase):
self.services["network_offering_internal_lb"])
# Create VPC
vpc = self.create_vpc("vpc_intlb_test01", "10.1.0.0/16")
vpc = self.create_vpc(vpc_offering)
# Create network tiers
network_guestnet = self.create_network_tier(
@ -692,14 +742,48 @@ class TestInternalLb(cloudstackTestCase):
return False
@attr(tags=["smoke", "advanced"], required_hardware="true")
def test02_internallb_haproxy_stats_on_all_interfaces(self):
def test_03_vpc_internallb_haproxy_stats_on_all_interfaces(self):
""" Test to verify access to loadbalancer haproxy admin stats page
when global setting network.loadbalancer.haproxy.stats.visibility is set to 'all'
with credentials from global setting network.loadbalancer.haproxy.stats.auth
using the uri from global setting network.loadbalancer.haproxy.stats.uri"""
using the uri from global setting network.loadbalancer.haproxy.stats.uri.
self.logger.debug(
"Starting test_02_internallb_haproxy_stats_on_all_interfaces")
It uses a Single Router VPC
"""
self.logger.debug("Starting test_03_vpc_internallb_haproxy_stats_on_all_interfaces")
self.logger.debug("Creating a VPC offering..")
vpc_offering = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"])
self.logger.debug("Enabling the VPC offering created")
vpc_offering.update(self.apiclient, state='Enabled')
self.execute_internallb_haproxy_tests(vpc_offering)
@attr(tags=["smoke", "advanced"], required_hardware="true")
def test_04_rvpc_internallb_haproxy_stats_on_all_interfaces(self):
""" Test to verify access to loadbalancer haproxy admin stats page
when global setting network.loadbalancer.haproxy.stats.visibility is set to 'all'
with credentials from global setting network.loadbalancer.haproxy.stats.auth
using the uri from global setting network.loadbalancer.haproxy.stats.uri.
It uses a Redundant Routers VPC
"""
self.logger.debug("Starting test_04_rvpc_internallb_haproxy_stats_on_all_interfaces")
self.logger.debug("Creating a Redundant VPC offering..")
redundant_vpc_offering = VpcOffering.create(
self.apiclient,
self.services["redundant_vpc_offering"])
self.logger.debug("Enabling the Redundant VPC offering created")
redundant_vpc_offering.update(self.apiclient, state='Enabled')
self.execute_internallb_haproxy_tests(redundant_vpc_offering)
def execute_internallb_haproxy_tests(self, vpc_offering):
settings = self.get_lb_stats_settings()
@ -720,7 +804,7 @@ class TestInternalLb(cloudstackTestCase):
self.services["network_offering_internal_lb"])
# Create VPC
vpc = self.create_vpc("vpc_intlb_test_02", "10.1.0.0/16")
vpc = self.create_vpc(vpc_offering)
# Create network tier with internal lb service enabled
network_internal_lb = self.create_network_tier(
@ -757,8 +841,14 @@ class TestInternalLb(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cls.logger.debug("Cleaning up testcase resources")
cleanup_resources(cls.apiclient, cls.cleanup)
cls.logger.debug("Cleaning up class resources")
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Cleanup failed with %s" % e)
def tearDown(self):
try:
self.logger.debug("Cleaning up test resources")
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Cleanup failed with %s" % e)

View File

@ -4055,17 +4055,25 @@ class VpcOffering:
@classmethod
def create(cls, apiclient, services):
"""Create vpc offering"""
import logging
cmd = createVPCOffering.createVPCOfferingCmd()
cmd.name = "-".join([services["name"], random_gen()])
cmd.displaytext = services["displaytext"]
cmd.supportedServices = services["supportedservices"]
if "serviceProviderList" in services:
for service, provider in services["serviceProviderList"].items():
cmd.serviceproviderlist.append({
'service': service,
'provider': provider
})
providers = provider
if isinstance(provider, str):
providers = [provider]
for provider_item in providers:
cmd.serviceproviderlist.append({
'service': service,
'provider': provider_item
})
if "serviceCapabilityList" in services:
cmd.servicecapabilitylist = []
for service, capability in \