def test_02_reboot_router_after_creating_vpc(self): """ Test to reboot the router after creating a VPC """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Reboot the VPC Virtual Router which is created as a result of VPC creation. # Stop the VPC Router self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) routers = Router.list(self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "List Routers should return a valid list") router = routers[0] self.debug("Rebooting the router ...") # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.api_client.rebootRouter(cmd) # List routers to check state of router router_response = list_routers(self.api_client, id=router.id) self.assertEqual(isinstance(router_response, list), True, "Check list response returns a valid list") # List router should have router in running state and same public IP self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state") return
def reboot_Router(self): vm_network_id = self.virtual_machine.nic[0].networkid list_routers_response = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid, networkid=vm_network_id) self.assertEqual(isinstance(list_routers_response, list), True, "Check for list routers response return valid data") router = list_routers_response[0] #Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd) #List routers to check state of router router_response = list_routers(self.apiclient, id=router.id) self.assertEqual(isinstance(router_response, list), True, "Check list response returns a valid list") #List router should have router in running state and same public IP self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state")
def test_10_reboot_router_forced(self): """Test force reboot router """ list_router_response = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual(isinstance(list_router_response, list), True, "Check list response returns a valid list") router = list_router_response[0] public_ip = router.publicip self.debug("Force rebooting the router with ID: %s" % router.id) # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id cmd.forced = True self.apiclient.rebootRouter(cmd) # List routers to check state of router retries_cnt = 10 while retries_cnt >= 0: router_response = list_routers(self.apiclient, id=router.id) if self.verifyRouterResponse(router_response, public_ip): self.debug("Router is running successfully after force reboot") return time.sleep(10) retries_cnt = retries_cnt - 1 self.fail("Router response after force reboot is either invalid\ or router in stopped state") return
def test_02_reboot_router_after_addition_of_one_guest_network(self): """ Test reboot of router after addition of one guest network """ # Validations # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Add network1(10.1.1.1/24) to this VPC. # 3. Deploy vm1,vm2 and vm3 such that they are part of network1. # 4. Create a PF /Static Nat/LB rule for vms in network1. # 5. Create ingress network ACL for allowing all the above rules from a public ip range on network1. # 6. Create egress network ACL for network1 to access google.com. # 7. Create a private gateway for this VPC and add a static route to this gateway. # 8. Create a VPN gateway for this VPC and add a static route to this gateway. # 9. Make sure that all the PF,LB and Static NAT rules work as expected. # 10. Make sure that we are able to access google.com from all the user Vms. # 11. Make sure that the newly added private gateway's and VPN # gateway's static routes work as expected self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) self.assertEqual( isinstance(self.gateways, list), True, "List private gateways should return a valid response") self.assertEqual(isinstance(self.static_routes, list), True, "List static route should return a valid response") routers = Router.list(self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "List Routers should return a valid list") router = routers[0] self.debug("Rebooting the router ...") # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.api_client.rebootRouter(cmd) # List routers to check state of router router_response = list_routers(self.api_client, id=router.id) self.assertEqual(isinstance(router_response, list), True, "Check list response returns a valid list") # List router should have router in running state and same public IP self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state") return
def test_02_reboot_router_after_creating_vpc(self): """ Test to reboot the router after creating a VPC """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Reboot the VPC Virtual Router which is created as a result of VPC creation. # Stop the VPC Router self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) routers = Router.list( self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "List Routers should return a valid list" ) router = routers[0] self.debug("Rebooting the router ...") # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.api_client.rebootRouter(cmd) # List routers to check state of router router_response = list_routers( self.api_client, id=router.id ) self.assertEqual( isinstance(router_response, list), True, "Check list response returns a valid list" ) # List router should have router in running state and same public IP self.assertEqual( router_response[0].state, 'Running', "Check list router response for router state" ) return
def test_09_reboot_router(self): """Test reboot router """ # Validate the following # 1. listRouter should report the router for the account as stopped list_router_response = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(list_router_response, list), True, "Check list response returns a valid list" ) router = list_router_response[0] public_ip = router.publicip self.debug("Rebooting the router with ID: %s" % router.id) # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd) # List routers to check state of router retries_cnt = 6 while retries_cnt >= 0: router_response = list_routers( self.apiclient, id=router.id ) if self.verifyRouterResponse(router_response, public_ip): self.debug("Router is running successfully after reboot") return time.sleep(10) retries_cnt = retries_cnt - 1 self.fail( "Router response after reboot is either is invalid\ or in stopped state") return
def test_reboot_router(self): """Test for reboot router""" # Validate the Following # 1. Post restart PF and LB rules should still function # 2. verify if the ssh into the virtual machine # still works through the sourceNAT Ip # Retrieve router for the user account self.debug("Public IP: %s" % self.vm_1.ssh_ip) self.debug("Public IP: %s" % self.public_ip.ipaddress.ipaddress) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(routers, list), True, "Check list routers returns a valid list" ) router = routers[0] self.debug("Rebooting the router (ID: %s)" % router.id) cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd) # Poll listVM to ensure VM is stopped properly timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( self.apiclient, id=self.vm_1.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Running': self.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception( "Failed to start VM (ID: %s) in change service offering" % vm.id) timeout = timeout - 1 # we should be able to SSH after successful reboot try: self.debug("SSH into VM (ID : %s ) after reboot" % self.vm_1.id) SshClient( self.public_ip.ipaddress.ipaddress, self.services["natrule"]["publicport"], self.vm_1.username, self.vm_1.password ) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.public_ip.ipaddress.ipaddress, e)) return
def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self): """ Acquire IPs in multiple subnets in isolated networks with single VR # Steps # 1. Create network offering with single VR, and enable it # 2. create isolated network with the network offering # 3. create a vm in the network. # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP # 4. get a free public ip, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP and new ip # 5. remove the port forwarding rule, and release the new ip # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic IP, eth2 -> source nat IP # 6. create new public ip range 1 # 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1 # 8. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 2, # 9. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 2, new ip 3 # 10. release new ip 2 # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 3 # 11. release new ip 1 # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3 # 12. create new public ip range 2 # 13. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4 # 14. get a free ip 5 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/5 # 15. get a free ip 6 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/5/6 # 16. release new ip 5 # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/6 # 17. release new ip 4 # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 6 # 18. release new ip 3 # verify the available nics in VR should be "eth0,eth1,eth2,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth4 -> new ip 6 # 19. restart network # verify the available nics in VR should be "eth0,eth1,eth2,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth4 -> new ip 6 # 20. reboot router # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 # 21. restart network with cleanup # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 # 22. restart network with cleanup, makeredundant=true # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 """ # Create new domain1 self.domain1 = Domain.create(self.apiclient, services=self.services["acl"]["domain1"], parentdomainid=self.domain.id) # Create account1 self.account1 = Account.create(self.apiclient, self.services["acl"]["accountD1"], domainid=self.domain1.id) self.cleanup.append(self.account1) self.cleanup.append(self.domain1) # 1. Create network offering with single VR, and enable it self.network_offering = NetworkOffering.create( self.apiclient, self.services["isolated_network_offering"], ) self.network_offering.update(self.apiclient, state='Enabled') self.cleanup.append(self.network_offering) # 2. create isolated network with the network offering self.services["network"]["zoneid"] = self.zone.id self.services["network"]["networkoffering"] = self.network_offering.id self.network1 = Network.create(self.apiclient, self.services["network"], self.account1.name, self.account1.domainid) # 3. create a vm in the network. try: self.virtual_machine1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account1.name, domainid=self.account1.domainid, serviceofferingid=self.service_offering.id, templateid=self.template.id, zoneid=self.zone.id, networkids=self.network1.id) except Exception as e: self.fail("Exception while deploying virtual machine: %s" % e) # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_router_publicnic_state(router, host, "eth2") # 4. get a free public ip, assign to network, and create port forwarding rules (ssh) to the vm ipaddress = PublicIPAddress.create( self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ) nat_rule = NATRule.create(self.apiclient, self.virtual_machine1, self.services["natrule"], ipaddressid=ipaddress.ipaddress.id, openfirewall=True) # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP/new ip routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress.ipaddress.ipaddress, "eth2", True) self.verify_router_publicnic_state(router, host, "eth2") # 5. release the new ip ipaddress.delete(self.apiclient) # verify the available nics in VR should be "eth0,eth1,eth2" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress.ipaddress.ipaddress, "eth2", False) self.verify_router_publicnic_state(router, host, "eth2") # 6. create new public ip range 1 self.services["publiciprange"]["zoneid"] = self.zone.id self.services["publiciprange"]["forvirtualnetwork"] = "true" random_subnet_number = random.randrange(10, 50) self.services["publiciprange"]["vlan"] = get_free_vlan( self.apiclient, self.zone.id)[1] self.services["publiciprange"]["gateway"] = "172.16." + str( random_subnet_number) + ".1" self.services["publiciprange"]["startip"] = "172.16." + str( random_subnet_number) + ".2" self.services["publiciprange"]["endip"] = "172.16." + str( random_subnet_number) + ".10" self.services["publiciprange"]["netmask"] = "255.255.255.0" self.public_ip_range1 = PublicIpRange.create( self.apiclient, self.services["publiciprange"]) self.cleanup.append(self.public_ip_range1) # 7. get a free ip 4 in new ip range 2, assign to network, and enable static nat to vm ip_address_1 = self.get_free_ipaddress(self.public_ip_range1.vlan.id) ipaddress_1 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_1) StaticNATRule.enable(self.apiclient, virtualmachineid=self.virtual_machine1.id, ipaddressid=ipaddress_1.ipaddress.id, networkid=self.network1.id) # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1 routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 8. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 2, ip_address_2 = self.get_free_ipaddress(self.public_ip_range1.vlan.id) ipaddress_2 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_2) nat_rule = NATRule.create(self.apiclient, self.virtual_machine1, self.services["natrule"], ipaddressid=ipaddress_2.ipaddress.id, openfirewall=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 9. get a free ip in new ip range, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 2, new ip 3 ip_address_3 = self.get_free_ipaddress(self.public_ip_range1.vlan.id) ipaddress_3 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_3) nat_rule = NATRule.create(self.apiclient, self.virtual_machine1, self.services["natrule"], ipaddressid=ipaddress_3.ipaddress.id, openfirewall=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 10. release new ip 2 # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 1, new ip 3 ipaddress_2.delete(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 11. release new ip 1 # verify the available nics in VR should be "eth0,eth1,eth2,eth3" # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3 ipaddress_1.delete(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_1.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_2.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 12. create new public ip range 2 self.services["publiciprange"]["zoneid"] = self.zone.id self.services["publiciprange"]["forvirtualnetwork"] = "true" self.services["publiciprange"]["vlan"] = get_free_vlan( self.apiclient, self.zone.id)[1] self.services["publiciprange"]["gateway"] = "172.16." + str( random_subnet_number + 1) + ".1" self.services["publiciprange"]["startip"] = "172.16." + str( random_subnet_number + 1) + ".2" self.services["publiciprange"]["endip"] = "172.16." + str( random_subnet_number + 1) + ".10" self.services["publiciprange"]["netmask"] = "255.255.255.0" self.public_ip_range2 = PublicIpRange.create( self.apiclient, self.services["publiciprange"]) self.cleanup.append(self.public_ip_range2) # 13. get a free ip 4 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4 ip_address_4 = self.get_free_ipaddress(self.public_ip_range2.vlan.id) ipaddress_4 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_4) StaticNATRule.enable(self.apiclient, virtualmachineid=self.virtual_machine1.id, ipaddressid=ipaddress_4.ipaddress.id, networkid=self.network1.id) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router( router, host, "eth0,eth1,eth2,eth3,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4") # 14. get a free ip 5 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/5 ip_address_5 = self.get_free_ipaddress(self.public_ip_range2.vlan.id) ipaddress_5 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_5) nat_rule = NATRule.create(self.apiclient, self.virtual_machine1, self.services["natrule"], ipaddressid=ipaddress_5.ipaddress.id, openfirewall=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router( router, host, "eth0,eth1,eth2,eth3,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4") # 15. get a free ip 6 in new ip range 2, assign to network, and create port forwarding rules (ssh) to the vm # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/5/6 ip_address_6 = self.get_free_ipaddress(self.public_ip_range2.vlan.id) ipaddress_6 = PublicIPAddress.create(self.apiclient, zoneid=self.zone.id, networkid=self.network1.id, ipaddress=ip_address_6) nat_rule = NATRule.create(self.apiclient, self.virtual_machine1, self.services["natrule"], ipaddressid=ipaddress_6.ipaddress.id, openfirewall=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router( router, host, "eth0,eth1,eth2,eth3,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", True) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4") # 16. release new ip 5 # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 4/6 ipaddress_5.delete(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router( router, host, "eth0,eth1,eth2,eth3,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", True) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4") # 17. release new ip 4 # verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 3, eth4 -> new ip 6 ipaddress_4.delete(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router( router, host, "eth0,eth1,eth2,eth3,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_3.ipaddress.ipaddress, "eth3", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth3|eth4") # 18. release new ip 3 # verify the available nics in VR should be "eth0,eth1,eth2,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth4 -> new ip 6 ipaddress_3.delete(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth4") # 19. restart network # verify the available nics in VR should be "eth0,eth1,eth2,eth4," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth4 -> new ip 6 self.network1.restart(self.apiclient) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth4,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth4", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth4", True) self.verify_router_publicnic_state(router, host, "eth2|eth4") # 20. reboot router # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 if len(routers) > 0: router = routers[0] cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd) router = self.get_router(router.id) host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3") # 21. restart network with cleanup # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 self.network1.restart(self.apiclient, cleanup=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth3", True) # 22. restart network with cleanup, makeredundant=true # verify the available nics in VR should be "eth0,eth1,eth2,eth3," # verify the IPs in VR. eth0 -> guest nic, eth2 -> source nat IP, eth3 -> new ip 6 self.network1.restart(self.apiclient, cleanup=True, makeredundant=True) routers = self.get_routers(self.network1.id) for router in routers: host = self.get_router_host(router) self.verify_network_interfaces_in_router(router, host, "eth0,eth1,eth2,eth3,") guestIp, controlIp, sourcenatIp = self.get_router_ips(router) self.verify_ip_address_in_router(router, host, guestIp, "eth0", True) self.verify_ip_address_in_router(router, host, controlIp, "eth1", True) self.verify_ip_address_in_router(router, host, sourcenatIp, "eth2", True) self.verify_ip_address_in_router(router, host, ipaddress_4.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_5.ipaddress.ipaddress, "eth3", False) self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth3", True) self.verify_router_publicnic_state(router, host, "eth2|eth3")
def test_reboot_router(self): """Test for reboot router""" # Validate the Following # 1. Post restart PF and LB rules should still function # 2. verify if the ssh into the virtual machine # still works through the sourceNAT Ip # Retrieve router for the user account logger.debug("Public IP: %s" % self.vm_1.ssh_ip) logger.debug("Public IP: %s" % self.public_ip.ipaddress.ipaddress) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(routers, list), True, "Check list routers returns a valid list" ) router = routers[0] logger.debug("Rebooting the router (ID: %s)" % router.id) cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd) # Poll listVM to ensure VM is stopped properly timeout = self.services["timeout"] while True: time.sleep(self.services["sleep"]) # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( self.apiclient, id=self.vm_1.id ) if isinstance(list_vm_response, list): vm = list_vm_response[0] if vm.state == 'Running': logger.debug("VM state: %s" % vm.state) break if timeout == 0: raise Exception( "Failed to start VM (ID: %s) in change service offering" % vm.id) timeout = timeout - 1 # we should be able to SSH after successful reboot try: logger.debug("SSH into VM (ID : %s ) after reboot" % self.vm_1.id) SshClient( self.public_ip.ipaddress.ipaddress, self.services["natrule"]["publicport"], self.vm_1.username, self.vm_1.password, retries=5 ) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.public_ip.ipaddress.ipaddress, e)) return
def reboot_router(self, router): self.logger.debug('Rebooting router %s' % router.id) cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.apiclient.rebootRouter(cmd)
def test_02_reboot_router_after_addition_of_one_guest_network(self): """ Test reboot of router after addition of one guest network """ # Validations # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Add network1(10.1.1.1/24) to this VPC. # 3. Deploy vm1,vm2 and vm3 such that they are part of network1. # 4. Create a PF /Static Nat/LB rule for vms in network1. # 5. Create ingress network ACL for allowing all the above rules from a public ip range on network1. # 6. Create egress network ACL for network1 to access google.com. # 7. Create a private gateway for this VPC and add a static route to this gateway. # 8. Create a VPN gateway for this VPC and add a static route to this gateway. # 9. Make sure that all the PF,LB and Static NAT rules work as expected. # 10. Make sure that we are able to access google.com from all the user Vms. # 11. Make sure that the newly added private gateway's and VPN # gateway's static routes work as expected self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) self.assertEqual( isinstance(self.gateways, list), True, "List private gateways should return a valid response" ) self.assertEqual( isinstance(self.static_routes, list), True, "List static route should return a valid response" ) routers = Router.list( self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "List Routers should return a valid list" ) router = routers[0] self.debug("Rebooting the router ...") # Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id self.api_client.rebootRouter(cmd) # List routers to check state of router router_response = list_routers( self.api_client, id=router.id ) self.assertEqual( isinstance(router_response, list), True, "Check list response returns a valid list" ) # List router should have router in running state and same public IP self.assertEqual( router_response[0].state, 'Running', "Check list router response for router state" ) return