cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [1/2] git commit: updated refs/heads/master to 0a9b9f7
Date Wed, 05 Jun 2013 11:31:04 GMT
Updated Branches:
  refs/heads/master 11a25b3b9 -> 0a9b9f794


Internal LB test refactored to use integration lib

Refactoring the internal lb test to use the marvin libraries. Also added
reqd methods for the internal lb related APIs into integration.lib

Signed-off-by: Prasanna Santhanam <tsp@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0a9b9f79
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0a9b9f79
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0a9b9f79

Branch: refs/heads/master
Commit: 0a9b9f7944bda908c927c9e7685cc827b7fd3eb9
Parents: 7819638
Author: Prasanna Santhanam <tsp@apache.org>
Authored: Wed Jun 5 17:00:06 2013 +0530
Committer: Prasanna Santhanam <tsp@apache.org>
Committed: Wed Jun 5 17:00:47 2013 +0530

----------------------------------------------------------------------
 test/integration/smoke/test_internal_lb.py  |  351 +++++++++-------------
 tools/marvin/marvin/integration/lib/base.py |   98 ++++++-
 2 files changed, 233 insertions(+), 216 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a9b9f79/test/integration/smoke/test_internal_lb.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_internal_lb.py b/test/integration/smoke/test_internal_lb.py
index 07a5395..0de2d4c 100644
--- a/test/integration/smoke/test_internal_lb.py
+++ b/test/integration/smoke/test_internal_lb.py
@@ -25,228 +25,163 @@ from marvin.integration.lib.common import *
 from nose.plugins.attrib import attr
 
 
