From de86c0cb170f55bdd2bf27874f1782b7333d71af Mon Sep 17 00:00:00 2001 From: Prashanth Manthena Date: Wed, 23 Mar 2016 15:59:41 +0100 Subject: [PATCH] CLOUDSTACK-9322 : Marvin tests for Internal Lb with Nuage VSP --- .../plugins/nuagevsp/nuageTestCase.py | 709 +++--- .../nuagevsp/test_nuage_password_reset.py | 100 +- .../nuagevsp/test_nuage_vpc_internal_lb.py | 2076 +++++++++++++++++ .../nuagevsp/test_nuage_vpc_network.py | 51 +- .../plugins/nuagevsp/test_nuage_vsp.py | 55 +- tools/marvin/marvin/config/test_data.py | 128 +- tools/marvin/marvin/lib/base.py | 7 +- 7 files changed, 2596 insertions(+), 530 deletions(-) create mode 100644 test/integration/plugins/nuagevsp/test_nuage_vpc_internal_lb.py diff --git a/test/integration/plugins/nuagevsp/nuageTestCase.py b/test/integration/plugins/nuagevsp/nuageTestCase.py index 55199d5d808..9d0d07743a1 100644 --- a/test/integration/plugins/nuagevsp/nuageTestCase.py +++ b/test/integration/plugins/nuagevsp/nuageTestCase.py @@ -15,43 +15,36 @@ # specific language governing permissions and limitations # under the License. -""" Custom base class for NuageVsp SDN Plugin specific Marvin tests +""" Custom base class for Nuage VSP SDN plugin specific Marvin tests """ # Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.lib.base import (NetworkServiceProvider, - ServiceOffering, - NetworkOffering, - Network, - Router, - Nuage, - VPC, - VpcOffering, - PublicIPAddress, - VirtualMachine, - StaticNATRule, - NetworkACLList, - NetworkACL, +from marvin.lib.base import (EgressFireWallRule, FireWallRule, - EgressFireWallRule, - Host) -from marvin.lib.common import (get_zone, - get_domain, + Hypervisor, + Network, + NetworkACL, + NetworkACLList, + NetworkOffering, + NetworkServiceProvider, + Nuage, + PhysicalNetwork, + PublicIPAddress, + Router, + ServiceOffering, + StaticNATRule, + VirtualMachine, + VPC, + VpcOffering) +from marvin.lib.common import (get_domain, get_template, - list_templates, - wait_for_cleanup) + get_zone) from marvin.lib.utils import cleanup_resources -from marvin.cloudstackAPI import (listPhysicalNetworks, - updateConfiguration, - updateTemplate, - listConfigurations, - listHypervisors, - stopRouter, - startRouter) +from marvin.cloudstackAPI import restartVPC # Import System Modules -import socket import importlib import logging +import socket class nuageTestCase(cloudstackTestCase): @@ -84,42 +77,36 @@ class nuageTestCase(cloudstackTestCase): ) cls._cleanup = [cls.service_offering] - # Get configured Nuage Vsp device details + # Get configured Nuage VSP device details try: - resp = listPhysicalNetworks.listPhysicalNetworksCmd() - resp.zoneid = cls.zone.id - physical_networks = cls.api_client.listPhysicalNetworks(resp) + physical_networks = PhysicalNetwork.list(cls.api_client, zoneid=cls.zone.id) for pn in physical_networks: - if pn.isolationmethods == 'VSP': + if pn.isolationmethods == "VSP": cls.vsp_physical_network = pn break cls.nuage_vsp_device = Nuage.list(cls.api_client, physicalnetworkid=cls.vsp_physical_network.id )[0] pns = cls.config.zones[0].physical_networks - providers = filter(lambda physical_network: 'VSP' in physical_network.isolationmethods, pns)[0].providers - devices = filter(lambda provider: provider.name == 'NuageVsp', providers)[0].devices + providers = filter(lambda physical_network: "VSP" in physical_network.isolationmethods, pns)[0].providers + devices = filter(lambda provider: provider.name == "NuageVsp", providers)[0].devices cls.nuage_vsp_device.username = devices[0].username cls.nuage_vsp_device.password = devices[0].password - listConfigurationsCmd = listConfigurations.listConfigurationsCmd() - listConfigurationsCmd.name = "nuagevsp.cms.id" - listConfigurationsCmd.scopename = "global" - cs_config_dict = cls.api_client.listConfigurations(listConfigurationsCmd) - cls.cms_id = str(cs_config_dict[0].value).split(":")[1] + cls.cms_id = cls.nuage_vsp_device.cmsid except Exception as e: cls.tearDownClass() - raise unittest.SkipTest("Warning: Couldn't get configured Nuage Vsp device details: %s" % e) + raise unittest.SkipTest("Warning: Couldn't get configured Nuage VSP device details: %s" % e) # Check if the host hypervisor type is simulator - resp = listHypervisors.listHypervisorsCmd() - resp.zoneid = cls.zone.id - cls.isSimulator = cls.api_client.listHypervisors(resp)[0].name == 'Simulator' + cls.isSimulator = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)[0].name == "Simulator" - # VSD is a Python SDK for Nuage Vsp + # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform + # vspk is a Python SDK for Nuage VSP's VSD + # cms_vspk_wrapper is a library that wraps vspk package try: vspk_module = "vspk." + cls.nuage_vsp_device.apiversion if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion - vsdk = importlib.import_module(vspk_module) + cls.vsdk = importlib.import_module(vspk_module) vspk_utils_module = "vspk.utils" if int(cls.nuage_vsp_device.apiversion[1]) >= 4 \ else "vspk.vsdk." + cls.nuage_vsp_device.apiversion + ".utils" vsdk_utils = importlib.import_module(vspk_utils_module) @@ -129,12 +116,12 @@ class nuageTestCase(cloudstackTestCase): raise unittest.SkipTest("vspk (and/or) cms_vspk_wrapper import failure") # Configure VSD session - cls._session = vsdk.NUVSDSession(username=cls.nuage_vsp_device.username, - password=cls.nuage_vsp_device.password, - enterprise="csp", api_url="https://%s:%d" % - (cls.nuage_vsp_device.hostname, - cls.nuage_vsp_device.port) - ) + cls._session = cls.vsdk.NUVSDSession(username=cls.nuage_vsp_device.username, + password=cls.nuage_vsp_device.password, + enterprise="csp", api_url="https://%s:%d" % + (cls.nuage_vsp_device.hostname, + cls.nuage_vsp_device.port) + ) cls._session.start() # Configure cms_vspk_wrapper session @@ -157,7 +144,7 @@ class nuageTestCase(cloudstackTestCase): # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: - cls.debug("Warning: Exception during cleanup : %s" % e) + cls.debug("Warning: Exception during cleanup: %s" % e) return def tearDown(self): @@ -176,69 +163,51 @@ class nuageTestCase(cloudstackTestCase): self.debug("Cleanup complete!") return - def getConfigurationValue(self, name, scope="global"): - listConfigurationsCmd = listConfigurations.listConfigurationsCmd() - listConfigurationsCmd.name = name - listConfigurationsCmd.scopename = scope - if scope is "zone": - listConfigurationsCmd.zoneid = self.zone.id - return self.api_client.listConfigurations(listConfigurationsCmd) - - def setConfigurationValue(self, name, value, scope="global"): - cmd = updateConfiguration.updateConfigurationCmd() - cmd.name = name - cmd.scopename = scope - if scope is "zone": - cmd.zoneid = self.zone.id - cmd.value = value - self.api_client.updateConfiguration(cmd) - - def updateTemplate(self, value): - self.debug("UPDATE TEMPLATE") - cmd = updateTemplate.updateTemplateCmd() - cmd.id = self.template.id - cmd.passwordenabled = value - self.api_client.updateTemplate(cmd) - list_template_response = list_templates(self.api_client, - templatefilter="all", - id=self.template.id - ) - self.template = list_template_response[0] - - # Creates the vpc offering + # create_VpcOffering - Creates VPC offering def create_VpcOffering(self, vpc_offering, suffix=None): - self.debug('Create VpcOffering') + self.debug("Creating VPC offering") if suffix: vpc_offering["name"] = "VPC_OFF-" + str(suffix) vpc_off = VpcOffering.create(self.api_client, vpc_offering ) # Enable VPC offering - vpc_off.update(self.api_client, state='Enabled') + vpc_off.update(self.api_client, state="Enabled") self.cleanup.append(vpc_off) - self.debug('Created and Enabled VpcOffering') + self.debug("Created and Enabled VPC offering") return vpc_off - # create_Vpc - Takes the vpc offering as arguments and creates the VPC - def create_Vpc(self, vpc_offering, cidr='10.1.1.1/16', cleanup=True): - self.debug("Creating a VPC network in the account: %s" % self.account.name) + # create_Vpc - Creates VPC with the given VPC offering + def create_Vpc(self, vpc_offering, cidr="10.1.1.1/16", cleanup=True): + self.debug("Creating a VPC in the account - %s" % self.account.name) + self.test_data["vpc"]["name"] = "TestVPC" + self.test_data["vpc"]["displaytext"] = "TestVPC" self.test_data["vpc"]["cidr"] = cidr - vpc = VPC.create( - self.api_client, - self.test_data["vpc"], - vpcofferingid=vpc_offering.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) - self.debug("Created VPC with ID: %s" % vpc.id) + vpc = VPC.create(self.api_client, + self.test_data["vpc"], + vpcofferingid=vpc_offering.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) + self.debug("Created VPC with ID - %s" % vpc.id) if cleanup: self.cleanup.append(vpc) return vpc - # create_NetworkOffering - Takes the network offering as argument and creates the Network Offering + # restart_Vpc - Restarts the given VPC with/without cleanup + def restart_Vpc(self, vpc, cleanup=None): + self.debug("Restarting VPC with ID - %s" % vpc.id) + cmd = restartVPC.restartVPCCmd() + cmd.id = vpc.id + cmd.cleanup = cleanup + cmd.makeredundant = False + self.api_client.restartVPC(cmd) + self.debug("Restarted VPC with ID - %s" % vpc.id) + + # create_NetworkOffering - Creates Network offering def create_NetworkOffering(self, net_offering, suffix=None, conserve_mode=False): - self.debug('Create NetworkOffering') + self.debug("Creating Network offering") if suffix: net_offering["name"] = "NET_OFF-" + str(suffix) nw_off = NetworkOffering.create(self.api_client, @@ -246,192 +215,78 @@ class nuageTestCase(cloudstackTestCase): conservemode=conserve_mode ) # Enable Network offering - nw_off.update(self.api_client, state='Enabled') + nw_off.update(self.api_client, state="Enabled") self.cleanup.append(nw_off) - self.debug('Created and Enabled NetworkOffering') + self.debug("Created and Enabled Network offering") return nw_off - # create_Network - Takes the network offering as argument and nw_key and creates the network - def create_Network(self, nw_off, nw_key="network", gateway='10.1.1.1', netmask='255.255.255.0', vpc=None, acl_list=None): - if not hasattr(nw_off, "id"): - nw_off = self.create_NetworkOffering(nw_off) - self.debug('Adding Network=%s' % self.test_data[nw_key]) - self.test_data[nw_key]["netmask"] = netmask - obj_network = Network.create(self.api_client, - self.test_data[nw_key], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=nw_off.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id if vpc else self.vpc.id if hasattr(self, "vpc") else None, - aclid=acl_list.id if acl_list else None - ) - self.debug("Created network with ID: %s" % obj_network.id) - self.cleanup.append(obj_network) - return obj_network + # create_Network - Creates network with the given Network offering + def create_Network(self, nw_off, gateway="10.1.1.1", netmask="255.255.255.0", vpc=None, acl_list=None): + self.debug("Creating a network in the account - %s" % self.account.name) + self.test_data["network"]["netmask"] = netmask + network = Network.create(self.api_client, + self.test_data["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=nw_off.id, + zoneid=self.zone.id, + gateway=gateway, + vpcid=vpc.id if vpc else self.vpc.id if hasattr(self, "vpc") else None, + aclid=acl_list.id if acl_list else None + ) + self.debug("Created network with ID - %s" % network.id) + self.cleanup.append(network) + return network # upgrade_Network - Upgrades the given network def upgrade_Network(self, nw_off, network): if not hasattr(nw_off, "id"): nw_off = self.create_NetworkOffering(nw_off, network.gateway) - self.debug('Update Network=%s' % network) - network.update( - self.api_client, - networkofferingid=nw_off.id, - changecidr=False - ) - self.debug("Updated network with ID: %s" % network.id) + self.debug("Updating Network with ID - %s" % network.id) + network.update(self.api_client, + networkofferingid=nw_off.id, + changecidr=False + ) + self.debug("Updated network with ID - %s" % network.id) # delete_Network - Deletes the given network def delete_Network(self, network): - self.debug('Deleting Network - %s' % network.name) - # Wait for network garbage collection before network deletion - wait_for_cleanup(self.api_client, - ["network.gc.interval", "network.gc.wait"] - ) + self.debug("Deleting Network with ID - %s" % network.id) network.delete(self.api_client) if network in self.cleanup: self.cleanup.remove(network) - self.debug('Deleted Network - %s' % network.name) + self.debug("Deleted Network with ID - %s" % network.id) - # create_VM_in_Network - Creates a VM in the given network, the vm_key - is the key for the services on the vm. - def create_VM_in_Network(self, network, vm_key="virtual_machine", host_id=None, start_vm=True): - self.debug('Creating VM in network=%s' % network.name) - self.debug('Passed vm_key=%s' % vm_key) + # create_VM - Creates VM in the given network, vm_key - Key for the services on the VM + def create_VM(self, network, vm_key="virtual_machine", host_id=None, start_vm=True): + self.debug("Creating VM in network with ID - %s" % network.id) + self.debug("Passed vm_key - %s" % vm_key) self.test_data[vm_key]["zoneid"] = self.zone.id self.test_data[vm_key]["template"] = self.template.id - vm = VirtualMachine.create( - self.api_client, - self.test_data[vm_key], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)], - startvm=start_vm, - hostid=host_id - ) - self.debug('Created VM=%s in network=%s' % (vm.id, network.name)) + vm = VirtualMachine.create(self.api_client, + self.test_data[vm_key], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(network.id)], + startvm=start_vm, + hostid=host_id + ) + self.debug("Created VM with ID - %s in network with ID - %s" % (vm.id, network.id)) self.cleanup.append(vm) return vm # delete_VM - Deletes the given VM - def delete_VM(self, vm): - self.debug('Deleting VM - %s' % vm.name) - vm.delete(self.api_client) - # Wait for expunge interval to cleanup VM - wait_for_cleanup(self.api_client, - ["expunge.delay", "expunge.interval"] - ) + def delete_VM(self, vm, expunge=True): + self.debug("Deleting VM with ID - %s" % vm.id) + vm.delete(self.api_client, expunge=expunge) if vm in self.cleanup: self.cleanup.remove(vm) - self.debug('Deleted VM - %s' % vm.name) + self.debug("Deleted VM with ID - %s" % vm.id) - # acquire_Public_IP - Acquires a public IP for the given network - def acquire_Public_IP(self, network, vpc=None): - self.debug("Associating public IP for network: %s" % network.name) - public_ip = PublicIPAddress.create(self.api_client, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id if vpc is None else None, - vpcid=vpc.id if vpc else self.vpc.id if hasattr(self, "vpc") else None - ) - self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, - network.id)) - return public_ip - - # create_StaticNatRule_For_VM - Creates static NAT rule for the given network , VM on the given public ip - def create_StaticNatRule_For_VM(self, vm, public_ip, network, vmguestip=None): - self.debug("Enabling static NAT for IP: %s" % - public_ip.ipaddress.ipaddress) - StaticNATRule.enable( - self.api_client, - ipaddressid=public_ip.ipaddress.id, - virtualmachineid=vm.id, - networkid=network.id, - vmguestip=vmguestip - ) - self.debug("Static NAT enabled for IP: %s" % - public_ip.ipaddress.ipaddress) - - # delete_StaticNatRule_For_VM - Deletes the static NAT rule for the given VM - def delete_StaticNatRule_For_VM(self, vm, public_ip): - self.debug("Disabling static NAT for IP: %s" % - public_ip.ipaddress.ipaddress) - StaticNATRule.disable( - self.api_client, - ipaddressid=public_ip.ipaddress.id, - virtualmachineid=vm.id - ) - self.debug("Static NAT disabled for IP: %s" % - public_ip.ipaddress.ipaddress) - - # create_firewall_rule - Creates the Ingress firewall rule on the given public ip - def create_firewall_rule(self, public_ip, rule=None): - if not rule: - rule = self.test_data["ingress_rule"] - self.debug("Adding an Ingress Firewall rule to make Guest VMs accessible through Static NAT") - return FireWallRule.create(self.api_client, - ipaddressid=public_ip.ipaddress.id, - protocol=rule["protocol"], - cidrlist=rule["cidrlist"], - startport=rule["startport"], - endport=rule["endport"] - ) - - # create_egress_firewall_rule - Creates the Egress firewall rule on the given public ip - def create_egress_firewall_rule(self, network, rule): - self.debug("Adding an Egress Firewall rule to allow/deny outgoing traffic from Guest VMs") - return EgressFireWallRule.create(self.api_client, - networkid=network.id, - protocol=rule["protocol"], - cidrlist=rule["cidrlist"], - startport=rule["startport"], - endport=rule["endport"] - ) - - # create_network_acl_list - Creates network ACL list in the given VPC - def create_network_acl_list(self, name, description, vpc): - self.debug("Adding NetworkACL list in VPC: %s" % vpc.id) - return NetworkACLList.create(self.api_client, - services={}, - name=name, - description=description, - vpcid=vpc.id - ) - - # create_network_acl_rule - Creates network ACL rule Ingree/Egress in the given network - def create_network_acl_rule(self, rule, traffic_type="Ingress", network=None, acl_list=None): - self.debug("Adding NetworkACL rule: %s" % rule) - return NetworkACL.create(self.api_client, - networkid=network.id if network else None, - services=rule, - traffictype=traffic_type, - aclid=acl_list.id if acl_list else None - ) - - # migrate_vm - Migrates the VM to a different host if available - def migrate_vm(self, vm): - self.debug("Checking if a host is available for migration?") - hosts = Host.listForMigration(self.api_client) - self.assertEqual(isinstance(hosts, list), True, - "List hosts should return a valid list" - ) - # Remove the host of current VM from the hosts list - hosts[:] = [host for host in hosts if host.id != vm.hostid] - if len(hosts) <= 0: - self.skipTest("No host available for migration. Test requires at-least 2 hosts") - host = hosts[0] - self.debug("Migrating VM-ID: %s to Host: %s" % (vm.id, host.id)) - try: - vm.migrate(self.api_client, hostid=host.id) - except Exception as e: - self.fail("Failed to migrate instance, %s" % e) - - # get_network_router - returns the router for the given network - def get_network_router(self, network): - self.debug("Finding the virtual router for network: %s" % network.name) + # get_Router - Returns router for the given network + def get_Router(self, network): + self.debug("Finding the virtual router for network with ID - %s" % network.id) routers = Router.list(self.api_client, networkid=network.id, listall=True @@ -441,50 +296,120 @@ class nuageTestCase(cloudstackTestCase): ) return routers[0] - # stop_network_router - Stops the given network router - def stop_network_router(self, router): - self.debug("Stopping Router with ID: %s" % router.id) - cmd = stopRouter.stopRouterCmd() - cmd.id = router.id - self.api_client.stopRouter(cmd) + # acquire_PublicIPAddress - Acquires public IP address for the given network/VPC + def acquire_PublicIPAddress(self, network, vpc=None): + self.debug("Associating public IP for network with ID - %s" % network.id) + public_ip = PublicIPAddress.create(self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id if vpc is None else None, + vpcid=vpc.id if vpc else self.vpc.id if hasattr(self, "vpc") else None + ) + self.debug("Associated public IP address - %s with network with ID - %s" % + (public_ip.ipaddress.ipaddress, network.id)) + return public_ip - # start_network_router - Starts the given network router - def start_network_router(self, router): - self.debug("Starting Router with ID: %s" % router.id) - cmd = startRouter.startRouterCmd() - cmd.id = router.id - self.api_client.startRouter(cmd) + # create_StaticNatRule_For_VM - Creates static NAT rule on the given public IP for the given network and VM + def create_StaticNatRule_For_VM(self, vm, public_ip, network, vmguestip=None): + self.debug("Enabling static NAT for public IP - %s" % public_ip.ipaddress.ipaddress) + StaticNATRule.enable(self.api_client, + ipaddressid=public_ip.ipaddress.id, + virtualmachineid=vm.id, + networkid=network.id, + vmguestip=vmguestip + ) + self.debug("Static NAT enabled for public IP - %s" % public_ip.ipaddress.ipaddress) - # ssh_into_vm - Gets into the shell of the given VM - def ssh_into_vm(self, vm, public_ip): - self.debug("SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) + # delete_StaticNatRule_For_VM - Deletes static NAT rule on the given public IP for the given VM + def delete_StaticNatRule_For_VM(self, vm, public_ip): + self.debug("Disabling static NAT for public IP - %s" % public_ip.ipaddress.ipaddress) + StaticNATRule.disable(self.api_client, + ipaddressid=public_ip.ipaddress.id, + virtualmachineid=vm.id + ) + self.debug("Static NAT disabled for public IP - %s" % public_ip.ipaddress.ipaddress) + + # create_FirewallRule - Creates Ingress firewall rule on the given public IP + def create_FirewallRule(self, public_ip, rule=None): + if not rule: + rule = self.test_data["ingress_rule"] + self.debug("Adding an Ingress Firewall rule to make Guest VMs accessible through Static NAT - %s" % rule) + return FireWallRule.create(self.api_client, + ipaddressid=public_ip.ipaddress.id, + protocol=rule["protocol"], + cidrlist=rule["cidrlist"], + startport=rule["startport"], + endport=rule["endport"] + ) + + # create_EgressFirewallRule - Creates Egress firewall rule on the given public IP + def create_EgressFirewallRule(self, network, rule): + self.debug("Adding an Egress Firewall rule to allow/deny outgoing traffic from Guest VMs - %s" % rule) + return EgressFireWallRule.create(self.api_client, + networkid=network.id, + protocol=rule["protocol"], + cidrlist=rule["cidrlist"], + startport=rule["startport"], + endport=rule["endport"] + ) + + # create_NetworkAclList - Creates network ACL list in the given VPC + def create_NetworkAclList(self, name, description, vpc): + self.debug("Adding NetworkACL list in VPC with ID - %s" % vpc.id) + return NetworkACLList.create(self.api_client, + services={}, + name=name, + description=description, + vpcid=vpc.id + ) + + # create_NetworkAclRule - Creates Ingress/Egress network ACL rule in the given network/acl list + def create_NetworkAclRule(self, rule, traffic_type="Ingress", network=None, acl_list=None): + self.debug("Adding NetworkACL rule - %s" % rule) + if acl_list: + return NetworkACL.create(self.api_client, + networkid=network.id if network else None, + services=rule, + traffictype=traffic_type, + aclid=acl_list.id + ) + else: + return NetworkACL.create(self.api_client, + networkid=network.id if network else None, + services=rule, + traffictype=traffic_type + ) + + # ssh_into_VM - Gets into the shell of the given VM + def ssh_into_VM(self, vm, public_ip): + self.debug("SSH into VM with ID - %s on public IP address - %s" % (vm.id, public_ip.ipaddress.ipaddress)) ssh_client = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress) return ssh_client # execute_cmd - Executes the given command on the given ssh client def execute_cmd(self, ssh_client, cmd): - self.debug("EXECUTE SSH COMMAND: " + cmd) + self.debug("SSH client executing command - %s" % cmd) ret_data = "" out_list = ssh_client.execute(cmd) if out_list is not None: ret_data = ' '.join(map(str, out_list)).strip() - self.debug("ssh execute cmd result=" + ret_data) + self.debug("SSH client executed command result - %s" % ret_data) else: - self.debug("ssh execute cmd result is None") + self.debug("SSH client executed command result is None") return ret_data - # wget_from_server - fetches the index.html file from the given public Ip + # wget_from_server - Fetches index.html file of web server running with the given public IP def wget_from_server(self, public_ip): import urllib - self.debug("wget from a http server on public_ip=%s" % public_ip.ipaddress.ipaddress) - wget_file = urllib.urlretrieve("http://%s/index.html" % public_ip.ipaddress.ipaddress, - filename="index.html" - ) - return wget_file + self.debug("wget from a http server on public IP address - %s" % public_ip.ipaddress.ipaddress) + filename, headers = urllib.urlretrieve("http://%s/index.html" % public_ip.ipaddress.ipaddress, + filename="index.html" + ) + return filename, headers - # validate_NetworkServiceProvider - Validates the Network Service Provider - # in the Nuage VSP Physical Network - matches the given provider name - # against the list of providers fetched + # validate_NetworkServiceProvider - Validates the given Network Service Provider in the Nuage VSP Physical Network, + # matches the given provider name and state against the list of providers fetched def validate_NetworkServiceProvider(self, provider_name, state=None): """Validates the Network Service Provider in the Nuage VSP Physical Network""" self.debug("Check if the Network Service Provider is created successfully ?") @@ -499,12 +424,13 @@ class nuageTestCase(cloudstackTestCase): ) if state: self.assertEqual(providers[0].state, state, - "Network Service Provider state should be '%s'" % state + "Network Service Provider state should be in state - %s" % state ) - self.debug("Network Service Provider creation successfully validated - %s" % provider_name) + self.debug("Network Service Provider creation successfully validated for %s" % provider_name) - # validate_vpc_offering - Validates the VPC offering, matches the given VPC off name against the list of VPC offerings fetched - def validate_vpc_offering(self, vpc_offering, state=None): + # validate_VpcOffering - Validates the given VPC offering, + # matches the given VPC offering name and state against the list of VPC offerings fetched + def validate_VpcOffering(self, vpc_offering, state=None): """Validates the VPC offering""" self.debug("Check if the VPC offering is created successfully ?") vpc_offs = VpcOffering.list(self.api_client, @@ -518,12 +444,13 @@ class nuageTestCase(cloudstackTestCase): ) if state: self.assertEqual(vpc_offs[0].state, state, - "VPC offering state should be '%s'" % state + "VPC offering state should be in state - %s" % state ) - self.debug("VPC offering creation successfully validated - %s" % vpc_offering.name) + self.debug("VPC offering creation successfully validated for %s" % vpc_offering.name) - # validate_vpc - Validates the given VPC matches, the given VPC name against the list of VPCs fetched - def validate_vpc(self, vpc, state=None): + # validate_Vpc - Validates the given VPC, + # matches the given VPC name and state against the list of VPCs fetched + def validate_Vpc(self, vpc, state=None): """Validates the VPC""" self.debug("Check if the VPC is created successfully ?") vpcs = VPC.list(self.api_client, @@ -537,14 +464,13 @@ class nuageTestCase(cloudstackTestCase): ) if state: self.assertEqual(vpcs[0].state, state, - "VPC state should be '%s'" % state + "VPC state should be in state - %s" % state ) - self.debug("VPC creation successfully validated - %s" % vpc.name) + self.debug("VPC creation successfully validated for %s" % vpc.name) - # validate_network_offering - Validates the given Network offering - # matches the given network offering name against the list of network - # offerings fetched - def validate_network_offering(self, net_offering, state=None): + # validate_NetworkOffering - Validates the given Network offering, + # matches the given network offering name and state against the list of network offerings fetched + def validate_NetworkOffering(self, net_offering, state=None): """Validates the Network offering""" self.debug("Check if the Network offering is created successfully ?") net_offs = NetworkOffering.list(self.api_client, @@ -558,13 +484,14 @@ class nuageTestCase(cloudstackTestCase): ) if state: self.assertEqual(net_offs[0].state, state, - "Network offering state should be '%s'" % state + "Network offering state should be in state - %s" % state ) - self.debug("Network offering creation successfully validated - %s" % net_offering.name) + self.debug("Network offering creation successfully validated for %s" % net_offering.name) - # validate_network - Validates the network - matches the given network name against the list of networks fetched - def validate_network(self, network, state=None): - """Validates the network""" + # validate_Network - Validates the given network, + # matches the given network name and state against the list of networks fetched + def validate_Network(self, network, state=None): + """Validates the Network""" self.debug("Check if the network is created successfully ?") networks = Network.list(self.api_client, id=network.id @@ -577,28 +504,13 @@ class nuageTestCase(cloudstackTestCase): ) if state: self.assertEqual(networks[0].state, state, - "Network state should be '%s'" % state + "Network state should be in state - %s" % state ) - self.debug("Network creation successfully validated - %s" % network.name) + self.debug("Network creation successfully validated for %s" % network.name) - # check_router_state - Fetches the list of routers and their states and matches the given router's state - def check_router_state(self, router, state=None): - self.debug("Check if the virtual router is in state - %s" % state) - routers = Router.list(self.api_client, - id=router.id, - listall=True - ) - self.assertEqual(isinstance(routers, list), True, - "List router should return a valid list" - ) - if state: - self.assertEqual(routers[0].state, state, - "Virtual router is not in the expected state" - ) - self.debug("Virtual router is in the expected state - %s" % state) - - # check_vm_state - Fetches the list of VMs and their states and matches the given VM's state - def check_vm_state(self, vm, state=None): + # check_VM_state - Checks if the given VM is in the expected state form the list of fetched VMs + def check_VM_state(self, vm, state=None): + """Validates the VM state""" self.debug("Check if the VM instance is in state - %s" % state) vms = VirtualMachine.list(self.api_client, id=vm.id, @@ -611,12 +523,30 @@ class nuageTestCase(cloudstackTestCase): self.assertEqual(vms[0].state, state, "Virtual machine is not in the expected state" ) - self.debug("Virtual machine is in the expected state - %s" % state) + self.debug("Virtual machine instance - %s is in the expected state - %s" % (vm.name, state)) - # validate_Public_IP - Looks if the given public ip is in the allocated state form the list of fetched public IPs - def validate_Public_IP(self, public_ip, network, static_nat=False, vm=None): - """Validates the Public IP""" - self.debug("Check if the Public IP is successfully assigned to the network ?") + # check_Router_state - Checks if the given router is in the expected state form the list of fetched routers + def check_Router_state(self, router, state=None): + """Validates the Router state""" + self.debug("Check if the virtual router instance is in state - %s" % state) + routers = Router.list(self.api_client, + id=router.id, + listall=True + ) + self.assertEqual(isinstance(routers, list), True, + "List router should return a valid list" + ) + if state: + self.assertEqual(routers[0].state, state, + "Virtual router is not in the expected state" + ) + self.debug("Virtual router instance - %s is in the expected state - %s" % (router.name, state)) + + # validate_PublicIPAddress - Validates if the given public IP address is in the expected state form the list of + # fetched public IP addresses + def validate_PublicIPAddress(self, public_ip, network, static_nat=False, vm=None): + """Validates the Public IP Address""" + self.debug("Check if the public IP is successfully assigned to the network ?") public_ips = PublicIPAddress.list(self.api_client, id=public_ip.ipaddress.id, networkid=network.id, @@ -624,24 +554,30 @@ class nuageTestCase(cloudstackTestCase): listall=True ) self.assertEqual(isinstance(public_ips, list), True, - "List public Ip for network should return a valid list" + "List public IP for network should return a valid list" ) self.assertEqual(public_ips[0].ipaddress, public_ip.ipaddress.ipaddress, - "List public Ip for network should list the assigned public Ip address" + "List public IP for network should list the assigned public IP address" ) self.assertEqual(public_ips[0].state, "Allocated", - "Assigned public Ip is not in the allocated state" + "Assigned public IP is not in the allocated state" ) if static_nat and vm: self.assertEqual(public_ips[0].virtualmachineid, vm.id, - "Static NAT Rule not enabled for the VM using the assigned public Ip" + "Static NAT Rule not enabled for the VM using the assigned public IP" ) - self.debug("Assigned Public IP is successfully validated - %s" % public_ip.ipaddress.ipaddress) + self.debug("Assigned Public IP address - %s is successfully validated" % public_ip.ipaddress.ipaddress) # VSD verifications + # VSD is a programmable policy and analytics engine of Nuage VSP SDN platform - def fetch_by_external_id(self, fetcher, *cs_objects): - """ Fetches a child object by external id using the given fetcher, and uuids of the given cloudstack objects. + # get_externalID - Returns corresponding external ID of the given object in VSD + def get_externalID(self, object_id): + return object_id + "@" + self.cms_id + + # fetch_by_externalID - Returns VSD object with the given external ID + def fetch_by_externalID(self, fetcher, *cs_objects): + """ Fetches a child object by external ID using the given fetcher, and uuids of the given cloudstack objects. E.G. - fetch_by_external_id(vsdk.NUSubnet(id="954de425-b860-410b-be09-c560e7dbb474").vms, cs_vm) - fetch_by_external_id(session.user.floating_ips, cs_network, cs_public_ip) @@ -651,12 +587,8 @@ class nuageTestCase(cloudstackTestCase): """ return fetcher.get_first(filter="externalID BEGINSWITH '%s'" % ":".join([o.id for o in cs_objects])) - # VSD verifications using cms_vspk_wrapper - - def get_externalID(self, object_id): - return object_id + "@" + self.cms_id - - # verify_vsp_network - Fetches the vsd domain, vsd zone and vsd subnet and Verifies the given network/VPC values match the fetched values + # verify_vsp_network - Verifies the given domain and network/VPC + # against the corresponding installed enterprise, domain, zone, and subnet in VSD def verify_vsp_network(self, domain_id, network, vpc=None): vsd_enterprise = self.vsd.get_enterprise(name=domain_id) if vpc: @@ -677,24 +609,24 @@ class nuageTestCase(cloudstackTestCase): self.debug(vsd_zone) self.debug(vsd_subnet) if vpc: - self.assertEqual(vsd_domain['description'], "VPC_" + vpc.name, + self.assertEqual(vsd_domain["description"], "VPC_" + vpc.name, "VSD domain description should match VPC name in CloudStack" ) - self.assertEqual(vsd_zone['description'], "VPC_" + vpc.name, + self.assertEqual(vsd_zone["description"], "VPC_" + vpc.name, "VSD zone description should match VPC name in CloudStack" ) else: - self.assertEqual(vsd_domain['description'], network.name, - "VSD domain description should match Isolated Network name in CloudStack" + self.assertEqual(vsd_domain["description"], network.name, + "VSD domain description should match network name in CloudStack" ) - self.assertEqual(vsd_zone['description'], network.name, - "VSD zone description should match Isolated Network name in CloudStack" + self.assertEqual(vsd_zone["description"], network.name, + "VSD zone description should match network name in CloudStack" ) - self.assertEqual(vsd_subnet['description'], network.name, - "VSD subnet description should match Isolated Network name in CloudStack" + self.assertEqual(vsd_subnet["description"], network.name, + "VSD subnet description should match network name in CloudStack" ) - # verify_vsp_vm - Fetches the vsd vport, vsd vm and interface and Verifies the given VM values match the fetched values + # verify_vsp_vm - Verifies the given VM deployment and state in VSD def verify_vsp_vm(self, vm, stopped=None): ext_vm_id = self.get_externalID(vm.id) for nic in vm.nic: @@ -705,10 +637,10 @@ class nuageTestCase(cloudstackTestCase): self.debug("SHOW VPORT and VM INTERFACE DATA FORMAT IN VSD") self.debug(vsd_vport) self.debug(vsd_vm_interface) - self.assertEqual(vsd_vport['active'], True, + self.assertEqual(vsd_vport["active"], True, "VSD VM vport should be active" ) - self.assertEqual(vsd_vm_interface['IPAddress'], nic.ipaddress, + self.assertEqual(vsd_vm_interface["IPAddress"], nic.ipaddress, "VSD VM interface IP address should match VM's NIC IP address in CloudStack" ) vsd_vm = self.vsd.get_vm(externalID=ext_vm_id) @@ -716,15 +648,15 @@ class nuageTestCase(cloudstackTestCase): self.debug(vsd_vm) if not self.isSimulator: if stopped: - self.assertEqual(vsd_vm['status'], "DELETE_PENDING", + self.assertEqual(vsd_vm["status"], "DELETE_PENDING", "VM state in VSD should be DELETE_PENDING" ) else: - self.assertEqual(vsd_vm['status'], vm.state.upper(), + self.assertEqual(vsd_vm["status"], vm.state.upper(), "VM state in VSD should match its state in CloudStack" ) - # verify_vsp_router - Fetches the vsd router and Verifies the given router status match the fetched status + # verify_vsp_router - Verifies the given network router deployment and state in VSD def verify_vsp_router(self, router, stopped=None): ext_router_id = self.get_externalID(router.id) vsd_router = self.vsd.get_vm(externalID=ext_router_id) @@ -732,22 +664,42 @@ class nuageTestCase(cloudstackTestCase): self.debug(vsd_router) if not self.isSimulator: if stopped: - self.assertEqual(vsd_router['status'], "DELETE_PENDING", + self.assertEqual(vsd_router["status"], "DELETE_PENDING", "Router state in VSD should be DELETE_PENDING" ) else: - self.assertEqual(vsd_router['status'], router.state.upper(), + self.assertEqual(vsd_router["status"], router.state.upper(), "Router state in VSD should match its state in CloudStack" ) - # verify_vsp_floating_ip - Verifies the floating IPs on the given public IP against the VSD FIP + # verify_vsp_LB_device - Verifies the given LB device deployment and state in VSD + def verify_vsp_LB_device(self, lb_device, stopped=None): + ext_lb_device_id = self.get_externalID(lb_device.id) + vsd_lb_device = self.vsd.get_vm(externalID=ext_lb_device_id) + self.debug("SHOW LB Device DATA FORMAT IN VSD") + self.debug(vsd_lb_device) + if not self.isSimulator: + if stopped: + self.assertEqual(vsd_lb_device['status'], "DELETE_PENDING", + "LB device state in VSD should be DELETE_PENDING" + ) + else: + self.assertEqual(vsd_lb_device['status'], lb_device.state.upper(), + "LB device state in VSD should match its state in CloudStack" + ) + + # verify_vsp_floating_ip - Verifies the static nat rule on the given public IP of the given network and VM + # against the corresponding installed FIP in VSD def verify_vsp_floating_ip(self, network, vm, public_ipaddress, vpc=None): - ext_fip_id = self.get_externalID(network.id + ":" + public_ipaddress.id) + if vpc: + ext_fip_id = self.get_externalID(vpc.id + ":" + public_ipaddress.id) + else: + ext_fip_id = self.get_externalID(network.id + ":" + public_ipaddress.id) vsd_fip = self.vsd.get_floating_ip(externalID=ext_fip_id) self.debug("SHOW FLOATING IP DATA FORMAT IN VSD") self.debug(vsd_fip) - self.assertEqual(vsd_fip['address'], public_ipaddress.ipaddress, - "Floating IP address in VSD should match acquired Public IP address in CloudStack" + self.assertEqual(vsd_fip["address"], public_ipaddress.ipaddress, + "Floating IP address in VSD should match acquired public IP address in CloudStack" ) if vpc: ext_network_id = self.get_externalID(vpc.id) @@ -756,28 +708,27 @@ class nuageTestCase(cloudstackTestCase): vsd_domain = self.vsd.get_domain(externalID=ext_network_id) self.debug("SHOW NETWORK DATA FORMAT IN VSD") self.debug(vsd_domain) - self.assertEqual(vsd_domain['ID'], vsd_fip['parentID'], + self.assertEqual(vsd_domain["ID"], vsd_fip["parentID"], "Floating IP in VSD should be associated with the correct VSD domain, " - "which in turn should correspond to the correct VPC (or) Isolated network in CloudStack" + "which in turn should correspond to the correct VPC (or) network in CloudStack" ) ext_subnet_id = self.get_externalID(network.id) vsd_subnet = self.vsd.get_subnet(externalID=ext_subnet_id) for nic in vm.nic: - if nic.networkname == vsd_subnet['description']: + if nic.networkname == vsd_subnet["description"]: ext_network_id = self.get_externalID(nic.networkid) ext_nic_id = self.get_externalID(nic.id) vsd_vport = self.vsd.get_vport(subnet_externalID=ext_network_id, vport_externalID=ext_nic_id) self.debug("SHOW VM VPORT DATA FORMAT IN VSD") self.debug(vsd_vport) - self.assertEqual(vsd_vport['associatedFloatingIPID'], vsd_fip['ID'], + self.assertEqual(vsd_vport["associatedFloatingIPID"], vsd_fip["ID"], "Floating IP in VSD should be associated to the correct VSD vport, " "which in turn should correspond to the correct Static NAT enabled VM " - "and Isolated Network in CloudStack" + "and network in CloudStack" ) - # verify_vsp_firewall_rule - Verifies the start port, destination port, - # protocol of the given firewall rule Ingress/Egress against the VSD - # firewall rule + # verify_vsp_firewall_rule - Verifies the given Ingress/Egress firewall rule + # against the corresponding installed firewall rule in VSD def verify_vsp_firewall_rule(self, firewall_rule, traffic_type="Ingress"): ext_fw_id = self.get_externalID(firewall_rule.id) if traffic_type is "Ingress": @@ -787,11 +738,11 @@ class nuageTestCase(cloudstackTestCase): self.debug("SHOW ACL ENTRY IN VSD") self.debug(vsd_fw_rule) dest_port = str(firewall_rule.startport) + "-" + str(firewall_rule.endport) - self.assertEqual(vsd_fw_rule['destinationPort'], dest_port, - "Destination Port in VSD should match Destination Port in CloudStack" + self.assertEqual(vsd_fw_rule["destinationPort"], dest_port, + "Destination port in VSD should match destination port in CloudStack" ) - vsd_protocol = str(vsd_fw_rule['protocol']) - self.debug("vsd protocol " + vsd_protocol) + vsd_protocol = str(vsd_fw_rule["protocol"]) + self.debug("vsd protocol - %s" % vsd_protocol) protocol = "tcp" if vsd_protocol == 6: protocol = "tcp" @@ -800,5 +751,5 @@ class nuageTestCase(cloudstackTestCase): elif vsd_protocol == 17: protocol = "udp" self.assertEqual(protocol, firewall_rule.protocol.lower(), - "Protocol in VSD should match Protocol in CloudStack" + "Protocol in VSD should match protocol in CloudStack" ) diff --git a/test/integration/plugins/nuagevsp/test_nuage_password_reset.py b/test/integration/plugins/nuagevsp/test_nuage_password_reset.py index 5582819d903..ee028c2c547 100644 --- a/test/integration/plugins/nuagevsp/test_nuage_password_reset.py +++ b/test/integration/plugins/nuagevsp/test_nuage_password_reset.py @@ -15,26 +15,29 @@ # specific language governing permissions and limitations # under the License. -""" Component tests for - userdata +""" Component tests for user data and password reset functionality with Nuage VSP SDN plugin """ # Import Local Modules -from marvin.lib.base import (Account, - VirtualMachine, - Volume, - Template) -from nose.plugins.attrib import attr from nuageTestCase import nuageTestCase +from marvin.lib.base import (Account, + Template, + VirtualMachine, + Volume) +from marvin.lib.common import list_templates from marvin.lib.utils import cleanup_resources -from marvin.cloudstackAPI import startVirtualMachine +from marvin.cloudstackAPI import updateTemplate +# Import System Modules +from nose.plugins.attrib import attr import base64 class TestNuagePasswordReset(nuageTestCase): + """Test user data and password reset functionality with Nuage VSP SDN plugin + """ @classmethod def setUpClass(cls): super(TestNuagePasswordReset, cls).setUpClass() - return def setUp(self): @@ -60,16 +63,15 @@ class TestNuagePasswordReset(nuageTestCase): self.vm_1.delete(self.apiclient, expunge=True) if self.remove_vm2: self.vm_2.delete(self.apiclient, expunge=True) - try: cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - self.debug("Warning: Exception during cleanup : %s" % e) + self.debug("Warning: Exception during cleanup: %s" % e) return - # create_template - Takes the VM object as the argument to create the template + # create_template - Creates template with the given VM object def create_template(self, vm): - self.debug("CREATE TEMPLATE") + self.debug("Creating template") list_volume = Volume.list(self.apiclient, virtualmachineid=vm.id, type='ROOT', @@ -77,18 +79,31 @@ class TestNuagePasswordReset(nuageTestCase): if isinstance(list_volume, list): self.volume = list_volume[0] else: - raise Exception("Exception: Unable to find root volume for VM: %s" % vm.id) - - self.test_data["template_pr"]["ostype"] = self.test_data["ostype_pr"] + raise Exception("Exception: Unable to find root volume for VM with ID - %s" % vm.id) self.pw_enabled_template = Template.create( self.apiclient, - self.test_data["template_pr"], + self.test_data["template"], self.volume.id, account=self.account.name, domainid=self.account.domainid ) self.assertEqual(self.pw_enabled_template.passwordenabled, True, "template is not passwordenabled") self.cleanup.append(self.pw_enabled_template) + self.debug("Created template") + + # updateTemplate - Updates value of template's password enabled setting + def updateTemplate(self, value): + self.debug("Updating value of template's password enabled setting") + cmd = updateTemplate.updateTemplateCmd() + cmd.id = self.template.id + cmd.passwordenabled = value + self.apiclient.updateTemplate(cmd) + list_template_response = list_templates(self.apiclient, + templatefilter="all", + id=self.template.id + ) + self.template = list_template_response[0] + self.debug("Updated template") # VM object is passed as an argument and its interface id is returned def get_vm_interface_id(self, vm): @@ -109,13 +124,13 @@ class TestNuagePasswordReset(nuageTestCase): # Creates and verifies the firewall rule def create_and_verify_fw(self, vm, public_ip, network): - self.debug("CREATE AND VERIFY FIREWALL RULE") + self.debug("Create and verify firewall rule") self.create_StaticNatRule_For_VM(vm, public_ip, network) # VSD verification self.verify_vsp_floating_ip(network, vm, public_ip.ipaddress) - fw_rule = self.create_firewall_rule(public_ip, self.test_data["ingress_rule"]) + fw_rule = self.create_FirewallRule(public_ip, self.test_data["ingress_rule"]) self.verify_vsp_firewall_rule(fw_rule) vm_interface_id = self.get_vm_interface_id(vm) pd = self.vsd.get_vm_interface_policydecisions(id=vm_interface_id) @@ -130,7 +145,7 @@ class TestNuagePasswordReset(nuageTestCase): raise ValueError('No firewall policy decision in vm interface') def stop_vm(self, vm): - self.debug("STOP VM") + self.debug("Stoping VM") vm.stop(self.apiclient) list_vm_response = VirtualMachine.list(self.apiclient, id=vm.id) @@ -159,8 +174,10 @@ class TestNuagePasswordReset(nuageTestCase): self.debug("get_set_password_file result " + result) @attr(tags=["advanced", "nuagevsp"], required_hardware="true") - def test_01_UserDataPasswordReset(self): - self.debug("START USER DATA PASSWORD RESET ON VM") + def test_nuage_UserDataPasswordReset(self): + """Test user data and password reset functionality with Nuage VSP SDN plugin + """ + """ Validate the following: 1) user data @@ -171,12 +188,12 @@ class TestNuagePasswordReset(nuageTestCase): 2. Create an Isolated network - Test Network (10.1.1.1/24). 3. Deploy VM1 in Test Network 4. Verify domain,zone subnet, vm. - 5. create public ip , Create Static Nat rule firewall rule and verify + 5. create public IP, Create Static Nat rule firewall rule and verify 6. SSH to VM should be successful 7. verify userdata 8. check cloud-set-guest-password exist. 9. if cloud-set-guest-password exist. - 9.1 change template password enabled to true + 9.1 change template password enabled to true 9.2 verify that template is password enbalded 9.3 SSH with new password should be successful 10. else cloud-set-guest-password does not exist. @@ -185,27 +202,30 @@ class TestNuagePasswordReset(nuageTestCase): 10.3 create a new template with password enabled. Verify that template is password enabled. 10.4 create vm 2 with new template in Test Network 10.5 Verify vm. - 10.6 create public ip , Create Static Nat rule firewall rule and verify + 10.6 create public IP, Create Static Nat rule firewall rule and verify 10.7 SSH to VM 2 should be successful 11. Reset VM password (VM_1 if guest password file exist. else it is VM2) 12 Starting VM and SSH to VM to verify new password """ + self.debug("TEST USER DATA & PASSWORD RESET ON VM") + self.defaultTemplateVal = self.template.passwordenabled if self.template.passwordenabled: self.updateTemplate(False) self.debug("CREATE AN ISOLATED NETWORK") - self.network_1 = self.create_Network(self.test_data["network_offering_pr"]) + net_off = self.create_NetworkOffering(self.test_data["nuagevsp"]["isolated_network_offering"]) + self.network_1 = self.create_Network(net_off) self.cleanup.append(self.network_1) expUserData = "hello world vm1" userdata = base64.b64encode(expUserData) - self.test_data["virtual_machine_pr"]["userdata"] = userdata + self.test_data["virtual_machine_userdata"]["userdata"] = userdata self.debug("DEPLOY VM 1 IN TEST NETWORK") # Pass the network and name of the vm type from the testdata with the configuration for the vm - self.vm_1 = self.create_VM_in_Network(self.network_1, "virtual_machine_pr") + self.vm_1 = self.create_VM(self.network_1, vm_key="virtual_machine_userdata") - self.vm_1.password = self.test_data["virtual_machine_pr"]["password"] + self.vm_1.password = self.test_data["virtual_machine_userdata"]["password"] user_data_cmd = self.get_userdata_url(self.vm_1) # VSD verification @@ -214,11 +234,11 @@ class TestNuagePasswordReset(nuageTestCase): self.verify_vsp_vm(self.vm_1) self.debug("CREATE PUBLIC IP, STATIC NAT RULE, FLOATING IP, FIREWALL AND VERIFY") - public_ip_1 = self.acquire_Public_IP(self.network_1) + public_ip_1 = self.acquire_PublicIPAddress(self.network_1) self.create_and_verify_fw(self.vm_1, public_ip_1, self.network_1) self.debug("SSH TO VM") - ssh = self.ssh_into_vm(self.vm_1, public_ip_1) + ssh = self.ssh_into_VM(self.vm_1, public_ip_1) self.debug("VERIFY USER DATA") self.debug("Get User Data with command: " + user_data_cmd) @@ -238,25 +258,23 @@ class TestNuagePasswordReset(nuageTestCase): self.stop_vm(self.vm_1) self.create_template(self.vm_1) self.debug("DEPLOY VM 2 IN TEST NETWORK WITH NEW TEMPLATE") - self.vm_2 = self.create_VM_in_Network(self.network_1, "virtual_machine_pr") + self.vm_2 = self.create_VM(self.network_1, vm_key="virtual_machine_userdata") self.remove_vm2 = True self.debug("STARTING VM_2 ") - startCmd = startVirtualMachine.startVirtualMachineCmd() - startCmd.id = self.vm_2.id - vm_2a = self.apiclient.startVirtualMachine(startCmd) + vm_2a = self.vm_2.start(self.apiclient) self.vm_2.password = vm_2a.password.strip() self.vm_2.nic = vm_2a.nic - self.debug("VM - %s password %s !" % (self.vm_2.name, self.vm_2.password)) + self.debug("VM - %s password - %s !" % (self.vm_2.name, self.vm_2.password)) self.assertNotEqual(self.vm_2.password, - self.test_data["virtual_machine_pr"]["password"], + self.test_data["virtual_machine_userdata"]["password"], "Password enabled not working. Password same as virtual_machine password " ) self.verify_vsp_vm(vm_2a) self.debug("GET PUBLIC IP. CREATE AND VERIFIED FIREWALL RULES") - public_ip_2 = self.acquire_Public_IP(self.network_1) + public_ip_2 = self.acquire_PublicIPAddress(self.network_1) self.create_and_verify_fw(self.vm_2, public_ip_2, self.network_1) - ssh = self.ssh_into_vm(self.vm_2, public_ip_2) + self.ssh_into_VM(self.vm_2, public_ip_2) vm_test = self.vm_2 vm_test_public_ip = public_ip_2 @@ -267,10 +285,10 @@ class TestNuagePasswordReset(nuageTestCase): vm_test = self.vm_1 vm_test_public_ip = public_ip_1 - self.debug("RESETTING VM PASSWORD for VM: %s" % vm_test.name) + self.debug("RESETTING VM PASSWORD for VM - %s" % vm_test.name) vm_test.password = vm_test.resetPassword(self.apiclient) - self.debug("Password reset to: %s" % vm_test.password) + self.debug("Password reset to - %s" % vm_test.password) self.debug("STARTING VM AND SSH TO VM TO VERIFY NEW PASSWORD") vm_test.start(self.apiclient) self.debug("VM - %s started!" % vm_test.name) - self.ssh_into_vm(vm_test, vm_test_public_ip) + self.ssh_into_VM(vm_test, vm_test_public_ip) diff --git a/test/integration/plugins/nuagevsp/test_nuage_vpc_internal_lb.py b/test/integration/plugins/nuagevsp/test_nuage_vpc_internal_lb.py new file mode 100644 index 00000000000..5a0d759fdd2 --- /dev/null +++ b/test/integration/plugins/nuagevsp/test_nuage_vpc_internal_lb.py @@ -0,0 +1,2076 @@ +# 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. + +""" Component tests for VPC Internal Load Balancer functionality with Nuage VSP SDN plugin +""" +# Import Local Modules +from nuageTestCase import nuageTestCase +from marvin.lib.base import (Account, + ApplicationLoadBalancer, + Network, + Router) +from marvin.cloudstackAPI import (listInternalLoadBalancerVMs, + stopInternalLoadBalancerVM, + startInternalLoadBalancerVM) +# Import System Modules +from nose.plugins.attrib import attr +import copy +import time + + +class TestNuageInternalLb(nuageTestCase): + """Test VPC Internal LB functionality with Nuage VSP SDN plugin + """ + + @classmethod + def setUpClass(cls): + super(TestNuageInternalLb, cls).setUpClass() + return + + def setUp(self): + # Create an account + self.account = Account.create(self.api_client, + self.test_data["account"], + admin=True, + domainid=self.domain.id + ) + self.cleanup = [self.account] + return + + # create_Internal_LB_Rule - Creates Internal LB rule in the given VPC network + def create_Internal_LB_Rule(self, network, vm_array=None, services=None, source_ip=None): + self.debug("Creating Internal LB rule in VPC network with ID - %s" % network.id) + if not services: + services = self.test_data["internal_lbrule"] + int_lb_rule = ApplicationLoadBalancer.create(self.api_client, + services=services, + sourcenetworkid=network.id, + networkid=network.id, + sourceipaddress=source_ip + ) + self.debug("Created Internal LB rule") + # Assigning VMs to the created Internal Load Balancer rule + if vm_array: + self.debug("Assigning virtual machines - %s to the created Internal LB rule" % vm_array) + int_lb_rule.assign(self.api_client, vms=vm_array) + self.debug("Assigned VMs to the created Internal LB rule") + return int_lb_rule + + # validate_Internal_LB_Rule - Validates the given Internal LB rule, + # matches the given Internal LB rule name and state against the list of Internal LB rules fetched + def validate_Internal_LB_Rule(self, int_lb_rule, state=None, vm_array=None): + """Validates the Internal LB Rule""" + self.debug("Check if the Internal LB Rule is created successfully ?") + int_lb_rules = ApplicationLoadBalancer.list(self.api_client, + id=int_lb_rule.id + ) + self.assertEqual(isinstance(int_lb_rules, list), True, + "List Internal LB Rule should return a valid list" + ) + self.assertEqual(int_lb_rule.name, int_lb_rules[0].name, + "Name of the Internal LB Rule should match with the returned list data" + ) + if state: + self.assertEqual(int_lb_rules[0].loadbalancerrule[0].state, state, + "Internal LB Rule state should be '%s'" % state + ) + if vm_array: + instance_ids = [instance.id for instance in int_lb_rules[0].loadbalancerinstance] + for vm in vm_array: + self.assertEqual(vm.id in instance_ids, True, + "Internal LB instance list should have the VM with ID - %s" % vm.id + ) + self.debug("Internal LB Rule creation successfully validated for %s" % int_lb_rule.name) + + # list_InternalLbVms - Lists deployed Internal LB VM instances + def list_InternalLbVms(self, network_id=None, source_ip=None): + listInternalLoadBalancerVMsCmd = listInternalLoadBalancerVMs.listInternalLoadBalancerVMsCmd() + listInternalLoadBalancerVMsCmd.account = self.account.name + listInternalLoadBalancerVMsCmd.domainid = self.account.domainid + if network_id: + listInternalLoadBalancerVMsCmd.networkid = network_id + internal_lb_vms = self.api_client.listInternalLoadBalancerVMs(listInternalLoadBalancerVMsCmd) + if source_ip: + return [internal_lb_vm for internal_lb_vm in internal_lb_vms + if str(internal_lb_vm.guestipaddress) == source_ip] + else: + return internal_lb_vms + + # get_InternalLbVm - Returns Internal LB VM instance for the given VPC network and source ip + def get_InternalLbVm(self, network, source_ip): + self.debug("Finding the InternalLbVm for network with ID - %s and source IP address - %s" % + (network.id, source_ip)) + internal_lb_vms = self.list_InternalLbVms(network.id, source_ip) + self.assertEqual(isinstance(internal_lb_vms, list), True, + "List InternalLbVms should return a valid list" + ) + return internal_lb_vms[0] + + # stop_InternalLbVm - Stops the given Internal LB VM instance + def stop_InternalLbVm(self, int_lb_vm, force=None): + self.debug("Stopping InternalLbVm with ID - %s" % int_lb_vm.id) + cmd = stopInternalLoadBalancerVM.stopInternalLoadBalancerVMCmd() + cmd.id = int_lb_vm.id + if force: + cmd.forced = force + self.api_client.stopInternalLoadBalancerVM(cmd) + + # start_InternalLbVm - Starts the given Internal LB VM instance + def start_InternalLbVm(self, int_lb_vm): + self.debug("Starting InternalLbVm with ID - %s" % int_lb_vm.id) + cmd = startInternalLoadBalancerVM.startInternalLoadBalancerVMCmd() + cmd.id = int_lb_vm.id + self.api_client.startInternalLoadBalancerVM(cmd) + + # check_InternalLbVm_state - Checks if the Internal LB VM instance of the given VPC network and source ip is in the + # expected state form the list of fetched Internal LB VM instances + def check_InternalLbVm_state(self, network, source_ip, state=None): + self.debug("Check if the InternalLbVm is in state - %s" % state) + internal_lb_vms = self.list_InternalLbVms(network.id, source_ip) + self.assertEqual(isinstance(internal_lb_vms, list), True, + "List InternalLbVm should return a valid list" + ) + if state: + self.assertEqual(internal_lb_vms[0].state, state, + "InternalLbVm is not in the expected state" + ) + self.debug("InternalLbVm instance - %s is in the expected state - %s" % (internal_lb_vms[0].name, state)) + + # wget_from_vm_cmd - From within the given VM (ssh client), + # fetches index.html file of web server running with the given public IP + def wget_from_vm_cmd(self, ssh_client, ip_address, port): + cmd = "wget --no-cache -t 1 http://" + ip_address + ":" + str(port) + "/" + response = self.execute_cmd(ssh_client, cmd) + if "200 OK" not in response: + self.fail("Failed to wget from a VM with http server IP address - %s" % ip_address) + # Reading the wget file + cmd = "cat index.html" + wget_file = self.execute_cmd(ssh_client, cmd) + # Removing the wget file + cmd = "rm -r index.html" + self.execute_cmd(ssh_client, cmd) + return wget_file + + # verify_lb_wget_file - Verifies that the given wget file (index.html) belongs to the given Internal LB rule + # assigned VMs (vm array) + def verify_lb_wget_file(self, wget_file, vm_array): + wget_server_ip = None + for vm in vm_array: + for nic in vm.nic: + if str(nic.ipaddress) in str(wget_file): + wget_server_ip = str(nic.ipaddress) + if wget_server_ip: + self.debug("Verified wget file from an Internal Load Balanced VM with http server IP address - %s" + % wget_server_ip) + else: + self.fail("Did not wget file from the Internal Load Balanced VMs - %s" % vm_array) + return wget_server_ip + + # validate_internallb_algorithm_traffic - Validates Internal LB algorithms by performing multiple wget traffic tests + # against the given Internal LB VM instance (source port) + def validate_internallb_algorithm_traffic(self, ssh_client, source_ip, port, vm_array, algorithm): + # Internal LB (wget) traffic tests + iterations = 2 * len(vm_array) + wget_files = [] + for i in range(iterations): + wget_files.append(self.wget_from_vm_cmd(ssh_client, source_ip, port)) + # Verifying Internal LB (wget) traffic tests + wget_servers_ip_list = [] + for i in range(iterations): + wget_servers_ip_list.append(self.verify_lb_wget_file(wget_files[i], vm_array)) + # Validating Internal LB algorithm + if algorithm == "roundrobin" or algorithm == "leastconn": + for i in range(iterations): + if wget_servers_ip_list.count(wget_servers_ip_list[i]) is not 2: + self.fail("Round Robin Internal LB algorithm validation failed - %s" % wget_servers_ip_list) + self.debug("Successfully validated Round Robin/Least connections Internal LB algorithm - %s" % + wget_servers_ip_list) + if algorithm == "source": + for i in range(iterations): + if wget_servers_ip_list.count(wget_servers_ip_list[i]) is not iterations: + self.fail("Source Internal LB algorithm validation failed - %s" % wget_servers_ip_list) + self.debug("Successfully validated Source Internal LB algorithm - %s" % wget_servers_ip_list) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_01_nuage_internallb_vpc_Offering(self): + """Test Nuage VSP VPC Offering with different combinations of LB service providers + """ + + # 1. Verify that the network service providers supported by Nuage VSP for VPC Internal LB functionality are all + # successfully created and enabled. + # 2. Create Nuage VSP VPC offering with LB service provider as "InternalLbVm", check if it is successfully + # created and enabled. Verify that the VPC creation succeeds with this VPC offering. + # 3. Create Nuage VSP VPC offering with LB service provider as "VpcVirtualRouter", check if it is successfully + # created and enabled. Verify that the VPC creation fails with this VPC offering as Nuage VSP does not + # support provider "VpcVirtualRouter" for service LB. + # 4. Create Nuage VSP VPC offering with LB service provider as "Netscaler", check if it is successfully + # created and enabled. Verify that the VPC creation fails with this VPC offering as Nuage VSP does not + # support provider "Netscaler" for service LB. + # 5. Delete the created VPC offerings (cleanup). + + self.debug("Validating network service providers supported by Nuage VSP for VPC Internal LB functionality") + providers = ["NuageVsp", "VpcVirtualRouter", "InternalLbVm"] + for provider in providers: + self.validate_NetworkServiceProvider(provider, state="Enabled") + + # Creating VPC offerings + self.debug("Creating Nuage VSP VPC offering with LB service provider as InternalLbVm...") + vpc_off_1 = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC offering with LB service provider as VpcVirtualRouter...") + vpc_offering_lb = copy.deepcopy(self.test_data["nuagevsp"]["vpc_offering_lb"]) + vpc_offering_lb["serviceProviderList"]["Lb"] = "VpcVirtualRouter" + vpc_off_2 = self.create_VpcOffering(vpc_offering_lb) + self.validate_VpcOffering(vpc_off_2, state="Enabled") + + self.debug("Creating Nuage VSP VPC offering with LB service provider as Netscaler...") + vpc_offering_lb["serviceProviderList"]["Lb"] = "Netscaler" + vpc_off_3 = self.create_VpcOffering(vpc_offering_lb) + self.validate_VpcOffering(vpc_off_3, state="Enabled") + + self.debug("Creating Nuage VSP VPC offering without LB service...") + vpc_off_4 = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering"]) + self.validate_VpcOffering(vpc_off_4, state="Enabled") + + # Creating VPCs + self.debug("Creating a VPC with LB service provider as InternalLbVm...") + vpc_1 = self.create_Vpc(vpc_off_1, cidr='10.1.0.0/16') + self.validate_Vpc(vpc_1, state="Enabled") + + self.debug("Creating a VPC with LB service provider as VpcVirtualRouter...") + with self.assertRaises(Exception): + self.create_Vpc(vpc_off_2, cidr='10.1.0.0/16') + self.debug("Nuage VSP does not support provider VpcVirtualRouter for service LB for VPCs") + + self.debug("Creating a VPC with LB service provider as Netscaler...") + with self.assertRaises(Exception): + self.create_Vpc(vpc_off_3, cidr='10.1.0.0/16') + self.debug("Nuage VSP does not support provider Netscaler for service LB for VPCs") + + self.debug("Creating a VPC without LB service...") + vpc_2 = self.create_Vpc(vpc_off_4, cidr='10.1.0.0/16') + self.validate_Vpc(vpc_2, state="Enabled") + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_02_nuage_internallb_vpc_network_offering(self): + """Test Nuage VSP VPC Network Offering with and without Internal LB service + """ + + # 1. Create Nuage Vsp VPC Network offering with LB Service Provider as "InternalLbVm" and LB Service Capability + # "lbSchemes" as "internal", check if it is successfully created and enabled. Verify that the VPC network + # creation succeeds with this Network offering. + # 2. Recreate above Network offering with ispersistent False, check if it is successfully created and enabled. + # Verify that the VPC network creation fails with this Network offering as Nuage VSP does not support non + # persistent VPC networks. + # 3. Recreate above Network offering with conserve mode On, check if the network offering creation failed + # as only networks with conserve mode Off can belong to VPC. + # 4. Create Nuage Vsp VPC Network offering with LB Service Provider as "InternalLbVm" and LB Service Capability + # "lbSchemes" as "public", check if the network offering creation failed as "public" lbScheme is not + # supported for LB Service Provider "InternalLbVm". + # 5. Create Nuage Vsp VPC Network offering without Internal LB Service, check if it is successfully created and + # enabled. Verify that the VPC network creation succeeds with this Network offering. + # 6. Recreate above Network offering with ispersistent False, check if it is successfully created and enabled. + # Verify that the VPC network creation fails with this Network offering as Nuage VSP does not support non + # persistent VPC networks. + # 7. Recreate the above Network offering with conserve mode On, check if the network offering creation failed + # as only networks with conserve mode Off can belong to VPC. + # 8. Delete the created Network offerings (cleanup). + + # Creating VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with LB Service Provider as InternalLbVm and LB Service " + "Capability lbSchemes as internal...") + net_off_1 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Recreating above Network offering with ispersistent False...") + vpc_net_off_lb_non_persistent = copy.deepcopy(self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + vpc_net_off_lb_non_persistent["ispersistent"] = "False" + net_off_2 = self.create_NetworkOffering(vpc_net_off_lb_non_persistent) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + self.debug("Recreating above Network offering with conserve mode On...") + with self.assertRaises(Exception): + self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"], + conserve_mode=True) + self.debug("Network offering creation failed as only networks with conserve mode Off can belong to VPC") + + self.debug("Creating Nuage VSP VPC Network offering with LB Service Provider as InternalLbVm and LB Service " + "Capability lbSchemes as public...") + network_offering_internal_lb = copy.deepcopy(self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + network_offering_internal_lb["serviceCapabilityList"]["Lb"]["lbSchemes"] = "public" + with self.assertRaises(Exception): + self.create_NetworkOffering(network_offering_internal_lb) + self.debug("Network offering creation failed as public lbScheme is not supported for LB Service Provider " + "InternalLbVm") + + self.debug("Creating Nuage Vsp VPC Network offering without Internal LB service...") + net_off_3 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_3, state="Enabled") + + self.debug("Recreating above Network offering with ispersistent False...") + vpc_net_off_non_persistent = copy.deepcopy(self.test_data["nuagevsp"]["vpc_network_offering"]) + vpc_net_off_non_persistent["ispersistent"] = "False" + net_off_4 = self.create_NetworkOffering(vpc_net_off_non_persistent) + self.validate_NetworkOffering(net_off_4, state="Enabled") + + self.debug("Recreating above Network offering with conserve mode On...") + with self.assertRaises(Exception): + self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"], conserve_mode=True) + self.debug("Network offering creation failed as only networks with conserve mode Off can belong to VPC") + + # Creating VPC networks in the VPC + self.debug("Creating a persistent VPC network with Internal LB service...") + internal_tier = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(internal_tier) + self.check_Router_state(vr, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + + self.debug("Creating a non persistent VPC network with Internal LB service...") + with self.assertRaises(Exception): + self.create_Network(net_off_2, gateway='10.1.2.1', vpc=vpc) + self.debug("Nuage VSP does not support non persistent VPC networks") + + self.debug("Creating a persistent VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_3, gateway='10.1.3.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + + self.debug("Creating a non persistent VPC network without Internal LB service...") + with self.assertRaises(Exception): + self.create_Network(net_off_4, gateway='10.1.4.1', vpc=vpc) + self.debug("Nuage VSP does not support non persistent VPC networks") + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_03_nuage_internallb_vpc_networks(self): + """Test Nuage VSP VPC Networks with and without Internal LB service + """ + + # 1. Create Nuage VSP VPC offering with Internal LB service, check if it is successfully created and enabled. + # 2. Create Nuage VSP VPC offering without Internal LB service, check if it is successfully created and enabled. + # 3. Create a VPC "vpc_1" with Internal LB service, check if it is successfully created and enabled. + # 4. Create a VPC "vpc_2" without Internal LB service, check if it is successfully created and enabled. + # 5. Create Nuage VSP VPC Network offering with Internal LB service, check if it is successfully created and + # enabled. + # 6. Create Nuage VSP VPC Network offering without Internal LB service, check if it is successfully created and + # enabled. + # 7. Create a VPC network in vpc_1 with Internal LB service and spawn a VM, check if the tier is added to the + # VPC VR, and the VM is deployed successfully in the tier. + # 8. Create one more VPC network in vpc_1 with Internal LB service and spawn a VM, check if the tier is added + # to the VPC VR, and the VM is deployed successfully in the tier. + # 9. Create a VPC network in vpc_2 with Internal LB service, check if the tier creation failed. + # 10. Create a VPC network in vpc_1 without Internal LB service and spawn a VM, check if the tier is added to + # the VPC VR, and the VM is deployed successfully in the tier. + # 11. Create a VPC network in vpc_2 without Internal LB service and spawn a VM, check if the tier is added to + # the VPC VR, and the VM is deployed successfully in the tier. + # 12. Upgrade the VPC network with Internal LB service to one with no Internal LB service and vice-versa, check + # if the VPC Network offering upgrade passed in both directions. + # 13. Delete the VPC network with Internal LB service, check if the tier is successfully deleted. + # 14. Recreate the VPC network with Internal LB service, check if the tier is successfully re-created. + # 15. Delete all the created objects (cleanup). + + # Creating VPC offerings + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off_1 = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC offering without Internal LB service...") + vpc_off_2 = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering"]) + self.validate_VpcOffering(vpc_off_2, state="Enabled") + + # Creating VPCs + self.debug("Creating a VPC with Internal LB service...") + vpc_1 = self.create_Vpc(vpc_off_1, cidr='10.1.0.0/16') + self.validate_Vpc(vpc_1, state="Enabled") + + self.debug("Creating a VPC without Internal LB service...") + vpc_2 = self.create_Vpc(vpc_off_2, cidr='10.1.0.0/16') + self.validate_Vpc(vpc_2, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in VPCs, and deploying VMs + self.debug("Creating a VPC network in vpc_1 with Internal LB service...") + internal_tier_1 = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc_1) + self.validate_Network(internal_tier_1, state="Implemented") + vr_1 = self.get_Router(internal_tier_1) + self.check_Router_state(vr_1, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier_1.name) + internal_vm_1 = self.create_VM(internal_tier_1) + self.check_VM_state(internal_vm_1, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_1, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(internal_vm_1) + + self.debug("Creating one more VPC network in vpc_1 with Internal LB service...") + internal_tier_2 = self.create_Network(net_off_1, gateway='10.1.2.1', vpc=vpc_1) + self.validate_Network(internal_tier_2, state="Implemented") + vr_1 = self.get_Router(internal_tier_2) + self.check_Router_state(vr_1, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier_2.name) + internal_vm_2 = self.create_VM(internal_tier_2) + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(internal_vm_2) + + self.debug("Creating a VPC network in vpc_2 with Internal LB service...") + with self.assertRaises(Exception): + self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc_2) + self.debug("VPC Network creation failed as vpc_2 does not support Internal Lb service") + + self.debug("Creating a VPC network in vpc_1 without Internal LB service...") + public_tier_1 = self.create_Network(net_off_2, gateway='10.1.3.1', vpc=vpc_1) + self.validate_Network(public_tier_1, state="Implemented") + vr_1 = self.get_Router(public_tier_1) + self.check_Router_state(vr_1, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier_1.name) + public_vm_1 = self.create_VM(public_tier_1) + self.check_VM_state(public_vm_1, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier_1, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(public_vm_1) + + self.debug("Creating a VPC network in vpc_2 without Internal LB service...") + public_tier_2 = self.create_Network(net_off_2, gateway='10.1.1.1', vpc=vpc_2) + self.validate_Network(public_tier_2, state="Implemented") + vr_2 = self.get_Router(public_tier_2) + self.check_Router_state(vr_2, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier_2.name) + public_vm_2 = self.create_VM(public_tier_2) + self.check_VM_state(public_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier_2, vpc_2) + self.verify_vsp_router(vr_2) + self.verify_vsp_vm(public_vm_2) + + # Upgrading a VPC network + self.debug("Upgrading a VPC network with Internal LB Service to one without Internal LB Service...") + self.upgrade_Network(net_off_2, internal_tier_2) + self.validate_Network(internal_tier_2, state="Implemented") + vr_1 = self.get_Router(internal_tier_2) + self.check_Router_state(vr_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(internal_vm_2) + + self.debug("Upgrading a VPC network without Internal LB Service to one with Internal LB Service...") + self.upgrade_Network(net_off_1, internal_tier_2) + self.validate_Network(internal_tier_2, state="Implemented") + vr_1 = self.get_Router(internal_tier_2) + self.check_Router_state(vr_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(internal_vm_2) + + # Deleting and re-creating a VPC network + self.debug("Deleting a VPC network with Internal LB Service...") + self.delete_VM(internal_vm_2) + self.delete_Network(internal_tier_2) + with self.assertRaises(Exception): + self.validate_Network(internal_tier_2) + self.debug("VPC network successfully deleted in CloudStack") + + # VSD verification + with self.assertRaises(Exception): + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc_1) + self.debug("VPC network successfully deleted in VSD") + + self.debug("Recreating a VPC network with Internal LB Service...") + internal_tier_2 = self.create_Network(net_off_1, gateway='10.1.2.1', vpc=vpc_1) + internal_vm_2 = self.create_VM(internal_tier_2) + self.validate_Network(internal_tier_2, state="Implemented") + vr_1 = self.get_Router(internal_tier_2) + self.check_Router_state(vr_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc_1) + self.verify_vsp_router(vr_1) + self.verify_vsp_vm(internal_vm_2) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="false") + def test_04_nuage_internallb_rules(self): + """Test Nuage VSP VPC Internal LB functionality with different combinations of Internal LB rules + """ + + # 1. Create an Internal LB Rule with source IP Address specified, check if the Internal LB Rule is successfully + # created. + # 2. Create an Internal LB Rule without source IP Address specified, check if the Internal LB Rule is + # successfully created. + # 3. Create an Internal LB Rule when the specified source IP Address is outside the VPC network (tier) CIDR + # range, check if the Internal LB Rule creation failed as the requested source IP is not in the network's + # CIDR subnet. + # 4. Create an Internal LB Rule when the specified source IP Address is outside the VPC super CIDR range, + # check if the Internal LB Rule creation failed as the requested source IP is not in the network's CIDR + # subnet. + # 5. Create an Internal LB Rule in the tier with LB service provider as VpcInlineLbVm, check if the Internal LB + # Rule creation failed as Scheme Internal is not supported by this network offering. + # 6. Create multiple Internal LB Rules using different Load Balancing source IP Addresses, check if the Internal + # LB Rules are successfully created. + # 7. Create multiple Internal LB Rules with different ports but using the same Load Balancing source IP Address, + # check if the Internal LB Rules are successfully created. + # 8. Create multiple Internal LB Rules with same ports and using the same Load Balancing source IP Address, + # check if the second Internal LB Rule creation failed as it conflicts with the first Internal LB rule. + # 9. Attach a VM to the above created Internal LB Rules, check if the VM is successfully attached to the + # Internal LB Rules. + # 10. Verify the InternalLbVm deployment after successfully creating the first Internal LB Rule and attaching a + # VM to it. + # 11. Verify the failure of attaching a VM from a different tier to an Internal LB Rule created on a tier. + # 12. Delete the above created Internal LB Rules, check if the Internal LB Rules are successfully deleted. + + # Creating a VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating a VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in the VPC, and deploying VMs + self.debug("Creating a VPC network with Internal LB service...") + internal_tier = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(internal_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier.name) + internal_vm = self.create_VM(internal_tier) + self.check_VM_state(internal_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + + self.debug("Creating a VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_2, gateway='10.1.2.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier.name) + public_vm = self.create_VM(public_tier) + self.check_VM_state(public_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + + # Creating Internal LB Rules + self.debug("Creating an Internal LB Rule without source IP Address specified...") + int_lb_rule = self.create_Internal_LB_Rule(internal_tier) + self.validate_Internal_LB_Rule(int_lb_rule, state="Add") + + # Validating InternalLbVm deployment + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule.sourceipaddress) + self.debug("InternalLbVm is not deployed in the network as there are no VMs assigned to this Internal LB Rule") + + self.debug('Deleting the Internal LB Rule - %s' % int_lb_rule.name) + int_lb_rule.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule) + self.debug("Internal LB Rule successfully deleted in CloudStack") + + free_source_ip = int_lb_rule.sourceipaddress + + self.debug("Creating an Internal LB Rule with source IP Address specified...") + int_lb_rule = self.create_Internal_LB_Rule(internal_tier, source_ip=free_source_ip) + self.validate_Internal_LB_Rule(int_lb_rule, state="Add") + + # Validating InternalLbVm deployment + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule.sourceipaddress) + self.debug("InternalLbVm is not deployed in the network as there are no VMs assigned to this Internal LB Rule") + + self.debug('Deleting the Internal LB Rule - %s' % int_lb_rule.name) + int_lb_rule.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule) + self.debug("Internal LB Rule successfully deleted in CloudStack") + + self.debug("Creating an Internal LB Rule when the specified source IP Address is outside the VPC network CIDR " + "range...") + with self.assertRaises(Exception): + self.create_Internal_LB_Rule(internal_tier, source_ip="10.1.1.256") + self.debug("Internal LB Rule creation failed as the requested IP is not in the network's CIDR subnet") + + self.debug("Creating an Internal LB Rule when the specified source IP Address is outside the VPC super CIDR " + "range...") + with self.assertRaises(Exception): + self.create_Internal_LB_Rule(internal_tier, source_ip="10.2.1.256") + self.debug("Internal LB Rule creation failed as the requested IP is not in the network's CIDR subnet") + + self.debug("Creating an Internal LB Rule in a VPC network without Internal Lb service...") + with self.assertRaises(Exception): + self.create_Internal_LB_Rule(public_tier) + self.debug("Internal LB Rule creation failed as Scheme Internal is not supported by this network offering") + + self.debug("Creating multiple Internal LB Rules using different Load Balancing source IP Addresses...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm]) + + # Validating InternalLbVms deployment and state + int_lb_vm_1 = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + int_lb_vm_2 = self.get_InternalLbVm(internal_tier, int_lb_rule_2.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_2.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + self.verify_vsp_LB_device(int_lb_vm_2) + + self.debug('Removing VMs from the Internal LB Rules - %s, %s' % (int_lb_rule_1.name, int_lb_rule_2.name)) + int_lb_rule_1.remove(self.api_client, vms=[internal_vm]) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_1, vm_array=[internal_vm]) + self.debug("VMs successfully removed from the Internal LB Rule in CloudStack") + int_lb_rule_2.remove(self.api_client, vms=[internal_vm]) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_2, vm_array=[internal_vm]) + self.debug("VMs successfully removed from the Internal LB Rule in CloudStack") + + # Validating InternalLbVms state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + self.check_InternalLbVm_state(internal_tier, int_lb_rule_2.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + self.verify_vsp_LB_device(int_lb_vm_2) + + self.debug('Deleting the Internal LB Rules - %s, %s' % (int_lb_rule_1.name, int_lb_rule_2.name)) + int_lb_rule_1.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_1) + self.debug("Internal LB Rule successfully deleted in CloudStack") + int_lb_rule_2.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_2) + self.debug("Internal LB Rule successfully deleted in CloudStack") + + # Validating InternalLbVms un-deployment + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress) + self.debug("InternalLbVm successfully destroyed in CloudStack") + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule_2.sourceipaddress) + self.debug("InternalLbVm successfully destroyed in CloudStack") + + # VSD Verification + with self.assertRaises(Exception): + self.verify_vsp_LB_device(int_lb_vm_1) + self.debug("InternalLbVm successfully destroyed in VSD") + with self.assertRaises(Exception): + self.verify_vsp_LB_device(int_lb_vm_2) + self.debug("InternalLbVm successfully destroyed in VSD") + + self.debug("Creating multiple Internal LB Rules with different ports but using the same Load Balancing source " + "IP Address...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_1.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm]) + + # Validating InternalLbVm deployment and state + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + self.debug('Removing VMs from the Internal LB Rules - %s, %s' % (int_lb_rule_1.name, int_lb_rule_2.name)) + int_lb_rule_1.remove(self.api_client, vms=[internal_vm]) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_1, vm_array=[internal_vm]) + self.debug("VMs successfully removed from the Internal LB Rule in CloudStack") + int_lb_rule_2.remove(self.api_client, vms=[internal_vm]) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_2, vm_array=[internal_vm]) + self.debug("VMs successfully removed from the Internal LB Rule in CloudStack") + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + self.debug('Deleting the Internal LB Rules - %s, %s' % (int_lb_rule_1.name, int_lb_rule_2.name)) + int_lb_rule_1.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_1) + self.debug("Internal LB Rule successfully deleted in CloudStack") + int_lb_rule_2.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule_2) + self.debug("Internal LB Rule successfully deleted in CloudStack") + + # Validating InternalLbVm un-deployment + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress) + self.debug("InternalLbVm successfully destroyed in CloudStack") + + # VSD Verification + with self.assertRaises(Exception): + self.verify_vsp_LB_device(int_lb_vm) + self.debug("InternalLbVm successfully destroyed in VSD") + + self.debug("Creating multiple Internal LB Rules with same ports and using the same Load Balacing source IP " + "Address...") + int_lb_rule = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule, state="Active", vm_array=[internal_vm]) + with self.assertRaises(Exception): + self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm], source_ip=int_lb_rule.sourceipaddress) + self.debug("Internal LB Rule creation failed as it conflicts with the existing rule") + + # Validating InternalLbVm deployment and state + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + self.debug('Removing VMs from the Internal LB Rule - %s' % int_lb_rule.name) + int_lb_rule.remove(self.api_client, vms=[internal_vm]) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule, vm_array=[internal_vm]) + self.debug("VMs successfully removed from the Internal LB Rule in CloudStack") + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + self.debug('Deleting the Internal LB Rule - %s' % int_lb_rule.name) + int_lb_rule.delete(self.api_client) + with self.assertRaises(Exception): + self.validate_Internal_LB_Rule(int_lb_rule) + self.debug("Internal LB Rule successfully deleted in CloudStack") + + # Validating InternalLbVm un-deployment + with self.assertRaises(Exception): + self.check_InternalLbVm_state(internal_tier, int_lb_rule.sourceipaddress) + self.debug("InternalLbVm successfully destroyed in CloudStack") + + # VSD Verification + with self.assertRaises(Exception): + self.verify_vsp_LB_device(int_lb_vm) + self.debug("InternalLbVm successfully destroyed in VSD") + + self.debug("Attaching a VM from a different tier to an Internal LB Rule created on a tier...") + with self.assertRaises(Exception): + self.create_Internal_LB_Rule(internal_tier, vm_array=[public_vm]) + self.debug("Internal LB Rule creation failed as the VM belongs to a different network") + + @attr(tags=["advanced", "nuagevsp"], required_hardware="true") + def test_05_nuage_internallb_traffic(self): + """Test Nuage VSP VPC Internal LB functionality by performing (wget) traffic tests within a VPC + """ + + # 1. Create an Internal LB Rule "internal_lbrule" with source IP Address specified on the Internal tier, check + # if the Internal LB Rule is successfully created. + # 2. Create an Internal LB Rule "internal_lbrule_http" with source IP Address (same as above) specified on the + # Internal tier, check if the Internal LB Rule is successfully created. + # 3. Attach a VM to the above created Internal LB Rules, check if the InternalLbVm is successfully deployed in + # the Internal tier. + # 4. Deploy two more VMs in the Internal tier, check if the VMs are successfully deployed. + # 5. Attach the newly deployed VMs to the above created Internal LB Rules, verify the validity of the above + # created Internal LB Rules over three Load Balanced VMs in the Internal tier. + # 6. Create the corresponding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible, + # check if the Network ACL rules are successfully added to the internal tier. + # 7. Validate the Internal LB functionality by performing (wget) traffic tests from a VM in the Public tier to + # the Internal load balanced guest VMs in the Internal tier, using Static NAT functionality to access (ssh) + # the VM on the Public tier. + # 8. Verify that the InternalLbVm gets destroyed when the last Internal LB rule is removed from the Internal + # tier. + # 9. Repeat the above steps for one more Internal tier as well, validate the Internal LB functionality. + + # Creating a VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating a VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in the VPC, and deploying VMs + self.debug("Creating a VPC network with Internal LB service...") + internal_tier_1 = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier_1, state="Implemented") + vr = self.get_Router(internal_tier_1) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier_1.name) + internal_vm_1 = self.create_VM(internal_tier_1) + self.check_VM_state(internal_vm_1, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_1, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm_1) + + self.debug("Creating one more VPC network with Internal LB service...") + internal_tier_2 = self.create_Network(net_off_1, gateway='10.1.2.1', vpc=vpc) + self.validate_Network(internal_tier_2, state="Implemented") + vr = self.get_Router(internal_tier_2) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier_2.name) + internal_vm_2 = self.create_VM(internal_tier_2) + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier_2, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm_2) + + self.debug("Creating a VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_2, gateway='10.1.3.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier.name) + public_vm = self.create_VM(public_tier) + self.check_VM_state(public_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + + # Creating Internal LB Rules in the Internal tiers + self.debug("Creating two Internal LB Rules (SSH & HTTP) using the same Load Balancing source IP Address...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier_1, vm_array=[internal_vm_1]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm_1]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier_1, + vm_array=[internal_vm_1], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_1.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm_1]) + + # Validating InternalLbVm deployment and state + int_lb_vm_1 = self.get_InternalLbVm(internal_tier_1, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier_1, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + + # Deploying more VMs in the Internal tier + self.debug("Deploying two more VMs in network - %s" % internal_tier_1.name) + internal_vm_1_1 = self.create_VM(internal_tier_1) + internal_vm_1_2 = self.create_VM(internal_tier_1) + + # VSD verification + self.verify_vsp_vm(internal_vm_1_1) + self.verify_vsp_vm(internal_vm_1_2) + + # Adding newly deployed VMs to the created Internal LB rules + self.debug("Adding two more virtual machines to the created Internal LB rules...") + int_lb_rule_1.assign(self.api_client, [internal_vm_1_1, internal_vm_1_2]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", + vm_array=[internal_vm_1, internal_vm_1_1, internal_vm_1_2]) + int_lb_rule_2.assign(self.api_client, [internal_vm_1_1, internal_vm_1_2]) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", + vm_array=[internal_vm_1, internal_vm_1_1, internal_vm_1_2]) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier_1, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + + # Adding Network ACL rules in the Internal tier + self.debug("Adding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible...") + ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=internal_tier_1) + http_rule = self.create_NetworkAclRule(self.test_data["http_rule"], network=internal_tier_1) + + # VSD verification + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Creating Internal LB Rules in the Internal tier + self.debug("Creating two Internal LB Rules (SSH & HTTP) using the same Load Balancing source IP Address...") + int_lb_rule_3 = self.create_Internal_LB_Rule(internal_tier_2, vm_array=[internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_3, state="Active", vm_array=[internal_vm_2]) + int_lb_rule_4 = self.create_Internal_LB_Rule(internal_tier_2, + vm_array=[internal_vm_2], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_3.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_4, state="Active", vm_array=[internal_vm_2]) + + # Validating InternalLbVm deployment and state + int_lb_vm_2 = self.get_InternalLbVm(internal_tier_2, int_lb_rule_3.sourceipaddress) + self.check_InternalLbVm_state(internal_tier_2, int_lb_rule_3.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_2) + + # Deploying more VMs in the Internal tier + self.debug("Deploying two more VMs in network - %s" % internal_tier_2.name) + internal_vm_2_1 = self.create_VM(internal_tier_2) + internal_vm_2_2 = self.create_VM(internal_tier_2) + + # VSD verification + self.verify_vsp_vm(internal_vm_2_1) + self.verify_vsp_vm(internal_vm_2_2) + + # Adding newly deployed VMs to the created Internal LB rules + self.debug("Adding two more virtual machines to the created Internal LB rules...") + int_lb_rule_3.assign(self.api_client, [internal_vm_2_1, internal_vm_2_2]) + self.validate_Internal_LB_Rule(int_lb_rule_3, state="Active", + vm_array=[internal_vm_2, internal_vm_2_1, internal_vm_2_2]) + int_lb_rule_4.assign(self.api_client, [internal_vm_2_1, internal_vm_2_2]) + self.validate_Internal_LB_Rule(int_lb_rule_4, state="Active", + vm_array=[internal_vm_2, internal_vm_2_1, internal_vm_2_2]) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier_2, int_lb_rule_3.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_2) + + # Adding Network ACL rules in the Internal tier + self.debug("Adding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible...") + ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=internal_tier_2) + http_rule = self.create_NetworkAclRule(self.test_data["http_rule"], network=internal_tier_2) + + # VSD verification + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Creating Static NAT Rule for the VM in the Public tier + public_ip = self.acquire_PublicIPAddress(public_tier, vpc) + self.validate_PublicIPAddress(public_ip, public_tier) + self.create_StaticNatRule_For_VM(public_vm, public_ip, public_tier) + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + + # Adding Network ACL rule in the Public tier + self.debug("Adding Network ACL rule to make the created NAT rule (SSH) accessible...") + public_ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=public_tier) + + # VSD verification + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Internal LB (wget) traffic tests + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file_1 = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file_2 = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_3.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic tests + self.verify_lb_wget_file(wget_file_1, [internal_vm_1, internal_vm_1_1, internal_vm_1_2]) + self.verify_lb_wget_file(wget_file_2, [internal_vm_2, internal_vm_2_1, internal_vm_2_2]) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="true") + def test_06_nuage_internallb_algorithms_traffic(self): + """Test Nuage VSP VPC Internal LB functionality with different LB algorithms by performing (wget) traffic tests + within a VPC + """ + + # Repeat the tests in the testcase "test_05_nuage_internallb_traffic" with different Internal LB algorithms: + # 1. Round Robin + # 2. Least connections + # 3. Source + # Verify the above Internal LB algorithms by performing multiple (wget) traffic tests within a VPC. + + # Creating a VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating a VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in the VPC, and deploying VMs + self.debug("Creating a VPC network with Internal LB service...") + internal_tier = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(internal_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier.name) + internal_vm = self.create_VM(internal_tier) + self.check_VM_state(internal_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + + self.debug("Creating a VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_2, gateway='10.1.2.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier.name) + public_vm = self.create_VM(public_tier) + self.check_VM_state(public_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + + # Creating Internal LB Rules in the Internal tier with Round Robin Algorithm + self.debug("Creating two Internal LB Rules (SSH & HTTP) with Round Robin Algorithm...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_1.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm]) + + # Validating InternalLbVm deployment and state + int_lb_vm_1 = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + + # Deploying more VMs in the Internal tier + self.debug("Deploying two more VMs in network - %s" % internal_tier.name) + internal_vm_1 = self.create_VM(internal_tier) + internal_vm_2 = self.create_VM(internal_tier) + + # VSD verification + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + + # Adding newly deployed VMs to the created Internal LB rules + self.debug("Adding two more virtual machines to the created Internal LB rules...") + int_lb_rule_1.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + int_lb_rule_2.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_1) + + # Creating Internal LB Rules in the Internal tier with Least connections Algorithm + self.debug("Creating two Internal LB Rules (SSH & HTTP) with Least connections Algorithm...") + self.test_data["internal_lbrule"]["algorithm"] = "leastconn" + int_lb_rule_3 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm, internal_vm_1, internal_vm_2], + services=self.test_data["internal_lbrule"] + ) + self.validate_Internal_LB_Rule(int_lb_rule_3, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + self.test_data["internal_lbrule_http"]["algorithm"] = "leastconn" + int_lb_rule_4 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm, internal_vm_1, internal_vm_2], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_3.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_4, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + + # Validating InternalLbVm deployment and state + int_lb_vm_2 = self.get_InternalLbVm(internal_tier, int_lb_rule_3.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_3.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_2) + + # Creating Internal LB Rules in the Internal tier with Source Algorithm + self.debug("Creating two Internal LB Rules (SSH & HTTP) with Source Algorithm...") + self.test_data["internal_lbrule"]["algorithm"] = "source" + int_lb_rule_5 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm, internal_vm_1, internal_vm_2], + services=self.test_data["internal_lbrule"] + ) + self.validate_Internal_LB_Rule(int_lb_rule_5, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + self.test_data["internal_lbrule_http"]["algorithm"] = "source" + int_lb_rule_6 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm, internal_vm_1, internal_vm_2], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_5.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_6, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + + # Validating InternalLbVm deployment and state + int_lb_vm_3 = self.get_InternalLbVm(internal_tier, int_lb_rule_5.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_5.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm_3) + + # Adding Network ACL rules in the Internal tier + self.debug("Adding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible...") + ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=internal_tier) + http_rule = self.create_NetworkAclRule(self.test_data["http_rule"], network=internal_tier) + + # VSD verification + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Creating Static NAT Rule for the VM in the Public tier + public_ip = self.acquire_PublicIPAddress(public_tier, vpc) + self.validate_PublicIPAddress(public_ip, public_tier) + self.create_StaticNatRule_For_VM(public_vm, public_ip, public_tier) + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + + # Adding Network ACL rule in the Public tier + self.debug("Adding Network ACL rule to make the created NAT rule (SSH) accessible...") + public_ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=public_tier) + + # VSD verification + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Internal LB (wget) traffic tests with Round Robin Algorithm + ssh_client = self.ssh_into_VM(public_vm, public_ip) + self.validate_internallb_algorithm_traffic(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"], + [internal_vm, internal_vm_1, internal_vm_2], + "roundrobin" + ) + + # Internal LB (wget) traffic tests with Least connections Algorithm + ssh_client = self.ssh_into_VM(public_vm, public_ip) + self.validate_internallb_algorithm_traffic(ssh_client, + int_lb_rule_3.sourceipaddress, + self.test_data["http_rule"]["publicport"], + [internal_vm, internal_vm_1, internal_vm_2], + "leastconn" + ) + + # Internal LB (wget) traffic tests with Source Algorithm + ssh_client = self.ssh_into_VM(public_vm, public_ip) + self.validate_internallb_algorithm_traffic(ssh_client, + int_lb_rule_5.sourceipaddress, + self.test_data["http_rule"]["publicport"], + [internal_vm, internal_vm_1, internal_vm_2], + "source" + ) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="true") + def test_07_nuage_internallb_vpc_network_restarts_traffic(self): + """Test Nuage VSP VPC Internal LB functionality with restarts of VPC network components by performing (wget) + traffic tests within a VPC + """ + + # Repeat the tests in the testcase "test_05_nuage_internallb_traffic" with restarts of VPC networks (tiers): + # 1. Restart tier with InternalLbVm (cleanup = false), verify that the InternalLbVm gets destroyed and deployed + # again in the Internal tier. + # 2. Restart tier with InternalLbVm (cleanup = true), verify that the InternalLbVm gets destroyed and deployed + # again in the Internal tier. + # 3. Restart tier without InternalLbVm (cleanup = false), verify that this restart has no effect on the + # InternalLbVm functionality. + # 4. Restart tier without InternalLbVm (cleanup = true), verify that this restart has no effect on the + # InternalLbVm functionality. + # 5. Stop all the VMs configured with InternalLbVm, verify that the InternalLbVm gets destroyed in the Internal + # tier. + # 6. Start all the VMs configured with InternalLbVm, verify that the InternalLbVm gets deployed again in the + # Internal tier. + # 7. Restart VPC, verify that the VPC VR gets rebooted and this restart has no effect on the InternalLbVm + # functionality. + # Verify the above restarts of VPC networks (tiers) by performing (wget) traffic tests within a VPC. + + # Creating a VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating a VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in the VPC, and deploying VMs + self.debug("Creating a VPC network with Internal LB service...") + internal_tier = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(internal_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier.name) + internal_vm = self.create_VM(internal_tier) + self.check_VM_state(internal_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + + self.debug("Creating a VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_2, gateway='10.1.2.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier.name) + public_vm = self.create_VM(public_tier) + self.check_VM_state(public_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + + # Creating Internal LB Rules in the Internal tier + self.debug("Creating two Internal LB Rules (SSH & HTTP) using the same Load Balancing source IP Address...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_1.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm]) + + # Validating InternalLbVm deployment and state + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Deploying more VMs in the Internal tier + self.debug("Deploying two more VMs in network - %s" % internal_tier.name) + internal_vm_1 = self.create_VM(internal_tier) + internal_vm_2 = self.create_VM(internal_tier) + + # VSD verification + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + + # Adding newly deployed VMs to the created Internal LB rules + self.debug("Adding two more virtual machines to the created Internal LB rules...") + int_lb_rule_1.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + int_lb_rule_2.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Adding Network ACL rules in the Internal tier + self.debug("Adding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible...") + ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=internal_tier) + http_rule = self.create_NetworkAclRule(self.test_data["http_rule"], network=internal_tier) + + # VSD verification + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Creating Static NAT Rule for the VM in the Public tier + public_ip = self.acquire_PublicIPAddress(public_tier, vpc) + self.validate_PublicIPAddress(public_ip, public_tier) + self.create_StaticNatRule_For_VM(public_vm, public_ip, public_tier) + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + + # Adding Network ACL rule in the Public tier + self.debug("Adding Network ACL rule to make the created NAT rule (SSH) accessible...") + public_ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=public_tier) + + # VSD verification + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restart Internal tier (cleanup = false) + # InternalLbVm gets destroyed and deployed again in the Internal tier + self.debug("Restarting the Internal tier without cleanup...") + Network.restart(internal_tier, self.api_client, cleanup=False) + self.validate_Network(internal_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(internal_vm, state="Running") + self.check_VM_state(internal_vm_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + # InternalLbVm gets destroyed and deployed again in the Internal tier + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting the Internal tier: %s" % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm in the Internal tier to be fully resolved for (wget) traffic " + "test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting the Internal tier") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restart Internal tier (cleanup = true) + # InternalLbVm gets destroyed and deployed again in the Internal tier + self.debug("Restarting the Internal tier with cleanup...") + Network.restart(internal_tier, self.api_client, cleanup=True) + self.validate_Network(internal_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(internal_vm, state="Running") + self.check_VM_state(internal_vm_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + # InternalLbVm gets destroyed and deployed again in the Internal tier + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting the Internal tier with cleanup: " + "%s" % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm in the Internal tier to be fully resolved for (wget) traffic " + "test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting the Internal tier with cleanup") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restart Public tier (cleanup = false) + # This restart has no effect on the InternalLbVm functionality + self.debug("Restarting the Public tier without cleanup...") + Network.restart(public_tier, self.api_client, cleanup=False) + self.validate_Network(public_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(public_vm, state="Running") + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restart Public tier (cleanup = true) + # This restart has no effect on the InternalLbVm functionality + self.debug("Restarting the Public tier with cleanup...") + Network.restart(public_tier, self.api_client, cleanup=True) + self.validate_Network(public_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(public_vm, state="Running") + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Stopping VMs in the Internal tier + # wget traffic test fails as all the VMs in the Internal tier are in stopped state + self.debug("Stopping all the VMs in the Internal tier...") + internal_vm.stop(self.api_client) + internal_vm_1.stop(self.api_client) + internal_vm_2.stop(self.api_client) + self.validate_Network(internal_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(internal_vm, state="Stopped") + self.check_VM_state(internal_vm_1, state="Stopped") + self.check_VM_state(internal_vm_2, state="Stopped") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm, stopped=True) + self.verify_vsp_vm(internal_vm_1, stopped=True) + self.verify_vsp_vm(internal_vm_2, stopped=True) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + with self.assertRaises(Exception): + self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + self.debug("Failed to wget file as all the VMs in the Internal tier are in stopped state") + + # Starting VMs in the Internal tier + # wget traffic test succeeds as all the VMs in the Internal tier are back in running state + self.debug("Starting all the VMs in the Internal tier...") + internal_vm.start(self.api_client) + internal_vm_1.start(self.api_client) + internal_vm_2.start(self.api_client) + self.validate_Network(internal_tier, state="Implemented") + self.check_Router_state(vr, state="Running") + self.check_VM_state(internal_vm, state="Running") + self.check_VM_state(internal_vm_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting all the VMs in the Internal tier" + ": %s" % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm and all the VMs in the Internal tier to be fully resolved for " + "(wget) traffic test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting all the VMs in the Internal " + "tier") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restarting VPC (cleanup = false) + # VPC VR gets destroyed and deployed again in the VPC + # This restart has no effect on the InternalLbVm functionality + self.debug("Restarting the VPC without cleanup...") + self.restart_Vpc(vpc, cleanup=False) + self.validate_Network(public_tier, state="Implemented") + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + self.check_VM_state(public_vm, state="Running") + self.check_VM_state(internal_vm, state="Running") + self.check_VM_state(internal_vm_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + self.verify_vsp_vm(internal_vm) + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + self.verify_vsp_firewall_rule(public_ssh_rule) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Restarting VPC (cleanup = true) + # VPC VR gets destroyed and deployed again in the VPC + # This restart has no effect on the InternalLbVm functionality + self.debug("Restarting the VPC with cleanup...") + self.restart_Vpc(vpc, cleanup=True) + self.validate_Network(public_tier, state="Implemented") + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + self.check_VM_state(public_vm, state="Running") + self.check_VM_state(internal_vm, state="Running") + self.check_VM_state(internal_vm_1, state="Running") + self.check_VM_state(internal_vm_2, state="Running") + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + self.verify_vsp_vm(internal_vm) + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + self.verify_vsp_firewall_rule(public_ssh_rule) + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + @attr(tags=["advanced", "nuagevsp"], required_hardware="true") + def test_08_nuage_internallb_appliance_operations_traffic(self): + """Test Nuage VSP VPC Internal LB functionality with InternalLbVm appliance operations by performing (wget) + traffic tests within a VPC + """ + + # Repeat the tests in the testcase "test_05_nuage_internallb_traffic" with InternalLbVm appliance operations: + # 1. Verify the InternalLbVm deployment by creating the Internal LB Rules when the VPC VR is in Stopped state, + # VPC VR has no effect on the InternalLbVm functionality. + # 2. Stop the InternalLbVm when the VPC VR is in Stopped State + # 3. Start the InternalLbVm when the VPC VR is in Stopped state + # 4. Stop the InternalLbVm when the VPC VR is in Running State + # 5. Start the InternalLbVm when the VPC VR is in Running state + # 6. Force stop the InternalLbVm when the VPC VR is in Running State + # 7. Start the InternalLbVm when the VPC VR is in Running state + # Verify the above restarts of VPC networks by performing (wget) traffic tests within a VPC. + + # Creating a VPC offering + self.debug("Creating Nuage VSP VPC offering with Internal LB service...") + vpc_off = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering_lb"]) + self.validate_VpcOffering(vpc_off, state="Enabled") + + # Creating a VPC + self.debug("Creating a VPC with Internal LB service...") + vpc = self.create_Vpc(vpc_off, cidr='10.1.0.0/16') + self.validate_Vpc(vpc, state="Enabled") + + # Creating network offerings + self.debug("Creating Nuage VSP VPC Network offering with Internal LB service...") + net_off_1 = self.create_NetworkOffering( + self.test_data["nuagevsp"]["vpc_network_offering_internal_lb"]) + self.validate_NetworkOffering(net_off_1, state="Enabled") + + self.debug("Creating Nuage VSP VPC Network offering without Internal LB service...") + net_off_2 = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(net_off_2, state="Enabled") + + # Creating VPC networks in the VPC, and deploying VMs + self.debug("Creating a VPC network with Internal LB service...") + internal_tier = self.create_Network(net_off_1, gateway='10.1.1.1', vpc=vpc) + self.validate_Network(internal_tier, state="Implemented") + vr = self.get_Router(internal_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % internal_tier.name) + internal_vm = self.create_VM(internal_tier) + self.check_VM_state(internal_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(internal_vm) + + self.debug("Creating a VPC network without Internal LB service...") + public_tier = self.create_Network(net_off_2, gateway='10.1.2.1', vpc=vpc) + self.validate_Network(public_tier, state="Implemented") + vr = self.get_Router(public_tier) + self.check_Router_state(vr, state="Running") + + self.debug("Deploying a VM in network - %s" % public_tier.name) + public_vm = self.create_VM(public_tier) + self.check_VM_state(public_vm, state="Running") + + # VSD verification + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_router(vr) + self.verify_vsp_vm(public_vm) + + # Stopping the VPC VR + # VPC VR has no effect on the InternalLbVm functionality + Router.stop(self.api_client, id=vr.id) + self.check_Router_state(vr, state="Stopped") + self.validate_Network(public_tier, state="Implemented") + self.validate_Network(internal_tier, state="Implemented") + + # VSD verification + self.verify_vsp_router(vr, stopped=True) + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + + # Creating Internal LB Rules in the Internal tier + self.debug("Creating two Internal LB Rules (SSH & HTTP) using the same Load Balancing source IP Address...") + int_lb_rule_1 = self.create_Internal_LB_Rule(internal_tier, vm_array=[internal_vm]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", vm_array=[internal_vm]) + int_lb_rule_2 = self.create_Internal_LB_Rule(internal_tier, + vm_array=[internal_vm], + services=self.test_data["internal_lbrule_http"], + source_ip=int_lb_rule_1.sourceipaddress + ) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", vm_array=[internal_vm]) + + # Validating InternalLbVm deployment and state + int_lb_vm = self.get_InternalLbVm(internal_tier, int_lb_rule_1.sourceipaddress) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Deploying more VMs in the Internal tier + self.debug("Deploying two more VMs in network - %s" % internal_tier.name) + internal_vm_1 = self.create_VM(internal_tier) + internal_vm_2 = self.create_VM(internal_tier) + + # VSD verification + self.verify_vsp_vm(internal_vm_1) + self.verify_vsp_vm(internal_vm_2) + + # Adding newly deployed VMs to the created Internal LB rules + self.debug("Adding two more virtual machines to the created Internal LB rules...") + int_lb_rule_1.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_1, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + int_lb_rule_2.assign(self.api_client, [internal_vm_1, internal_vm_2]) + self.validate_Internal_LB_Rule(int_lb_rule_2, state="Active", + vm_array=[internal_vm, internal_vm_1, internal_vm_2]) + + # Validating InternalLbVm state + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Adding Network ACL rules in the Internal tier + self.debug("Adding Network ACL rules to make the created Internal LB rules (SSH & HTTP) accessible...") + ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=internal_tier) + http_rule = self.create_NetworkAclRule(self.test_data["http_rule"], network=internal_tier) + + # VSD verification + self.verify_vsp_firewall_rule(ssh_rule) + self.verify_vsp_firewall_rule(http_rule) + + # Creating Static NAT Rule for the VM in the Public tier + public_ip = self.acquire_PublicIPAddress(public_tier, vpc) + self.validate_PublicIPAddress(public_ip, public_tier) + self.create_StaticNatRule_For_VM(public_vm, public_ip, public_tier) + self.validate_PublicIPAddress(public_ip, public_tier, static_nat=True, vm=public_vm) + + # VSD verification + self.verify_vsp_floating_ip(public_tier, public_vm, public_ip.ipaddress, vpc) + + # Adding Network ACL rule in the Public tier + self.debug("Adding Network ACL rule to make the created NAT rule (SSH) accessible...") + public_ssh_rule = self.create_NetworkAclRule(self.test_data["ingress_rule"], network=public_tier) + + # VSD verification + self.verify_vsp_firewall_rule(public_ssh_rule) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # # Stopping the InternalLbVm when the VPC VR is in Stopped state + self.stop_InternalLbVm(int_lb_vm) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Stopped") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm, stopped=True) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + with self.assertRaises(Exception): + self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + self.debug("Failed to wget file as the InternalLbVm is in stopped state") + + # # Starting the InternalLbVm when the VPC VR is in Stopped state + self.start_InternalLbVm(int_lb_vm) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting the InternalLbVm appliance: %s" + % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm to be fully resolved for (wget) traffic test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting the InternalLbVm appliance") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # Starting the VPC VR + # VPC VR has no effect on the InternalLbVm functionality + Router.start(self.api_client, id=vr.id) + self.check_Router_state(vr) + self.validate_Network(public_tier, state="Implemented") + self.validate_Network(internal_tier, state="Implemented") + + # VSD verification + self.verify_vsp_router(vr) + self.verify_vsp_network(self.domain.id, public_tier, vpc) + self.verify_vsp_network(self.domain.id, internal_tier, vpc) + + # # Stopping the InternalLbVm when the VPC VR is in Running state + self.stop_InternalLbVm(int_lb_vm) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Stopped") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm, stopped=True) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + with self.assertRaises(Exception): + self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + self.debug("Failed to wget file as the InternalLbVm is in stopped state") + + # # Starting the InternalLbVm when the VPC VR is in Running state + self.start_InternalLbVm(int_lb_vm) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting the InternalLbVm appliance: %s" + % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm to be fully resolved for (wget) traffic test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting the InternalLbVm appliance") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) + + # # Force Stopping the InternalLbVm when the VPC VR is in Running state + self.stop_InternalLbVm(int_lb_vm, force=True) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Stopped") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm, stopped=True) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + with self.assertRaises(Exception): + self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + self.debug("Failed to wget file as the InternalLbVm is in stopped state") + + # # Starting the InternalLbVm when the VPC VR is in Running state + self.start_InternalLbVm(int_lb_vm) + self.check_InternalLbVm_state(internal_tier, int_lb_rule_1.sourceipaddress, state="Running") + + # VSD Verification + self.verify_vsp_LB_device(int_lb_vm) + + # Internal LB (wget) traffic test + ssh_client = self.ssh_into_VM(public_vm, public_ip) + tries = 0 + while True: + try: + wget_file = self.wget_from_vm_cmd(ssh_client, + int_lb_rule_1.sourceipaddress, + self.test_data["http_rule"]["publicport"] + ) + except Exception as e: + self.debug("Failed to wget file via the InternalLbVm after re-starting the InternalLbVm appliance: %s" + % e) + if tries == 10: + break + self.debug("Waiting for the InternalLbVm to be fully resolved for (wget) traffic test...") + time.sleep(30) + tries += 1 + continue + self.debug("Internal LB (wget) traffic test is successful after re-starting the InternalLbVm appliance") + break + + # Verifying Internal LB (wget) traffic test + self.verify_lb_wget_file(wget_file, [internal_vm, internal_vm_1, internal_vm_2]) diff --git a/test/integration/plugins/nuagevsp/test_nuage_vpc_network.py b/test/integration/plugins/nuagevsp/test_nuage_vpc_network.py index 3fc9c32cfec..a8361d0e0bf 100644 --- a/test/integration/plugins/nuagevsp/test_nuage_vpc_network.py +++ b/test/integration/plugins/nuagevsp/test_nuage_vpc_network.py @@ -15,16 +15,17 @@ # specific language governing permissions and limitations # under the License. -""" Tests for Basic VPC Network Functionality with NuageVsp network Plugin +""" Tests for basic VPC Network functionality with Nuage VSP SDN plugin """ # Import Local Modules -from marvin.lib.base import Account -from nose.plugins.attrib import attr from nuageTestCase import nuageTestCase +from marvin.lib.base import Account +# Import System Modules +from nose.plugins.attrib import attr class TestVpcNetworkNuage(nuageTestCase): - """ Test Basic VPC Network Functionality with NuageVsp network Plugin + """ Test basic VPC Network functionality with Nuage VSP SDN plugin """ @classmethod @@ -44,55 +45,55 @@ class TestVpcNetworkNuage(nuageTestCase): @attr(tags=["advanced", "nuagevsp"], required_hardware="false") def test_nuage_vpc_network(self): - """ Test Basic VPC Network Functionality with NuageVsp network Plugin + """ Test Basic VPC Network Functionality with Nuage VSP SDN plugin """ # 1. Create Nuage VSP VPC offering, check if it is successfully created and enabled. # 2. Create a VPC with Nuage VSP VPC offering, check if it is successfully created and enabled. - # 3. Create Nuage Vsp VPC Network offering, check if it is successfully created and enabled. + # 3. Create Nuage VSP VPC Network offering, check if it is successfully created and enabled. # 4. Create an ACL list in the created VPC, and add an ACL item to it. - # 5. Create a VPC Network with Nuage Vsp VPC Network offering and the created ACL list, check if it is + # 5. Create a VPC Network with Nuage VSP VPC Network offering and the created ACL list, check if it is # successfully created, is in the "Implemented" state, and is added to the VPC VR. # 6. Deploy a VM in the created VPC network, check if the VM is successfully deployed and is in the "Running" # state. - # 7. Verify that the created ACL item is successfully implemented in Nuage Vsp. + # 7. Verify that the created ACL item is successfully implemented in Nuage VSP. # Creating a VPC offering self.debug("Creating Nuage VSP VPC offering...") - vpc_offering = self.create_VpcOffering(self.test_data["nuage_vsp_services"]["vpc_offering"]) - self.validate_vpc_offering(vpc_offering, state="Enabled") + vpc_offering = self.create_VpcOffering(self.test_data["nuagevsp"]["vpc_offering"]) + self.validate_VpcOffering(vpc_offering, state="Enabled") # Creating a VPC self.debug("Creating a VPC with Nuage VSP VPC offering...") vpc = self.create_Vpc(vpc_offering, cidr='10.1.0.0/16') - self.validate_vpc(vpc, state="Enabled") + self.validate_Vpc(vpc, state="Enabled") # Creating a network offering - self.debug("Creating Nuage Vsp VPC Network offering...") - network_offering = self.create_NetworkOffering(self.test_data["nuage_vsp_services"]["vpc_network_offering"]) - self.validate_network_offering(network_offering, state="Enabled") + self.debug("Creating Nuage VSP VPC Network offering...") + network_offering = self.create_NetworkOffering(self.test_data["nuagevsp"]["vpc_network_offering"]) + self.validate_NetworkOffering(network_offering, state="Enabled") # Creating an ACL list - acl_list = self.create_network_acl_list(name="acl", description="acl", vpc=vpc) + acl_list = self.create_NetworkAclList(name="acl", description="acl", vpc=vpc) # Creating an ACL item - acl_item = self.create_network_acl_rule(self.test_data["ingress_rule"], acl_list=acl_list) + acl_item = self.create_NetworkAclRule(self.test_data["ingress_rule"], acl_list=acl_list) # Creating a VPC network in the VPC - self.debug("Creating a VPC network with Nuage Vsp VPC Network offering...") - vpc_network = self.create_Network(network_offering, gateway='10.1.1.1', vpc=vpc, acl_list=acl_list) - self.validate_network(vpc_network, state="Implemented") - vr = self.get_network_router(vpc_network) - self.check_router_state(vr, state="Running") + self.debug("Creating a VPC network with Nuage VSP VPC Network offering...") + vpc_network = self.create_Network(network_offering, vpc=vpc, acl_list=acl_list) + self.validate_Network(vpc_network, state="Implemented") + vr = self.get_Router(vpc_network) + self.check_Router_state(vr, state="Running") # Deploying a VM in the VPC network - vm = self.create_VM_in_Network(vpc_network) - self.check_vm_state(vm, state="Running") + vm = self.create_VM(vpc_network) + self.check_VM_state(vm, state="Running") - # VSPK verification + # VSD verification self.verify_vsp_network(self.domain.id, vpc_network, vpc) self.verify_vsp_router(vr) self.verify_vsp_vm(vm) - # VSPK verification for ACL item + # VSD verification for ACL item self.verify_vsp_firewall_rule(acl_item) diff --git a/test/integration/plugins/nuagevsp/test_nuage_vsp.py b/test/integration/plugins/nuagevsp/test_nuage_vsp.py index a6ec7e1feeb..ca2a28e2769 100644 --- a/test/integration/plugins/nuagevsp/test_nuage_vsp.py +++ b/test/integration/plugins/nuagevsp/test_nuage_vsp.py @@ -15,16 +15,17 @@ # specific language governing permissions and limitations # under the License. -""" P1 tests for NuageVsp network Plugin +""" P1 tests for Nuage VSP SDN plugin """ # Import Local Modules -from marvin.lib.base import Account -from nose.plugins.attrib import attr from nuageTestCase import nuageTestCase +from marvin.lib.base import Account +# Import System Modules +from nose.plugins.attrib import attr class TestNuageVsp(nuageTestCase): - """ Test NuageVsp network plugin + """ Test Nuage VSP SDN plugin """ @classmethod @@ -44,12 +45,12 @@ class TestNuageVsp(nuageTestCase): @attr(tags=["advanced", "nuagevsp"], required_hardware="false") def test_nuage_vsp(self): - """ Test NuageVsp network plugin with basic Isolated Network functionality + """ Test Nuage VSP SDN plugin with basic Isolated Network functionality """ - # 1. Verify that the NuageVsp network service provider is successfully created and enabled. - # 2. Create and enable Nuage Vsp Isolated Network offering, check if it is successfully created and enabled. - # 3. Create an Isolated Network with Nuage Vsp Isolated Network offering, check if it is successfully created + # 1. Verify that the Nuage VSP network service provider is successfully created and enabled. + # 2. Create and enable Nuage VSP Isolated Network offering, check if it is successfully created and enabled. + # 3. Create an Isolated Network with Nuage VSP Isolated Network offering, check if it is successfully created # and is in the "Allocated" state. # 4. Deploy a VM in the created Isolated network, check if the Isolated network state is changed to # "Implemented", and both the VM & VR are successfully deployed and are in the "Running" state. @@ -58,49 +59,49 @@ class TestNuageVsp(nuageTestCase): # 6. Delete the created Isolated Network after destroying its VMs, check if the Isolated network is successfully # deleted. - self.debug("Validating the NuageVsp network service provider...") + self.debug("Validating the Nuage VSP network service provider...") self.validate_NetworkServiceProvider("NuageVsp", state="Enabled") # Creating a network offering - self.debug("Creating and enabling Nuage Vsp Isolated Network offering...") + self.debug("Creating and enabling Nuage VSP Isolated Network offering...") network_offering = self.create_NetworkOffering( - self.test_data["nuage_vsp_services"]["isolated_network_offering"]) - self.validate_network_offering(network_offering, state="Enabled") + self.test_data["nuagevsp"]["isolated_network_offering"]) + self.validate_NetworkOffering(network_offering, state="Enabled") # Creating a network - self.debug("Creating an Isolated Network with Nuage Vsp Isolated Network offering...") - network = self.create_Network(network_offering, gateway='10.1.1.1') - self.validate_network(network, state="Allocated") + self.debug("Creating an Isolated Network with Nuage VSP Isolated Network offering...") + network = self.create_Network(network_offering) + self.validate_Network(network, state="Allocated") # Deploying a VM in the network - vm_1 = self.create_VM_in_Network(network) - self.validate_network(network, state="Implemented") - vr = self.get_network_router(network) - self.check_router_state(vr, state="Running") - self.check_vm_state(vm_1, state="Running") + vm_1 = self.create_VM(network) + self.validate_Network(network, state="Implemented") + vr = self.get_Router(network) + self.check_Router_state(vr, state="Running") + self.check_VM_state(vm_1, state="Running") - # VSPK verification + # VSD verification self.verify_vsp_network(self.domain.id, network) self.verify_vsp_router(vr) self.verify_vsp_vm(vm_1) # Deploying one more VM in the network - vm_2 = self.create_VM_in_Network(network) - self.check_vm_state(vm_2, state="Running") + vm_2 = self.create_VM(network) + self.check_VM_state(vm_2, state="Running") - # VSPK verification + # VSD verification self.verify_vsp_vm(vm_2) # Deleting the network - self.debug("Deleting the Isolated Network with Nuage Vsp Isolated Network offering...") + self.debug("Deleting the Isolated Network with Nuage VSP Isolated Network offering...") self.delete_VM(vm_1) self.delete_VM(vm_2) self.delete_Network(network) with self.assertRaises(Exception): - self.validate_network(network) + self.validate_Network(network) self.debug("Isolated Network successfully deleted in CloudStack") - # VSPK verification + # VSD verification with self.assertRaises(Exception): self.verify_vsp_network(self.domain.id, network) self.debug("Isolated Network successfully deleted in VSD") diff --git a/tools/marvin/marvin/config/test_data.py b/tools/marvin/marvin/config/test_data.py index 352f8a23072..c9bb7c603de 100644 --- a/tools/marvin/marvin/config/test_data.py +++ b/tools/marvin/marvin/config/test_data.py @@ -735,6 +735,34 @@ test_data = { "publicport": 22, "protocol": 'TCP' }, + "internal_lbrule": { + "name": "SSH", + "algorithm": "roundrobin", + # Algorithm used for load balancing + "sourceport": 22, + "instanceport": 22, + "scheme": "internal", + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "internal_lbrule_http": { + "name": "HTTP", + "algorithm": "roundrobin", + # Algorithm used for load balancing + "sourceport": 80, + "instanceport": 80, + "scheme": "internal", + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "http_rule": { + "privateport": 80, + "publicport": 80, + "startport": 80, + "endport": 80, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, "icmprule": { "icmptype": -1, "icmpcode": -1, @@ -1696,9 +1724,9 @@ test_data = { "mode": 'HTTP_DOWNLOAD' } }, - # Nuage Vsp supported services - "nuage_vsp_services": { - # Services supported by Nuage Vsp for Isolated networks + # Nuage VSP SDN plugin specific test data + "nuagevsp": { + # Services supported by the Nuage VSP plugin for Isolated networks "isolated_network_offering": { "name": 'nuage_marvin', "displaytext": 'nuage_marvin', @@ -1718,7 +1746,7 @@ test_data = { "SourceNat": {"SupportedSourceNatTypes": "perzone"} } }, - # Services supported by Nuage Vsp for VPC networks + # Services supported by the Nuage VSP plugin for VPC networks "vpc_network_offering": { "name": 'nuage_vpc_marvin', "displaytext": 'nuage_vpc_marvin', @@ -1740,7 +1768,30 @@ test_data = { "SourceNat": {"SupportedSourceNatTypes": "perzone"} } }, - # Nuage Vsp supports only pre-defined and custom VPC offerings + "vpc_network_offering_internal_lb": { + "name": "nuage_vpc_marvin_internal_lb", + "displaytext": "nuage_vpc_marvin_internal_lb", + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Lb,StaticNat,SourceNat,NetworkACL,Connectivity,UserData', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "ispersistent": 'True', + "serviceProviderList": { + "Dhcp": "NuageVsp", + "Lb": "InternalLbVm", + "StaticNat": "NuageVsp", + "SourceNat": "NuageVsp", + "NetworkACL": "NuageVsp", + "Connectivity": "NuageVsp", + "UserData": "VpcVirtualRouter" + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "perzone"}, + "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} + } + }, + # Services supported by the Nuage VSP plugin for VPCs "vpc_offering": { "name": 'Nuage VSP VPC offering', "displaytext": 'Nuage VSP VPC offering', @@ -1753,57 +1804,20 @@ test_data = { "Connectivity": "NuageVsp", "UserData": "VpcVirtualRouter" } - } - }, - - #_pr -_ passwordreset - below services used in test_nuage_password_reset - "network_offering_pr": { - "name": 'nuage_marvin', - "displaytext": 'nuage_marvin', - "guestiptype": 'Isolated', - "supportedservices": - 'Dhcp,SourceNat,Connectivity,StaticNat,UserData,Firewall', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList": { - "UserData": 'VirtualRouter', - "Dhcp": 'NuageVsp', - "Connectivity": 'NuageVsp', - "StaticNat": 'NuageVsp', - "SourceNat": 'NuageVsp', - "Firewall": 'NuageVsp' }, - }, - "network_pr": { - "name": "Test Network", - "displaytext": "Test Network", - "netmask": '255.255.255.0' - }, - "fw_rule_pr": { - "startport": 1, - "endport": 6000, - "cidr": '0.0.0.0/0', - # Any network (For creating FW rule) - "protocol": "TCP" - }, - "virtual_machine_pr": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'kvm', - # Hypervisor type should be same as - # hypervisor type of cluster - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - "userdata": "This is sample data", - }, - "template_pr": { - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "passwordenabled": True, - }, - "ostype_pr": 'CentOS 5.5 (64-bit)', - + "vpc_offering_lb": { + "name": 'Nuage VSP VPC offering with Lb', + "displaytext": 'Nuage VSP VPC offering with Lb', + "supportedservices": 'Dhcp,Lb,StaticNat,SourceNat,NetworkACL,Connectivity,UserData', + "serviceProviderList": { + "Dhcp": "NuageVsp", + "Lb": "InternalLbVm", + "StaticNat": "NuageVsp", + "SourceNat": "NuageVsp", + "NetworkACL": "NuageVsp", + "Connectivity": "NuageVsp", + "UserData": "VpcVirtualRouter" + } + } + } } diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py index e2f4a2c8644..4ceb7ace9da 100755 --- a/tools/marvin/marvin/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -4673,7 +4673,7 @@ class ApplicationLoadBalancer: @classmethod def create(cls, apiclient, services, name=None, sourceport=None, instanceport=22, algorithm="roundrobin", scheme="internal", - sourcenetworkid=None, networkid=None): + sourcenetworkid=None, networkid=None, sourceipaddress=None): """Create Application Load Balancer""" cmd = createLoadBalancer.createLoadBalancerCmd() @@ -4712,6 +4712,11 @@ class ApplicationLoadBalancer: elif networkid: cmd.networkid = networkid + if "sourceipaddress" in services: + cmd.sourceipaddress = services["sourceipaddress"] + elif sourceipaddress: + cmd.sourceipaddress = sourceipaddress + return LoadBalancerRule(apiclient.createLoadBalancer(cmd).__dict__) def delete(self, apiclient):