cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [26/47] Marvin IP cleared tests for various cloudstack components
Date Tue, 14 May 2013 13:57:45 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/894413e3/test/integration/component/test_netscaler_configs.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_netscaler_configs.py b/test/integration/component/test_netscaler_configs.py
new file mode 100644
index 0000000..2cfe463
--- /dev/null
+++ b/test/integration/component/test_netscaler_configs.py
@@ -0,0 +1,3024 @@
+# 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.
+
+""" P1 tests for netscaler configurations
+"""
+#Import Local Modules
+import marvin
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+from marvin.remoteSSHClient import remoteSSHClient
+import datetime
+
+
+class Services:
+    """Test netscaler Services
+    """
+
+    def __init__(self):
+        self.services = {
+                         "account": {
+                                    "email": "test@test.com",
+                                    "firstname": "Test",
+                                    "lastname": "User",
+                                    "username": "test",
+                                    # Random characters are appended for unique
+                                    # username
+                                    "password": "password",
+                         },
+                         "service_offering": {
+                                    "name": "Tiny Instance",
+                                    "displaytext": "Tiny Instance",
+                                    "cpunumber": 1,
+                                    "cpuspeed": 100, # in MHz
+                                    "memory": 128, # In MBs
+                         },
+                         "virtual_machine": {
+                                    "displayname": "TestVM",
+                                    "username": "root",
+                                    "password": "password",
+                                    "ssh_port": 22,
+                                    "hypervisor": 'XenServer',
+                                    "privateport": 22,
+                                    "publicport": 22,
+                                    "protocol": 'TCP',
+                                },
+                         "netscaler": {
+                                "ipaddress": '192.168.100.213',
+                                "username": 'nsroot',
+                                "password": 'nsroot',
+                                "networkdevicetype": 'NetscalerVPXLoadBalancer',
+                                "publicinterface": '1/1',
+                                "privateinterface": '1/1',
+                                "numretries": 2,
+                                "lbdevicededicated": False,
+                                "lbdevicecapacity": 50,
+                                "port": 22,
+                         },
+                         "netscaler_dedicated": {
+                                "ipaddress": '192.168.100.213',
+                                "username": 'nsroot',
+                                "password": 'nsroot',
+                                "networkdevicetype": 'NetscalerVPXLoadBalancer',
+                                "publicinterface": '1/1',
+                                "privateinterface": '1/1',
+                                "numretries": 2,
+                                "lbdevicededicated": True,
+                                "port": 22,
+                         },
+                         "network_offering_dedicated": {
+                                    "name": 'Netscaler',
+                                    "displaytext": 'Netscaler',
+                                    "guestiptype": 'Isolated',
+                                    "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat',
+                                    "traffictype": 'GUEST',
+                                    "availability": 'Optional',
+                                    "specifyVlan": False,
+                                    "specifyIpRanges": False,
+                                    "serviceProviderList" : {
+                                            "Dhcp": 'VirtualRouter',
+                                            "Dns": 'VirtualRouter',
+                                            "SourceNat": 'VirtualRouter',
+                                            "PortForwarding": 'VirtualRouter',
+                                            "Vpn": 'VirtualRouter',
+                                            "Firewall": 'VirtualRouter',
+                                            "Lb": 'Netscaler',
+                                            "UserData": 'VirtualRouter',
+                                            "StaticNat": 'VirtualRouter',
+                                    },
+                                    "servicecapabilitylist": {
+                                        "SourceNat": {
+                                            "SupportedSourceNatTypes": "peraccount"
+                                        },
+                                        "lb": {
+                                               "SupportedLbIsolation": "dedicated"
+                                        },
+                                    },
+                         },
+                         "network_offering": {
+                                    "name": 'Netscaler',
+                                    "displaytext": 'Netscaler',
+                                    "guestiptype": 'Isolated',
+                                    "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat',
+                                    "traffictype": 'GUEST',
+                                    "availability": 'Optional',
+                                    "serviceProviderList" : {
+                                            "Dhcp": 'VirtualRouter',
+                                            "Dns": 'VirtualRouter',
+                                            "SourceNat": 'VirtualRouter',
+                                            "PortForwarding": 'VirtualRouter',
+                                            "Vpn": 'VirtualRouter',
+                                            "Firewall": 'VirtualRouter',
+                                            "Lb": 'Netscaler',
+                                            "UserData": 'VirtualRouter',
+                                            "StaticNat": 'VirtualRouter',
+                                    },
+                         },
+                         "network": {
+                                  "name": "Netscaler",
+                                  "displaytext": "Netscaler",
+                         },
+                         "lbrule": {
+                                    "name": "SSH",
+                                    "alg": "roundrobin",
+                                    # Algorithm used for load balancing
+                                    "privateport": 22,
+                                    "publicport": 22,
+                                    "openfirewall": False,
+                         },
+                         "ostype": 'CentOS 5.3 (64-bit)',
+                         # Cent OS 5.3 (64 bit)
+                         "sleep": 60,
+                         "timeout": 10,
+                         "mode":'advanced'
+                    }
+
+
+class TestAddNetScaler(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestAddNetScaler,
+                               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)
+        cls._cleanup = []
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_add_netscaler_device(self):
+        """Test add netscaler device
+        """
+        # Validate the following
+        # 1. Add Netscaler device into a Zone by providing valid log in
+        #    credentials , public , private interface and enabling Load
+        #    Balancing feature.
+        # 2. Netscaler should be configured successfully.
+
+        physical_networks = PhysicalNetwork.list(
+                                                 self.apiclient,
+                                                 zoneid=self.zone.id
+                                                 )
+        self.assertEqual(
+            isinstance(physical_networks, list),
+            True,
+            "There should be atleast one physical network for advanced zone"
+            )
+        physical_network = physical_networks[0]
+        self.debug("Adding netscaler device: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+        netscaler = NetScaler.add(
+                                  self.apiclient,
+                                  self.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+        self.cleanup.append(netscaler)
+        self.debug("Checking if Netscaler network service provider is enabled?")
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        self.apiclient,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        self.assertEqual(
+                         isinstance(nw_service_providers, list),
+                         True,
+                         "Network service providers list should not be empty"
+                         )
+        netscaler_provider = nw_service_providers[0]
+        if netscaler_provider.state != 'Enabled':
+            self.debug("Netscaler provider is not enabled. Enabling it..")
+            response = NetworkServiceProvider.update(
+                                          self.apiclient,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+            self.assertEqual(
+                        response.state,
+                        "Enabled",
+                        "Network service provider should be in enabled state"
+                         )
+        else:
+            self.debug("Netscaler service provider is already enabled.")
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         False,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        self.assertEqual(
+            ns.physicalnetworkid,
+            physical_network.id,
+            "Physical network id should match with the network in which device is configured"
+            )
+        return
+
+
+
+class TestInvalidParametersNetscaler(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestInvalidParametersNetscaler,
+                               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)
+        cls._cleanup = []
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_invalid_cred(self):
+        """Test add netscaler device with invalid credential
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device into a Zone by providing invalid log in
+        #    credentials , but valid public, private interface
+        # 2. Netscaler API should throw error
+
+        physical_networks = PhysicalNetwork.list(
+                                                 self.apiclient,
+                                                 zoneid=self.zone.id
+                                                 )
+        self.assertEqual(
+            isinstance(physical_networks, list),
+            True,
+            "There should be atleast one physical network for advanced zone"
+            )
+        physical_network = physical_networks[0]
+
+        self.debug("Checking if Netscaler network service provider is enabled?")
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        self.apiclient,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        self.assertEqual(
+                         isinstance(nw_service_providers, list),
+                         True,
+                         "Network service providers list should not be empty"
+                         )
+        netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            self.debug("Netscaler provider is not enabled. Enabling it..")
+            response = NetworkServiceProvider.update(
+                                          self.apiclient,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+            self.assertEqual(
+                        response.state,
+                        "Enabled",
+                        "Network service provider should be in enabled state"
+                         )
+        else:
+            self.debug("NetScaler service provider is already enabled.")
+
+        self.debug("Passing invalid credential for NetScaler")
+        self.services["netscaler"]["username"] = random_gen()
+        self.services["netscaler"]["password"] = random_gen()
+        self.debug("Adding netscaler device: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+
+        self.debug("Username: %s, password: %s" % (
+                                    self.services["netscaler"]["username"],
+                                    self.services["netscaler"]["password"]
+                                    ))
+
+        with self.assertRaises(Exception):
+            NetScaler.add(
+                                  self.apiclient,
+                                  self.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_invalid_public_interface(self):
+        """Test add netscaler device with invalid public interface
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device into a Zone by providing valid log in
+        #    credentials , private interface and invalid public interface
+        # 2. Netscaler API should throw error
+
+        physical_networks = PhysicalNetwork.list(
+                                                 self.apiclient,
+                                                 zoneid=self.zone.id
+                                                 )
+        self.assertEqual(
+            isinstance(physical_networks, list),
+            True,
+            "There should be atleast one physical network for advanced zone"
+            )
+        physical_network = physical_networks[0]
+
+        self.debug("Checking if Netscaler network service provider is enabled?")
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        self.apiclient,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        self.assertEqual(
+                         isinstance(nw_service_providers, list),
+                         True,
+                         "Network service providers list should not be empty"
+                         )
+        netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            self.debug("Netscaler provider is not enabled. Enabling it..")
+            response = NetworkServiceProvider.update(
+                                          self.apiclient,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+            self.assertEqual(
+                        response.state,
+                        "Enabled",
+                        "Network service provider should be in enabled state"
+                         )
+        else:
+            self.debug("NetScaler service provider is already enabled.")
+
+        self.debug("Passing invalid public interface for NetScaler")
+        self.services["netscaler"]["publicinterface"] = random_gen()
+
+        self.debug("Adding netscaler device: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+
+        self.debug("Public interface: %s" %
+                                self.services["netscaler"]["publicinterface"])
+
+        with self.assertRaises(Exception):
+            NetScaler.add(
+                                  self.apiclient,
+                                  self.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_invalid_private_interface(self):
+        """Test add netscaler device with invalid private interface
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device into a Zone by providing valid log in
+        #    credentials , public interface and invalid private interface
+        # 2. Netscaler API should throw error
+
+        physical_networks = PhysicalNetwork.list(
+                                                 self.apiclient,
+                                                 zoneid=self.zone.id
+                                                 )
+        self.assertEqual(
+            isinstance(physical_networks, list),
+            True,
+            "There should be atleast one physical network for advanced zone"
+            )
+        physical_network = physical_networks[0]
+
+        self.debug("Checking if Netscaler network service provider is enabled?")
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        self.apiclient,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        self.assertEqual(
+                         isinstance(nw_service_providers, list),
+                         True,
+                         "Network service providers list should not be empty"
+                         )
+        netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            self.debug("Netscaler provider is not enabled. Enabling it..")
+            response = NetworkServiceProvider.update(
+                                          self.apiclient,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+            self.assertEqual(
+                        response.state,
+                        "Enabled",
+                        "Network service provider should be in enabled state"
+                         )
+        else:
+            self.debug("NetScaler service provider is already enabled.")
+
+        self.debug("Passing invalid private interface for NetScaler")
+        self.services["netscaler"]["privateinterface"] = random_gen()
+
+        self.debug("Adding netscaler device: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+
+        self.debug("Private interface: %s" %
+                                self.services["netscaler"]["privateinterface"])
+
+        with self.assertRaises(Exception):
+            NetScaler.add(
+                                  self.apiclient,
+                                  self.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+        return
+
+
+class TestNetScalerDedicated(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestNetScalerDedicated,
+                               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)
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        physical_networks = PhysicalNetwork.list(
+                                                 cls.api_client,
+                                                 zoneid=cls.zone.id
+                                                 )
+        if isinstance(physical_networks, list):
+            physical_network = physical_networks[0]
+
+        cls.netscaler = NetScaler.add(
+                                  cls.api_client,
+                                  cls.services["netscaler_dedicated"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        cls.api_client,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        if isinstance(nw_service_providers, list):
+            netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            response = NetworkServiceProvider.update(
+                                          cls.api_client,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+
+        cls.network_offering = NetworkOffering.create(
+                                            cls.api_client,
+                                            cls.services["network_offering_dedicated"],
+                                            conservemode=False,
+                                            state="Creating",
+                                            status="Creating",
+                                            allocationstate="Creating",
+                                            )
+        # Enable Network offering
+        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["virtual_machine"]["template"] = cls.template.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.network_offering,
+                        cls.netscaler,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.account_1 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_2 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.cleanup = [self.account_1, self.account_2]
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            interval = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.interval'
+                                    )
+            wait = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.wait'
+                                    )
+            # Sleep to ensure that all resources are deleted
+            time.sleep(int(interval[0].value) + int(wait[0].value))
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_netscaler_dedicated_mode(self):
+        """Test netscaler device in dedicated mode
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device in dedicated mode.
+        # 2. Netscaler should be configured successfully.It should be able to
+        #    service only 1 account.
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=self.netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         True,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+
+        Network.create(
+                            self.apiclient,
+                            self.services["network"],
+                            accountid=self.account_2.account.name,
+                            domainid=self.account_2.account.domainid,
+                            networkofferingid=self.network_offering.id,
+                            zoneid=self.zone.id
+                        )
+	self.debug("Deploying an instance in account: %s" % self.account_2.account.name)
+        with self.assertRaises(Exception):
+        	VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_2.account.name,
+                                  domainid=self.account_2.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network.id)]
+                                  )
+	self.debug("Deply instacne in dedicated Network offering mode failed")
+        return
+
+
+
+class TestNetScalerShared(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestNetScalerShared,
+                               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)
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        physical_networks = PhysicalNetwork.list(
+                                                 cls.api_client,
+                                                 zoneid=cls.zone.id
+                                                 )
+        if isinstance(physical_networks, list):
+            physical_network = physical_networks[0]
+
+        cls.netscaler = NetScaler.add(
+                                  cls.api_client,
+                                  cls.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        cls.api_client,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        if isinstance(nw_service_providers, list):
+            netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            response = NetworkServiceProvider.update(
+                                          cls.api_client,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+        cls.network_offering = NetworkOffering.create(
+                                            cls.api_client,
+                                            cls.services["network_offering"],
+                                            conservemode=True
+                                            )
+        # Enable Network offering
+        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["virtual_machine"]["template"] = cls.template.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.network_offering,
+                        cls.netscaler,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.account_1 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_2 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.cleanup = [self.account_1, self.account_2]
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            interval = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.interval'
+                                    )
+            wait = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.wait'
+                                    )
+            # Sleep to ensure that all resources are deleted
+            time.sleep(int(interval[0].value) + int(wait[0].value))
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_netscaler_shared_mode(self):
+        """Test netscaler device in shared mode
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device in shared mode.
+        # 2. Netscaler should be configured successfully.It should be able to
+        #    service only 1 account.
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=self.netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         False,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_1 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_1 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_1.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_1.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_1.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_1.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_2 = Network.create(
+                                self.apiclient,
+                                self.services["network"],
+                                accountid=self.account_2.account.name,
+                                domainid=self.account_2.account.domainid,
+                                networkofferingid=self.network_offering.id,
+                                zoneid=self.zone.id
+                                )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_2.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_2 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_2.account.name,
+                                  domainid=self.account_2.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_2.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_2.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_2.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_2.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        return
+
+
+
+class TestNetScalerCustomCapacity(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestNetScalerCustomCapacity,
+                               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)
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        physical_networks = PhysicalNetwork.list(
+                                                 cls.api_client,
+                                                 zoneid=cls.zone.id
+                                                 )
+        if isinstance(physical_networks, list):
+            physical_network = physical_networks[0]
+        cls.services["netscaler"]["lbdevicecapacity"] = 2
+        cls.netscaler = NetScaler.add(
+                                  cls.api_client,
+                                  cls.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        cls.api_client,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        if isinstance(nw_service_providers, list):
+            netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            response = NetworkServiceProvider.update(
+                                          cls.api_client,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+        cls.network_offering = NetworkOffering.create(
+                                            cls.api_client,
+                                            cls.services["network_offering"],
+                                            conservemode=True
+                                            )
+        # Enable Network offering
+        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["virtual_machine"]["template"] = cls.template.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.network_offering,
+                        cls.netscaler,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.account_1 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_2 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_3 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.cleanup = [self.account_1, self.account_2, self.account_3]
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            interval = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.interval'
+                                    )
+            wait = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.wait'
+                                    )
+            # Sleep to ensure that all resources are deleted
+            time.sleep(int(interval[0].value) + int(wait[0].value))
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_netscaler_custom_capacity(self):
+        """Test netscaler device with custom capacity
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device in shared mode with capacity 3
+        # 2. Netscaler should be configured successfully.It should be able to
+        #    service only 3 accounts.
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=self.netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         False,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_1 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_1 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_1.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_1.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_1.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_1.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_2 = Network.create(
+                                self.apiclient,
+                                self.services["network"],
+                                accountid=self.account_2.account.name,
+                                domainid=self.account_2.account.domainid,
+                                networkofferingid=self.network_offering.id,
+                                zoneid=self.zone.id
+                                )
+        self.debug("Created network with ID: %s" % self.network_2.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_2.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_2 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_2.account.name,
+                                  domainid=self.account_2.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_2.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_2.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_2.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_2.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_3 = Network.create(
+                            self.apiclient,
+                            self.services["network"],
+                            accountid=self.account_3.account.name,
+                            domainid=self.account_3.account.domainid,
+                            networkofferingid=self.network_offering.id,
+                            zoneid=self.zone.id
+                        )
+        self.debug("Created network with ID: %s" % self.network_3.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_3.account.name)
+        with self.assertRaises(Exception):
+            # Spawn an instance in that network
+            virtual_machine_3 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_3.account.name,
+                                  domainid=self.account_3.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_3.id)]
+                                  )
+        return
+
+
+
+class TestNetScalerNoCapacity(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestNetScalerNoCapacity,
+                               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)
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        physical_networks = PhysicalNetwork.list(
+                                                 cls.api_client,
+                                                 zoneid=cls.zone.id
+                                                 )
+        if isinstance(physical_networks, list):
+            physical_network = physical_networks[0]
+	cls.services["netscaler"]["lbdevicecapacity"] = 2
+        cls.netscaler = NetScaler.add(
+                                  cls.api_client,
+                                  cls.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        cls.api_client,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        if isinstance(nw_service_providers, list):
+            netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            response = NetworkServiceProvider.update(
+                                          cls.api_client,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+        cls.network_offering = NetworkOffering.create(
+                                            cls.api_client,
+                                            cls.services["network_offering"],
+                                            conservemode=True
+                                            )
+        # Enable Network offering
+        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["virtual_machine"]["template"] = cls.template.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.network_offering,
+                        cls.netscaler,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.account_1 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_2 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_3 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.cleanup = [self.account_1, self.account_2, self.account_3]
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            interval = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.interval'
+                                    )
+            wait = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.wait'
+                                    )
+            # Sleep to ensure that all resources are deleted
+            time.sleep(int(interval[0].value) + int(wait[0].value))
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_netscaler_no_capacity(self):
+        """Test netscaler device with no capacity remaining
+        """
+
+        # Validate the following
+        # 1. Add Netscaler device in shared mode with capacity 2
+        # 2. Netscaler should be configured successfully.It should be able to
+        #    service only 2 accounts.
+        # 3. Deploy instance for account 3 should fail
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=self.netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         False,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_1 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_1 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_1.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_1.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_1.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_1.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_2 = Network.create(
+                                self.apiclient,
+                                self.services["network"],
+                                accountid=self.account_2.account.name,
+                                domainid=self.account_2.account.domainid,
+                                networkofferingid=self.network_offering.id,
+                                zoneid=self.zone.id
+                                )
+        self.debug("Created network with ID: %s" % self.network_2.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_2.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_2 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_2.account.name,
+                                  domainid=self.account_2.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_2.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_2.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_2.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_2.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        # Creating network using the network offering created
+        self.debug("Trying to create network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_3 = Network.create(
+                            self.apiclient,
+                            self.services["network"],
+                            accountid=self.account_3.account.name,
+                            domainid=self.account_3.account.domainid,
+                            networkofferingid=self.network_offering.id,
+                            zoneid=self.zone.id
+                        )
+        self.debug("Created network with ID: %s" % self.network_3.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_3.account.name)
+        with self.assertRaises(Exception):
+            # Spawn an instance in that network
+            virtual_machine_3 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_3.account.name,
+                                  domainid=self.account_3.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_3.id)]
+                                  )
+        return
+
+
+
+class TestGuestNetworkWithNetScaler(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(
+                               TestGuestNetworkWithNetScaler,
+                               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)
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        physical_networks = PhysicalNetwork.list(
+                                                 cls.api_client,
+                                                 zoneid=cls.zone.id
+                                                 )
+        if isinstance(physical_networks, list):
+            physical_network = physical_networks[0]
+
+        cls.netscaler = NetScaler.add(
+                                  cls.api_client,
+                                  cls.services["netscaler"],
+                                  physicalnetworkid=physical_network.id
+                                  )
+
+        nw_service_providers = NetworkServiceProvider.list(
+                                        cls.api_client,
+                                        name='Netscaler',
+                                        physicalnetworkid=physical_network.id
+                                        )
+        if isinstance(nw_service_providers, list):
+            netscaler_provider = nw_service_providers[0]
+
+        if netscaler_provider.state != 'Enabled':
+            response = NetworkServiceProvider.update(
+                                          cls.api_client,
+                                          id=netscaler_provider.id,
+                                          state='Enabled'
+                                          )
+        cls.network_offering = NetworkOffering.create(
+                                            cls.api_client,
+                                            cls.services["network_offering"],
+                                            conservemode=True
+                                            )
+        # Enable Network offering
+        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        cls.services["virtual_machine"]["template"] = cls.template.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+        cls._cleanup = [
+                        cls.service_offering,
+                        cls.network_offering,
+                        cls.netscaler,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.account_1 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.account_2 = Account.create(
+                                     self.apiclient,
+                                     self.services["account"],
+                                     admin=True,
+                                     domainid=self.domain.id
+                                     )
+        self.cleanup = [self.account_1, self.account_2]
+        return
+
+    def tearDown(self):
+        try:
+            self.debug("Cleaning up the resources")
+            #Clean up, terminate the created network offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+            interval = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.interval'
+                                    )
+            wait = list_configurations(
+                                    self.apiclient,
+                                    name='network.gc.wait'
+                                    )
+            # Sleep to ensure that all resources are deleted
+            time.sleep(int(interval[0].value) + int(wait[0].value))
+            self.debug("Cleanup complete!")
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_01_guest_network(self):
+        """Implementing Guest Network when first VM gets deployed using the network having Netscaler as LB
+        """
+
+        # Validate the following
+        # 1. Configure Netscaler for load balancing. 
+        # 2. Create a Network offering with LB services provided by Netscaler
+        #    and all other services by VR.
+        # 3.Create a new account/user. 
+        # 4. Deploy the first VM using a network from the above created
+        #    Network offering.
+        # In Netscaler:
+        # 1. Private interface of Netscaler device will be configured to make
+        #    it part of the virtual guest network by binding the interface to
+        #    the VLAN and subnet allocated for the virtual guest network
+        # 2. Private interface should be associated with a self-ip (second IP
+        #    in the subnet) from the guest subnet.
+
+        ns_list = NetScaler.list(
+                                 self.apiclient,
+                                 lbdeviceid=self.netscaler.lbdeviceid
+                                 )
+        self.assertEqual(
+                         isinstance(ns_list, list),
+                         True,
+                         "NetScaler list should not be empty"
+                         )
+        ns = ns_list[0]
+
+        self.assertEqual(
+                         ns.lbdevicededicated,
+                         False,
+                         "NetScaler device is configured in shared mode"
+                         )
+        self.assertEqual(
+                         ns.lbdevicestate,
+                         "Enabled",
+                         "NetScaler device state should be enabled"
+                         )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_1 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_1 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_1.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_1.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_1.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_1.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        # Find Network vlan used
+        network_list = Network.list(
+                                    self.apiclient,
+                                    id=self.network_1.id,
+                                    listall=True
+                                    )
+        nw = network_list[0]
+        self.debug("SSH into netscaler: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+        try:
+            ssh_client = remoteSSHClient(
+                                    self.services["netscaler"]["ipaddress"],
+                                    self.services["netscaler"]["port"],
+                                    self.services["netscaler"]["username"],
+                                    self.services["netscaler"]["password"],
+                                    )
+            cmd = "show vlan %s" % (nw.vlan)
+            self.debug("command: %s" % cmd)
+            res = ssh_client.execute(cmd)
+            result = str(res)
+            self.debug("Output: %s" % result)
+            # Output: ERROR: No such resource [id, 123]
+
+            self.assertNotEqual(
+                    result.count("ERROR: No such resource "),
+                    1,
+                    "Netscaler should have vlan configured for the network"
+                    )
+        except Exception as e:
+            self.fail("SSH Access failed for %s: %s" % \
+                      (self.services["netscaler"]["ipaddress"], e))
+        return
+
+    @attr(tags = ["advancedns"])
+    def test_02_guest_network_multiple(self):
+        """Implementing Guest Network when multiple VMs gets deployed using the network having Netscaler as LB
+        """
+
+        # Validate the following
+        # 1. Configure Netscaler for load balancing. 
+        # 2. Create a Network offering with LB services provided by Netscaler
+        #    and all other services by VR.
+        # 3.Create a new account/user. 
+        # 4. Deploy the first VM using a network from the above created
+        #    Network offering.
+        # In Netscaler:
+        # 1. Private interface of Netscaler device will be configured to make
+        #    it part of the virtual guest network by binding the interface to
+        #    the VLAN and subnet allocated for the virtual guest network
+        # 2. Private interface should be associated with a self-ip (second IP
+        #    in the subnet) from the guest subnet.
+
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_1 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_1.account.name,
+                                    domainid=self.account_1.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_1.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_1.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_1 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_1.account.name,
+                                  domainid=self.account_1.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_1.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_1.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_1.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_1.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        # Creating network using the network offering created
+        self.debug("Creating network with network offering: %s" %
+                                                    self.network_offering.id)
+        self.network_2 = Network.create(
+                                    self.apiclient,
+                                    self.services["network"],
+                                    accountid=self.account_2.account.name,
+                                    domainid=self.account_2.account.domainid,
+                                    networkofferingid=self.network_offering.id,
+                                    zoneid=self.zone.id
+                                    )
+        self.debug("Created network with ID: %s" % self.network_2.id)
+
+        self.debug("Deploying VM in account: %s" % self.account_2.account.name)
+
+        # Spawn an instance in that network
+        virtual_machine_2 = VirtualMachine.create(
+                                  self.apiclient,
+                                  self.services["virtual_machine"],
+                                  accountid=self.account_2.account.name,
+                                  domainid=self.account_2.account.domainid,
+                                  serviceofferingid=self.service_offering.id,
+                                  networkids=[str(self.network_2.id)]
+                                  )
+        self.debug("Deployed VM in network: %s" % self.network_2.id)
+        list_vm_response = VirtualMachine.list(
+                                        self.apiclient,
+                                        id=virtual_machine_2.id
+                                        )
+
+        self.debug(
+                "Verify listVirtualMachines response for virtual machine: %s" \
+                % virtual_machine_2.id
+            )
+
+        self.assertEqual(
+                            isinstance(list_vm_response, list),
+                            True,
+                            "Check list response returns a valid list"
+                        )
+        vm_response = list_vm_response[0]
+
+        self.assertEqual(
+                            vm_response.state,
+                            "Running",
+                            "VM state should be running after deployment"
+                        )
+        self.debug("SSH into netscaler: %s" %
+                                    self.services["netscaler"]["ipaddress"])
+        try:
+            # Find Network vlan used
+            network_list = Network.list(
+                                    self.apiclient,
+                                    id=self.network_1.id,
+                                    listall=True
+                                    )
+            nw = network_list[0]
+            ssh_client = remoteSSHClient(
+                                    self.services["netscaler"]["ipaddress"],
+                                    self.services["netscaler"]["port"],
+                                    self.services["netscaler"]["username"],
+                                    self.services["netscaler"]["password"],
+                                    )
+            cmd = "show vlan %s" % (nw.vlan)
+            self.debug("command: %s" % cmd)
+            res = ssh_client.execute(cmd)
+            result = str(res)
+            self.debug("Output: %s" % result)
+            # Output: ERROR: No such resource [id, 123]
+
+            self.assertNotEqual(
+                    result.count("ERROR: No such resource "),
+                    1,
+                    "Netscaler should have vlan configured for the network"
+                    )
+
+            # Find Network vlan used
+            network_list = Network.list(
+                                    self.apiclient,
+                                    id=self.network_2.id,
+                                    listall=True
+                                    )
+            nw = network_list[0]
+            cmd = "show vlan %s" % (nw.vlan)
+            self.debug("command: %s" % cmd)
+            res = ssh_client.execute(cmd)
+            result = str(res)
+            self.debug("Output: %s" % result)
+            # Output: ERROR: No such resource [id, 123]
+
+            self.assertNotEqual(
+                    result.count("ERROR: No such resource"),
+                    1,
+                    "Netscaler should have vlan configured for the network"
+                    )
+        except Exception as e:
+            self.fail("SSH Access failed for %s: %s" % \
+ 

<TRUNCATED>

Mime
View raw message