-class TestInternalLb(cloudstackTestCase):
-    networkOfferingId = None
-    networkId = None
-    vmId = None
-    lbId = None
-
-    zoneId = 1
-    serviceOfferingId = 1 
-    templateId = 5
-
-
-    serviceProviderList = [
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "Vpn"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "UserData"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "Dhcp"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "Dns"
-        },
-        {
-            "provider": "InternalLbVM",
-            "service": "Lb"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "SourceNat"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "StaticNat"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "PortForwarding"
-        },
-        {
-            "provider": "VpcVirtualRouter",
-            "service": "NetworkACL"
-        }
-    ]
-
-    serviceCapsList = [
-        {
-            "service": "SourceNat",
-            "capabilitytype": "SupportedSourceNatTypes",
-            "capabilityvalue": "peraccount"
-        },
-        {
-            "service": "Lb",
-            "capabilitytype": "SupportedLbIsolation",
-            "capabilityvalue": "dedicated"
-        },
-        {
-            "service": "Lb",
-            "capabilitytype": "lbSchemes",
-            "capabilityvalue": "internal"
+class Services:
+    def __init__(self):
+        self.services = {
+            "account": {
+                "email": "test@test.com",
+                "firstname": "Test",
+                "lastname": "User",
+                "username": "test",
+                "password": "password",
+            },
+            "virtual_machine": {
+                "displayname": "Test VM",
+                "username": "root",
+                "password": "password",
+                "ssh_port": 22,
+                "hypervisor": 'XenServer',
+                "privateport": 22,
+                "publicport": 22,
+                "protocol": 'TCP',
+            },
+            "ostype": 'CentOS 5.3 (64-bit)',
+            "service_offering": {
+                "name": "Tiny Instance",
+                "displaytext": "Tiny Instance",
+                "cpunumber": 1,
+                "cpuspeed": 100,
+                "memory": 256,
+            },
+            "network_offering": {
+                "name": "Network offering for internal lb service",
+                "displaytext": "Network offering for internal lb service",
+                "guestiptype": "Isolated",
+                "traffictype": "Guest",
+                "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL",
+                "serviceProviderList": {
+                    "Dhcp": "VpcVirtualRouter",
+                    "Dns": "VpcVirtualRouter",
+                    "Vpn": "VpcVirtualRouter",
+                    "UserData": "VpcVirtualRouter",
+                    "Lb": "InternalLbVM",
+                    "SourceNat": "VpcVirtualRouter",
+                    "StaticNat": "VpcVirtualRouter",
+                    "PortForwarding": "VpcVirtualRouter",
+                    "NetworkACL": "VpcVirtualRouter",
+                },
+                "serviceCapabilityList": {
+                    "SourceNat": {"SupportedSourceNatTypes": "peraccount"},
+                    "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"}
+                }
+            }
         }
-    ]
-
-    def setUp(self):
-        self.apiClient = self.testClient.getApiClient()
 
 
-    
-    @attr(tags=["advanced"])
+class TestInternalLb(cloudstackTestCase):
+    """Test Internal LB
+    """
+
+    @classmethod
+    def setUpClass(cls):
+        cls.apiclient = super(TestInternalLb, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        cls.zone = get_zone(cls.apiclient, cls.services)
+        cls.domain = get_domain(cls.apiclient)
+        cls.service_offering = ServiceOffering.create(
+            cls.apiclient,
+            cls.services["service_offering"]
+        )
+        cls.account = Account.create(cls.apiclient, services=cls.services["account"])
+        cls.template = get_template(
+            cls.apiclient,
+            cls.zone.id,
+            cls.services["ostype"]
+        )
+        cls.debug("Successfully created account: %s, id: \
+                   %s" % (cls.account.name,\
+                          cls.account.id))
+        cls.cleanup = [cls.account]
+
+    @attr(tags=["smoke", "advanced"])
     def test_internallb(self):
+        """Test create, delete, assign, remove of internal loadbalancer
+        """
 
         #1) Create and enable network offering with Internal Lb vm service
-        self.createNetworkOffering()
-        
+        self.networkOffering = NetworkOffering.create(self.apiclient, self.services["network_offering"],
conservemode=False)
+        self.networkOffering.update(self.apiclient, state="Enabled")
+
         #2) Create VPC and network in it
-        self.createNetwork()
-      
-        #3) Deploy a vm 
-        self.deployVm()
+        vpcOffering = VpcOffering.list(self.apiclient)
+        self.assert_(vpcOffering is not None and len(vpcOffering)>0, "No VPC offerings
found")
+        self.services["vpc"] = {}
+        self.services["vpc"]["name"] = "vpc-internallb"
+        self.services["vpc"]["displaytext"] = "vpc-internallb"
+        self.services["vpc"]["cidr"] = "10.1.1.0/24"
+        vpc = VPC.create(
+                apiclient=self.apiclient,
+                services=self.services["vpc"],
+                networkDomain="vpc.internallb",
+                vpcofferingid=vpcOffering[0].id,
+                zoneid=self.zone.id,
+                account=self.account.name,
+                domainid=self.domain.id
+        )
+        self.assert_(vpc is not None, "VPC creation failed")
+        self.services["vpcnetwork"] = {}
+        self.services["vpcnetwork"]["name"] = "vpcntwk"
+        self.services["vpcnetwork"]["displaytext"] = "vpcntwk"
+        ntwk = Network.create(
+            apiclient=self.apiclient,
+            services=self.services["vpcnetwork"],
+            accountid=self.account.name,
+            domainid=self.domain.id,
+            networkofferingid=self.networkOffering.id,
+            zoneid=self.zone.id,
+            vpcid=vpc.id,
+            gateway="10.1.1.1",
+            netmask="255.255.255.192"
+        )
+        self.assertIsNotNone(ntwk, "Network failed to create")
+        self.debug("Network %s created in VPC %s" %(ntwk.id, vpc.id))
+
+        #3) Deploy a vm
+        self.services["virtual_machine"]["networkids"] = ntwk.id
+        vm = VirtualMachine.create(self.apiclient, services=self.services["virtual_machine"],
+            templateid=self.template.id,
+            zoneid=self.zone.id,
+            accountid=self.account.name,
+            domainid= self.domain.id,
+            serviceofferingid=self.service_offering.id,
+        )
+        self.assert_(vm is not None, "VM failed to deploy")
+        self.assert_(vm.state == 'Running', "VM is not running")
+        self.debug("VM %s deployed in VPC %s" %(vm.id, vpc.id))
         
         #4) Create an Internal Load Balancer
-        self.createInternalLoadBalancer()
+        applb = ApplicationLoadBalancer.create(self.apiclient, services=self.services,
+                name="lbrule",
+                sourceport=22,
+                instanceport=22,
+                algorithm="roundrobin",
+                scheme="internal",
+                sourcenetworkid=ntwk.id,
+                networkid=ntwk.id)
 
         #5) Assign the VM to the Internal Load Balancer
-        self.assignToLoadBalancerRule()
+        applb.assign(self.apiclient, vms=[vm.id])
 
         #6) Remove the vm from the Interanl Load Balancer
-        self.removeFromLoadBalancerRule()
+        applb.remove(self.apiclient, vms=[vm.id])
 
         #7) Delete the Load Balancer
-        self.deleteLoadBalancer()
-
-
-    def deployVm(self):
-        deployVirtualMachineCmd = deployVirtualMachine.deployVirtualMachineCmd()
-        deployVirtualMachineCmd.networkids = TestInternalLb.networkId
-        deployVirtualMachineCmd.serviceofferingid = TestInternalLb.serviceOfferingId
-        deployVirtualMachineCmd.zoneid = TestInternalLb.zoneId
-        deployVirtualMachineCmd.templateid = TestInternalLb.templateId
-        deployVirtualMachineCmd.hypervisor = "XenServer"
-        deployVMResponse = self.apiClient.deployVirtualMachine(deployVirtualMachineCmd)
-        TestInternalLb.vmId = deployVMResponse.id
-
-
-    def createInternalLoadBalancer(self):
-        createLoadBalancerCmd = createLoadBalancer.createLoadBalancerCmd()
-        createLoadBalancerCmd.name = "lb rule"
-        createLoadBalancerCmd.sourceport = 22
-        createLoadBalancerCmd.instanceport = 22
-        createLoadBalancerCmd.algorithm = "roundrobin"
-        createLoadBalancerCmd.scheme = "internal"
-        createLoadBalancerCmd.sourceipaddressnetworkid = TestInternalLb.networkId
-        createLoadBalancerCmd.networkid = TestInternalLb.networkId
-        createLoadBalancerResponse = self.apiClient.createLoadBalancer(createLoadBalancerCmd)
-        TestInternalLb.lbId = createLoadBalancerResponse.id
-        self.assertIsNotNone(createLoadBalancerResponse.id, "Failed to create a load balancer")
-
-
-    def assignToLoadBalancerRule(self):
-        assignToLoadBalancerRuleCmd = assignToLoadBalancerRule.assignToLoadBalancerRuleCmd()
-        assignToLoadBalancerRuleCmd.id = TestInternalLb.lbId
-        assignToLoadBalancerRuleCmd.virtualMachineIds = TestInternalLb.vmId
-        assignToLoadBalancerRuleResponse = self.apiClient.assignToLoadBalancerRule(assignToLoadBalancerRuleCmd)
-        self.assertTrue(assignToLoadBalancerRuleResponse.success, "Failed to assign the vm
to the load balancer")
-
-
-
-    def removeFromLoadBalancerRule(self):
-        removeFromLoadBalancerRuleCmd = removeFromLoadBalancerRule.removeFromLoadBalancerRuleCmd()
-        removeFromLoadBalancerRuleCmd.id = TestInternalLb.lbId
-        removeFromLoadBalancerRuleCmd.virtualMachineIds = TestInternalLb.vmId
-        removeFromLoadBalancerRuleResponse = self.apiClient.removeFromLoadBalancerRule(removeFromLoadBalancerRuleCmd)
-        self.assertTrue(removeFromLoadBalancerRuleResponse.success, "Failed to remove the
vm from the load balancer")
-
-
-
-    #def removeInternalLoadBalancer(self):
-    def deleteLoadBalancer(self):
-        deleteLoadBalancerCmd = deleteLoadBalancer.deleteLoadBalancerCmd()
-        deleteLoadBalancerCmd.id = TestInternalLb.lbId
-        deleteLoadBalancerResponse = self.apiClient.deleteLoadBalancer(deleteLoadBalancerCmd)
-        self.assertTrue(deleteLoadBalancerResponse.success, "Failed to remove the load balancer")
-
-
-
-    def createNetwork(self):
-        createVPCCmd = createVPC.createVPCCmd()
-        createVPCCmd.name = "new vpc"
-        createVPCCmd.cidr = "10.1.1.0/24"
-        createVPCCmd.displaytext = "new vpc"
-        createVPCCmd.vpcofferingid = 1
-        createVPCCmd.zoneid = self.zoneId
-        createVPCResponse = self.apiClient.createVPC(createVPCCmd)
-
-
-        createNetworkCmd = createNetwork.createNetworkCmd()
-        createNetworkCmd.name = "vpc network"
-        createNetworkCmd.displaytext = "vpc network"
-        createNetworkCmd.netmask = "255.255.255.0"
-        createNetworkCmd.gateway = "10.1.1.1"
-        createNetworkCmd.zoneid = self.zoneId
-        createNetworkCmd.vpcid = createVPCResponse.id
-        createNetworkCmd.networkofferingid = TestInternalLb.networkOfferingId
-        createNetworkResponse = self.apiClient.createNetwork(createNetworkCmd)
-        TestInternalLb.networkId = createNetworkResponse.id
-
-        self.assertIsNotNone(createNetworkResponse.id, "Network failed to create")
-
-
-    def createNetworkOffering(self):
-            createNetworkOfferingCmd = createNetworkOffering.createNetworkOfferingCmd()
-            createNetworkOfferingCmd.name = "Network offering for internal lb service - "
+ str(random.randrange(1,100+1))
-            createNetworkOfferingCmd.displaytext = "Network offering for internal lb service"
-            createNetworkOfferingCmd.guestiptype = "isolated"
-            createNetworkOfferingCmd.traffictype = "Guest"
-            createNetworkOfferingCmd.conservemode = "false"
-            createNetworkOfferingCmd.supportedservices = "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL"
-
-
-            createNetworkOfferingCmd.serviceproviderlist = []
-            for item in self.serviceProviderList:
-                createNetworkOfferingCmd.serviceproviderlist.append({
-                                                'service': item['service'],
-                                                'provider': item['provider']
-                                               })
-                
-            createNetworkOfferingCmd.servicecapabilitylist = []
-            for item in self.serviceCapsList:
-                createNetworkOfferingCmd.servicecapabilitylist.append({
-                                                'service': item['service'],
-                                                'capabilitytype': item['capabilitytype'],
-                                                'capabilityvalue': item['capabilityvalue']
-                                               })
-
-
-            createNetworkOfferingResponse = self.apiClient.createNetworkOffering(createNetworkOfferingCmd)
-            TestInternalLb.networkOfferingId = createNetworkOfferingResponse.id
-
-            #enable network offering
-            updateNetworkOfferingCmd = updateNetworkOffering.updateNetworkOfferingCmd()
-            updateNetworkOfferingCmd.id = TestInternalLb.networkOfferingId
-            updateNetworkOfferingCmd.state = "Enabled"
-            updateNetworkOfferingResponse = self.apiClient.updateNetworkOffering(updateNetworkOfferingCmd)
-
-
-            #list network offering to see if its enabled
-            listNetworkOfferingsCmd = listNetworkOfferings.listNetworkOfferingsCmd()
-            listNetworkOfferingsCmd.id = TestInternalLb.networkOfferingId
-            listOffResponse = self.apiClient.listNetworkOfferings(listNetworkOfferingsCmd)
-
-            self.assertNotEqual(len(listOffResponse), 0, "Check if the list network offerings
API \
-                                returns a non-empty response")
+        applb.delete(self.apiclient)
 
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            cleanup_resources(cls.apiclient, cls.cleanup)
+        except Exception, e:
+            raise Exception("Cleanup failed with %s" % e)
 
-    def tearDown(self):
-        #destroy the vm
-        if TestInternalLb.vmId is not None:
-            destroyVirtualMachineCmd = destroyVirtualMachine.destroyVirtualMachineCmd()
-            destroyVirtualMachineCmd.id = TestInternalLb.vmId
-            destroyVirtualMachineResponse = self.apiClient.destroyVirtualMachine(destroyVirtualMachineCmd)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a9b9f79/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 6b3be75..5daacbb 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -1371,18 +1371,18 @@ class NetworkOffering:
 
         if "useVpc" in services:
             cmd.useVpc = services["useVpc"]
-        cmd.serviceProviderList = []
+        cmd.serviceproviderlist = []
         if "serviceProviderList" in services:
             for service, provider in services["serviceProviderList"].items():
-                cmd.serviceProviderList.append({
+                cmd.serviceproviderlist.append({
                                             'service': service,
                                             'provider': provider
                                            })
-        if "servicecapabilitylist" in services:
-            cmd.serviceCapabilityList = []
-            for service, capability in services["servicecapabilitylist"].items():
+        if "serviceCapabilityList" in services:
+            cmd.servicecapabilitylist = []
+            for service, capability in services["serviceCapabilityList"].items():
                 for ctype, value in capability.items():
-                    cmd.serviceCapabilityList.append({
+                    cmd.servicecapabilitylist.append({
                                             'service': service,
                                             'capabilitytype': ctype,
                                             'capabilityvalue': value
@@ -2798,7 +2798,7 @@ class VPC:
 
     @classmethod
     def create(cls, apiclient, services, vpcofferingid,
-                    zoneid, networkDomain=None, account=None, domainid=None):
+                    zoneid, networkDomain=None, account=None, domainid=None, **kwargs):
         """Creates the virtual private connection (VPC)"""
 
         cmd = createVPC.createVPCCmd()
@@ -2806,13 +2806,15 @@ class VPC:
         cmd.displaytext = "-".join([services["displaytext"], random_gen()])
         cmd.vpcofferingid = vpcofferingid
         cmd.zoneid = zoneid
-        cmd.cidr = services["cidr"]
+        if "cidr" in services:
+            cmd.cidr = services["cidr"]
         if account:
             cmd.account = account
         if domainid:
             cmd.domainid = domainid
         if networkDomain:
             cmd.networkDomain = networkDomain
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
         return VPC(apiclient.createVPC(cmd).__dict__)
 
     def update(self, apiclient, name=None, displaytext=None):
@@ -3216,3 +3218,83 @@ class Region:
         cmd.id = self.id
         region = apiclient.removeRegion(cmd)
         return region
+
+
+class ApplicationLoadBalancer:
+    """Manage Application Load Balancers in VPC"""
+
+    def __init__(self, items):
+        self.__dict__.update(items)
+
+    @classmethod
+    def create(cls, apiclient, services, name=None, sourceport=None, instanceport=22,
+               algorithm="roundrobin", scheme="internal", sourcenetworkid=None, networkid=None):
+        """Create Application Load Balancer"""
+        cmd = createLoadBalancer.createLoadBalancerCmd()
+
+        if "name" in services:
+            cmd.name = services["name"]
+        elif name:
+            cmd.name = name
+
+        if "sourceport" in services:
+            cmd.sourceport = services["sourceport"]
+        elif sourceport:
+            cmd.sourceport = sourceport
+
+        if "instanceport" in services:
+            cmd.instanceport = services["instanceport"]
+        elif instanceport:
+            cmd.instanceport = instanceport
+
+        if "algorithm" in services:
+            cmd.algorithm = services["algorithm"]
+        elif algorithm:
+            cmd.algorithm = algorithm
+
+        if "scheme" in services:
+            cmd.scheme = services["scheme"]
+        elif scheme:
+            cmd.scheme = scheme
+
+        if "sourceipaddressnetworkid" in services:
+            cmd.sourceipaddressnetworkid = services["sourceipaddressnetworkid"]
+        elif sourcenetworkid:
+            cmd.sourceipaddressnetworkid = sourcenetworkid
+
+        if "networkid" in services:
+            cmd.networkid = services["networkid"]
+        elif networkid:
+            cmd.networkid = networkid
+
+        return LoadBalancerRule(apiclient.createLoadBalancer(cmd).__dict__)
+
+    def delete(self, apiclient):
+        """Delete application load balancer"""
+        cmd = deleteLoadBalancer.deleteLoadBalancerCmd()
+        cmd.id = self.id
+        apiclient.deleteLoadBalancerRule(cmd)
+        return
+
+    def assign(self, apiclient, vms):
+        """Assign virtual machines to load balancing rule"""
+        cmd = assignToLoadBalancerRule.assignToLoadBalancerRuleCmd()
+        cmd.id = self.id
+        cmd.virtualmachineids = [str(vm.id) for vm in vms]
+        apiclient.assignToLoadBalancerRule(cmd)
+        return
+
+    def remove(self, apiclient, vms):
+        """Remove virtual machines from load balancing rule"""
+        cmd = removeFromLoadBalancerRule.removeFromLoadBalancerRuleCmd()
+        cmd.id = self.id
+        cmd.virtualmachineids = [str(vm.id) for vm in vms]
+        apiclient.removeFromLoadBalancerRule(cmd)
+        return
+
+    @classmethod
+    def list(cls, apiclient, **kwargs):
+        """List all appln load balancers"""
+        cmd = listLoadBalancers.listLoadBalancersCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return(apiclient.listLoadBalancerRules(cmd))
\ No newline at end of file


Mime
View raw message