You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/07/04 10:07:57 UTC

git commit: updated refs/heads/master to 30039e1

Updated Branches:
  refs/heads/master 4bf6c1e2f -> 30039e121


Separate the loadbalancing tests

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


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

Branch: refs/heads/master
Commit: 30039e121b948d1e21cc7b762c6e3fe6ac16a09a
Parents: 4bf6c1e
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Thu Jul 4 13:31:32 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Thu Jul 4 13:37:27 2013 +0530

----------------------------------------------------------------------
 test/integration/smoke/test_loadbalance.py | 590 ++++++++++++++++++++++
 test/integration/smoke/test_network.py     | 645 ------------------------
 2 files changed, 590 insertions(+), 645 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30039e12/test/integration/smoke/test_loadbalance.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_loadbalance.py b/test/integration/smoke/test_loadbalance.py
new file mode 100644
index 0000000..97bce10
--- /dev/null
+++ b/test/integration/smoke/test_loadbalance.py
@@ -0,0 +1,590 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin import remoteSSHClient
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+from nose.plugins.attrib import attr
+#Import System modules
+import time
+
+_multiprocess_shared_ = True
+
+class Services:
+    """Test Network Services
+    """
+
+    def __init__(self):
+        self.services = {
+                            "ostype": "CentOS 5.3 (64-bit)",
+                            # Cent OS 5.3 (64 bit)
+                            "lb_switch_wait": 10,
+                            # Time interval after which LB switches the requests
+                            "sleep": 60,
+                            "timeout":10,
+                            "network_offering": {
+                                    "name": 'Test Network offering',
+                                    "displaytext": 'Test Network offering',
+                                    "guestiptype": 'Isolated',
+                                    "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding',
+                                    "traffictype": 'GUEST',
+                                    "availability": 'Optional',
+                                    "serviceProviderList" : {
+                                            "Dhcp": 'VirtualRouter',
+                                            "Dns": 'VirtualRouter',
+                                            "SourceNat": 'VirtualRouter',
+                                            "PortForwarding": 'VirtualRouter',
+                                        },
+                                },
+                            "network": {
+                                  "name": "Test Network",
+                                  "displaytext": "Test Network",
+                                },
+                            "service_offering": {
+                                    "name": "Tiny Instance",
+                                    "displaytext": "Tiny Instance",
+                                    "cpunumber": 1,
+                                    "cpuspeed": 100,
+                                    # in MHz
+                                    "memory": 256,
+                                    # In MBs
+                                    },
+                            "account": {
+                                    "email": "test@test.com",
+                                    "firstname": "Test",
+                                    "lastname": "User",
+                                    "username": "test",
+                                    "password": "password",
+                                    },
+                            "server":
+                                    {
+                                    "displayname": "Small Instance",
+                                    "username": "root",
+                                    "password": "password",
+                                    "hypervisor": 'XenServer',
+                                    "privateport": 22,
+                                    "publicport": 22,
+                                    "ssh_port": 22,
+                                    "protocol": 'TCP',
+                                },
+                        "natrule":
+                                {
+                                    "privateport": 22,
+                                    "publicport": 2222,
+                                    "protocol": "TCP"
+                                },
+                        "lbrule":
+                                {
+                                    "name": "SSH",
+                                    "alg": "roundrobin",
+                                    # Algorithm used for load balancing
+                                    "privateport": 22,
+                                    "publicport": 2222,
+                                    "protocol": 'TCP'
+                                }
+                        }
+
+class TestLoadBalance(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+
+        cls.api_client = super(TestLoadBalance, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+        cls.services["server"]["zoneid"] = cls.zone.id
+
+        #Create an account, network, VM and IP addresses
+        cls.account = Account.create(
+                            cls.api_client,
+                            cls.services["account"],
+                            admin=True,
+                            domainid=cls.domain.id
+                            )
+        cls.service_offering = ServiceOffering.create(
+                                        cls.api_client,
+                                        cls.services["service_offering"]
+                                        )
+        cls.vm_1 = VirtualMachine.create(
+                                    cls.api_client,
+                                    cls.services["server"],
+                                    templateid=template.id,
+                                    accountid=cls.account.name,
+                                    domainid=cls.account.domainid,
+                                    serviceofferingid=cls.service_offering.id
+                                    )
+        cls.vm_2 = VirtualMachine.create(
+                                    cls.api_client,
+                                    cls.services["server"],
+                                    templateid=template.id,
+                                    accountid=cls.account.name,
+                                    domainid=cls.account.domainid,
+                                    serviceofferingid=cls.service_offering.id
+                                    )
+        cls.non_src_nat_ip = PublicIPAddress.create(
+                                            cls.api_client,
+                                            cls.account.name,
+                                            cls.zone.id,
+                                            cls.account.domainid,
+                                            cls.services["server"]
+                                            )
+        # Open up firewall port for SSH
+        cls.fw_rule = FireWallRule.create(
+                            cls.api_client,
+                            ipaddressid=cls.non_src_nat_ip.ipaddress.id,
+                            protocol=cls.services["lbrule"]["protocol"],
+                            cidrlist=['0.0.0.0/0'],
+                            startport=cls.services["lbrule"]["publicport"],
+                            endport=cls.services["lbrule"]["publicport"]
+                            )
+        cls._cleanup = [
+                        cls.account,
+                        cls.service_offering
+                        ]
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        cleanup_resources(self.apiclient, self.cleanup)
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        cleanup_resources(cls.api_client, cls._cleanup)
+        return
+
+    def try_ssh(self, src_nat_ip_addr, hostnames):
+        try:
+            self.debug(
+                "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
+                (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
+            )
+           # If Round Robin Algorithm is chosen,
+            # each ssh command should alternate between VMs
+
+            ssh_1  = remoteSSHClient(
+                src_nat_ip_addr.ipaddress,
+                self.services['lbrule']["publicport"],
+                self.vm_1.username,
+                self.vm_1.password
+            )
+            hostnames.append(ssh_1.execute("hostname")[0])
+            self.debug(hostnames)
+        except Exception as e:
+            self.fail("%s: SSH failed for VM with IP Address: %s" %
+                                    (e, src_nat_ip_addr.ipaddress))
+        time.sleep(self.services["lb_switch_wait"])
+        return
+
+    @attr(tags = ["advanced", "advancedns", "smoke", "needle"])
+    def test_01_create_lb_rule_src_nat(self):
+        """Test to create Load balancing rule with source NAT"""
+
+        # Validate the Following:
+        #1. listLoadBalancerRules should return the added rule
+        #2. attempt to ssh twice on the load balanced IP
+        #3. verify using the hostname of the VM
+        #   that round robin is indeed happening as expected
+        src_nat_ip_addrs = PublicIPAddress.list(
+                                    self.apiclient,
+                                    account=self.account.name,
+                                    domainid=self.account.domainid
+                                  )
+        self.assertEqual(
+                            isinstance(src_nat_ip_addrs, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        src_nat_ip_addr = src_nat_ip_addrs[0]
+
+        # Check if VM is in Running state before creating LB rule
+        vm_response = VirtualMachine.list(
+                                          self.apiclient,
+                                          account=self.account.name,
+                                          domainid=self.account.domainid
+                                          )
+
+        self.assertEqual(
+                            isinstance(vm_response, list),
+                            True,
+                            "Check list VM returns a valid list"
+                        )
+
+        self.assertNotEqual(
+                            len(vm_response),
+                            0,
+                            "Check Port Forwarding Rule is created"
+                            )
+        for vm in vm_response:
+            self.assertEqual(
+                            vm.state,
+                            'Running',
+                            "VM state should be Running before creating a NAT rule."
+                        )
+
+        #Create Load Balancer rule and assign VMs to rule
+        lb_rule = LoadBalancerRule.create(
+                                          self.apiclient,
+                                          self.services["lbrule"],
+                                          src_nat_ip_addr.id,
+                                          accountid=self.account.name
+                                          )
+        self.cleanup.append(lb_rule)
+        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
+        lb_rules = list_lb_rules(
+                                 self.apiclient,
+                                 id=lb_rule.id
+                                 )
+        self.assertEqual(
+                            isinstance(lb_rules, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        #verify listLoadBalancerRules lists the added load balancing rule
+        self.assertNotEqual(
+                            len(lb_rules),
+                            0,
+                            "Check Load Balancer Rule in its List"
+                        )
+        self.assertEqual(
+                            lb_rules[0].id,
+                            lb_rule.id,
+                            "Check List Load Balancer Rules returns valid Rule"
+                        )
+
+        # listLoadBalancerRuleInstances should list all
+        # instances associated with that LB rule
+        lb_instance_rules = list_lb_instances(
+                                              self.apiclient,
+                                              id=lb_rule.id
+                                              )
+        self.assertEqual(
+                            isinstance(lb_instance_rules, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        self.assertNotEqual(
+                            len(lb_instance_rules),
+                            0,
+                            "Check Load Balancer instances Rule in its List"
+                        )
+        self.debug("lb_instance_rules Ids: %s, %s" % (
+                                                    lb_instance_rules[0].id,
+                                                    lb_instance_rules[1].id
+                                                    ))
+        self.debug("VM ids: %s, %s" % (self.vm_1.id, self.vm_2.id))
+
+        self.assertIn(
+                lb_instance_rules[0].id,
+                [self.vm_1.id, self.vm_2.id],
+                "Check List Load Balancer instances Rules returns valid VM ID"
+            )
+
+        self.assertIn(
+            lb_instance_rules[1].id,
+            [self.vm_1.id, self.vm_2.id],
+            "Check List Load Balancer instances Rules returns valid VM ID"
+            )
+
+
+        hostnames = []
+        self.try_ssh(src_nat_ip_addr, hostnames)
+        self.try_ssh(src_nat_ip_addr, hostnames)
+        self.try_ssh(src_nat_ip_addr, hostnames)
+        self.try_ssh(src_nat_ip_addr, hostnames)
+        self.try_ssh(src_nat_ip_addr, hostnames)
+
+        self.debug("Hostnames: %s" % str(hostnames))
+        self.assertIn(
+              self.vm_1.name,
+              hostnames,
+              "Check if ssh succeeded for server1"
+            )
+        self.assertIn(
+              self.vm_2.name,
+              hostnames,
+              "Check if ssh succeeded for server2"
+              )
+
+        #SSH should pass till there is a last VM associated with LB rule
+        lb_rule.remove(self.apiclient, [self.vm_2])
+
+        # making hostnames list empty
+        hostnames[:] = []
+
+        try:
+            self.debug("SSHing into IP address: %s after removing VM (ID: %s)" %
+                                            (
+                                             src_nat_ip_addr.ipaddress,
+                                             self.vm_2.id
+                                             ))
+
+            self.try_ssh(src_nat_ip_addr, hostnames)
+            self.assertIn(
+                          self.vm_1.name,
+                          hostnames,
+                          "Check if ssh succeeded for server1"
+                          )
+        except Exception as e:
+            self.fail("%s: SSH failed for VM with IP Address: %s" %
+                                        (e, src_nat_ip_addr.ipaddress))
+
+        lb_rule.remove(self.apiclient, [self.vm_1])
+
+        with self.assertRaises(Exception):
+            self.debug("Removed all VMs, trying to SSH")
+            self.try_ssh(src_nat_ip_addr, hostnames)
+        return
+
+    @attr(tags = ["advanced", "advancedns", "smoke"])
+    def test_02_create_lb_rule_non_nat(self):
+        """Test to create Load balancing rule with non source NAT"""
+
+        # Validate the Following:
+        #1. listLoadBalancerRules should return the added rule
+        #2. attempt to ssh twice on the load balanced IP
+        #3. verify using the hostname of the VM that
+        #   round robin is indeed happening as expected
+
+        #Create Load Balancer rule and assign VMs to rule
+        lb_rule = LoadBalancerRule.create(
+            self.apiclient,
+            self.services["lbrule"],
+            self.non_src_nat_ip.ipaddress.id,
+            accountid=self.account.name
+        )
+        self.cleanup.append(lb_rule)
+        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
+        lb_rules = list_lb_rules(
+            self.apiclient,
+            id=lb_rule.id
+        )
+        self.assertEqual(
+            isinstance(lb_rules, list),
+            True,
+            "Check list response returns a valid list"
+        )
+        #verify listLoadBalancerRules lists the added load balancing rule
+        self.assertNotEqual(
+            len(lb_rules),
+            0,
+            "Check Load Balancer Rule in its List"
+        )
+        self.assertEqual(
+            lb_rules[0].id,
+            lb_rule.id,
+            "Check List Load Balancer Rules returns valid Rule"
+        )
+        # listLoadBalancerRuleInstances should list
+        # all instances associated with that LB rule
+        lb_instance_rules = list_lb_instances(
+            self.apiclient,
+            id=lb_rule.id
+        )
+        self.assertEqual(
+            isinstance(lb_instance_rules, list),
+            True,
+            "Check list response returns a valid list"
+        )
+        self.assertNotEqual(
+            len(lb_instance_rules),
+            0,
+            "Check Load Balancer instances Rule in its List"
+        )
+
+        self.assertIn(
+            lb_instance_rules[0].id,
+            [self.vm_1.id, self.vm_2.id],
+            "Check List Load Balancer instances Rules returns valid VM ID"
+        )
+
+        self.assertIn(
+            lb_instance_rules[1].id,
+            [self.vm_1.id, self.vm_2.id],
+            "Check List Load Balancer instances Rules returns valid VM ID"
+        )
+        try:
+            hostnames = []
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+
+            self.debug("Hostnames: %s" % str(hostnames))
+            self.assertIn(
+                    self.vm_1.name,
+                    hostnames,
+                    "Check if ssh succeeded for server1"
+                    )
+            self.assertIn(
+                    self.vm_2.name,
+                    hostnames,
+                    "Check if ssh succeeded for server2"
+                    )
+
+            #SSH should pass till there is a last VM associated with LB rule
+            lb_rule.remove(self.apiclient, [self.vm_2])
+            self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
+                       (
+                           self.non_src_nat_ip.ipaddress.ipaddress,
+                           self.vm_2.id
+                           ))
+            # Making host list empty
+            hostnames[:] = []
+
+            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
+            self.assertIn(
+                self.vm_1.name,
+                hostnames,
+                "Check if ssh succeeded for server1"
+            )
+            self.debug("Hostnames after removing VM2: %s" % str(hostnames))
+        except Exception as e:
+            self.fail("%s: SSH failed for VM with IP Address: %s" %
+                      (e, self.non_src_nat_ip.ipaddress.ipaddress))
+
+        lb_rule.remove(self.apiclient, [self.vm_1])
+        with self.assertRaises(Exception):
+            self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
+                       (
+                           self.non_src_nat_ip.ipaddress.ipaddress,
+                           self.vm_1.id
+                           ))
+            self.try_ssh(self.non_src_nat_ip, hostnames)
+        return
+
+    @attr(tags = ["advanced", "advancedns", "smoke"])
+    def test_assign_and_removal_lb(self):
+        """Test for assign & removing load balancing rule"""
+
+        # Validate:
+        #1. Verify list API - listLoadBalancerRules lists
+        #   all the rules with the relevant ports
+        #2. listLoadBalancerInstances will list
+        #   the instances associated with the corresponding rule.
+        #3. verify ssh attempts should pass as long as there
+        #   is at least one instance associated with the rule
+
+        # Check if VM is in Running state before creating LB rule
+        vm_response = VirtualMachine.list(
+                                          self.apiclient,
+                                          account=self.account.name,
+                                          domainid=self.account.domainid
+                                          )
+
+        self.assertEqual(
+                            isinstance(vm_response, list),
+                            True,
+                            "Check list VM returns a valid list"
+                        )
+
+        self.assertNotEqual(
+                            len(vm_response),
+                            0,
+                            "Check Port Forwarding Rule is created"
+                            )
+        for vm in vm_response:
+            self.assertEqual(
+                            vm.state,
+                            'Running',
+                            "VM state should be Running before creating a NAT rule."
+                        )
+
+        lb_rule = LoadBalancerRule.create(
+                                self.apiclient,
+                                self.services["lbrule"],
+                                self.non_src_nat_ip.ipaddress.id,
+                                self.account.name
+                              )
+        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
+
+        hostnames = []
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+
+        self.debug("Hostnames: %s" % str(hostnames))
+        self.assertIn(
+                  self.vm_1.name,
+                  hostnames,
+                  "Check if ssh succeeded for server1"
+                )
+        self.assertIn(
+                  self.vm_2.name,
+                  hostnames,
+                  "Check if ssh succeeded for server2"
+                  )
+        #Removing VM and assigning another VM to LB rule
+        lb_rule.remove(self.apiclient, [self.vm_2])
+
+        # making hostnames list empty
+        hostnames[:] = []
+
+        try:
+            self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" %
+                                            (
+                                             self.non_src_nat_ip.ipaddress,
+                                             self.vm_1.id,
+                                             ))
+            self.try_ssh(self.non_src_nat_ip, hostnames)
+
+            self.assertIn(
+                          self.vm_1.name,
+                          hostnames,
+                          "Check if ssh succeeded for server1"
+                          )
+        except Exception as e:
+            self.fail("SSH failed for VM with IP: %s" %
+                                    self.non_src_nat_ip.ipaddress)
+
+        lb_rule.assign(self.apiclient, [self.vm_3])
+
+#        # Making hostnames list empty
+        hostnames[:] = []
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.try_ssh(self.non_src_nat_ip, hostnames)
+        self.debug("Hostnames: %s" % str(hostnames))
+        self.assertIn(
+                  self.vm_1.name,
+                  hostnames,
+                  "Check if ssh succeeded for server1"
+                )
+        self.assertIn(
+                  self.vm_3.name,
+                  hostnames,
+                  "Check if ssh succeeded for server3"
+                  )
+        return
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30039e12/test/integration/smoke/test_network.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_network.py b/test/integration/smoke/test_network.py
index ca67121..dad5630 100644
--- a/test/integration/smoke/test_network.py
+++ b/test/integration/smoke/test_network.py
@@ -585,432 +585,7 @@ class TestPortForwarding(cloudstackTestCase):
         return
 
 
-class TestLoadBalancingRule(cloudstackTestCase):
 
-    @classmethod
-    def setUpClass(cls):
-
-        cls.api_client = super(TestLoadBalancingRule, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
-        template = get_template(
-                            cls.api_client,
-                            cls.zone.id,
-                            cls.services["ostype"]
-                            )
-        cls.services["server"]["zoneid"] = cls.zone.id
-
-        #Create an account, network, VM and IP addresses
-        cls.account = Account.create(
-                            cls.api_client,
-                            cls.services["account"],
-                            admin=True,
-                            domainid=cls.domain.id
-                            )
-        cls.service_offering = ServiceOffering.create(
-                                        cls.api_client,
-                                        cls.services["service_offering"]
-                                        )
-        cls.vm_1 = VirtualMachine.create(
-                                    cls.api_client,
-                                    cls.services["server"],
-                                    templateid=template.id,
-                                    accountid=cls.account.name,
-                                    domainid=cls.account.domainid,
-                                    serviceofferingid=cls.service_offering.id
-                                    )
-        cls.vm_2 = VirtualMachine.create(
-                                    cls.api_client,
-                                    cls.services["server"],
-                                    templateid=template.id,
-                                    accountid=cls.account.name,
-                                    domainid=cls.account.domainid,
-                                    serviceofferingid=cls.service_offering.id
-                                    )
-        cls.non_src_nat_ip = PublicIPAddress.create(
-                                            cls.api_client,
-                                            cls.account.name,
-                                            cls.zone.id,
-                                            cls.account.domainid,
-                                            cls.services["server"]
-                                            )
-        # Open up firewall port for SSH        
-        cls.fw_rule = FireWallRule.create(
-                            cls.api_client,
-                            ipaddressid=cls.non_src_nat_ip.ipaddress.id,
-                            protocol=cls.services["lbrule"]["protocol"],
-                            cidrlist=['0.0.0.0/0'],
-                            startport=cls.services["lbrule"]["publicport"],
-                            endport=cls.services["lbrule"]["publicport"]
-                            )
-        cls._cleanup = [
-                        cls.account,
-                        cls.service_offering
-                        ]
-
-    def setUp(self):
-        self.apiclient = self.testClient.getApiClient()
-        self.cleanup = []
-        return
-
-    def tearDown(self):
-        cleanup_resources(self.apiclient, self.cleanup)
-        return
-
-    @classmethod
-    def tearDownClass(cls):
-        cleanup_resources(cls.api_client, cls._cleanup)
-        return
-
-    def try_ssh(self, src_nat_ip_addr, hostnames):
-        try:
-            self.debug(
-                "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
-                (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
-            )
-
-            ssh_1 = remoteSSHClient(
-                                    src_nat_ip_addr.ipaddress,
-                                    self.services['lbrule']["publicport"],
-                                    self.vm_1.username,
-                                    self.vm_1.password
-                                    )
-
-            # If Round Robin Algorithm is chosen,
-            # each ssh command should alternate between VMs
-            # hostnames = [ssh_1.execute("hostname")[0]]
-            hostnames.append(ssh_1.execute("hostname")[0])
-
-        except Exception as e:
-            self.fail("%s: SSH failed for VM with IP Address: %s" %
-                                    (e, src_nat_ip_addr.ipaddress))
-
-        time.sleep(self.services["lb_switch_wait"])
-        return
-
-    @attr(tags = ["advanced", "advancedns", "smoke"])
-    def test_01_create_lb_rule_src_nat(self):
-        """Test to create Load balancing rule with source NAT"""
-
-        # Validate the Following:
-        #1. listLoadBalancerRules should return the added rule
-        #2. attempt to ssh twice on the load balanced IP
-        #3. verify using the hostname of the VM
-        #   that round robin is indeed happening as expected
-
-        src_nat_ip_addrs = list_publicIP(
-                                    self.apiclient,
-                                    account=self.account.name,
-                                    domainid=self.account.domainid
-                                  )
-        self.assertEqual(
-                            isinstance(src_nat_ip_addrs, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        src_nat_ip_addr = src_nat_ip_addrs[0]
-
-        # Check if VM is in Running state before creating LB rule
-        vm_response = VirtualMachine.list(
-                                          self.apiclient,
-                                          account=self.account.name,
-                                          domainid=self.account.domainid
-                                          )
-
-        self.assertEqual(
-                            isinstance(vm_response, list),
-                            True,
-                            "Check list VM returns a valid list"
-                        )
-
-        self.assertNotEqual(
-                            len(vm_response),
-                            0,
-                            "Check Port Forwarding Rule is created"
-                            )
-        for vm in vm_response:
-            self.assertEqual(
-                            vm.state,
-                            'Running',
-                            "VM state should be Running before creating a NAT rule."
-                        )
-
-        #Create Load Balancer rule and assign VMs to rule
-        lb_rule = LoadBalancerRule.create(
-                                          self.apiclient,
-                                          self.services["lbrule"],
-                                          src_nat_ip_addr.id,
-                                          accountid=self.account.name
-                                          )
-        self.cleanup.append(lb_rule)
-
-        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
-
-        lb_rules = list_lb_rules(
-                                 self.apiclient,
-                                 id=lb_rule.id
-                                 )
-        self.assertEqual(
-                            isinstance(lb_rules, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        #verify listLoadBalancerRules lists the added load balancing rule
-        self.assertNotEqual(
-                            len(lb_rules),
-                            0,
-                            "Check Load Balancer Rule in its List"
-                        )
-        self.assertEqual(
-                            lb_rules[0].id,
-                            lb_rule.id,
-                            "Check List Load Balancer Rules returns valid Rule"
-                        )
-
-        # listLoadBalancerRuleInstances should list all
-        # instances associated with that LB rule
-        lb_instance_rules = list_lb_instances(
-                                              self.apiclient,
-                                              id=lb_rule.id
-                                              )
-        self.assertEqual(
-                            isinstance(lb_instance_rules, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        self.assertNotEqual(
-                            len(lb_instance_rules),
-                            0,
-                            "Check Load Balancer instances Rule in its List"
-                        )
-        self.debug("lb_instance_rules Ids: %s, %s" % (
-                                                    lb_instance_rules[0].id,
-                                                    lb_instance_rules[1].id
-                                                    ))
-        self.debug("VM ids: %s, %s" % (self.vm_1.id, self.vm_2.id))
-
-        self.assertIn(
-                lb_instance_rules[0].id,
-                [self.vm_1.id, self.vm_2.id],
-                "Check List Load Balancer instances Rules returns valid VM ID"
-            )
-
-        self.assertIn(
-            lb_instance_rules[1].id,
-            [self.vm_1.id, self.vm_2.id],
-            "Check List Load Balancer instances Rules returns valid VM ID"
-            )
-
-
-        hostnames = []
-        self.try_ssh(src_nat_ip_addr, hostnames)
-        self.try_ssh(src_nat_ip_addr, hostnames)
-        self.try_ssh(src_nat_ip_addr, hostnames)
-        self.try_ssh(src_nat_ip_addr, hostnames)
-        self.try_ssh(src_nat_ip_addr, hostnames)
-
-        self.debug("Hostnames: %s" % str(hostnames))
-        self.assertIn(
-              self.vm_1.name,
-              hostnames,
-              "Check if ssh succeeded for server1"
-            )
-        self.assertIn(
-              self.vm_2.name,
-              hostnames,
-              "Check if ssh succeeded for server2"
-              )
-
-        #SSH should pass till there is a last VM associated with LB rule
-        lb_rule.remove(self.apiclient, [self.vm_2])
-
-        # making hostnames list empty
-        hostnames[:] = []
-
-        try:
-            self.debug("SSHing into IP address: %s after removing VM (ID: %s)" %
-                                            (
-                                             src_nat_ip_addr.ipaddress,
-                                             self.vm_2.id
-                                             ))
-
-            self.try_ssh(src_nat_ip_addr, hostnames)
-            self.assertIn(
-                          self.vm_1.name,
-                          hostnames,
-                          "Check if ssh succeeded for server1"
-                          )
-        except Exception as e:
-            self.fail("%s: SSH failed for VM with IP Address: %s" %
-                                        (e, src_nat_ip_addr.ipaddress))
-
-        lb_rule.remove(self.apiclient, [self.vm_1])
-
-        with self.assertRaises(Exception):
-            self.debug("Removed all VMs, trying to SSH")
-            ssh_1 = remoteSSHClient(
-                                        src_nat_ip_addr.ipaddress,
-                                        self.services['lbrule']["publicport"],
-                                        self.vm_1.username,
-                                        self.vm_1.password
-                                        )
-            ssh_1.execute("hostname")[0]
-        return
-
-    @attr(tags = ["advanced", "advancedns", "smoke"])
-    def test_02_create_lb_rule_non_nat(self):
-        """Test to create Load balancing rule with source NAT"""
-
-        # Validate the Following:
-        #1. listLoadBalancerRules should return the added rule
-        #2. attempt to ssh twice on the load balanced IP
-        #3. verify using the hostname of the VM that
-        #   round robin is indeed happening as expected
-
-        # Check if VM is in Running state before creating LB rule
-        vm_response = VirtualMachine.list(
-            self.apiclient,
-            account=self.account.name,
-            domainid=self.account.domainid
-        )
-
-        self.assertEqual(
-            isinstance(vm_response, list),
-            True,
-            "Check list VM returns a valid list"
-        )
-
-        self.assertNotEqual(
-            len(vm_response),
-            0,
-            "Check Port Forwarding Rule is created"
-        )
-        for vm in vm_response:
-            self.assertEqual(
-                vm.state,
-                'Running',
-                "VM state should be Running before creating a NAT rule."
-            )
-
-        #Create Load Balancer rule and assign VMs to rule
-        lb_rule = LoadBalancerRule.create(
-            self.apiclient,
-            self.services["lbrule"],
-            self.non_src_nat_ip.ipaddress.id,
-            accountid=self.account.name
-        )
-        self.cleanup.append(lb_rule)
-
-        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
-
-        lb_rules = list_lb_rules(
-            self.apiclient,
-            id=lb_rule.id
-        )
-
-        self.assertEqual(
-            isinstance(lb_rules, list),
-            True,
-            "Check list response returns a valid list"
-        )
-        #verify listLoadBalancerRules lists the added load balancing rule
-        self.assertNotEqual(
-            len(lb_rules),
-            0,
-            "Check Load Balancer Rule in its List"
-        )
-        self.assertEqual(
-            lb_rules[0].id,
-            lb_rule.id,
-            "Check List Load Balancer Rules returns valid Rule"
-        )
-        # listLoadBalancerRuleInstances should list
-        # all instances associated with that LB rule
-        lb_instance_rules = list_lb_instances(
-            self.apiclient,
-            id=lb_rule.id
-        )
-        self.assertEqual(
-            isinstance(lb_instance_rules, list),
-            True,
-            "Check list response returns a valid list"
-        )
-        self.assertNotEqual(
-            len(lb_instance_rules),
-            0,
-            "Check Load Balancer instances Rule in its List"
-        )
-
-        self.assertIn(
-            lb_instance_rules[0].id,
-            [self.vm_1.id, self.vm_2.id],
-            "Check List Load Balancer instances Rules returns valid VM ID"
-        )
-
-        self.assertIn(
-            lb_instance_rules[1].id,
-            [self.vm_1.id, self.vm_2.id],
-            "Check List Load Balancer instances Rules returns valid VM ID"
-        )
-        try:
-            hostnames = []
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-
-            self.debug("Hostnames: %s" % str(hostnames))
-            self.assertIn(
-                    self.vm_1.name,
-                    hostnames,
-                    "Check if ssh succeeded for server1"
-                    )
-            self.assertIn(
-                    self.vm_2.name,
-                    hostnames,
-                    "Check if ssh succeeded for server2"
-                    )
-
-            #SSH should pass till there is a last VM associated with LB rule
-            lb_rule.remove(self.apiclient, [self.vm_2])
-
-            self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
-                       (
-                           self.non_src_nat_ip.ipaddress.ipaddress,
-                           self.vm_2.id
-                           ))
-            # Making host list empty
-            hostnames[:] = []
-
-            self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames)
-            self.assertIn(
-            self.vm_1.name,
-            hostnames,
-            "Check if ssh succeeded for server1"
-            )
-            self.debug("Hostnames after removing VM2: %s" % str(hostnames))
-        except Exception as e:
-            self.fail("%s: SSH failed for VM with IP Address: %s" %
-                      (e, self.non_src_nat_ip.ipaddress.ipaddress))
-
-        lb_rule.remove(self.apiclient, [self.vm_1])
-        with self.assertRaises(Exception):
-            self.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
-                       (
-                           self.non_src_nat_ip.ipaddress.ipaddress,
-                           self.vm_1.id
-                           ))
-            ssh_1 = remoteSSHClient(
-                self.non_src_nat_ip.ipaddress.ipaddress,
-                self.services['lbrule']["publicport"],
-                self.vm_1.username,
-                self.vm_1.password
-            )
-            ssh_1.execute("hostname")[0]
-        return
 
 class TestRebootRouter(cloudstackTestCase):
 
@@ -1173,226 +748,6 @@ class TestRebootRouter(cloudstackTestCase):
         return
 
 
-class TestAssignRemoveLB(cloudstackTestCase):
-
-    def setUp(self):
-        self.apiclient = self.testClient.getApiClient()
-        self.services = Services().services
-        # Get Zone, Domain and templates
-        self.domain = get_domain(self.apiclient, self.services)
-        self.zone = get_zone(self.apiclient, self.services)
-        template = get_template(
-                            self.apiclient,
-                            self.zone.id,
-                            self.services["ostype"]
-                            )
-        self.services["server"]["zoneid"] = self.zone.id
-
-        #Create VMs, accounts
-        self.account = Account.create(
-                                      self.apiclient,
-                                      self.services["account"],
-                                      admin=True,
-                                      domainid=self.domain.id
-                                      )
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                        )
-
-        self.vm_1 = VirtualMachine.create(
-                                  self.apiclient,
-                                  self.services["server"],
-                                  templateid=template.id,
-                                  accountid=self.account.name,
-                                  domainid=self.account.domainid,
-                                  serviceofferingid=self.service_offering.id
-                                  )
-
-        self.vm_2 = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["server"],
-                                templateid=template.id,
-                                accountid=self.account.name,
-                                domainid=self.account.domainid,
-                                serviceofferingid=self.service_offering.id
-                              )
-
-        self.vm_3 = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["server"],
-                                templateid=template.id,
-                                accountid=self.account.name,
-                                domainid=self.account.domainid,
-                                serviceofferingid=self.service_offering.id
-                              )
-
-        self.cleanup = [
-                        self.account,
-                        self.service_offering
-                        ]
-        return
-
-    def tearDown(self):
-        cleanup_resources(self.apiclient, self.cleanup)
-        return
-
-    def try_ssh(self, src_nat_ip_addr, hostnames):
-        try:
-            self.debug(
-                "SSH into VM (IPaddress: %s) & NAT Rule (Public IP: %s)" %
-                (self.vm_1.ipaddress, src_nat_ip_addr.ipaddress)
-                )
-
-            ssh_1 = remoteSSHClient(
-                                    src_nat_ip_addr.ipaddress,
-                                    self.services['lbrule']["publicport"],
-                                    self.vm_1.username,
-                                    self.vm_1.password
-                                    )
-
-            # If Round Robin Algorithm is chosen,
-            # each ssh command should alternate between VMs
-            # hostnames = [ssh_1.execute("hostname")[0]]
-            hostnames.append(ssh_1.execute("hostname")[0])
-
-        except Exception as e:
-            self.fail("%s: SSH failed for VM with IP Address: %s" %
-                                    (e, src_nat_ip_addr.ipaddress))
-
-        time.sleep(self.services["lb_switch_wait"])
-        return
-
-    @attr(tags = ["advanced", "advancedns", "smoke"])
-    def test_assign_and_removal_lb(self):
-        """Test for assign & removing load balancing rule"""
-
-        # Validate:
-        #1. Verify list API - listLoadBalancerRules lists
-        #   all the rules with the relevant ports
-        #2. listLoadBalancerInstances will list
-        #   the instances associated with the corresponding rule.
-        #3. verify ssh attempts should pass as long as there
-        #   is at least one instance associated with the rule
-
-        src_nat_ip_addrs = list_publicIP(
-                                    self.apiclient,
-                                    account=self.account.name,
-                                    domainid=self.account.domainid
-                                  )
-        self.assertEqual(
-                            isinstance(src_nat_ip_addrs, list),
-                            True,
-                            "Check list response returns a valid list"
-                        )
-        self.non_src_nat_ip = src_nat_ip_addrs[0]
-
-        # Open up firewall port for SSH        
-        fw_rule = FireWallRule.create(
-                            self.apiclient,
-                            ipaddressid=self.non_src_nat_ip.id,
-                            protocol=self.services["lbrule"]["protocol"],
-                            cidrlist=['0.0.0.0/0'],
-                            startport=self.services["lbrule"]["publicport"],
-                            endport=self.services["lbrule"]["publicport"]
-                            )
-
-        # Check if VM is in Running state before creating LB rule
-        vm_response = VirtualMachine.list(
-                                          self.apiclient,
-                                          account=self.account.name,
-                                          domainid=self.account.domainid
-                                          )
-
-        self.assertEqual(
-                            isinstance(vm_response, list),
-                            True,
-                            "Check list VM returns a valid list"
-                        )
-
-        self.assertNotEqual(
-                            len(vm_response),
-                            0,
-                            "Check Port Forwarding Rule is created"
-                            )
-        for vm in vm_response:
-            self.assertEqual(
-                            vm.state,
-                            'Running',
-                            "VM state should be Running before creating a NAT rule."
-                        )
-
-        lb_rule = LoadBalancerRule.create(
-                                self.apiclient,
-                                self.services["lbrule"],
-                                self.non_src_nat_ip.id,
-                                self.account.name
-                              )
-        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
-
-        hostnames = []
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-
-        self.debug("Hostnames: %s" % str(hostnames))
-        self.assertIn(
-                  self.vm_1.name,
-                  hostnames,
-                  "Check if ssh succeeded for server1"
-                )
-        self.assertIn(
-                  self.vm_2.name,
-                  hostnames,
-                  "Check if ssh succeeded for server2"
-                  )
-        #Removing VM and assigning another VM to LB rule
-        lb_rule.remove(self.apiclient, [self.vm_2])
-
-        # making hostnames list empty
-        hostnames[:] = []
-
-        try:
-            self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" %
-                                            (
-                                             self.non_src_nat_ip.ipaddress,
-                                             self.vm_1.id,
-                                             ))
-            self.try_ssh(self.non_src_nat_ip, hostnames)
-
-            self.assertIn(
-                          self.vm_1.name,
-                          hostnames,
-                          "Check if ssh succeeded for server1"
-                          )
-        except Exception as e:
-            self.fail("SSH failed for VM with IP: %s" %
-                                    self.non_src_nat_ip.ipaddress)
-
-        lb_rule.assign(self.apiclient, [self.vm_3])
-
-        # Making hostnames list empty
-        hostnames[:] = []
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.try_ssh(self.non_src_nat_ip, hostnames)
-        self.debug("Hostnames: %s" % str(hostnames))
-        self.assertIn(
-                  self.vm_1.name,
-                  hostnames,
-                  "Check if ssh succeeded for server1"
-                )
-        self.assertIn(
-                  self.vm_3.name,
-                  hostnames,
-                  "Check if ssh succeeded for server3"
-                  )
-        return
-
 class TestReleaseIP(cloudstackTestCase):
 
     def setUp(self):