You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by gi...@apache.org on 2014/02/21 13:17:18 UTC
[1/3] CLOUDSTACK-2232: Adding automation test cases for Persistent
Networks feature
Repository: cloudstack
Updated Branches:
refs/heads/master 167babd8c -> 2091211c2
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2091211c/tools/marvin/marvin/config/config.cfg
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/config/config.cfg b/tools/marvin/marvin/config/config.cfg
index 7840b7c..356a291 100644
--- a/tools/marvin/marvin/config/config.cfg
+++ b/tools/marvin/marvin/config/config.cfg
@@ -140,12 +140,245 @@
"ingress_rule": {
"protocol": "TCP",
"startport": "22",
- "endport": "80",
+ "endport": "22",
"cidrlist": "0.0.0.0/0"
},
"ostype": "CentOS 5.3 (64-bit)",
"sleep": 90,
"timeout": 10,
+ "netscaler_VPX": {
+ "ipaddress": "10.223.240.174",
+ "username": "nsroot",
+ "password": "nsroot",
+ "networkdevicetype": "NetscalerVPXLoadBalancer",
+ "publicinterface": "1/1",
+ "privateinterface": "1/2",
+ "numretries": 2,
+ "lbdevicededicated": "True",
+ "lbdevicecapacity": 2,
+ "port": 22
+ },
+ "nw_offering_shared_persistent": {
+ "name": "Network offering for Shared Persistent Network",
+ "displaytext": "Network offering-DA services",
+ "guestiptype": "Shared",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "True",
+ "serviceProviderList": {
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Vpn": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "VirtualRouter",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ }
+ },
+ "nw_off_isolated_persistent": {
+ "name": "Network offering for Isolated Persistent Network",
+ "displaytext": "Network Offering for Isolated Persistent Network",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat",
+ "traffictype":"GUEST",
+ "availability":"Optional",
+ "ispersistent": "True",
+ "serviceProviderList": {
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Vpn": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "VirtualRouter",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ }
+ },
+ "nw_off_isolated_persistent_netscaler": {
+ "name": "Network offering for Isolated Persistent Network",
+ "displaytext": "Network Offering for Isolated Persistent Network",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "True",
+ "serviceProviderList": {
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Vpn": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "Netscaler",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ }
+ },
+ "nw_offering_isolated": {
+ "name": "Network offering for Isolated Persistent Network",
+ "displaytext": "Network offering-DA services",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "serviceProviderList": {
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Vpn": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "VirtualRouter",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ }
+ },
+ "nw_off_isolated_netscaler": {
+ "name": "Network offering for Isolated Persistent Network",
+ "displaytext": "Network offering-DA services",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "serviceProviderList": {
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Vpn": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "Netscaler",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ }
+ },
+ "nw_off_persistent_RVR": {
+ "name": "Network offering-RVR services",
+ "displaytext": "Network off-RVR services",
+ "guestiptype": "Isolated",
+ "supportedservices": "Vpn,Dhcp,Dns,SourceNat,PortForwarding,Firewall,Lb,UserData,StaticNat",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "True",
+ "serviceProviderList": {
+ "Vpn": "VirtualRouter",
+ "Dhcp": "VirtualRouter",
+ "Dns": "VirtualRouter",
+ "SourceNat": "VirtualRouter",
+ "PortForwarding": "VirtualRouter",
+ "Firewall": "VirtualRouter",
+ "Lb": "VirtualRouter",
+ "UserData": "VirtualRouter",
+ "StaticNat": "VirtualRouter"
+ },
+ "serviceCapabilityList": {
+ "SourceNat": {
+ "SupportedSourceNatTypes": "peraccount",
+ "RedundantRouter": "true"
+ },
+ "lb": {
+ "SupportedLbIsolation": "dedicated"
+ }
+ }
+ },
+ "nw_off_persistent_VPCVR_NoLB": {
+ "name": "Persistent Network VPC No LB",
+ "displaytext": "Persistent Network VPC No LB",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,UserData,StaticNat,NetworkACL",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "False",
+ "useVpc": "on",
+ "serviceProviderList": {
+ "Dhcp": "VpcVirtualRouter",
+ "Dns": "VpcVirtualRouter",
+ "SourceNat": "VpcVirtualRouter",
+ "PortForwarding": "VpcVirtualRouter",
+ "Vpn": "VpcVirtualRouter",
+ "UserData": "VpcVirtualRouter",
+ "StaticNat": "VpcVirtualRouter",
+ "NetworkACL": "VpcVirtualRouter"
+ }
+ },
+ "nw_off_persistent_VPCVR_LB": {
+ "name": "Persistent Network VPC with LB",
+ "displaytext": "Persistent Network VPC No LB",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat,NetworkACL",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "False",
+ "useVpc": "on",
+ "serviceProviderList": {
+ "Dhcp": "VpcVirtualRouter",
+ "Dns": "VpcVirtualRouter",
+ "SourceNat": "VpcVirtualRouter",
+ "PortForwarding": "VpcVirtualRouter",
+ "Vpn": "VpcVirtualRouter",
+ "Lb": "VpcVirtualRouter",
+ "UserData": "VpcVirtualRouter",
+ "StaticNat": "VpcVirtualRouter",
+ "NetworkACL": "VpcVirtualRouter"
+ }
+ },
+ "nw_offering_isolated_vpc": {
+ "name": "Isolated Network for VPC",
+ "displaytext": "Isolated Network for VPC",
+ "guestiptype": "Isolated",
+ "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,UserData,StaticNat,NetworkACL",
+ "traffictype": "GUEST",
+ "availability": "Optional",
+ "ispersistent": "False",
+ "useVpc": "on",
+ "serviceProviderList": {
+ "Dhcp": "VpcVirtualRouter",
+ "Dns": "VpcVirtualRouter",
+ "SourceNat": "VpcVirtualRouter",
+ "PortForwarding": "VpcVirtualRouter",
+ "Vpn": "VpcVirtualRouter",
+ "UserData": "VpcVirtualRouter",
+ "StaticNat": "VpcVirtualRouter",
+ "NetworkACL": "VpcVirtualRouter"
+ }
+ },
+ "natrule": {
+ "privateport": 22,
+ "publicport": 22,
+ "startport": 22,
+ "endport": 22,
+ "protocol": "TCP",
+ "cidrlist": "0.0.0.0/0"
+ },
+ "fwrule": {
+ "startport": 22,
+ "endport": 22,
+ "cidr": "0.0.0.0/0",
+ "protocol": "TCP"
+ },
+ "lbrule": {
+ "name": "SSH",
+ "alg": "leastconn",
+ # Algorithm used for load balancing
+ "privateport": 22,
+ "publicport": 22,
+ "openfirewall": "False",
+ "startport": 22,
+ "endport": 22,
+ "protocol": "TCP",
+ "cidrlist": "0.0.0.0/0"
+ },
+ "icmprule": {
+ "icmptype": -1,
+ "icmpcode": -1,
+ "cidrlist": "0.0.0.0/0",
+ "protocol": "ICMP"
+ },
+ "host_password": "password",
"advanced_sg": {
"zone": {
"name": "",
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2091211c/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 1d8229d..0a7ad94 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -131,6 +131,13 @@ class Account:
[setattr(cmd, k, v) for k, v in kwargs.items()]
return(apiclient.listAccounts(cmd))
+ def disable(self, apiclient, lock=False):
+ """Disable an account"""
+ cmd = disableAccount.disableAccountCmd()
+ cmd.id = self.id
+ cmd.lock = lock
+ apiclient.disableAccount(cmd)
+
class User:
""" User Life Cycle """
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2091211c/tools/marvin/marvin/integration/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/integration/lib/common.py
index 5b56c73..b2da3ff 100644
--- a/tools/marvin/marvin/integration/lib/common.py
+++ b/tools/marvin/marvin/integration/lib/common.py
@@ -64,7 +64,8 @@ from marvin.integration.lib.base import (Configurations,
PhysicalNetwork,
Host,
PublicIPAddress,
- NetworkOffering)
+ NetworkOffering,
+ Network)
from marvin.integration.lib.utils import (get_process_status,
xsplit,
validateList)
@@ -969,3 +970,13 @@ def shouldTestBeSkipped(networkType, zoneType):
and (zoneType.lower() == BASIC_ZONE)):
skipIt = True
return skipIt
+
+def verifyNetworkState(apiclient, networkid, state):
+ """List networks and check if the network state matches the given state"""
+ try:
+ networks = Network.list(apiclient, id=networkid)
+ except Exception as e:
+ raise Exception("Failed while fetching network list with error: %s" % e)
+ assert validateList(networks)[0] == PASS, "Networks list validation failed, list is %s" % networks
+ assert str(networks[0].state).lower() == state, "network state should be %s, it is %s" % (state, networks[0].state)
+ return
[3/3] git commit: updated refs/heads/master to 2091211
Posted by gi...@apache.org.
CLOUDSTACK-2232: Adding automation test cases for Persistent Networks feature
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2091211c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2091211c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2091211c
Branch: refs/heads/master
Commit: 2091211c2828dfd4b6e15eae9c459fbb09b9a27f
Parents: 167babd
Author: Ashutosh K <as...@clogeny.com>
Authored: Fri Feb 21 17:46:14 2014 +0530
Committer: Girish Shilamkar <gi...@clogeny.com>
Committed: Fri Feb 21 17:46:14 2014 +0530
----------------------------------------------------------------------
.../component/test_persistent_networks.py | 2045 ++++++++++++++++--
tools/marvin/marvin/config/config.cfg | 235 +-
tools/marvin/marvin/integration/lib/base.py | 7 +
tools/marvin/marvin/integration/lib/common.py | 13 +-
4 files changed, 2132 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
[2/3] CLOUDSTACK-2232: Adding automation test cases for Persistent
Networks feature
Posted by gi...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2091211c/test/integration/component/test_persistent_networks.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_persistent_networks.py b/test/integration/component/test_persistent_networks.py
index f61ccaa..8c1d54d 100644
--- a/test/integration/component/test_persistent_networks.py
+++ b/test/integration/component/test_persistent_networks.py
@@ -15,122 +15,60 @@
# specific language governing permissions and limitations
# under the License.
""" Tests for Persistent Networks without running VMs feature
-"""
-import marvin
-from marvin.cloudstackTestCase import *
-from marvin.cloudstackAPI import *
-from marvin.cloudstackException import cloudstackAPIException
-from marvin.integration.lib.utils import *
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import *
-import netaddr
-from nose.plugins.attrib import attr
+ Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Persistent+Networks+without+a+running+VM
-class Services(object):
- """Test Persistent Networks without running VMs
- """
- def __init__(self):
- self.services = {
- "account": {
- "email": "test@test.com",
- "firstname": "Test",
- "lastname": "User",
- "username": "test",
- # Random characters are appended for unique
- # username
- "password": "password",
- },
- "service_offering": {
- "name": "Tiny Instance ",
- "displaytext": "Tiny Instance",
- "cpunumber": 1,
- "cpuspeed": 200, # in MHz
- "memory": 256, # In MBs
- },
- "shared_persistent_network_offering": {
- "name": 'Network offering for Shared Persistent Network',
- "displaytext": 'Network offering-DA services',
- "guestiptype": 'Shared',
- "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat',
- "traffictype": 'GUEST',
- "availability": 'Optional',
- "ispersistent": 'True',
- "serviceProviderList": {
- "Dhcp": 'VirtualRouter',
- "Dns": 'VirtualRouter',
- "SourceNat": 'VirtualRouter',
- "PortForwarding": 'VirtualRouter',
- "Vpn": 'VirtualRouter',
- "Firewall": 'VirtualRouter',
- "Lb": 'VirtualRouter',
- "UserData": 'VirtualRouter',
- "StaticNat": 'VirtualRouter',
- },
- },
- "isolated_persistent_network_offering": {
- "name": 'Network offering for Isolated Persistent Network',
- "displaytext": 'Network offering-DA services',
- "guestiptype": 'Isolated',
- "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat',
- "traffictype": 'GUEST',
- "availability": 'Optional',
- "ispersistent": 'True',
- "serviceProviderList": {
- "Dhcp": 'VirtualRouter',
- "Dns": 'VirtualRouter',
- "SourceNat": 'VirtualRouter',
- "PortForwarding": 'VirtualRouter',
- "Vpn": 'VirtualRouter',
- "Firewall": 'VirtualRouter',
- "Lb": 'VirtualRouter',
- "UserData": 'VirtualRouter',
- "StaticNat": 'VirtualRouter',
- },
- },
- "isolated_network_offering": {
- "name": 'Network offering for Isolated Persistent Network',
- "displaytext": 'Network offering-DA services',
- "guestiptype": 'Isolated',
- "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat',
- "traffictype": 'GUEST',
- "availability": 'Optional',
- "serviceProviderList": {
- "Dhcp": 'VirtualRouter',
- "Dns": 'VirtualRouter',
- "SourceNat": 'VirtualRouter',
- "PortForwarding": 'VirtualRouter',
- "Vpn": 'VirtualRouter',
- "Firewall": 'VirtualRouter',
- "Lb": 'VirtualRouter',
- "UserData": 'VirtualRouter',
- "StaticNat": 'VirtualRouter',
- },
- },
- "isolated_network": {
- "name": "Isolated Network",
- "displaytext": "Isolated Network",
- },
- "virtual_machine": {
- "displayname": "Test VM",
- },
- "ostype": 'CentOS 5.3 (64-bit)',
- # Cent OS 5.3 (64 bit)
- "sleep": 90,
- "timeout": 10,
- "mode": 'advanced'
- }
+ Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-2232
+ Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/FS+-+Persistent+Networks
+"""
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.utils import (cleanup_resources,
+ validateList,
+ get_hypervisor_type)
+from marvin.integration.lib.base import (Account,
+ ServiceOffering,
+ NetworkOffering,
+ Network,
+ VirtualMachine,
+ PublicIPAddress,
+ FireWallRule,
+ Router,
+ Host,
+ NATRule,
+ Project,
+ LoadBalancerRule,
+ VpcOffering,
+ VPC,
+ Domain,
+ StaticNATRule,
+ NetworkACL)
+from marvin.integration.lib.common import (get_domain,
+ get_zone,
+ get_template,
+ wait_for_cleanup,
+ add_netscaler,
+ verifyNetworkState)
+from nose.plugins.attrib import attr
+from marvin.codes import PASS, FAIL
+from marvin.sshClient import SshClient
+from ddt import ddt, data
+import time
+@ddt
class TestPersistentNetworks(cloudstackTestCase):
"""Test Persistent Networks without running VMs
"""
@classmethod
def setUpClass(cls):
- cls.api_client = super(TestPersistentNetworks, cls).getClsTestClient().getApiClient()
- cls.services = Services().services
+ cloudstackTestClient = super(TestPersistentNetworks,cls).getClsTestClient()
+ cls.api_client = cloudstackTestClient.getApiClient()
+
+ # Fill services from the external config file
+ cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client, cls.services)
cls.zone = get_zone(cls.api_client, cls.services)
@@ -139,28 +77,39 @@ class TestPersistentNetworks(cloudstackTestCase):
cls.zone.id,
cls.services["ostype"]
)
- cls.services["domainid"] = cls.domain.id
- cls.services["zoneid"] = cls.zone.id
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
- cls.services["account"] = cls.account.name
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
- cls.isolated_persistent_network_offering = cls.create_network_offering("isolated_persistent_network_offering")
- cls.isolated_network = cls.create_isolated_network(cls.isolated_persistent_network_offering.id)
- cls.isolated_network_offering = cls.create_network_offering("isolated_network_offering")
+ cls.isolated_persistent_network_offering = cls.createNetworkOffering("nw_off_isolated_persistent")
+ cls.isolated_persistent_network_offering_netscaler = cls.createNetworkOffering("nw_off_isolated_persistent_netscaler")
+ cls.isolated_persistent_network_offering_RVR = cls.createNetworkOffering("nw_off_persistent_RVR")
+ cls.isolated_network_offering = cls.createNetworkOffering("isolated_network_offering")
+ cls.isolated_network_offering_netscaler = cls.createNetworkOffering("nw_off_isolated_netscaler")
+
+ # Configure Netscaler device
+ # If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
+ cls.ns_configured = False
+ try:
+ cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler_VPX"])
+ cls._cleanup.append(cls.netscaler)
+ cls.ns_configured = True
+ except Exception:
+ cls.ns_configured = False
# network will be deleted as part of account cleanup
cls._cleanup = [
- cls.account, cls.service_offering, cls.isolated_persistent_network_offering, cls.isolated_network_offering
+ cls.account, cls.service_offering, cls.isolated_persistent_network_offering, cls.isolated_network_offering,
+ cls.isolated_persistent_network_offering_RVR, cls.isolated_persistent_network_offering_netscaler,
+ cls.isolated_network_offering_netscaler
]
return
@@ -174,33 +123,76 @@ class TestPersistentNetworks(cloudstackTestCase):
return
@classmethod
- def create_network_offering(cls, network_offering_type):
+ def createNetworkOffering(cls, network_offering_type):
network_offering = NetworkOffering.create(
cls.api_client,
cls.services[network_offering_type],
conservemode=False
)
# Update network offering state from disabled to enabled.
- network_offering_update_response = NetworkOffering.update(
- network_offering,
- cls.api_client,
- id=network_offering.id,
- state="enabled"
- )
+ NetworkOffering.update(network_offering, cls.api_client, id=network_offering.id,
+ state="enabled")
return network_offering
- @classmethod
- def create_isolated_network(cls, network_offering_id):
- isolated_network = Network.create(
- cls.api_client,
- cls.services["isolated_network"],
- networkofferingid=network_offering_id,
- accountid=cls.account.name,
- domainid=cls.domain.id,
- zoneid=cls.zone.id
+ def checkRouterAccessibility(self, router):
+ """Check if router is accessible through its linklocalip"""
+
+ hypervisor = str(get_hypervisor_type(self.api_client))
+
+ if hypervisor.lower() == 'vmware':
+ #SSH is done via management server for Vmware
+ sourceip = self.api_client.connection.mgtSvr
+ else:
+ #For others, we will have to get the ipaddress of host connected to vm
+ hosts = Host.list(self.api_client,id=router.hostid)
+ self.assertEqual(validateList(hosts)[0], PASS, "hosts list validation failed, list is %s" % hosts)
+ host = hosts[0]
+ sourceip = host.ipaddress
+ # end else
+
+ try:
+ sshClient = SshClient(host=sourceip, port=22, user='root',passwd=self.services["host_password"])
+ res = sshClient.execute("ping -c 1 %s" % (
+ router.linklocalip
+ ))
+ self.debug("SSH result: %s" % res)
+ except Exception as e:
+ self.fail("SSH Access failed for %s: %s" % \
+ (sourceip, e)
+ )
+ result = str(res)
+ self.assertEqual(
+ result.count("1 received"),
+ 1,
+ "Ping to router should be successful"
)
- cls.debug("persistent isolated network is created: " + isolated_network.id)
- return isolated_network
+ return
+
+ def verifyVmExpungement(self, virtual_machine):
+ """verify if vm is expunged"""
+ isVmExpunged = False
+ try:
+ virtual_machine.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to delete VM: %s with error %s" % (virtual_machine.id, e))
+
+ # Verify if it is expunged
+ retriesCount = 20
+ while True:
+ vms = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+ # When vm is expunged, list will be None
+ if vms is None:
+ isVmExpunged = True
+ break
+ elif retriesCount == 0:
+ break
+ time.sleep(60)
+ retriesCount -= 1
+ # end while
+
+ if not isVmExpunged:
+ self.fail("Failed to expunge vm even after 20 minutes")
+ return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@@ -212,54 +204,49 @@ class TestPersistentNetworks(cloudstackTestCase):
try:
# Clean up, terminate the resources created
cleanup_resources(self.apiclient, self.cleanup)
+ self.cleanup[:] = []
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
- def create_virtual_machine(self, network_id=None):
- virtual_machine = VirtualMachine.create(self.apiclient,
- self.services["virtual_machine"],
- networkids=network_id,
- serviceofferingid=self.service_offering.id,
- accountid=self.account.name,
- domainid=self.domain.id
- )
- self.debug("Virtual Machine is created: " + virtual_machine.id)
- return virtual_machine
-
@attr(tags=["advanced"])
def test_network_state_after_destroying_vms(self):
# steps
- # 1. create virtual machine in network
- # 2. destroy created virtual machine
+ # 1. Create an isolated persistent network
+ # 2. Deploy virtual machine in network
+ # 3. destroy created virtual machine
#
# validation
# 1. Persistent network state should be implemented before VM creation and have some vlan assigned
# 2. virtual machine should be created successfully
# 3. Network state should be implemented even after destroying all vms in network
- self.assertEquals(self.isolated_network.state, u"Implemented", "network state of persistent is not implemented")
- self.assertIsNotNone(self.isolated_network.vlan, "vlan must not be null for persistent network")
+
+ # Creating isolated persistent network
+ network = Network.create(self.apiclient,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=self.account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.cleanup.append(network)
+ verifyNetworkState(self.apiclient, network.id, "implemented")
+ self.assertIsNotNone(network.vlan, "vlan must not be null for persistent network")
try:
- virtual_machine = self.create_virtual_machine(network_id=self.isolated_network.id)
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[network.id],serviceofferingid=self.service_offering.id,
+ accountid=self.account.name,domainid=self.domain.id)
virtual_machine.delete(self.apiclient)
except Exception as e:
- self.skipTest("vm creation/deletion fails")
+ self.fail("vm creation failed: %s" % e)
+
+ # Verify VM is expunged
+ self.verifyVmExpungement(virtual_machine)
# wait for time such that, network is cleaned up
# assuming that it will change its state to allocated after this much period
wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
-
- networks = Network.list(self.apiclient, id=self.isolated_network.id)
- self.assertEqual(
- isinstance(networks, list),
- True,
- "list Networks should return valid response"
- )
-
-
- self.assertEquals(networks[0].state, u"Implemented", "network state of persistent network after all vms are destroyed is not implemented")
+ verifyNetworkState(self.api_client, network.id, "implemented")
+ return
@attr(tags=["advanced"])
def test_shared_network_offering_with_persistent(self):
@@ -269,22 +256,1748 @@ class TestPersistentNetworks(cloudstackTestCase):
# validation
# 1. network offering should throw an exception
try:
- shared_persistent_network_offering = self.create_network_offering("shared_persistent_network_offering")
+ shared_persistent_network_offering = self.createNetworkOffering("nw_offering_shared_persistent")
shared_persistent_network_offering.delete(self.apiclient)
- self.fail("For shared network ispersistent must be False")
- except Exception as e:
+ self.fail("Shared network got created with ispersistent flag True in the offering, it should have failed")
+ except Exception:
pass
@attr(tags=["advanced"])
- def test_upgrade_network_offering_to_persistent(self):
+ def test_persistent_network_offering_with_VPCVR_services(self):
+ # steps
+ # 1. create network offering with persistent field enabled and all the services through VpcVirtualRouter
+ #
+ # validation
+ # 1. network offering should be created successfully
+ try:
+ persistent_network_offering_VPCVR = self.createNetworkOffering("nw_off_persistent_VPCVR_LB")
+ persistent_network_offering_VPCVR.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed creating persistent network offering with VPCVR services: %s" % e)
+
+ @attr(tags=["advanced"])
+ def test_list_persistent_network_offering(self):
+ # steps
+ # 1. create isolated network offering with ispersistent True
+ # 2. List network offerings by id and check ispersistent flag
+ #
+ # validation
+ # 1. ispersistent flag should list as True
+ network_offering = self.createNetworkOffering("nw_off_isolated_persistent")
+ self.cleanup.append(network_offering)
+ nw_offering_list = NetworkOffering.list(self.api_client, id=network_offering.id)
+ self.assertEqual(validateList(nw_offering_list)[0], PASS, "network offerings' list validation failed, list is %s" %
+ nw_offering_list)
+ self.assertEqual(nw_offering_list[0].ispersistent, True, "ispersistent flag should be true for the network offering")
+ return
+
+ @data("LB-VR","LB-NS")
+ @attr(tags=["advanced","advancedns"])
+ def test_upgrade_to_persistent_services_VR(self, value):
+
+ # This test is run against two networks (one with LB as virtual router and other one is LB with Netscaler)
+ # All other services through VR
+
+ # steps
+ # 1. create isolated network with network offering which has ispersistent field disabled
+ # 2. upgrade isolated network offering to network offering which has ispersistent field enabled
+ # 3. Deploy VM ,acquire IP, create Firewall, NAT rules
+ # 4. Verify the working of NAT, Firewall rules
+ # 5. Delete VM
+ # 6. Verify network state after network cleanup interval
+ #
+ # validation
+ # 1. update of network should happen successfully
+ # 2. NAT and Firewall rule should work as expected
+ # 3. After network clenaup interval, network state should be implemented and have some vlan assigned
+
+ # Set network offering as required (either LB through VR or LB through Netscaler)
+ networkOffering = self.isolated_network_offering
+
+ changecidr = False # This will be true in case of Netscaler case, you have to change cidr while updating network
+
+ # In case Netscaler is used for LB
+ if value == "LB-NS":
+ if self.ns_configured:
+ networkOffering = self.isolated_network_offering_netscaler
+ changecidr = True
+ else:
+ self.skipTest("Skipping - this test required netscaler configured in the network")
+
+ # Create Account
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ # create network with the appropriate offering (not persistent)
+ isolated_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=networkOffering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.api_client, isolated_network.id, "allocated")
+
+ # Update the network with persistent network offering
+ isolated_network.update(self.apiclient, networkofferingid=self.isolated_persistent_network_offering.id, changecidr=changecidr)
+
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_network.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ # Acquire public ip and open firewall for it
+ self.debug("Associating public IP for network: %s" % isolated_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+
+ # Create NAT rule
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=isolated_network.id)
+
+ # Check if SSH works
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ # Delete VM
+ virtual_machine.delete(self.api_client)
+
+ # Verify VM is expunged
+ self.verifyVmExpungement(virtual_machine)
+
+ # wait for time such that, network is cleaned up
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ # Check network state now, this will bolster that network updation has taken effect
+ verifyNetworkState(self.api_client, isolated_network.id, "implemented")
+ return
+
+ @attr(tags=["advanced"])
+ def test_upgrade_network_VR_to_PersistentRVR(self):
+ # steps
+ # 1. create isolated network with network offering which has ispersistent field disabled (services through VR)
+ # 2. upgrade isolated network offering to network offering which has ispersistent field enabled (with RVR)
+ # 3. Deploy VM ,acquire IP, create Firewall, NAT rules
+ # 4. Verify the working of NAT, Firewall rules
+ # 5. Delete VM
+ # 6. Verify network state after network cleanup interval
+ #
+ # validation
+ # 1. update of network should happen successfully
+ # 2. NAT and Firewall rule should work as expected
+ # 3. After network clenaup interval, network state should be implemented and have some vlan assigned
+
+ # Create Account and isolated network in it
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ isolated_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.api_client, isolated_network.id, "allocated")
+
+ # Update network with network offering which has RVR
+ isolated_network.update(self.apiclient, networkofferingid=self.isolated_persistent_network_offering_RVR.id)
+
+ # Deploy VM
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_network.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ # Acquire public IP and open firewall rule, create NAT rule
+ self.debug("Associating public IP for network: %s" % isolated_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=isolated_network.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ virtual_machine.delete(self.api_client)
+
+ # Verify VM is expunged
+ self.verifyVmExpungement(virtual_machine)
+
+ # wait for time such that, network is cleaned up
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ # Check network state now, this will bolster that network updation has taken effect
+ verifyNetworkState(self.api_client, isolated_network.id, "implemented")
+ return
+
+ @attr(tags=["advanced", "advancedns"])
+ def test_upgrade_network_NS_to_persistent_NS(self):
# steps
# 1. create isolated network with network offering which has ispersistent field disabled
+ # and LB service through Netscaler
# 2. upgrade isolated network offering to network offering which has ispersistent field enabled
+ # and LB service through Netscaler
+ # 3. Deploy VM ,acquire IP, create Firewall, NAT rules
+ # 4. Verify the working of NAT, Firewall rules
+ # 5. Delete VM
+ # 6. Verify network state after network cleanup interval
#
# validation
# 1. update of network should happen successfully
- # 2. network state should be implemented and have some vlan assigned
- isolated_network = self.create_isolated_network(self.isolated_network_offering.id)
- isolated_network_response = isolated_network.update(self.apiclient, networkofferingid=self.isolated_persistent_network_offering.id)
- self.assertEquals(self.isolated_network.state, u"Implemented", "network state of isolated network upgraded to persistent is not implemented")
- self.assertIsNotNone(self.isolated_network.vlan, "vlan must not be null isolated network upgraded to for persistent network")
+ # 2. NAT and Firewall rule should work as expected
+ # 3. After network clenaup interval, network state should be implemented and have some vlan assigned
+
+ # Skip test if Netscaler is not configured
+ if not self.ns_configured:
+ self.skipTest("Skipping - this test required netscaler configured in the network")
+
+ # Create Account and create isolated network in it
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ isolated_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_network_offering_netscaler.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.api_client, isolated_network.id, "allocated")
+
+ isolated_network.update(self.apiclient, networkofferingid=self.isolated_persistent_network_offering_netscaler.id, changecidr=True)
+
+ # Deploy VM
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_network.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % isolated_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=isolated_network.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ virtual_machine.delete(self.api_client)
+
+ # Verify VM is expunged
+ self.verifyVmExpungement(virtual_machine)
+
+ # wait for time such that, network is cleaned up
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ # Check network state now, this will bolster that network updation has taken effect
+ verifyNetworkState(self.api_client, isolated_network.id, "implemented")
+ return
+
+ @data("LB-VR","LB-Netscaler")
+ @attr(tags=["advanced", "advancedns"])
+ def test_pf_nat_rule_persistent_network(self, value):
+
+ # This test shall run with two scenarios, one with LB services through VR and other through LB service
+ # through Netscaler"""
+
+ # steps
+ # 1. create isolated network with network offering which has ispersistent field enabled
+ # and LB service through VR or Netscaler
+ # 2. Check routers belonging to network and verify that router is reachable through host using linklocalip
+ # 3. Deploy VM ,acquire IP, create Firewall, NAT rules
+ # 4. Verify the working of NAT, Firewall rules
+ #
+ # validation
+ # 1. Router should be reachable
+ # 2. NAT and Firewall rule should work as expected
+
+ # Set network offering according to data passed to test case
+ networkOffering = self.isolated_persistent_network_offering
+ if value == "LB-Netscaler":
+ if self.ns_configured:
+ networkOffering = self.isolated_persistent_network_offering_netscaler
+ else:
+ self.skipTest("Skipping - this test required netscaler configured in the network")
+
+ # Create account and network in it
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ isolated_persistent_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=networkOffering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(isolated_persistent_network.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % isolated_persistent_network.state)
+ self.assertIsNotNone(isolated_persistent_network.vlan, "vlan must not be null for persistent network")
+
+ # Check if router is assigned to the persistent network
+ routers = Router.list(self.api_client, account=account.name,
+ domainid=account.domainid,
+ networkid=isolated_persistent_network.id)
+
+ self.assertEqual(validateList(routers)[0], PASS, "Routers list validation failed, list is %s" % routers)
+ router = routers[0]
+
+ # Check if router if reachable from the host
+ self.checkRouterAccessibility(router)
+
+ # Deploy VM in the network
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_persistent_network.id],serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ # Acquire IP address, create Firewall, NAT rule
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=isolated_persistent_network.id)
+
+ # Check working of PF, NAT rules
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+ return
+
+ @attr(tags=["advanced"])
+ def test_persistent_network_with_RVR(self):
+ # steps
+ # 1. create account and isolated network with network offering which has ispersistent field enabled
+ # and supporting Redundant Virtual Router in it
+ # 2. Check the Master and Backup Routers are present
+ # 3. Deploy VM ,acquire IP, create Firewall, NAT rules
+ # 4. Verify the working of NAT, Firewall rules
+ #
+ # validation
+ # 1. Two routers should belong to the network amd they should be reachable from host
+ # 2. NAT and Firewall rule should work as expected
+
+ # Create account and create isolated persistent network with RVR in it
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ # Create isolated persistent network with RVR
+ isolated_persistent_network_RVR = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering_RVR.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(isolated_persistent_network_RVR.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % isolated_persistent_network_RVR.state)
+ self.assertIsNotNone(isolated_persistent_network_RVR.vlan, "vlan must not be null for persistent network")
+
+ # Check if two routers belong to the network
+ self.debug("Listing routers for network: %s" % isolated_persistent_network_RVR.name)
+ routers = Router.list(self.api_client, listall=True,
+ networkid=isolated_persistent_network_RVR.id)
+
+ self.assertEqual(validateList(routers)[0], PASS, "Routers list validation failed, list is %s" % routers)
+ self.assertEqual(len(routers), 2, "Length of the list router should be 2 (Backup & master)")
+
+ # Check if routers are reachable from the host
+ for router in routers:
+ self.checkRouterAccessibility(router)
+
+ # Deploy VM
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_persistent_network_RVR.id],serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ # Acquire public ip, create Firewall, NAT rule
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network_RVR.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network_RVR.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=isolated_persistent_network_RVR.id)
+
+ # Check if Firewall, NAT rule work as expected
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+ return
+
+ @attr(tags=["advanced"])
+ def test_vm_deployment_two_persistent_networks(self):
+ # steps
+ # 1. Deploy VM in two persistent networks
+ # 2. Check working of NAT, Firewall rules in both the networks
+ #
+ # validation
+ # 1. VM should be deployed successfully in two networks
+ # 2. All network rules should work as expected
+
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ isolated_persistent_network_1 = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(isolated_persistent_network_1.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % isolated_persistent_network_1.state)
+ self.assertIsNotNone(isolated_persistent_network_1.vlan, "vlan must not be null for persistent network")
+
+ isolated_persistent_network_2 = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(isolated_persistent_network_2.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % isolated_persistent_network_2.state)
+ self.assertIsNotNone(isolated_persistent_network_2.vlan, "vlan must not be null for persistent network")
+
+ self.debug("Listing routers for network: %s" % isolated_persistent_network_1.name)
+ routers_nw_1 = Router.list(self.api_client, listall=True,
+ networkid=isolated_persistent_network_1.id)
+
+ self.assertEqual(validateList(routers_nw_1)[0], PASS, "Routers list validation failed, list is %s" % routers_nw_1)
+
+ # Check if router is reachable from the host
+ for router in routers_nw_1:
+ self.checkRouterAccessibility(router)
+
+ self.debug("Listing routers for network: %s" % isolated_persistent_network_2.name)
+ routers_nw_2 = Router.list(self.api_client, listall=True,
+ networkid=isolated_persistent_network_2.id)
+
+ self.assertEqual(validateList(routers_nw_2)[0], PASS, "Routers list validation failed, list is %s" % routers_nw_2)
+
+ # Check if router is reachable from the host
+ for router in routers_nw_2:
+ self.checkRouterAccessibility(router)
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_persistent_network_1.id, isolated_persistent_network_2.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network_1.id)
+ ipaddress_nw_1 = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network_1.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress_nw_1.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network_2.id)
+ ipaddress_nw_2 = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network_2.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress_nw_2.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress_nw_1.ipaddress.id,
+ networkid=isolated_persistent_network_1.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress_nw_1.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress_nw_1.ipaddress.ipaddress))
+
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress_nw_2.ipaddress.id,
+ networkid=isolated_persistent_network_2.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress_nw_2.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress_nw_2.ipaddress.ipaddress))
+ return
+
+ @attr(tags=["advanced"])
+ def test_vm_deployment_persistent_and_non_persistent_networks(self):
+ # steps
+ # 1. create account and create two networks in it (persistent and non persistent)
+ # 2. Deploy virtual machine in these two networks
+ # 3. Associate ip address with both the accounts and create firewall,port forwarding rule
+ # 4. Try to SSH to VM through both the IPs
+ #
+ # validation
+ # 1. Both persistent and non persistent networks should be created
+ # 2. virtual machine should be created successfully
+ # 3. SSH should be successful through both the IPs
+
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ network_1 = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(network_1.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % network_1.state)
+ self.assertIsNotNone(network_1.vlan, "vlan must not be null for persistent network")
+
+ network_2 = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[network_1.id, network_2.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % network_1.id)
+ ipaddress_nw_1 = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=network_1.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress_nw_1.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress_nw_1.ipaddress.id,
+ networkid=network_1.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress_nw_1.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress_nw_1.ipaddress.ipaddress))
+
+ self.debug("Associating public IP for network: %s" % network_2.id)
+ ipaddress_nw_2 = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=network_2.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress_nw_2.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress_nw_2.ipaddress.id,
+ networkid=network_2.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress_nw_2.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress_nw_2.ipaddress.ipaddress))
+ return
+
+ @attr(tags=["advanced"])
+ def test_change_persistent_network_to_non_persistent(self):
+ # steps
+ # 1. Create a persistent network and deploy VM in it
+ # 2. Update network with non persistent network offering
+ # 3. Acquire IP, create NAT, firewall rules
+ # 4. Test NAT, Firewall rules
+ # 5. Delete VM
+ # 6. Check the network state after network clenaup interval
+ #
+ # validation
+ # 1. Network updation should be successful
+ # 2. Network rules should work as expected
+ # 3. Network state should be allocated after network cleanup interval
+
+ # Create account and create persistent network in it
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+ network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ self.assertEqual(str(network.state).lower(), "implemented", "network state should be implemented, it is %s" \
+ % network.state)
+ self.assertIsNotNone(network.vlan, "vlan must not be null for persistent network")
+
+ # Update network with non persistent network offering
+ network.update(self.apiclient, networkofferingid=self.isolated_network_offering.id)
+
+ # Deploy VM, acquire IP, create NAT, firewall rules
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[network.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=network.id)
+
+ # Verify working of network rules
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ # Delete VM
+ virtual_machine.delete(self.api_client)
+
+ # Verify VM is expunged
+ self.verifyVmExpungement(virtual_machine)
+
+ # wait for time such that, network is cleaned up
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ # Check network state now, this will bolster that network updation has taken effect
+ verifyNetworkState(self.api_client, network.id, "allocated")
+ return
+
+ @attr(tags=["advanced"])
+ def test_delete_account(self):
+ # steps
+ # 1. create persistent network and deploy VM in it
+ # 2. Deploy VM in it and acquire IP address, create NAT, firewall rules
+ # 3. Delete the account in which network is created
+ #
+ # validation
+ # 1. Persistent network state should be implemented before VM creation and have some vlan assigned
+ # 2. Network rules should work as expected
+ # 3. Network and IPs should be freed after account is deleted
+
+ account = Account.create(self.api_client, self.services["account"],domainid=self.domain.id)
+ network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[network.id],serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+ self.debug("Associating public IP for network: %s" % network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+ NATRule.create(self.api_client, virtual_machine,
+ self.services["natrule"],ipaddressid=ipaddress.ipaddress.id,
+ networkid=network.id)
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ # Delete the account
+ account.delete(self.api_client)
+
+ # Verify the resources belonging to account have been cleaned up
+ networks = Network.list(self.apiclient, id=network.id)
+ self.assertEqual(validateList(networks)[0], FAIL, "network list should be enmpty, it is %s" % networks)
+
+ public_ips = PublicIPAddress.list(self.apiclient, id=ipaddress.ipaddress.id)
+ self.assertEqual(validateList(public_ips)[0], FAIL, "Public Ip list be empty, it is %s" % public_ips)
+
+ return
+
+@ddt
+class TestAssignVirtualMachine(cloudstackTestCase):
+ """Test Persistent Network creation with assigning VM to different account/domain
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cloudstackTestClient = super(TestAssignVirtualMachine,cls).getClsTestClient()
+ cls.api_client = cloudstackTestClient.getApiClient()
+
+ # Fill services from the external config file
+ cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.isolated_persistent_network_offering = cls.createNetworkOffering("nw_off_isolated_persistent")
+ cls.isolated_persistent_network_offering_RVR = cls.createNetworkOffering("nw_off_persistent_RVR")
+ cls.persistent_network_offering_netscaler = cls.createNetworkOffering("nw_off_isolated_persistent_netscaler")
+
+ # Configure Netscaler device
+ # If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
+ cls.ns_configured = False
+ try:
+ cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler_VPX"])
+ cls._cleanup.append(cls.netscaler)
+ cls.ns_configured = True
+ except Exception:
+ cls.ns_configured = False
+
+
+ # network will be deleted as part of account cleanup
+ cls._cleanup = [
+ cls.service_offering, cls.isolated_persistent_network_offering,
+ cls.isolated_persistent_network_offering_RVR,
+ cls.persistent_network_offering_netscaler
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Cleanup resources used
+ cleanup_resources(cls.api_client, cls._cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @classmethod
+ def createNetworkOffering(cls, network_offering_type):
+ network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services[network_offering_type],
+ conservemode=False
+ )
+ # Update network offering state from disabled to enabled.
+ NetworkOffering.update(network_offering, cls.api_client, id=network_offering.id,
+ state="enabled")
+ return network_offering
+
+ def setUp(self):
+ self.apiclient = self.testClient.getApiClient()
+ self.dbclient = self.testClient.getDbConnection()
+ self.cleanup = [ ]
+ return
+
+ def tearDown(self):
+ try:
+ # Clean up, terminate the resources created
+ cleanup_resources(self.apiclient, self.cleanup)
+ self.cleanup[:] = []
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @data("VR","RVR","LB-NS")
+ @attr(tags=["advanced", "advancedns"])
+ def test_assign_vm_different_account_VR(self, value):
+
+ # This test shall be run with three types of persistent networks
+ # a) All services through VR
+ # b) LB service through Netscaler
+ # c) with Redundant Virtual Router facility
+
+ # steps
+ # 1. create two accounts (account1 and account2)
+ # 2. Create a persistent network (with VR/RVR/Netscaler-LB with VR services) in account1 and deploy VM in it with this network
+ # 3. Stop the VM and assign the VM to account2
+ #
+ # validation
+ # 1. Assign VM operation should be successful
+ # 2. New network should be created in the other account
+
+ # Create Accounts
+ account_1 = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account_1)
+
+ account_2 = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account_2)
+
+ # Set the network offering according to the test scenario (data passed to the test case
+ if value == "VR":
+ network_offering = self.isolated_persistent_network_offering
+ elif value == "RVR":
+ network_offering = self.isolated_persistent_network_offering_RVR
+ elif value == "LB-NS":
+ if self.ns_configured:
+ network_offering = self.persistent_network_offering_netscaler
+ else:
+ self.skipTest("This test requires netscaler to be configured in the network")
+
+ network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=network_offering.id,
+ accountid=account_1.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.api_client, network.id, "implemented")
+ self.assertIsNotNone(network.vlan, "vlan must not be null for persistent network")
+
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[network.id],
+ serviceofferingid=self.service_offering.id,
+ accountid=account_1.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ virtual_machine.stop(self.apiclient)
+
+ vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id)
+ self.assertEqual(validateList(vms)[0], PASS, "vm list validation failed, vm list is %s" % vms)
+ self.assertEqual(str(vms[0].state).lower(), "stopped", "vm state should be stopped, it is %s" % vms[0].state)
+
+ # Assign virtual machine to different account
+ virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
+
+ # Start VM
+ virtual_machine.start(self.apiclient)
+
+ # Verify that new network is created in other account
+ networks = Network.list(self.apiclient, account=account_2.name, domainid = account_2.domainid)
+ self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+ return
+
+@ddt
+class TestProjectAccountOperations(cloudstackTestCase):
+ """Test suspend/disable/lock account/project operations when they have persistent network
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cloudstackTestClient = super(TestProjectAccountOperations,cls).getClsTestClient()
+ cls.api_client = cloudstackTestClient.getApiClient()
+
+ # Fill services from the external config file
+ cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.isolated_persistent_network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["nw_off_isolated_persistent"],
+ conservemode=False
+ )
+ # Update network offering state from disabled to enabled.
+ cls.isolated_persistent_network_offering.update(cls.api_client, state="enabled")
+
+ # network will be deleted as part of account cleanup
+ cls._cleanup = [
+ cls.service_offering, cls.isolated_persistent_network_offering
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Cleanup resources used
+ cleanup_resources(cls.api_client, cls._cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ def setUp(self):
+ self.apiclient = self.testClient.getApiClient()
+ self.dbclient = self.testClient.getDbConnection()
+ self.cleanup = [ ]
+ return
+
+ def tearDown(self):
+ try:
+ # Clean up, terminate the resources created
+ cleanup_resources(self.apiclient, self.cleanup)
+ self.cleanup[:] = []
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @data("locked","disabled")
+ @attr(tags=["advanced"])
+ def test_account_operations(self, value):
+ # steps
+ # 1. create account and create persistent network in it
+ # 2. Disable/lock the account
+ #
+ # validation
+ # 3. Wait for network cleanup interval and verify that network is not cleaned up and it is still in
+ # implemented state
+
+ account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.api_client, network.id, "implemented")
+ self.assertIsNotNone(network.vlan, "vlan must not be null for persistent network")
+
+ if value == "disabled":
+ account.disable(self.apiclient)
+ elif value == "locked":
+ account.disable(self.apiclient, lock=True)
+
+ accounts = Account.list(self.apiclient, id=account.id)
+ self.assertEqual(validateList(accounts)[0], PASS, "accounts list validation failed, list id %s" % accounts)
+ self.assertEqual(str(accounts[0].state).lower(), value, "account state should be %s, it is %s" % (value, accounts[0].state))
+
+ # Wait for network cleanup interval
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ networks = Network.list(self.apiclient, account=account.name, domainid = account.domainid)
+ self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+
+ verifyNetworkState(self.api_client, networks[0].id, "implemented")
+ self.assertIsNotNone(networks[0].vlan, "vlan must not be null for persistent network")
+ return
+
+ @attr(tags=["advanced"])
+ def test_project_operations(self):
+ # steps
+ # 1. create account and create persistent network in it
+ # 2. Add account to project
+ # 3. Suspend the project
+ #
+ # validation
+ # 1. Verify that account has been added to the project
+ # 2. Wait for network cleanup interval and verify that network is not cleaned up and it is still in
+ # implemented state
+
+ # Create Account
+ account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ # Create Project
+ project = Project.create(self.apiclient, self.services["project"])
+ self.cleanup.append(project)
+
+ network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+
+ # Add account to the project
+ project.addAccount(self.apiclient, account = account.name)
+
+ # Verify the account name in the list of accounts belonging to the project
+ projectAccounts = Project.listAccounts(self.apiclient, projectid = project.id)
+ self.assertEqual(validateList(projectAccounts)[0], PASS, "project accounts list validation failed, list is %s" % projectAccounts)
+
+ accountNames = [projectAccount.account for projectAccount in projectAccounts]
+ self.assertTrue(account.name in accountNames, "account %s is not present in account list %s of project %s" %
+ (account.name, accountNames, project.id))
+
+ # Suspend Project
+ project.suspend(self.apiclient)
+
+ # Verify the project is suspended
+ projects = Project.list(self.apiclient, id=project.id)
+ self.assertEqual(validateList(projects)[0], PASS, "projects list validation failed, list is %s" % projects)
+ self.assertEqual(str(projects[0].state).lower(), "suspended", "project state should be suspended, it is %s" % projects[0].state)
+
+ # Wait for network cleanup interval
+ wait_for_cleanup(self.api_client, ["network.gc.interval", "network.gc.wait"])
+
+ verifyNetworkState(self.apiclient, network.id, "implemented")
+ return
+
+@ddt
+class TestRestartPersistentNetwork(cloudstackTestCase):
+ """Test restart persistent network with cleanup parameter true and false
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cloudstackTestClient = super(TestRestartPersistentNetwork,cls).getClsTestClient()
+ cls.api_client = cloudstackTestClient.getApiClient()
+
+ # Fill services from the external config file
+ cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.isolated_persistent_network_offering = NetworkOffering.create(cls.api_client,
+ cls.services["nw_off_isolated_persistent"],
+ conservemode=False)
+
+ cls.isolated_persistent_network_offering_netscaler = NetworkOffering.create(cls.api_client,
+ cls.services["nw_off_isolated_persistent_netscaler"],
+ conservemode=False)
+ # Update network offering state from disabled to enabled.
+ cls.isolated_persistent_network_offering.update(cls.api_client, state="enabled")
+ cls.isolated_persistent_network_offering_netscaler.update(cls.api_client, state="enabled")
+
+
+ # Configure Netscaler device
+ # If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
+ cls.ns_configured = False
+ try:
+ cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler_VPX"])
+ cls._cleanup.append(cls.netscaler)
+ cls.ns_configured = True
+ except Exception:
+ cls.ns_configured = False
+
+ # network will be deleted as part of account cleanup
+ cls._cleanup = [
+ cls.service_offering, cls.isolated_persistent_network_offering,
+ cls.isolated_persistent_network_offering_netscaler
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ # Cleanup resources used
+ cleanup_resources(cls.api_client, cls._cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ def setUp(self):
+ self.apiclient = self.testClient.getApiClient()
+ self.dbclient = self.testClient.getDbConnection()
+ self.cleanup = [ ]
+ return
+
+ def tearDown(self):
+ try:
+ # Clean up, terminate the resources created
+ cleanup_resources(self.apiclient, self.cleanup)
+ self.cleanup[:] = []
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ def checkRouterAccessibility(self, router):
+ """Check if router is accessible through its linklocalip"""
+
+ hypervisor = str(get_hypervisor_type(self.api_client))
+
+ if hypervisor.lower() == 'vmware':
+ #SSH is done via management server for Vmware
+ sourceip = self.api_client.connection.mgtSvr
+ else:
+ #For others, we will have to get the ipaddress of host connected to vm
+ hosts = Host.list(self.api_client,id=router.hostid)
+ self.assertEqual(validateList(hosts)[0], PASS, "hosts list validation failed, list is %s" % hosts)
+ host = hosts[0]
+ sourceip = host.ipaddress
+ # end else
+
+ try:
+ sshClient = SshClient(host=sourceip, port=22, user='root',passwd=self.services["host_password"])
+ res = sshClient.execute("ping -c 1 %s" % (
+ router.linklocalip
+ ))
+ except Exception as e:
+ self.fail("SSH Access failed for %s: %s" % \
+ (sourceip, e)
+ )
+ result = str(res)
+ self.assertEqual(
+ result.count("1 received"),
+ 1,
+ "ping to router should be successful"
+ )
+ return
+
+ @data("true","false")
+ @attr(tags=["advanced"])
+ def test_cleanup_persistent_network(self, value):
+ # steps
+ # 1. Create account and create persistent network in it
+ # 2. Verify that router is reachable from the host
+ # 3. Acquire public IP, open firewall and create LB rule
+ # 4. Restart the network with clenup parameter true/false
+ # 5. Check network state after restart, it should be implemented
+ # 6. Deploy VM, assign LB rule to it, and verify the LB rule
+
+ account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ isolated_persistent_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.apiclient, isolated_persistent_network.id, "implemented")
+ self.assertIsNotNone(isolated_persistent_network.vlan, "vlan must not be null for persistent network")
+
+ self.debug("Listing routers for network: %s" % isolated_persistent_network.name)
+ routers = Router.list(self.api_client, listall=True,
+ networkid=isolated_persistent_network.id)
+
+ self.assertEqual(validateList(routers)[0], PASS, "Routers list validation failed, list is %s" % routers)
+
+ # Check if router is reachable from the host
+ for router in routers:
+ self.checkRouterAccessibility(router)
+
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network.id)
+
+ FireWallRule.create(self.apiclient,ipaddressid=ipaddress.ipaddress.id,
+ protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
+ startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])
+
+ # Create LB Rule
+ lb_rule = LoadBalancerRule.create(self.apiclient,self.services["lbrule"],
+ ipaddressid=ipaddress.ipaddress.id, accountid=account.name,
+ networkid=isolated_persistent_network.id, domainid=account.domainid)
+
+ # Restart Network
+ isolated_persistent_network.restart(self.apiclient, cleanup=value)
+
+ # List networks
+ networks = Network.list(self.apiclient, account=account.name, domainid = account.domainid)
+ self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+
+ verifyNetworkState(self.apiclient, networks[0].id, "implemented")
+ self.assertIsNotNone(networks[0].vlan, "vlan must not be null for persistent network")
+
+ # Deploy VM
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_persistent_network.id],serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ lb_rule.assign(self.api_client, [virtual_machine])
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ return
+
+ @data("true","false")
+ @attr(tags=["advanced", "advancedns"])
+ def test_cleanup_persistent_network_lb_netscaler(self, value):
+ # steps
+ # 1. Create account and create persistent network in it with LB service provided by netscaler
+ # 2. Verify that router is reachable from the host
+ # 3. Acquire public IP, open firewall and create LB rule
+ # 4. Restart the network with clenup parameter true/false
+ # 5. Check network state after restart, it should be implemented
+ # 6. Deploy VM, assign LB rule to it, and verify the LB rule
+
+ if not self.ns_configured:
+ self.skipTest("This test required netscaler to be configured in the network")
+
+ account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
+ self.cleanup.append(account)
+
+ isolated_persistent_network = Network.create(self.api_client,self.services["isolated_network"],
+ networkofferingid=self.isolated_persistent_network_offering_netscaler.id,
+ accountid=account.name,domainid=self.domain.id,
+ zoneid=self.zone.id)
+ verifyNetworkState(self.apiclient, isolated_persistent_network.id, "implemented")
+ self.assertIsNotNone(isolated_persistent_network.vlan, "vlan must not be null for persistent network")
+
+ self.debug("Listing routers for network: %s" % isolated_persistent_network.name)
+ routers = Router.list(self.api_client, listall=True,
+ networkid=isolated_persistent_network.id)
+
+ self.assertEqual(validateList(routers)[0], PASS, "Routers list validation failed, list is %s" % routers)
+
+ # Check if router is reachable from the host
+ for router in routers:
+ self.checkRouterAccessibility(router)
+
+ self.debug("Associating public IP for network: %s" % isolated_persistent_network.id)
+ ipaddress = PublicIPAddress.create(self.api_client,accountid=account.name,
+ zoneid=self.zone.id,domainid=account.domainid,
+ networkid=isolated_persistent_network.id)
+
+ # Create LB Rule
+ lb_rule = LoadBalancerRule.create(self.apiclient,self.services["lbrule"],
+ ipaddressid=ipaddress.ipaddress.id, accountid=account.name,
+ networkid=isolated_persistent_network.id, domainid=account.domainid)
+
+ # Restart Network
+ isolated_persistent_network.restart(self.apiclient, cleanup=value)
+
+ # List networks
+ networks = Network.list(self.apiclient, account=account.name, domainid = account.domainid)
+ self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
+
+ verifyNetworkState(self.apiclient, networks[0].id, "implemented")
+ self.assertIsNotNone(networks[0].vlan, "vlan must not be null for persistent network")
+
+ # Deploy VM
+ try:
+ virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
+ networkids=[isolated_persistent_network.id],serviceofferingid=self.service_offering.id,
+ accountid=account.name,domainid=self.domain.id)
+ except Exception as e:
+ self.fail("vm creation failed: %s" % e)
+
+ lb_rule.assign(self.api_client, [virtual_machine])
+
+ try:
+ virtual_machine.get_ssh_client(ipaddress=ipaddress.ipaddress.ipaddress)
+ except Exception as e:
+ self.fail("Exception while SSHing to VM %s with IP %s" % (virtual_machine.id, ipaddress.ipaddress.ipaddress))
+
+ return
+
+@ddt
+class TestVPCNetworkOperations(cloudstackTestCase):
+ """Test VPC network operations consisting persistent networks
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ cloudstackTestClient = super(TestVPCNetworkOperations,cls).getClsTestClient()
+ cls.api_client = cloudstackTestC
<TRUNCATED>