def test_08_start_router(self): """Test start 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] self.debug("Starting the router with ID: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(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 self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state") return
def start_routers(self): self.check_routers_state(showall=True) self.logger.debug('Starting stopped routers') for router in self.routers: self.logger.debug('Router %s has state %s' % (router.id, router.state)) if router.state == "Stopped": self.logger.debug('Starting stopped router %s' % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd)
def test_01_stop_start_router_after_creating_vpc(self): """ Test to stop and start router after creation of VPC """ # Validate following: # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Stop the VPC Virtual Router which is created as a result of VPC creation. # 3. Start the Stopped VPC Virtual Router self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) # Stop the VPC Router 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("Stopping the router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.api_client.stopRouter(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 stopped state self.assertEqual(router_response[0].state, 'Stopped', "Check list router response for router state") self.debug("Stopped the router with ID: %s" % router.id) # Start The Router self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.api_client.startRouter(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 self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state") self.debug("Started the router with ID: %s" % router.id) return
def start_VPC_VRouter(self, router): # Start the VPC Router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state")
def test_08_start_router(self): """Test start 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] self.debug("Starting the router with ID: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(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 self.assertEqual( router_response[0].state, 'Running', "Check list router response for router state" ) return
def start_VPC_VRouter(self, router): # Start the VPC Router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state" )
def test_network_gc(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=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("Stopping the user VM: %s" % virtual_machine.name) try: virtual_machine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop guest Vm: %s - %s" % (virtual_machine.name, e)) interval = Configurations(self.apiclient, name='network.gc.interval') delay = int(interval[0].value) interval = Configurations.list(self.apiclient, name='network.gc.wait') exp = int(interval[0].value) self.debug("Sleeping for network gc wait + interval time") # Sleep to ensure that all resources are deleted time.sleep((delay + exp) * 2) routers = Router.list(self.apiclient, networkid=network.id, listall=True) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers") for router in routers: self.assertEqual(router.state, "Stopped", "Router should be in stopped state") self.debug("Starting the stopped router again") cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = Router.list(self.apiclient, networkid=network.id, listall=True) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers") for router in routers: self.assertEqual(router.state, "Running", "Router should be in running state") self.debug("Sleeping for network gc wait + interval time") # Sleep to ensure that all resources are deleted time.sleep((delay + exp) * 3) routers = Router.list(self.apiclient, networkid=network.id, listall=True) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers") for router in routers: self.assertEqual(router.state, "Stopped", "Router should be in stopped state") return
def test_01_RouterStopCreateLB(self): """Test router stop create Load balancing """ # validate the following # 1. listLoadBalancerRules (publicipid=ipaddressid of source NAT) # 2. rule should be for port 22 as applied and # should be in state=Active # 3. ssh access should be allowed to the userVMs over the source NAT IP # and port 22 # Get router details associated for that account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) self.assertNotEqual( len(routers), 0, "Check list router response" ) router = routers[0] self.debug("Stopping router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Stopped', "Check list router response for router state" ) public_ips = list_publicIP( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data" ) public_ip = public_ips[0] # Open up firewall port for SSH FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["lbrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["lbrule"]["publicport"], endport=self.services["lbrule"]["publicport"] ) self.debug("Creating LB rule for public IP: %s" % public_ip.id) # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( self.apiclient, self.services["lbrule"], public_ip.id, accountid=self.account.name ) self.debug("Assigning VM %s to LB rule: %s" % ( self.vm_1.id, lb_rule.id )) lb_rule.assign(self.apiclient, [self.vm_1]) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Running', "Check list router response for router state" ) # After router start, LB RUle should be in Active state lb_rules = list_lb_rules( self.apiclient, id=lb_rule.id ) self.assertEqual( isinstance(lb_rules, list), True, "Check for list LB rules response return valid data" ) self.assertEqual( lb_rules[0].state, 'Active', "Check list load balancing rules" ) self.assertEqual( lb_rules[0].publicport, str(self.services["lbrule"]["publicport"]), "Check list load balancing rules" ) try: self.debug("SSH into VM with IP: %s" % public_ip.ipaddress) self.vm_1.ssh_port = self.services["lbrule"]["publicport"] self.vm_1.get_ssh_client(public_ip.ipaddress) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.vm_1.ipaddress, e) ) return
def start_network_router(self, router): self.debug("Starting Router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.api_client.startRouter(cmd)
def test_01_CreatePFOnStoppedRouter(self): """Stop existing router, add a PF rule and check we can access the VM """ # Get router details associated for that account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) self.assertNotEqual( len(routers), 0, "Check list router response" ) router = routers[0] self.logger.debug("Stopping router ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Stopped', "Check list router response for router state" ) public_ips = list_publicIP( self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id ) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data" ) public_ip = public_ips[0] # Open up firewall port for SSH FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule"]["publicport"], endport=self.services["natrule"]["publicport"] ) self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id) # Create NAT rule nat_rule = NATRule.create( self.apiclient, self.vm_1, self.services["natrule"], public_ip.id ) self.logger.debug("Starting router ID: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Running', "Check list router response for router state" ) # NAT Rule should be in Active state after router start nat_rules = list_nat_rules( self.apiclient, id=nat_rule.id ) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data" ) self.assertEqual( nat_rules[0].state, 'Active', "Check list port forwarding rules" ) try: self.logger.debug("SSH into VM with ID: %s" % nat_rule.ipaddress) self.vm_1.get_ssh_client( ipaddress=nat_rule.ipaddress, port=self.services["natrule"]["publicport"]) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (nat_rule.ipaddress, e) ) return
def test_01_RouterStopCreatePF(self): """Test router stop create port forwarding """ # validate the following # 1. wait for router to start, guest network to be implemented and # VM to report Running # 2. stopRouter for this account # 3. wait for listRouters to report Router as 'Stopped' # 4. listPublicIpAddresses account=user, domainid=1 - pick ipaddressid # 5. createPortForwardingRule (ipaddressid from step 5.) # a. for port 22 (ssh) for user VM deployed in step 1. # b. public port 22 , private port 22 # 6. startRouter stopped for this account # 7. wait for listRouters to show router as Running # Get router details associated for that account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) self.assertNotEqual( len(routers), 0, "Check list router response" ) router = routers[0] self.debug("Stopping router ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Stopped', "Check list router response for router state" ) public_ips = list_publicIP( self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id ) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data" ) public_ip = public_ips[0] # Open up firewall port for SSH FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule"]["publicport"], endport=self.services["natrule"]["publicport"] ) self.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id) # Create NAT rule nat_rule = NATRule.create( self.apiclient, self.vm_1, self.services["natrule"], public_ip.id ) self.debug("Starting router ID: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Running', "Check list router response for router state" ) # NAT Rule should be in Active state after router start nat_rules = list_nat_rules( self.apiclient, id=nat_rule.id ) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data" ) self.assertEqual( nat_rules[0].state, 'Active', "Check list port forwarding rules" ) try: self.debug("SSH into VM with ID: %s" % nat_rule.ipaddress) self.vm_1.get_ssh_client( ipaddress=nat_rule.ipaddress, port=self.services["natrule"]["publicport"]) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (nat_rule.ipaddress, e) ) return
def test_01_RouterStopCreateLB(self): """Test router stop create Load balancing """ # validate the following # 1. listLoadBalancerRules (publicipid=ipaddressid of source NAT) # 2. rule should be for port 22 as applied and # should be in state=Active # 3. ssh access should be allowed to the userVMs over the source NAT IP # and port 22 # Get router details associated for that account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") self.assertNotEqual(len(routers), 0, "Check list router response") router = routers[0] self.debug("Stopping router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Stopped', "Check list router response for router state") public_ips = list_publicIP(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") public_ip = public_ips[0] # Open up firewall port for SSH FireWallRule.create(self.apiclient, ipaddressid=public_ip.id, protocol=self.services["lbrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["lbrule"]["publicport"], endport=self.services["lbrule"]["publicport"]) self.debug("Creating LB rule for public IP: %s" % public_ip.id) # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create(self.apiclient, self.services["lbrule"], public_ip.id, accountid=self.account.name) self.debug("Assigning VM %s to LB rule: %s" % (self.vm_1.id, lb_rule.id)) lb_rule.assign(self.apiclient, [self.vm_1]) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state") # After router start, LB RUle should be in Active state lb_rules = list_lb_rules(self.apiclient, id=lb_rule.id) self.assertEqual(isinstance(lb_rules, list), True, "Check for list LB rules response return valid data") self.assertEqual(lb_rules[0].state, 'Active', "Check list load balancing rules") self.assertEqual(lb_rules[0].publicport, str(self.services["lbrule"]["publicport"]), "Check list load balancing rules") try: self.debug("SSH into VM with IP: %s" % public_ip.ipaddress) self.vm_1.ssh_port = self.services["lbrule"]["publicport"] self.vm_1.get_ssh_client(public_ip.ipaddress) except Exception as e: self.fail("SSH Access failed for %s: %s" % (self.vm_1.ipaddress, e)) return
def test_network_gc(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=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("Stopping the user VM: %s" % virtual_machine.name) try: virtual_machine.stop(self.apiclient) except Exception as e: self.fail("Failed to stop guest Vm: %s - %s" % (virtual_machine.name, e)) interval = Configurations.list( self.apiclient, name='network.gc.interval' ) delay = int(interval[0].value) interval = Configurations.list( self.apiclient, name='network.gc.wait' ) exp = int(interval[0].value) self.debug("Sleeping for network gc wait + interval time") # Sleep to ensure that all resources are deleted time.sleep((delay + exp) * 2) routers = Router.list( self.apiclient, networkid=network.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers" ) for router in routers: self.assertEqual( router.state, "Stopped", "Router should be in stopped state" ) self.debug("Starting the stopped router again") cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = Router.list( self.apiclient, networkid=network.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers" ) for router in routers: self.assertEqual( router.state, "Running", "Router should be in running state" ) self.debug("Sleeping for network gc wait + interval time") # Sleep to ensure that all resources are deleted time.sleep((delay + exp) * 3) routers = Router.list( self.apiclient, networkid=network.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "list router should return Master and backup routers" ) for router in routers: self.assertEqual( router.state, "Stopped", "Router should be in stopped state" ) return
def test_01_stop_start_router_after_creating_vpc(self): """ Test to stop and start router after creation of VPC """ # Validate following: # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Stop the VPC Virtual Router which is created as a result of VPC creation. # 3. Start the Stopped VPC Virtual Router self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) # Stop the VPC Router 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("Stopping the router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.api_client.stopRouter(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 stopped state self.assertEqual( router_response[0].state, 'Stopped', "Check list router response for router state" ) self.debug("Stopped the router with ID: %s" % router.id) # Start The Router self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.api_client.startRouter(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 self.assertEqual( router_response[0].state, 'Running', "Check list router response for router state" ) self.debug("Started the router with ID: %s" % router.id) return
def test_01_start_stop_router_after_addition_of_one_guest_network(self): """ Test start/stop 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" ) # Stop the VPC Router 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("Stopping the router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.api_client.stopRouter(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 stopped state self.assertEqual( router_response[0].state, 'Stopped', "Check list router response for router state" ) self.debug("Stopped the router with ID: %s" % router.id) # Start The Router self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.api_client.startRouter(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 self.assertEqual( router_response[0].state, 'Running', "Check list router response for router state" ) self.debug("Started the router with ID: %s" % router.id) return
def test_01_start_stop_router_after_addition_of_one_guest_network(self): """ Test start/stop 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") # Stop the VPC Router 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("Stopping the router with ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.api_client.stopRouter(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 stopped state self.assertEqual(router_response[0].state, 'Stopped', "Check list router response for router state") self.debug("Stopped the router with ID: %s" % router.id) # Start The Router self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.api_client.startRouter(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 self.assertEqual(router_response[0].state, 'Running', "Check list router response for router state") self.debug("Started the router with ID: %s" % router.id) return
def test_01_RouterStopCreatePF(self): """Test router stop create port forwarding """ # validate the following # 1. wait for router to start, guest network to be implemented and # VM to report Running # 2. stopRouter for this account # 3. wait for listRouters to report Router as 'Stopped' # 4. listPublicIpAddresses account=user, domainid=1 - pick ipaddressid # 5. createPortForwardingRule (ipaddressid from step 5.) # a. for port 22 (ssh) for user VM deployed in step 1. # b. public port 22 , private port 22 # 6. startRouter stopped for this account # 7. wait for listRouters to show router as Running # Get router details associated for that account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") self.assertNotEqual(len(routers), 0, "Check list router response") router = routers[0] self.debug("Stopping router ID: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Stopped', "Check list router response for router state") public_ips = list_publicIP(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") public_ip = public_ips[0] # Open up firewall port for SSH FireWallRule.create(self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule"]["publicport"], endport=self.services["natrule"]["publicport"]) self.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id) # Create NAT rule nat_rule = NATRule.create(self.apiclient, self.vm_1, self.services["natrule"], public_ip.id) self.debug("Starting router ID: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state") # NAT Rule should be in Active state after router start nat_rules = list_nat_rules(self.apiclient, id=nat_rule.id) self.assertEqual( isinstance(nat_rules, list), True, "Check for list NAT rules response return valid data") self.assertEqual(nat_rules[0].state, 'Active', "Check list port forwarding rules") try: self.debug("SSH into VM with ID: %s" % nat_rule.ipaddress) self.vm_1.get_ssh_client( ipaddress=nat_rule.ipaddress, port=self.services["natrule"]["publicport"]) except Exception as e: self.fail("SSH Access failed for %s: %s" % (nat_rule.ipaddress, e)) return
def test_01_RouterStopCreateFW(self): """Test router stop create Firewall rule """ # validate the following # 1. 1. listFirewallRules (filter by ipaddressid of sourcenat) # 2. rule should be for ports 1-600 and in state=Active # (optional backend) # 3. verify on router using iptables -t nat -nvx if rules are applied # Get the router details associated with account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) self.assertNotEqual( len(routers), 0, "Check list router response" ) router = routers[0] self.debug("Stopping the router: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Stopped', "Check list router response for router state" ) public_ips = list_publicIP( self.apiclient, account=self.account.name, domainid=self.account.domainid ) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IP response return valid data" ) public_ip = public_ips[0] # Create Firewall rule with configurations from settings file fw_rule = FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], startport=self.services["fwrule"]["startport"], endport=self.services["fwrule"]["endport"] ) self.debug("Created firewall rule: %s" % fw_rule.id) self.debug("Starting the router: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual( isinstance(routers, list), True, "Check for list routers response return valid data" ) router = routers[0] self.assertEqual( router.state, 'Running', "Check list router response for router state" ) # After Router start, FW rule should be in Active state fw_rules = list_firewall_rules( self.apiclient, id=fw_rule.id, ) self.assertEqual( isinstance(fw_rules, list), True, "Check for list FW rules response return valid data" ) self.assertEqual( fw_rules[0].state, 'Active', "Check list load balancing rules" ) self.assertEqual( fw_rules[0].startport, self.services["fwrule"]["startport"], "Check start port of firewall rule" ) self.assertEqual( fw_rules[0].endport, self.services["fwrule"]["endport"], "Check end port of firewall rule" ) # For DNS and DHCP check 'dnsmasq' process status if (self.hypervisor.lower() == 'vmware' or self.hypervisor.lower() == 'hyperv'): result = get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, 'iptables -t nat -L', hypervisor=self.hypervisor ) else: hosts = list_hosts( self.apiclient, id=router.hostid, ) self.assertEqual( isinstance(hosts, list), True, "Check for list hosts response return valid data" ) host = hosts[0] try: result = get_process_status( host.ipaddress, 22, self.hostConfig['username'], self.hostConfig['password'], router.linklocalip, 'iptables -t nat -L' ) except KeyError: self.skipTest( "Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.debug("iptables -t nat -L: %s" % result) self.debug("Public IP: %s" % public_ip.ipaddress) res = str(result) self.assertEqual( res.count(str(public_ip.ipaddress)), 1, "Check public IP address" ) return
def test_01_RouterStopCreateFW(self): """Test router stop create Firewall rule """ # validate the following # 1. 1. listFirewallRules (filter by ipaddressid of sourcenat) # 2. rule should be for ports 1-600 and in state=Active # (optional backend) # 3. verify on router using iptables -t nat -nvx if rules are applied # Get the router details associated with account routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") self.assertNotEqual(len(routers), 0, "Check list router response") router = routers[0] self.debug("Stopping the router: %s" % router.id) # Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.apiclient.stopRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Stopped', "Check list router response for router state") public_ips = list_publicIP(self.apiclient, account=self.account.name, domainid=self.account.domainid) self.assertEqual( isinstance(public_ips, list), True, "Check for list public IP response return valid data") public_ip = public_ips[0] # Create Firewall rule with configurations from settings file fw_rule = FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], startport=self.services["fwrule"]["startport"], endport=self.services["fwrule"]["endport"]) self.debug("Created firewall rule: %s" % fw_rule.id) self.debug("Starting the router: %s" % router.id) # Start the router cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) routers = list_routers( self.apiclient, account=self.account.name, domainid=self.account.domainid, ) self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data") router = routers[0] self.assertEqual(router.state, 'Running', "Check list router response for router state") # After Router start, FW rule should be in Active state fw_rules = list_firewall_rules( self.apiclient, id=fw_rule.id, ) self.assertEqual(isinstance(fw_rules, list), True, "Check for list FW rules response return valid data") self.assertEqual(fw_rules[0].state, 'Active', "Check list load balancing rules") self.assertEqual(fw_rules[0].startport, str(self.services["fwrule"]["startport"]), "Check start port of firewall rule") self.assertEqual(fw_rules[0].endport, str(self.services["fwrule"]["endport"]), "Check end port of firewall rule") # For DNS and DHCP check 'dnsmasq' process status if (self.hypervisor.lower() == 'vmware' or self.hypervisor.lower() == 'hyperv'): result = get_process_status(self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, 'iptables -t nat -L', hypervisor=self.hypervisor) else: hosts = list_hosts( self.apiclient, id=router.hostid, ) self.assertEqual( isinstance(hosts, list), True, "Check for list hosts response return valid data") host = hosts[0] host.user = self.services["configurableData"]["host"]["username"] host.passwd = self.services["configurableData"]["host"]["password"] try: result = get_process_status(host.ipaddress, 22, host.user, host.passwd, router.linklocalip, 'iptables -t nat -L') except KeyError: self.skipTest("Provide a marvin config file with host\ credentials to run %s" % self._testMethodName) self.debug("iptables -t nat -L: %s" % result) self.debug("Public IP: %s" % public_ip.ipaddress) res = str(result) self.assertEqual(res.count(str(public_ip.ipaddress)), 1, "Check public IP address") return