You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/06/20 03:17:53 UTC
[32/51] [abbrv] Split Redundant Router tests
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13e1f4fc/test/integration/component/test_redundant_router.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_redundant_router.py b/test/integration/component/test_redundant_router.py
index 814f3e2..5f7b1ca 100644
--- a/test/integration/component/test_redundant_router.py
+++ b/test/integration/component/test_redundant_router.py
@@ -15,8 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-from random import random
-import marvin
from nose.plugins.attrib import attr
from marvin.integration.lib.base import *
from marvin.integration.lib.utils import *
@@ -132,8 +130,6 @@ class Services:
},
"ostype": 'CentOS 5.3 (64-bit)',
"sleep": 60,
- "mode": 'advanced',
- # Networking mode, Advanced, Basic
}
@@ -221,6 +217,14 @@ class TestCreateRvRNetworkOffering(cloudstackTestCase):
1,
"List network off should have newly created network off"
)
+ for service in network_offs[0].service:
+ if service.name == 'SourceNat':
+ self.debug("Verifying SourceNat capabilites")
+ for capability in service.capability:
+ if capability.name == 'RedundantRouter':
+ self.assertTrue(capability.value=='true')
+ self.debug("RedundantRouter is enabled")
+
return
@@ -476,7 +480,7 @@ class TestCreateRvRNetworkNonDefaultGuestCidr(cloudstackTestCase):
@attr(tags=["advanced", "advancedns", "ssh"])
def test_createRvRNetwork(self):
- """Test create network with redundant routers
+ """Test create network with non-default guest cidr with redundant routers
"""
# Validate the following:
@@ -903,12 +907,12 @@ class TestRVRInternals(cloudstackTestCase):
return
-class TestRedundancy(cloudstackTestCase):
+class TestRvRRedundancy(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.api_client = super(
- TestRedundancy,
+ TestRvRRedundancy,
cls
).getClsTestClient().getApiClient()
cls.services = Services().services
@@ -1531,3799 +1535,3 @@ class TestRedundancy(cloudstackTestCase):
"Redundant state of the router should be BACKUP"
)
return
-
-
-class TestApplyAndDeleteNetworkRulesOnRvR(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestApplyAndDeleteNetworkRulesOnRvR,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self.cleanup = []
- self.cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_apply_and__delete_NetworkRulesOnRvR(self):
- """Test apply and delete network rules on redundant router
- """
-
- # Steps to validate
- # 1. listNetworks should show the created network in allocated state
- # 2. listRouters returns no running routers
- # 3. VMs should be deployed and in Running state
- # 4. should list MASTER and BACKUP routers
- # 5. listPublicIpAddresses for networkid should show acquired IP
- # 6. listRemoteAccessVpns for the network associated should show the
- # VPN created
- # 7. listRemoteAccessVpns for the network associated should return
- # empty response
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip.ipaddress.ipaddress,
- network.id
- ))
- self.debug("Enabling static NAT for IP: %s" %
- public_ip.ipaddress.ipaddress)
- try:
- static_nat = StaticNATRule.create(
- self.apiclient,
- self.services["fw_rule"],
- ipaddressid=public_ip.ipaddress.id
- )
- self.debug("Static NAT enabled for IP: %s" %
- public_ip.ipaddress.ipaddress)
- static_nat.enable(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- virtualmachineid=virtual_machine.id
- )
- except Exception as e:
- self.fail("Failed to enable static NAT on IP: %s - %s" % (
- public_ip.ipaddress.ipaddress, e))
-
- public_ips = PublicIPAddress.list(
- self.apiclient,
- networkid=network.id,
- listall=True,
- isstaticnat=True
- )
- self.assertEqual(
- isinstance(public_ips, list),
- True,
- "List public Ip for network should list the Ip addr"
- )
- self.assertEqual(
- public_ips[0].ipaddress,
- public_ip.ipaddress.ipaddress,
- "List public Ip for network should list the Ip addr"
- )
-
- self.debug("creating a FW rule on IP: %s" %
- public_ip.ipaddress.ipaddress)
- fw_rule = FireWallRule.create(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- protocol='TCP',
- cidrlist=[self.services["fw_rule"]["cidr"]],
- startport=self.services["fw_rule"]["startport"],
- endport=self.services["fw_rule"]["endport"]
- )
- self.debug("Created a firewall rule on 22 port of IP: %s" %
- public_ip.ipaddress.ipaddress)
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip.ipaddress.ipaddress)
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_2 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_2.ipaddress.ipaddress,
- network.id
- ))
-
- nat_rule = NATRule.create(
- self.apiclient,
- virtual_machine,
- self.services["natrule_221"],
- ipaddressid=public_ip_2.ipaddress.id,
- openfirewall=True
- )
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_2.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["natrule_221"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_3 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_3.ipaddress.ipaddress,
- network.id
- ))
-
- self.debug("Creating LB rule for IP address: %s" %
- public_ip_3.ipaddress.ipaddress)
-
- lb_rule = LoadBalancerRule.create(
- self.apiclient,
- self.services["lbrule"],
- ipaddressid=public_ip_3.ipaddress.id,
- accountid=self.account.name,
- networkid=network.id
- )
-
- self.debug("Adding %s to the LB rule %s" % (
- virtual_machine.name,
- lb_rule.name
- ))
- lb_rule.assign(self.apiclient, [virtual_machine])
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_3.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["lbrule"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
- return
-
-
-class TestEnableVPNOverRvR(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestEnableVPNOverRvR,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_enableVPNOverRvR(self):
- """Test redundant router internals
- """
-
- # Steps to validate
- # 1. listNetworks should show the created network in allocated state
- # 2. listRouters returns no running routers
- # 3. VMs should be deployed and in Running state
- # 4. should list MASTER and BACKUP routers
- # 5. listPublicIpAddresses for networkid should show acquired IP addr
- # 6. listRemoteAccessVpns for the network associated should show VPN
- # created
- # 7. listRemoteAccessVpns for the network associated should return
- # empty response
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip.ipaddress.ipaddress,
- network.id
- ))
-
- self.debug("Creating a remote access VPN for account: %s" %
- self.account.name)
-
- try:
- vpn = Vpn.create(
- self.apiclient,
- publicipid=public_ip.ipaddress.id,
- account=self.account.name,
- domainid=self.account.domainid
- )
- except Exception as e:
- self.fail("Failed to create VPN for account: %s - %s" % (
- self.account.name, e))
-
- try:
- vpnuser = VpnUser.create(
- self.apiclient,
- username="root",
- password="password",
- account=self.account.name,
- domainid=self.account.domainid
- )
- except Exception as e:
- self.fail("Failed to create VPN user: %s" % e)
-
- self.debug("Checking if the remote access VPN is created or not?")
- remote_vpns = Vpn.list(
- self.apiclient,
- account=self.account.name,
- domainid=self.account.domainid,
- publicipid=public_ip.ipaddress.id,
- listall=True
- )
- self.assertEqual(
- isinstance(remote_vpns, list),
- True,
- "List remote VPNs should not return empty response"
- )
- self.debug("Deleting the remote access VPN for account: %s" %
- self.account.name)
-
- try:
- vpn.delete(self.apiclient)
- except Exception as e:
- self.fail("Failed to delete VPN : %s" % e)
-
- self.debug("Checking if the remote access VPN is created or not?")
- remote_vpns = Vpn.list(
- self.apiclient,
- account=self.account.name,
- domainid=self.account.domainid,
- publicipid=public_ip.ipaddress.id,
- listall=True
- )
- self.assertEqual(
- remote_vpns,
- None,
- "List remote VPNs should not return empty response"
- )
- return
-
-
-class TestNetworkRulesMasterDownDeleteNetworkRules(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestNetworkRulesMasterDownDeleteNetworkRules,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_applyNetworkRules_MasterDown_deleteNetworkRules(self):
- """Test apply network rules when master down and delete network rules
- """
-
- # Steps to validate
- # 1. listNetworks should show the created network in allocated state
- # 2. listRouters returns no running routers
- # 3. VMs should be deployed and in Running state
- # 4. should list MASTER and BACKUP routers
- # 5. listPublicIpAddresses for networkid should show acquired IP addr
- # 6. listStaticNats for the network associated
- # 7. listFirewallRules should show allowed ports open
- # 8. ssh to succeed to the guestVM
- # 9. listPublicIpAddresses for networkid should show acquired IP addr
- # 10. listPortForwardRules to show open ports 221, 222
- # 11. ssh should succeed for both ports
- # 12. listPublicIpAddresses for networkid should show acquired IP addr
- # 13 and 14. listLoadBalancerRules should show associated VMs for
- # public IP
- # 15. ssh should succeed to the user VMs
- # 16. listRouters should show one Router in MASTER state and Running
- # 17. ssh should work for PF, FW, and LB ips
- # 18. listRouters should show both routers MASTER and BACKUP in
- # Running state
- # 19. listPortForwardingRules, listFirewallRules, listLoadBalancerRule
- # should return empty response
- # 20. listPublicIpAddresses should show now more addresses
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- if routers[0].redundantstate == 'MASTER':
- master_router = routers[0]
- backup_router = routers[1]
- else:
- master_router = routers[1]
- backup_router = routers[0]
-
- self.debug("Stopping router ID: %s" % master_router.id)
-
- try:
- Router.stop(self.apiclient, id=master_router.id)
- except Exception as e:
- self.fail("Failed to stop master router..")
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip.ipaddress.ipaddress,
- network.id
- ))
- self.debug("Enabling static NAT for IP: %s" %
- public_ip.ipaddress.ipaddress)
- try:
- static_nat = StaticNATRule.create(
- self.apiclient,
- self.services["fw_rule"],
- ipaddressid=public_ip.ipaddress.id
- )
- static_nat.enable(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- virtualmachineid=virtual_machine.id
- )
- self.debug("Static NAT enabled for IP: %s" %
- public_ip.ipaddress.ipaddress)
- except Exception as e:
- self.fail("Failed to enable static NAT on IP: %s - %s" % (
- public_ip.ipaddress.ipaddress, e))
-
- public_ips = PublicIPAddress.list(
- self.apiclient,
- networkid=network.id,
- listall=True,
- isstaticnat=True
- )
- self.assertEqual(
- isinstance(public_ips, list),
- True,
- "List public Ip for network should list the Ip addr"
- )
- self.assertEqual(
- public_ips[0].ipaddress,
- public_ip.ipaddress.ipaddress,
- "List public Ip for network should list the Ip addr"
- )
-
- self.debug("creating a FW rule on IP: %s" %
- public_ip.ipaddress.ipaddress)
- fw_rule = FireWallRule.create(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- protocol='TCP',
- cidrlist=[self.services["fw_rule"]["cidr"]],
- startport=self.services["fw_rule"]["startport"],
- endport=self.services["fw_rule"]["endport"]
- )
- self.debug("Created a firewall rule on 22 port of IP: %s" %
- public_ip.ipaddress.ipaddress)
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip.ipaddress.ipaddress)
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_2 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_2.ipaddress.ipaddress,
- network.id
- ))
-
- nat_rule = NATRule.create(
- self.apiclient,
- virtual_machine,
- self.services["natrule_221"],
- ipaddressid=public_ip_2.ipaddress.id,
- openfirewall=True
- )
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_2.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["natrule_221"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_3 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_3.ipaddress.ipaddress,
- network.id
- ))
-
- self.debug("Creating LB rule for IP address: %s" %
- public_ip_3.ipaddress.ipaddress)
-
- lb_rule = LoadBalancerRule.create(
- self.apiclient,
- self.services["lbrule"],
- ipaddressid=public_ip_3.ipaddress.id,
- accountid=self.account.name,
- networkid=network.id
- )
-
- self.debug("Adding %s to the LB rule %s" % (
- virtual_machine.name,
- lb_rule.name
- ))
- lb_rule.assign(self.apiclient, [virtual_machine])
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_3.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["lbrule"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Starting router ID: %s" % master_router.id)
-
- try:
- Router.start(self.apiclient, id=master_router.id)
- except Exception as e:
- self.fail("Failed to start master router..")
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
- for router in routers:
- self.assertEqual(
- router.state,
- "Running",
- "Router state should be running"
- )
- return
-
-
-class TestApplyDeleteNetworkRulesRebootRouter(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestApplyDeleteNetworkRulesRebootRouter,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._clean.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_applyNetworkRules_MasterDown_deleteNetworkRules(self):
- """Test apply network rules when master & backup routers rebooted
- """
-
- # Steps to validate
- # 1. listNetworks should show the created network in allocated state
- # 2. listRouters returns no running routers
- # 3. VMs should be deployed and in Running state
- # 4. should list MASTER and BACKUP routers
- # 5. listPublicIpAddresses for networkid should show acquired IP addr
- # 6. listStaticNats for the network associated
- # 7. listFirewallRules should show allowed ports open
- # 8. ssh to succeed to the guestVM
- # 9. listPublicIpAddresses for networkid should show acquired IP addr
- # 10. listPortForwardRules to show open ports 221, 222
- # 11. ssh should succeed for both ports
- # 12. listPublicIpAddresses for networkid should show acquired IP addr
- # 13 and 14. listLoadBalancerRules should show associated VMs for
- # public IP
- # 15. ssh should succeed to the user VMs
- # 16. listRouters should show one Router in MASTER state and Running
- # 17. ssh should work for PF, FW, and LB ips
- # 18. listRouters should show both routers MASTER and BACKUP in
- # Running state
- # 19. listPortForwardingRules, listFirewallRules, listLoadBalancerRule
- # should return empty response
- # 20. listPublicIpAddresses should show now more addresses
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- if routers[0].redundantstate == 'MASTER':
- master_router = routers[0]
- backup_router = routers[1]
- else:
- master_router = routers[1]
- backup_router = routers[0]
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip.ipaddress.ipaddress,
- network.id
- ))
- self.debug("Enabling static NAT for IP: %s" %
- public_ip.ipaddress.ipaddress)
- try:
- static_nat = StaticNATRule.create(
- self.apiclient,
- self.services["fw_rule"],
- ipaddressid=public_ip.ipaddress.id
- )
- static_nat.enable(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- virtualmachineid=virtual_machine.id
- )
- self.debug("Static NAT enabled for IP: %s" %
- public_ip.ipaddress.ipaddress)
- except Exception as e:
- self.fail("Failed to enable static NAT on IP: %s - %s" % (
- public_ip.ipaddress.ipaddress, e))
-
- public_ips = PublicIPAddress.list(
- self.apiclient,
- networkid=network.id,
- listall=True,
- isstaticnat=True
- )
- self.assertEqual(
- isinstance(public_ips, list),
- True,
- "List public Ip for network should list the Ip addr"
- )
- self.assertEqual(
- public_ips[0].ipaddress,
- public_ip.ipaddress.ipaddress,
- "List public Ip for network should list the Ip addr"
- )
-
- self.debug("creating a FW rule on IP: %s" %
- public_ip.ipaddress.ipaddress)
- fw_rule = FireWallRule.create(
- self.apiclient,
- ipaddressid=public_ip.ipaddress.id,
- protocol='TCP',
- cidrlist=[self.services["fw_rule"]["cidr"]],
- startport=self.services["fw_rule"]["startport"],
- endport=self.services["fw_rule"]["endport"]
- )
- self.debug("Created a firewall rule on 22 port of IP: %s" %
- public_ip.ipaddress.ipaddress)
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_2 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_2.ipaddress.ipaddress,
- network.id
- ))
-
- nat_rule = NATRule.create(
- self.apiclient,
- virtual_machine,
- self.services["natrule_221"],
- ipaddressid=public_ip_2.ipaddress.id,
- openfirewall=True
- )
-
- self.debug("Associating public IP for network: %s" % network.name)
- public_ip_3 = PublicIPAddress.create(
- self.apiclient,
- accountid=self.account.name,
- zoneid=self.zone.id,
- domainid=self.account.domainid,
- networkid=network.id
- )
- self.debug("Associated %s with network %s" % (
- public_ip_3.ipaddress.ipaddress,
- network.id
- ))
-
- self.debug("Creating LB rule for IP address: %s" %
- public_ip_3.ipaddress.ipaddress)
-
- lb_rule = LoadBalancerRule.create(
- self.apiclient,
- self.services["lbrule"],
- ipaddressid=public_ip_3.ipaddress.id,
- accountid=self.account.name,
- networkid=network.id
- )
-
- self.debug("Adding %s to the LB rule %s" % (
- virtual_machine.name,
- lb_rule.name
- ))
- lb_rule.assign(self.apiclient, [virtual_machine])
-
- self.debug("Starting router ID: %s" % master_router.id)
-
- for router in routers:
- try:
- self.debug("Rebooting router ID: %s" % master_router.id)
- #Stop the router
- cmd = rebootRouter.rebootRouterCmd()
- cmd.id = router.id
- self.apiclient.rebootRouter(cmd)
- except Exception as e:
- self.fail("Failed to reboot router..")
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
- for router in routers:
- self.assertEqual(
- router.state,
- "Running",
- "Router state should be running"
- )
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip.ipaddress.ipaddress)
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_2.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["natrule_221"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- self.debug("Trying to SSH into the virtual machine")
- try:
- virtual_machine.get_ssh_client(
- ipaddress=public_ip_3.ipaddress.ipaddress,
- reconnect=True,
- port=self.services["lbrule"]["publicport"]
- )
- self.debug("SSH to guest VM succeeded")
- except Exception as e:
- self.fail("SSH to guest VM failed: %s" % e)
-
- return
-
-
-class TestRestartRvRNetworkWithoutCleanup(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestRestartRvRNetworkWithoutCleanup,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_restartRvRNetwork_withoutCleanup(self):
- """Test apply rules after network restart
- """
-
- # Steps to validate
- # 1. createNetwork using network offering for redundant virtual router
- # 2. listRouters in above network
- # 3. deployVM in above user account in the created network
- # 4. restartNetwork cleanup=false
- # 5. listRouters in the account
- # 6. delete the account
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- if routers[0].redundantstate == 'MASTER':
- master_router = routers[0]
- backup_router = routers[1]
- else:
- master_router = routers[1]
- backup_router = routers[0]
-
- self.debug("restarting network with cleanup=False")
- try:
- network.restart(self.apiclient, cleanup=False)
- except Exception as e:
- self.fail("Failed to cleanup network - %s" % e)
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
- for router in routers:
- self.assertEqual(
- router.state,
- "Running",
- "Router state should be running"
- )
- self.assertIn(
- router.linklocalip,
- [master_router.linklocalip, backup_router.linklocalip],
- "Routers should have same linklocal IP after nw restart"
- )
- return
-
-
-class TestRestartRvRNetworkWithCleanup(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestRestartRvRNetworkWithCleanup,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_restartRvRNetwork_withCleanup(self):
- """Test Restart network with cleanup
- """
-
- # Steps to validate
- # 1. createNetwork using network offering for redundant virtual router
- # 2. listRouters in above network
- # 3. deployVM in above user account in the created network
- # 4. restartNetwork cleanup=false
- # 5. listRouters in the account
- # 6. delete the account
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- if routers[0].redundantstate == 'MASTER':
- master_router = routers[0]
- backup_router = routers[1]
- else:
- master_router = routers[1]
- backup_router = routers[0]
-
- self.debug("restarting network with cleanup=True")
- try:
- network.restart(self.apiclient, cleanup=True)
- except Exception as e:
- self.fail("Failed to cleanup network - %s" % e)
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
- for router in routers:
- self.assertEqual(
- router.state,
- "Running",
- "Router state should be running"
- )
- self.assertIn(
- router.linklocalip,
- [master_router.linklocalip, backup_router.linklocalip],
- "Routers should have same linklocal IP after nw restart"
- )
- return
-
-
-class TestDeleteRvRNetwork(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestDeleteRvRNetwork,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_restartRvRNetwork_withCleanup(self):
- """Test Restart network with cleanup
- """
-
- # Steps to validate
- # 1. createNetwork using network offering for redundant virtual router
- # 2. listRouters in above network
- # 3. deployVM in above user account in the created network
- # 4. restartNetwork cleanup=false
- # 5. listRouters in the account
- # 6. delete the account
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(networks, list),
- True,
- "List networks should return a valid response for created network"
- )
- nw_response = networks[0]
-
- self.debug("Network state: %s" % nw_response.state)
- self.assertEqual(
- nw_response.state,
- "Allocated",
- "The network should be in allocated state after creation"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- routers,
- None,
- "Routers should not be spawned when network is in allocated state"
- )
-
- self.debug("Deploying VM in account: %s" % self.account.name)
-
- # Spawn an instance in that network
- virtual_machine = VirtualMachine.create(
- self.apiclient,
- self.services["virtual_machine"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- serviceofferingid=self.service_offering.id,
- networkids=[str(network.id)]
- )
- self.debug("Deployed VM in network: %s" % network.id)
-
- vms = VirtualMachine.list(
- self.apiclient,
- id=virtual_machine.id,
- listall=True
- )
- self.assertEqual(
- isinstance(vms, list),
- True,
- "List Vms should return a valid list"
- )
- vm = vms[0]
- self.assertEqual(
- vm.state,
- "Running",
- "Vm should be in running state after deployment"
- )
-
- self.debug("Listing routers for network: %s" % network.name)
- routers = Router.list(
- self.apiclient,
- networkid=network.id,
- listall=True
- )
- self.assertEqual(
- isinstance(routers, list),
- True,
- "list router should return Master and backup routers"
- )
- self.assertEqual(
- len(routers),
- 2,
- "Length of the list router should be 2 (Backup & master)"
- )
-
- self.debug("Trying to delete the network with running Vms")
- with self.assertRaises(Exception):
- network.delete(self.apiclient, cleanup=True)
-
- self.debug("Network delete failed!")
- self.debug("Destroying the user VMs for account: %s" %
- self.account.name)
-
- try:
- virtual_machine.delete(self.apiclient)
- except Exception as e:
- self.fail("Failed to delete guest Vm from account: %s - %s" %
- (self.account.name, e))
-
- interval = list_configurations(
- self.apiclient,
- name='expunge.delay'
- )
- delay = int(interval[0].value)
- interval = list_configurations(
- self.apiclient,
- name='expunge.interval'
- )
- exp = int(interval[0].value)
-
- self.debug("Sleeping for exp delay + interval time")
- # Sleep to ensure that all resources are deleted
- time.sleep((delay + exp) * 2)
-
- self.debug("Trying to delete guest network for account: %s" %
- self.account.name)
- try:
- network.delete(self.apiclient)
- except Exception as e:
- self.fail("Failed to delete network: %s" % e)
- return
-
-
-class TestNetworkGCRvR(cloudstackTestCase):
-
- @classmethod
- def setUpClass(cls):
- cls.api_client = super(
- TestNetworkGCRvR,
- cls
- ).getClsTestClient().getApiClient()
- cls.services = Services().services
- # Get Zone, Domain and templates
- cls.domain = get_domain(cls.api_client, cls.services)
- cls.zone = get_zone(cls.api_client, cls.services)
- cls.template = get_template(
- cls.api_client,
- cls.zone.id,
- cls.services["ostype"]
- )
- 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.network_offering = NetworkOffering.create(
- cls.api_client,
- cls.services["network_offering"],
- conservemode=True
- )
- # Enable Network offering
- cls.network_offering.update(cls.api_client, state='Enabled')
-
- cls._cleanup = [
- cls.service_offering,
- cls.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.account = Account.create(
- self.apiclient,
- self.services["account"],
- admin=True,
- domainid=self.domain.id
- )
- self._cleanup.insert(0, self.account)
- return
-
- @attr(tags=["advanced", "advancedns", "ssh"])
- def test_networkGC_RvR(self):
- """Test network garbage collection with RVR
- """
-
- # Steps to validate
- # 1. createNetwork using network offering for redundant virtual router
- # 2. listRouters in above network
- # 3. deployVM in above user account in the created network
- # 4. stop the running user VM
- # 5. wait for network.gc time
- # 6. listRouters
- # 7. start the routers MASTER and BACK
- # 8. wait for network.gc time and listRouters
- # 9. delete the account
-
- # Creating network using the network offering created
- self.debug("Creating network with network offering: %s" %
- self.network_offering.id)
- network = Network.create(
- self.apiclient,
- self.services["network"],
- accountid=self.account.name,
- domainid=self.account.domainid,
- networkofferingid=self.network_offering.id,
- zoneid=self.zone.id
- )
- self.debug("Created network with ID: %s" % network.id)
-
- networks = Network.list(
- self.apiclient,
- id=netw
<TRUNCATED>