def test_04_change_service_offerring_vpc(self): """ Tests to change service offering of the Router after creating a vpc """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Change the service offerings of the VPC Virtual Router which is # created as a result of VPC creation. 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" ) # Stop the router router = routers[0] self.debug("Stopping the router with ID: %s" % router.id) cmd = stopRouter.stopRouterCmd() cmd.id = router.id self.api_client.stopRouter(cmd) service_offering = ServiceOffering.create( self.api_client, self.services["service_offering_new"] ) self.debug("Changing service offering for the Router %s" % router.id) try: router = Router.change_service_offering(self.api_client, router.id, service_offering.id ) except: self.fail("Changing service offering failed") self.debug("Router %s" % router) routers = Router.list( self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) router = routers[0] self.assertEqual( router.serviceofferingid, service_offering.id, "Changing service offering failed as id is %s and expected" "is %s" % (router.serviceofferingid, service_offering.id) ) return
def test_05_destroy_router_after_addition_of_one_guest_network(self): """ Test destroy 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.destroy(self.api_client, id=routers[0].id ) routers = Router.list( self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), False, "List Routers should be empty" ) return
def test_13_1_egress_fr13(self): """Test Redundant Router : Master failover """ # Validate the following: # 1. deploy VM using network offering with egress policy false. # 2. create egress rule valid cidr valid port range. # 3. redundant router # 3. All should work fine. #TODO: setup network with RR self.create_vm(RR=True, egress_policy=False) self.createEgressRule() vm_network_id = self.virtual_machine.nic[0].networkid self.debug("Listing routers for network: %s" % vm_network_id) routers = Router.list(self.apiclient, networkid=vm_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("Redundant states: %s, %s" % (master_router.redundantstate, backup_router.redundantstate)) self.debug("Stopping the Master router") try: Router.stop(self.apiclient, id=master_router.id) except Exception as e: self.fail("Failed to stop master router: %s" % e) # wait for VR update state time.sleep(60) self.debug("Checking state of the master router in %s" % self.network.name) routers = Router.list(self.apiclient, id=master_router.id, listall=True) self.assertEqual(isinstance(routers, list), True, "list router should return Master and backup routers") self.exec_script_on_user_vm('ping -c 1 www.google.com', "| grep -oP \'\d+(?=% packet loss)\'", "['0']", negative_test=False)
def test_01_deploy_vm_no_startvm(self): """Test Deploy Virtual Machine with no startVM parameter """ # Validate the following: # 1. deploy Vm without specifying the startvm parameter # 2. Should be able to login to the VM. # 3. listVM command should return the deployed VM.State of this VM # should be "Running". self.debug("Deploying instance in the account: %s" % self.account.name) self.virtual_machine_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id, startvm=False, ) response = self.virtual_machine_1.getState(self.apiclient, VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Checking the router state after VM deployment") routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(routers, None, "List routers should return empty response") self.debug("Deploying another instance (startvm=true) in the account: %s" % self.account.name) self.virtual_machine_2 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id, startvm=True, ) response = self.virtual_machine_2.getState(self.apiclient, VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) self.debug("Checking the router state after VM deployment") routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "List routers should not return empty response") for router in routers: self.debug("Router state: %s" % router.state) self.assertEqual( router.state, "Running", "Router should be in running state when instance is running in the account" ) self.debug("Destroying the running VM:%s" % self.virtual_machine_2.name) self.virtual_machine_2.delete(self.apiclient, expunge=True) routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertNotEqual(routers, None, "Router should get deleted after expunge delay+wait") return
def test_03_reconnect_host(self): """ Test reconnect Host which has VPC elements """ # Steps: # 1.Reconnect one of the host on which VPC Virtual Router is present. # Validate the following # 1. Host should successfully reconnect. # 2. Network connectivity to all the VMs on the host should not be # effected due to reconnection. self.debug("Reconnecting the host where VPC VR is running") try: Host.reconnect(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to reconnect to host: %s" % e) self.debug("Check the status of router after migration") routers = Router.list( self.apiclient, id=self.vpcvr.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return the valid response" ) self.assertEqual( routers[0].state, "Running", "Router state should be running" ) # TODO: Check for the network connectivity return
def test_03_deploy_vm_startvm_false(self): """Test Deploy Virtual Machine with startVM=false parameter """ # Validate the following: # 1. deploy Vm with the startvm=false # 2. Should not be able to login to the VM. # 3. listVM command should return the deployed VM.State of this VM # should be "Stopped". # 4. Check listRouters call for that account. List routers should # return empty response self.debug("Deploying instance in the account: %s" % self.account.name) self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, startvm=False, diskofferingid=self.disk_offering.id, ) response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(routers, None, "List routers should return empty response") self.debug("Destroying instance: %s" % self.virtual_machine.name) self.virtual_machine.delete(self.apiclient, expunge=True) return
def VerifyRouterState(apiclient, account, domainid, desiredState, retries=0): """List the router associated with the account and verify that router state matches with the desired state Return PASS/FAIL depending upon whether router state matches or not""" isRouterStateDesired = False failureMessage = "" while retries >= 0: routers = Router.list( apiclient, account=account, domainid=domainid, listall=True ) if str(routers[0].state).lower() == str(desiredState).lower(): isRouterStateDesired = True break time.sleep(60) retries -= 1 # whileEnd if not isRouterStateDesired: failureMessage = "Router state should be %s,\ but it is %s" %\ (desiredState, routers[0].state) return [isRouterStateDesired, failureMessage]
def test_03_reconnect_host(self): """ Test reconnect Host which has VPC elements """ # Steps: # 1.Reconnect one of the host on which VPC Virtual Router is present. # Validate the following # 1. Host should successfully reconnect. # 2. Network connectivity to all the VMs on the host should not be # effected due to reconnection. try: timeout = self.services["timeout"] while True: list_host_response = Host.list( self.apiclient, id=self.vpcvr.hostid, resourcestate="Enabled") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Up State") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Up State") except: self.fail("Failed to find the Host in Up State") self.debug("Reconnecting the host where VPC VR is running") try: Host.reconnect(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to reconnect to host: %s" % e) self.debug("Check the status of router after migration") routers = Router.list( self.apiclient, id=self.vpcvr.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return the valid response" ) self.assertEqual( routers[0].state, "Running", "Router state should be running" ) # TODO: Check for the network connectivity return
def get_Router(self, network): self.debug("Finding the virtual router for network with ID - %s" % network.id) routers = Router.list(self.api_client, networkid=network.id, listall=True ) self.assertEqual(isinstance(routers, list), True, "List routers should return a valid virtual router for network" ) return routers[0]
def get_router(self, account): """Returns a default router for account""" routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertIsInstance(routers, list, "List routers should return a valid repsonse") return routers[0]
def test_05_destroy_router_after_addition_of_one_guest_network(self): """ Test destroy 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.destroy(self.api_client, id=routers[0].id) routers = Router.list(self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), False, "List Routers should be empty") 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 check_Router_state(self, router, state=None): """Validates the Router state""" self.debug("Validating the deployment and state of Router - %s" % router.name) routers = Router.list(self.api_client, id=router.id, listall=True) self.assertEqual(isinstance(routers, list), True, "List router should return a valid list") if state: self.assertEqual(routers[0].state, state, "Virtual router is not in the expected state") self.debug( "Successfully validated the deployment and state of Router - %s" % router.name)
def check_router_state(self, router, state=None): self.debug("Check if the virtual router is in state - %s" % state) routers = Router.list(self.api_client, id=router.id, listall=True ) self.assertEqual(isinstance(routers, list), True, "List router should return a valid list" ) if state: self.assertEqual(routers[0].state, state, "Virtual router is not in the expected state" ) self.debug("Virtual router is in the expected state - %s" % state)
def test_basicZoneVirtualRouter(self): #TODO: SIMENH: duplicate test, remove it """ Tests for basic zone virtual router 1. Is Running 2. is in the account the VM was deployed in @return: """ routers = Router.list(self.apiclient, account=self.account.name) self.assertTrue(len(routers) > 0, msg = "No virtual router found") router = routers[0] self.assertEqual(router.state, 'Running', msg="Router is not in running state") self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account")
def test_basicZoneVirtualRouter(self): # TODO: SIMENH: duplicate test, remove it """ Tests for basic zone virtual router 1. Is Running 2. is in the account the VM was deployed in @return: """ routers = Router.list(self.apiclient, account=self.account.name) self.assertTrue(len(routers) > 0, msg="No virtual router found") router = routers[0] self.assertEqual(router.state, 'Running', msg="Router is not in running state") self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account")
def test_05_destroy_router_after_creating_vpc(self): """ Test to destroy the router after creating a VPC """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Destroy the VPC Virtual Router which is created as a result of VPC # creation. 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.destroy(self.api_client, id=routers[0].id ) routers = Router.list( self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), False, "List Routers should be empty" ) return
def test_03_migrate_router_after_creating_vpc(self): """ Test migration of router to another host after creating VPC """ self.hypervisor = self.testClient.getHypervisorInfo() 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") self.migrate_router(routers[0]) return
def check_Router_state(self, router, state=None): """Validates the Router state""" self.debug("Validating the deployment and state of Router - %s" % router.name) routers = Router.list(self.api_client, id=router.id, listall=True ) self.assertEqual(isinstance(routers, list), True, "List router should return a valid list" ) if state: self.assertEqual(routers[0].state, state, "Virtual router is not in the expected state" ) self.debug("Successfully validated the deployment and state of Router - %s" % router.name)
def check_Router_state(self, router, state=None): """Validates the Router state""" self.debug("Check if the virtual router instance is in state - %s" % state) routers = Router.list(self.api_client, id=router.id, listall=True ) self.assertEqual(isinstance(routers, list), True, "List router should return a valid list" ) if state: self.assertEqual(routers[0].state, state, "Virtual router is not in the expected state" ) self.debug("Virtual router instance - %s is in the expected state - %s" % (router.name, state))
def getNetworkRouter(self, network, red_state="PRIMARY"): routers = Router.list( self.apiclient, networkid=network.id, listall=True ) self.assertTrue( isinstance(routers, list) and len(routers) > 0, "No routers found for network %s" % network.id ) if len(routers) == 1: return routers[0] for router in routers: if router.redundantstate == red_state: return router
def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.debug("Check the status of VPC virtual router") routers = Router.list(self.apiclient, networkid=self.network_1.id, listall=True) if not isinstance(routers, list): raise Exception("No response from list routers API") self.router = routers[0] if self.router.state == "Running": self.debug("Verified that the Router is in Running State") self.cleanup = [] return
def test_02_cancel_maintenance(self): """ Test cancel Maintenance Mode on the above Hosts + Migrate VMs Back """ # Steps # 1. Cancel Maintenance Mode on the host. # 2. Migrate the VMs back onto the host on which Maintenance mode is # cancelled. # Validate the following # 1. Successfully cancel the Maintenance mode on the host. # 2. Migrate the VMs back successfully onto the host. # 3. Check that the network connectivity exists with the migrated VMs. self.debug("Cancel host maintenence on which the VPCVR is running") try: Host.cancelMaintenance(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to enable maintenance mode on host: %s" % e) self.debug( "Migrating the instances back to the host: %s" % self.vpcvr.hostid) try: cmd = migrateSystemVm.migrateSystemVmCmd() cmd.hostid = self.vpcvr.hostid cmd.virtualmachineid = self.vpcvr.id self.apiclient.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate VPCVR back: %s" % e) self.debug("Check the status of router after migration") routers = Router.list( self.apiclient, id=self.vpcvr.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return the valid response" ) self.assertEqual( routers[0].state, "Running", "Router state should be running" ) # TODO: Check for the network connectivity 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_03_reconnect_host(self): """ Test reconnect Host which has VPC elements """ # Steps: # 1.Reconnect one of the host on which VPC Virtual Router is present. # Validate the following # 1. Host should successfully reconnect. # 2. Network connectivity to all the VMs on the host should not be # effected due to reconnection. try: timeout = self.services["timeout"] while True: list_host_response = Host.list(self.apiclient, id=self.vpcvr.hostid, resourcestate="Enabled") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Up State") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Up State") except: self.fail("Failed to find the Host in Up State") self.debug("Reconnecting the host where VPC VR is running") try: Host.reconnect(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to reconnect to host: %s" % e) self.debug("Check the status of router after migration") routers = Router.list(self.apiclient, id=self.vpcvr.id, listall=True) self.assertEqual(isinstance(routers, list), True, "List routers shall return the valid response") self.assertEqual(routers[0].state, "Running", "Router state should be running") # TODO: Check for the network connectivity return
def test_advZoneVirtualRouter(self): #TODO: SIMENH: duplicate test, remove it """ Test advanced zone virtual router 1. Is Running 2. is in the account the VM was deployed in 3. Has a linklocalip, publicip and a guestip @return: """ routers = Router.list(self.apiclient, account="system") self.assertTrue(len(routers) > 0, msg = "No virtual router found") router = routers[0] self.assertEqual(router.state, 'Running', msg="Router is not in running state") # self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account") #Has linklocal, public and guest ips self.assertIsNotNone(router.linklocalip, msg="Router has no linklocal ip") self.assertIsNotNone(router.guestipaddress, msg="Router has no guest ip")
def test_advZoneVirtualRouter(self): #TODO: SIMENH: duplicate test, remove it """ Test advanced zone virtual router 1. Is Running 2. is in the account the VM was deployed in 3. Has a linklocalip, publicip and a guestip @return: """ routers = Router.list(self.apiclient, account=self.account.name) self.assertTrue(len(routers) > 0, msg = "No virtual router found") router = routers[0] self.assertEqual(router.state, 'Running', msg="Router is not in running state") self.assertEqual(router.account, self.account.name, msg="Router does not belong to the account") #Has linklocal, public and guest ips self.assertIsNotNone(router.linklocalip, msg="Router has no linklocal ip") self.assertIsNotNone(router.publicip, msg="Router has no public ip") self.assertIsNotNone(router.guestipaddress, msg="Router has no guest ip")
def test_03_migrate_router_after_creating_vpc(self): """ Test migration of router to another host after creating VPC """ self.hypervisor = self.testClient.getHypervisorInfo() 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" ) self.migrate_router(routers[0]) return
def verifyRouterState(apiclient, routerid, state, listall=True): """List router and check if the router state matches the given state""" retriesCount = 10 isRouterInDesiredState = False exceptionOccured = False exceptionMessage = "" try: while retriesCount >= 0: routers = Router.list(apiclient, id=routerid, listall=listall) assert validateList( routers)[0] == PASS, "Routers list validation failed" if str(routers[0].state).lower() == state: isRouterInDesiredState = True break retriesCount -= 1 time.sleep(60) if not isRouterInDesiredState: exceptionMessage = "Router state should be %s, it is %s" %\ (state, routers[0].state) except Exception as e: exceptionOccured = True exceptionMessage = e return [exceptionOccured, isRouterInDesiredState, exceptionMessage] return [exceptionOccured, isRouterInDesiredState, exceptionMessage]
def test_01_enable_maintenance_with_vpc_nw(self): """ Test enable Maintenance Mode on Hosts which have VPC elements """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. # 3. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2. Make # sure vm1 and vm3 are deployed on one host in the cluster while # vm2 and vm4 are deployed on the other host in the cluster. This # can be done using host's tags & service offerings with host tags # Steps: # 1.Enable Maintenance on one of host on which VPCVR is present # Validations: # 1. Successfully push the host into maintenance mode. # 2. VMs present on the above host should successfully migrate to the # other host present in the cluster self.validate_vm_deployment() self.debug("Stop the host on which the VPC virtual router is running") try: Host.enableMaintenance(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to enable maintenance mode on host: %s" % e) self.debug( "Check if all instances belonging to the account are up again?") routers = Router.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return a valid VPCVR for account" ) for router in routers: self.assertEqual( router.state, "Running", "Router state should be running after migration" ) vms = VirtualMachine.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(vms, list), True, "VM response should return instances running for account" ) for vm in vms: self.assertEqual( vm.state, "Ruuning", "Vm state should be running after migration" ) return
def test_network_rules_acquired_public_ip(self, value): """Test for Router rules for network rules on acquired public IP""" # Validate the following: # 1. listPortForwardingRules should not return the deleted rule anymore # 2. attempt to do ssh should now fail self.ipaddress = PublicIPAddress.create( self.apiclient, accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, networkid=self.defaultNetworkId ) self.createNetworkRules(rule=value, ipaddressobj=self.ipaddress, networkid=self.defaultNetworkId) router = Router.list(self.apiclient, networkid=self.virtual_machine.nic[0].networkid, listall=True)[0] response = self.getCommandResultFromRouter(router, "ip addr") logger.debug(response) stringToMatch = "inet %s" % self.ipaddress.ipaddress.ipaddress self.assertTrue(stringToMatch in str(response), "IP address is\ not added to the VR!") try: logger.debug("SSHing into VM with IP address %s with NAT IP %s" % ( self.virtual_machine.ipaddress, self.ipaddress.ipaddress.ipaddress )) self.virtual_machine.get_ssh_client( self.ipaddress.ipaddress.ipaddress) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress, e) ) # Validate the following: # 1. listIpForwardingRules should not return the deleted rule anymore # 2. attempt to do ssh should now fail self.removeNetworkRules(rule=value) response = self.getCommandResultFromRouter(router, "ip addr") logger.debug(response) stringToMatch = "inet %s" % self.ipaddress.ipaddress.ipaddress self.assertFalse(stringToMatch in str(response), "IP address is\ not removed from VR even after disabling stat in NAT") # Check if the Public SSH port is inaccessible with self.assertRaises(Exception): logger.debug( "SSHing into VM with IP address %s after NAT rule deletion" % self.virtual_machine.ipaddress) SshClient( self.ipaddress.ipaddress.ipaddress, self.virtual_machine.ssh_port, self.virtual_machine.username, self.virtual_machine.password, retries=2, delay=0 ) return
def setUpClass(cls): cls.testClient = super(TestMultipleIpRanges, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.dbclient = cls.testClient.getDbConnection() cls.testdata = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.pod = get_pod(cls.api_client, cls.zone.id) cls.testdata['mode'] = cls.zone.networktype cls.testdata["domainid"] = cls.domain.id cls.testdata["zoneid"] = cls.zone.id cls.account = Account.create(cls.api_client, cls.testdata["account"], domainid=cls.domain.id) cls.testdata["account"] = cls.account.name cls.disk_offering = DiskOffering.create(cls.api_client, cls.testdata["disk_offering"]) cls.service_offering = ServiceOffering.create( cls.api_client, cls.testdata["service_offering"]) cls.template = get_template(cls.api_client, cls.zone.id, cls.testdata["ostype"]) cls.testdata["diskoffering"] = cls.disk_offering.id cls.dc_id = cls.dbclient.execute( "select id from data_center where uuid = '%s';" % str(cls.testdata["zoneid"])) cls.dc_id = cls.dc_id[0][0] cls.ids = cls.dbclient.execute( "select id from user_ip_address where allocated is null and data_center_id = '%s';" % str(cls.dc_id)) cls.id_list = [] for i in range(len(cls.ids)): cls.id_list.append(cls.ids[i][0]) # Check if VR is already present in the setup vr_list = Router.list(cls.api_client, listall='true') cls.debug("vr list {}".format(vr_list)) if isinstance(vr_list, list) and len(vr_list) > 0: cls.debug("VR is running in the setup") cls.vr_state = True else: cls.debug("VR is not present in the setup") cls.vr_state = False cls.id_list = cls.id_list[:-2] for id in cls.id_list: cls.dbclient.execute( "update user_ip_address set allocated=now() where id = '%s';" % str(id)) # create new vlan ip range # Before creating ip range check the zone's network type if cls.zone.networktype.lower() == 'basic': cls.new_vlan = cls.createNewVlanRange() else: raise unittest.SkipTest( "These tests can be run only on basic zone.\ So skipping the tests") # Deploy vm in existing subnet if VR is not present if cls.vr_state is False: cls.vm_res = VirtualMachine.create( cls.api_client, cls.testdata["small"], templateid=cls.template.id, accountid=cls.account.name, domainid=cls.testdata["domainid"], zoneid=cls.testdata["zoneid"], serviceofferingid=cls.service_offering.id, mode=cls.testdata["mode"], ) cls._cleanup = [ cls.new_vlan, cls.account, ] return
def test_restart_network_with_destroyed_masterVR(self): """Test restarting RvR network without cleanup after destroying master VR """ # 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. Destroy master VR # 5. restartNetwork cleanup=false # 6. Verify RVR status after network restart # 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( validateList(networks)[0], PASS, "List networks should return a valid response for created network") 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( validateList(vms)[0], PASS, "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( validateList(routers)[0], PASS, "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' and\ routers[1].redundantstate == 'BACKUP': master_router = routers[0] backup_router = routers[1] elif routers[1].redundantstate == 'MASTER' and \ routers[0].redundantstate == 'BACKUP': master_router = routers[1] backup_router = routers[0] else: self.fail( "Both the routers in RVR are in BackupState - CLOUDSTACK-9015") Router.stop(self.apiclient, id=master_router.id) Router.destroy(self.apiclient, id=master_router.id) masterVR = Router.list(self.apiclient, id=master_router.id) self.assertIsNone(masterVR, "Router is not destroyed") new_master = Router.list(self.apiclient, id=backup_router.id) self.assertEqual( validateList(new_master)[0], PASS, "Invalid response after vr destroy") self.assertEqual( new_master[0].redundantstate, "MASTER", "Backup didn't switch to Master after destroying Master VR") 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( validateList(routers)[0], PASS, "list router should return Master and backup routers afrer network restart" ) 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") if routers[0].redundantstate == 'MASTER' and\ routers[1].redundantstate == 'BACKUP': self.debug("Found master and backup VRs after network restart") elif routers[0].redundantstate == 'BACKUP' and \ routers[1].redundantstate == 'MASTER': self.debug("Found master and backup routers") else: self.fail("RVR is not in proper start after network restart") return
def test_02_cancel_maintenance(self): """ Test cancel Maintenance Mode on the above Hosts + Migrate VMs Back """ # Steps # 1. Cancel Maintenance Mode on the host. # 2. Migrate the VMs back onto the host on which Maintenance mode is # cancelled. # Validate the following # 1. Successfully cancel the Maintenance mode on the host. # 2. Migrate the VMs back successfully onto the host. # 3. Check that the network connectivity exists with the migrated VMs. try: timeout = self.services["timeout"] while True: list_host_response = Host.list(self.apiclient, id=self.vpcvr.hostid, resourcestate="Maintenance") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Maintenance State") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Maintenance State") except: self.fail("Failed to find the Host in maintenance state") self.debug("Cancel host maintenence on which the VPCVR is running") try: Host.cancelMaintenance(self.apiclient, id=self.vpcvr.hostid) timeout = self.services["timeout"] while True: list_host_response = Host.list(self.apiclient, id=self.vpcvr.hostid, state="Up") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Up State after Canceling Maintenance Mode") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Up State after Canceling Maintenance Mode") except Exception as e: self.fail("Failed to cancel maintenance mode on host: %s" % e) self.debug("Migrating the instances back to the host: %s" % self.vpcvr.hostid) try: cmd = migrateSystemVm.migrateSystemVmCmd() cmd.hostid = self.vpcvr.hostid cmd.virtualmachineid = self.vpcvr.id self.apiclient.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate VPCVR back: %s" % e) self.debug("Check the status of router after migration") routers = Router.list(self.apiclient, id=self.vpcvr.id, listall=True) self.assertEqual(isinstance(routers, list), True, "List routers shall return the valid response") self.assertEqual(routers[0].state, "Running", "Router state should be running") # TODO: Check for the network connectivity return
def test_downgradeRvR_to_VR(self): """Test downgrade redundant virtual router to virtual router """ # Steps to validate # 1. create a network Offering that has redundant router enabled and # all VR based services # 2. create a network with above offering # 3. deploy a VM in the above network and listRouters # 4. create a network Offering that has redundant router disabled and # all VR based services # 5. updateNetwork - downgrade - created above to the offfering in 4. # 6. listRouters in the network # 7. delete account in which resources are created # Validate the following # 1. listNetworkOfferings should show craeted offering for RvR # 2. listNetworks should show the created network in allocated state # 3. VM should be deployed and in Running state and there should be # two routers (MASTER and BACKUP) for this network # 4. listNetworkOfferings should show craeted offering for VR # 5. listNetworks shows the network still successfully implemented # 6. listRouters shows only one router for this network in Running # 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("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 the account: %s" % self.account.name) 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 account: %s" % self.account.name) routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "list router should return two routers") self.assertEqual( len(routers), 2, "Length of the list router should be 2 (MASTER & BACKUP)") network_offerings = NetworkOffering.list( self.apiclient, name='DefaultIsolatedNetworkOfferingWithSourceNatService', listall=True) self.assertEqual( isinstance(network_offerings, list), True, "List network offering should not return empty response") network_off_vr = network_offerings[0] self.debug("Upgrading the network to RVR network offering..") try: network.update(self.apiclient, networkofferingid=network_off_vr.id) except Exception as e: self.fail("Failed to upgrade the network from VR to RVR: %s" % e) self.debug("Listing routers for account: %s" % self.account.name) routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "list router should return only one router") self.assertEqual(len(routers), 1, "Length of the list router should be 1") return
def test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true(self): """ Test redundant router internals """ self.logger.debug( "Starting test_01_RVR_Network_FW_PF_SSH_default_routes_egress_true..." ) network_offering_egress_true = get_default_redundant_isolated_network_offering_with_egress( self.apiclient) self.logger.debug("Creating network with network offering: %s" % network_offering_egress_true.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_true.id, zoneid=self.zone.id) self.logger.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") self.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)]) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) 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.logger.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)") public_ips = list_public_ip(self.apiclient, account=self.account.name, domainid=self.account.domainid, zoneid=self.zone.id) public_ip = public_ips[0] self.assertEqual( isinstance(public_ips, list), True, "Check for list public IPs response return valid data") self.logger.debug("Creating Firewall rule for VM ID: %s" % virtual_machine.id) FireWallRule.create( self.apiclient, ipaddressid=public_ip.id, protocol=self.services["natrule_ssh"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule_ssh"]["publicport"], endport=self.services["natrule_ssh"]["publicport"]) self.logger.debug("Creating NAT rule for VM ID: %s" % virtual_machine.id) nat_rule = NATRule.create(self.apiclient, virtual_machine, self.services["natrule_ssh"], public_ip.id) # Test SSH after closing port 22 expected = 1 ssh_command = "ping -c 3 8.8.8.8" check_string = "3 packets received" result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Ping to outside world from VM should be successful!") expected = 1 ssh_command = self.HTTP_COMMAND check_string = self.HTTP_CHECK_STRING result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_SUCCESS_MESSAGE) EgressFireWallRule.create( self.apiclient, networkid=network.id, protocol=self.services["egress_443"]["protocol"], startport=self.services["egress_443"]["startport"], endport=self.services["egress_443"]["endport"], cidrlist=self.services["egress_443"]["cidrlist"]) expected = 0 result = self.check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual(result, expected, self.HTTP_ASSERT_FAILURE_MESSAGE) return
def test_02_cancel_maintenance(self): """ Test cancel Maintenance Mode on the above Hosts + Migrate VMs Back """ # Steps # 1. Cancel Maintenance Mode on the host. # 2. Migrate the VMs back onto the host on which Maintenance mode is # cancelled. # Validate the following # 1. Successfully cancel the Maintenance mode on the host. # 2. Migrate the VMs back successfully onto the host. # 3. Check that the network connectivity exists with the migrated VMs. try: timeout = self.services["timeout"] while True: list_host_response = Host.list( self.apiclient, id=self.vpcvr.hostid, resourcestate="Maintenance") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Maintenance State") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Maintenance State") except: self.fail("Failed to find the Host in maintenance state") self.debug("Cancel host maintenence on which the VPCVR is running") try: Host.cancelMaintenance(self.apiclient, id=self.vpcvr.hostid) timeout = self.services["timeout"] while True: list_host_response = Host.list( self.apiclient, id=self.vpcvr.hostid, state="Up") if list_host_response is not None: break elif timeout == 0: raise Exception("Failed to list the Host in Up State after Canceling Maintenance Mode") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Verified that the Host is in Up State after Canceling Maintenance Mode") except Exception as e: self.fail("Failed to cancel maintenance mode on host: %s" % e) self.debug( "Migrating the instances back to the host: %s" % self.vpcvr.hostid) try: cmd = migrateSystemVm.migrateSystemVmCmd() cmd.hostid = self.vpcvr.hostid cmd.virtualmachineid = self.vpcvr.id self.apiclient.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate VPCVR back: %s" % e) self.debug("Check the status of router after migration") routers = Router.list( self.apiclient, id=self.vpcvr.id, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return the valid response" ) self.assertEqual( routers[0].state, "Running", "Router state should be running" ) # TODO: Check for the network connectivity return
def test_01_enable_maintenance_with_vpc_nw(self): """ Test enable Maintenance Mode on Hosts which have VPC elements """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. # 3. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2. Make # sure vm1 and vm3 are deployed on one host in the cluster while # vm2 and vm4 are deployed on the other host in the cluster. This # can be done using host's tags & service offerings with host tags # Steps: # 1.Enable Maintenance on one of host on which VPCVR is present # Validations: # 1. Successfully push the host into maintenance mode. # 2. VMs present on the above host should successfully migrate to the # other host present in the cluster Host.update(self.apiclient, id=self.hosts[0].id, hosttags="hosttag1,hosttag2") Host.update(self.apiclient, id=self.hosts[1].id, hosttags="hosttag1,hosttag2") self.validate_vm_deployment() self.debug("Stop the host on which the VPC virtual router is running") try: Host.enableMaintenance(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to enable maintenance mode on host: %s" % e) self.debug( "Check if all instances belonging to the account are up again?") routers = Router.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "List routers shall return a valid VPCVR for account" ) router = routers[0] try: timeout = self.services["timeout"] self.debug("Timeout Value %d : " % timeout) while True: list_router_response = Router.list( self.apiclient, id = router.id, state = "Running" ) if list_router_response is not None: break elif timeout == 0: raise Exception("Router state should be running after migration") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Waiting for %d seconds - %d tries left" % (self.services["sleep"],timeout)) self.debug("Verified that the Router is in Running State") except Exception as e: self.fail("Failed to find the Router in Running state %s " % e) vms = VirtualMachine.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(vms, list), True, "VM response should return instances running for account" ) for vm in vms: self.assertEqual( vm.state, "Running", "Vm state should be running after migration" ) return
def setUpClass(cls): cls.testClient = super(TestVMLifeCycleHostmaintenance, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id clusterWithSufficientHosts = None clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id) for cluster in clusters: cls.hosts = Host.list(cls.api_client, clusterid=cluster.id) if len(cls.hosts) >= 2: clusterWithSufficientHosts = cluster break if clusterWithSufficientHosts is None: raise unittest.SkipTest("No Cluster with 2 hosts found") Host.update(cls.api_client, id=cls.hosts[0].id, hosttags="hosttag1") Host.update(cls.api_client, id=cls.hosts[1].id, hosttags="hosttag2") cls.service_offering_1 = ServiceOffering.create( cls.api_client, cls.services["service_offering_1"] ) cls.service_offering_2 = ServiceOffering.create( cls.api_client, cls.services["service_offering_2"] ) cls.vpc_off = VpcOffering.create( cls.api_client, cls.services["vpc_offering"] ) cls.vpc_off.update(cls.api_client, state='Enabled') cls.account = Account.create( cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id ) cls.vpc_off = VpcOffering.create( cls.api_client, cls.services["vpc_offering"] ) cls.vpc_off.update(cls.api_client, state='Enabled') cls.services["vpc"]["cidr"] = '10.1.1.1/16' cls.vpc = VPC.create( cls.api_client, cls.services["vpc"], vpcofferingid=cls.vpc_off.id, zoneid=cls.zone.id, account=cls.account.name, domainid=cls.account.domainid ) cls.nw_off = NetworkOffering.create( cls.api_client, cls.services["network_offering"], conservemode=False ) # Enable Network offering cls.nw_off.update(cls.api_client, state='Enabled') # Creating network using the network offering created cls.network_1 = Network.create( cls.api_client, cls.services["network"], accountid=cls.account.name, domainid=cls.account.domainid, networkofferingid=cls.nw_off.id, zoneid=cls.zone.id, gateway='10.1.1.1', vpcid=cls.vpc.id ) cls.nw_off_no_lb = NetworkOffering.create( cls.api_client, cls.services["network_offering_no_lb"], conservemode=False ) # Enable Network offering cls.nw_off_no_lb.update(cls.api_client, state='Enabled') # Creating network using the network offering created cls.network_2 = Network.create( cls.api_client, cls.services["network"], accountid=cls.account.name, domainid=cls.account.domainid, networkofferingid=cls.nw_off_no_lb.id, zoneid=cls.zone.id, gateway='10.1.2.1', vpcid=cls.vpc.id ) # Spawn an instance in that network cls.vm_1 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_1.id, networkids=[str(cls.network_1.id)] ) # Spawn an instance in that network cls.vm_2 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_1.id, networkids=[str(cls.network_1.id)] ) cls.vm_3 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_2.id, networkids=[str(cls.network_2.id)] ) routers = Router.list( cls.api_client, account=cls.account.name, domainid=cls.account.domainid, listall=True ) if isinstance(routers, list): cls.vpcvr = routers[0] cls._cleanup = [ cls.service_offering_1, cls.service_offering_2, cls.nw_off, cls.nw_off_no_lb, ] return
def test_01_create_tier_Vmxnet3(self): """ Test to create vpc tier with nic type as Vmxnet3 #1.Set global setting parameter "vmware.systemvm.nic.device.type" to "Vmxnet3" #2.Create VPC #3.Create one tier #4.Deploy one guest vm in the tier created in step3 """ if self.hypervisor.lower() not in ['vmware']: self.skipTest("This test can only run on vmware setup") nic_types = Configurations.list(self.apiclient, name="vmware.systemvm.nic.device.type") self.assertEqual( validateList(nic_types)[0], PASS, "Invalid list config") nic_type = nic_types[0].value reset = False if nic_type.lower() != "vmxnet3": self.updateConfigurAndRestart("vmware.systemvm.nic.device.type", "Vmxnet3") reset = True self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % self.account.name) try: vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) vpc_res = VPC.list(self.apiclient, id=vpc.id) self.assertEqual( validateList(vpc_res)[0], PASS, "Invalid response from listvpc") self.network_offering = NetworkOffering.create( self.apiclient, self.services["network_offering"], conservemode=False) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') self.cleanup.append(self.network_offering) gateway = vpc.cidr.split('/')[0] # Split the cidr to retrieve gateway # for eg. cidr = 10.0.0.1/24 # Gateway = 10.0.0.1 # 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, gateway=gateway, vpcid=vpc.id) self.debug("Created network with ID: %s" % network.id) vm = 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.assertIsNotNone(vm, "VM creation failed") self.debug("Deployed VM in network: %s" % network.id) vm_res = VirtualMachine.list(self.apiclient, id=vm.id) self.assertEqual( validateList(vm_res)[0], PASS, "list vm returned invalid response") vr_res = Router.list(self.apiclient, vpcid=vpc.id, listall="true") self.assertEqual( validateList(vr_res)[0], PASS, "list vrs failed for vpc") vr_linklocal_ip = vr_res[0].linklocalip result = get_process_status(self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, vr_linklocal_ip, 'lspci | grep "Ethernet controller"', hypervisor=self.hypervisor) self.assertEqual( validateList(result)[0], PASS, "We didn't find NICS with adapter type VMXNET3") reg = re.compile("VMware VMXNET3") count = 0 for line in result: if reg.search(line): count += 1 self.assertEqual(count, 3, "Not all NICs on VR are of type VMXNET3") except Exception as e: self.fail("NIC creation failed for vpc tier with systemvm nic \ adapter type as Vmxnet3: %s" % e) finally: if reset: self.updateConfigurAndRestart( "vmware.systemvm.nic.device.type", nic_type) return
def test_downgradeRvR_to_VR(self): """Test downgrade redundant virtual router to virtual router """ # Steps to validate # 1. create a network Offering that has redundant router enabled and # all VR based services # 2. create a network with above offering # 3. deploy a VM in the above network and listRouters # 4. create a network Offering that has redundant router disabled and # all VR based services # 5. updateNetwork - downgrade - created above to the offfering in 4. # 6. listRouters in the network # 7. delete account in which resources are created # Validate the following # 1. listNetworkOfferings should show craeted offering for RvR # 2. listNetworks should show the created network in allocated state # 3. VM should be deployed and in Running state and there should be # two routers (MASTER and BACKUP) for this network # 4. listNetworkOfferings should show craeted offering for VR # 5. listNetworks shows the network still successfully implemented # 6. listRouters shows only one router for this network in Running # 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("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 the account: %s" % self.account.name) 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 account: %s" % self.account.name) routers = Router.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "list router should return two routers" ) self.assertEqual( len(routers), 2, "Length of the list router should be 2 (MASTER & BACKUP)" ) network_offerings = NetworkOffering.list( self.apiclient, name='DefaultIsolatedNetworkOfferingWithSourceNatService', listall=True ) self.assertEqual( isinstance(network_offerings, list), True, "List network offering should not return empty response" ) network_off_vr = network_offerings[0] self.debug("Upgrading the network to RVR network offering..") try: network.update( self.apiclient, networkofferingid=network_off_vr.id ) except Exception as e: self.fail("Failed to upgrade the network from VR to RVR: %s" % e) self.debug("Listing routers for account: %s" % self.account.name) routers = Router.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual( isinstance(routers, list), True, "list router should return only one router" ) self.assertEqual( len(routers), 1, "Length of the list router should be 1" ) return
def test_network_rules_acquired_public_ip(self, value): """Test for Router rules for network rules on acquired public IP""" # Validate the following: # 1. listPortForwardingRules should not return the deleted rule anymore # 2. attempt to do ssh should now fail self.ipaddress = PublicIPAddress.create( self.apiclient, accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, networkid=self.defaultNetworkId ) self.cleanup.append(self.ipaddress) self.createNetworkRules(rule=value, ipaddressobj=self.ipaddress, networkid=self.defaultNetworkId) router = Router.list(self.apiclient, networkid=self.virtual_machine.nic[0].networkid, listall=True)[0] response = self.getCommandResultFromRouter(router, "ip addr") self.debug(response) stringToMatch = "inet %s" % self.ipaddress.ipaddress.ipaddress self.assertTrue(stringToMatch in str(response), "IP address is\ not removed from VR even after disabling statin NAT") try: self.debug("SSHing into VM with IP address %s with NAT IP %s" % ( self.virtual_machine.ipaddress, self.ipaddress.ipaddress.ipaddress )) self.virtual_machine.get_ssh_client( self.ipaddress.ipaddress.ipaddress) except Exception as e: self.fail( "SSH Access failed for %s: %s" % (self.virtual_machine.ipaddress, e) ) # Validate the following: # 1. listIpForwardingRules should not return the deleted rule anymore # 2. attempt to do ssh should now fail self.removeNetworkRules(rule=value, ipaddressobj=self.ipaddress) response = self.getCommandResultFromRouter(router, "ip addr") self.debug(response) stringToMatch = "inet %s" % self.ipaddress.ipaddress.ipaddress self.assertFalse(stringToMatch in str(response), "IP address is\ not removed from VR even after disabling statin NAT") # Check if the Public SSH port is inaccessible with self.assertRaises(Exception): self.debug( "SSHing into VM with IP address %s after NAT rule deletion" % self.virtual_machine.ipaddress) SshClient( self.ipaddress.ipaddress.ipaddress, self.virtual_machine.ssh_port, self.virtual_machine.username, self.virtual_machine.password, retries=2, delay=0 ) return
def test_03_RVR_Network_check_router_state(self): """ Test redundant router internals """ self.logger.debug("Starting test_03_RVR_Network_check_router_state...") network_offering_egress_false = get_default_redundant_isolated_network_offering( self.apiclient) self.logger.debug("Creating network with network offering: %s" % network_offering_egress_false.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_false.id, zoneid=self.zone.id) self.logger.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") self.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)]) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) 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.logger.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)") vals = ["MASTER", "BACKUP", "UNKNOWN"] cnts = [0, 0, 0] result = "UNKNOWN" for router in routers: if router.state == "Running": hosts = list_hosts(self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid) self.assertEqual(isinstance(hosts, list), True, "Check list host returns a valid list") host = hosts[0] try: host.user, host.passwd = get_host_credentials( self.config, host.ipaddress) result = str( get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cosmic/router/scripts/checkrouter.sh ")) except KeyError: self.skipTest( "Marvin configuration has no host credentials to\ check router services") if result.count(vals[0]) == 1: cnts[vals.index(vals[0])] += 1 if cnts[vals.index('MASTER')] != 1: self.fail("No Master or too many master routers found %s" % cnts[vals.index('MASTER')]) return
def test_01_create_tier_Vmxnet3(self): """ Test to create vpc tier with nic type as Vmxnet3 #1.Set global setting parameter "vmware.systemvm.nic.device.type" to "Vmxnet3" #2.Create VPC #3.Create one tier #4.Deploy one guest vm in the tier created in step3 """ if self.hypervisor.lower() not in ['vmware']: self.skipTest("This test can only run on vmware setup") nic_types = Configurations.list( self.apiclient, name="vmware.systemvm.nic.device.type" ) self.assertEqual(validateList(nic_types)[0], PASS, "Invalid list config") nic_type = nic_types[0].value reset = False if nic_type.lower() != "vmxnet3": self.updateConfigurAndRestart("vmware.systemvm.nic.device.type", "Vmxnet3") reset = True self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % self.account.name) try: vpc = VPC.create( self.apiclient, self.services["vpc"], vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid ) vpc_res = VPC.list(self.apiclient, id=vpc.id) self.assertEqual(validateList(vpc_res)[0], PASS, "Invalid response from listvpc") self.network_offering = NetworkOffering.create( self.apiclient, self.services["network_offering"], conservemode=False ) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') self.cleanup.append(self.network_offering) gateway = vpc.cidr.split('/')[0] # Split the cidr to retrieve gateway # for eg. cidr = 10.0.0.1/24 # Gateway = 10.0.0.1 # 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, gateway=gateway, vpcid=vpc.id ) self.debug("Created network with ID: %s" % network.id) vm = 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.assertIsNotNone(vm, "VM creation failed") self.debug("Deployed VM in network: %s" % network.id) vm_res = VirtualMachine.list(self.apiclient, id=vm.id) self.assertEqual( validateList(vm_res)[0], PASS, "list vm returned invalid response" ) vr_res = Router.list( self.apiclient, vpcid=vpc.id, listall="true" ) self.assertEqual(validateList(vr_res)[0], PASS, "list vrs failed for vpc") vr_linklocal_ip = vr_res[0].linklocalip result = get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, vr_linklocal_ip, 'lspci | grep "Ethernet controller"', hypervisor=self.hypervisor ) self.assertEqual( validateList(result)[0], PASS, "We didn't find NICS with adapter type VMXNET3" ) reg = re.compile("VMware VMXNET3") count = 0 for line in result: if reg.search(line): count += 1 self.assertEqual( count, 3, "Not all NICs on VR are of type VMXNET3" ) except Exception as e: self.fail("NIC creation failed for vpc tier with systemvm nic \ adapter type as Vmxnet3: %s" % e) finally: if reset: self.updateConfigurAndRestart("vmware.systemvm.nic.device.type", nic_type) return
def setUpClass(cls): cls.testClient = super(TestVMLifeCycleHostmaintenance, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) 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 clusterWithSufficientHosts = None clusters = Cluster.list(cls.api_client, zoneid=cls.zone.id) for cluster in clusters: cls.hosts = Host.list(cls.api_client, clusterid=cluster.id) if len(cls.hosts) >= 2: clusterWithSufficientHosts = cluster if clusterWithSufficientHosts is None: raise unittest.SkipTest("No Cluster with 2 hosts found") Host.update(cls.api_client, id=cls.hosts[0].id, hosttags="hosttag1") Host.update(cls.api_client, id=cls.hosts[1].id, hosttags="hosttag2") cls.service_offering_1 = ServiceOffering.create(cls.api_client, cls.services["service_offering_1"]) cls.service_offering_2 = ServiceOffering.create(cls.api_client, cls.services["service_offering_2"]) cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) cls.vpc_off.update(cls.api_client, state="Enabled") cls.account = Account.create(cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id) cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) cls.vpc_off.update(cls.api_client, state="Enabled") cls.services["vpc"]["cidr"] = "10.1.1.1/16" cls.vpc = VPC.create( cls.api_client, cls.services["vpc"], vpcofferingid=cls.vpc_off.id, zoneid=cls.zone.id, account=cls.account.name, domainid=cls.account.domainid, ) cls.nw_off = NetworkOffering.create(cls.api_client, cls.services["network_offering"], conservemode=False) # Enable Network offering cls.nw_off.update(cls.api_client, state="Enabled") # Creating network using the network offering created cls.network_1 = Network.create( cls.api_client, cls.services["network"], accountid=cls.account.name, domainid=cls.account.domainid, networkofferingid=cls.nw_off.id, zoneid=cls.zone.id, gateway="10.1.1.1", vpcid=cls.vpc.id, ) cls.nw_off_no_lb = NetworkOffering.create( cls.api_client, cls.services["network_offering_no_lb"], conservemode=False ) # Enable Network offering cls.nw_off_no_lb.update(cls.api_client, state="Enabled") # Creating network using the network offering created cls.network_2 = Network.create( cls.api_client, cls.services["network"], accountid=cls.account.name, domainid=cls.account.domainid, networkofferingid=cls.nw_off_no_lb.id, zoneid=cls.zone.id, gateway="10.1.2.1", vpcid=cls.vpc.id, ) # Spawn an instance in that network cls.vm_1 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_1.id, networkids=[str(cls.network_1.id)], ) # Spawn an instance in that network cls.vm_2 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_1.id, networkids=[str(cls.network_1.id)], ) cls.vm_3 = VirtualMachine.create( cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering_2.id, networkids=[str(cls.network_2.id)], ) routers = Router.list(cls.api_client, account=cls.account.name, domainid=cls.account.domainid, listall=True) if isinstance(routers, list): cls.vpcvr = routers[0] cls._cleanup = [cls.service_offering_1, cls.service_offering_2, cls.nw_off, cls.nw_off_no_lb] return
def test_02_RVR_Network_FW_PF_SSH_default_routes_egress_false(self): """ Test redundant router internals """ self.logger.debug("Starting test_02_RVR_Network_FW_PF_SSH_default_routes_egress_false...") self.logger.debug("Creating Network Offering with default egress FALSE") network_offering_egress_false = NetworkOffering.create( self.apiclient, self.services["nw_off_persistent_RVR_egress_false"], conservemode=True ) network_offering_egress_false.update(self.api_client, state='Enabled') self.logger.debug("Creating network with network offering: %s" % network_offering_egress_false.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_false.id, zoneid=self.zone.id ) self.logger.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.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)] ) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network_offering_egress_false) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) 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.logger.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)" ) 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] self.logger.debug("Creating Firewall rule for VM ID: %s" % virtual_machine.id) 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" % virtual_machine.id) nat_rule = NATRule.create( self.apiclient, virtual_machine, self.services["natrule"], public_ip.id ) expected = 0 ssh_command = "ping -c 3 8.8.8.8" check_string = " 0% packet loss" result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Ping to outside world from VM should NOT be successful" ) expected = 0 ssh_command = "wget -t 1 -T 1 www.google.com" check_string = "HTTP request sent, awaiting response... 200 OK" result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Attempt to retrieve google.com index page should NOT be successful" ) EgressFireWallRule.create( self.apiclient, networkid=network.id, protocol=self.services["egress_80"]["protocol"], startport=self.services["egress_80"]["startport"], endport=self.services["egress_80"]["endport"], cidrlist=self.services["egress_80"]["cidrlist"] ) EgressFireWallRule.create( self.apiclient, networkid=network.id, protocol=self.services["egress_53"]["protocol"], startport=self.services["egress_53"]["startport"], endport=self.services["egress_53"]["endport"], cidrlist=self.services["egress_53"]["cidrlist"] ) expected = 1 ssh_command = "wget -t 1 -T 5 www.google.com" check_string = "HTTP request sent, awaiting response... 200 OK" result = check_router_command(virtual_machine, nat_rule.ipaddress, ssh_command, check_string, self) self.assertEqual( result, expected, "Attempt to retrieve google.com index page should be successful once rule is added!" ) return
def test_01_enable_maintenance_with_vpc_nw(self): """ Test enable Maintenance Mode on Hosts which have VPC elements """ # Validate the following # 1. Create a VPC with cidr - 10.1.1.1/16 # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC. # 3. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2. Make # sure vm1 and vm3 are deployed on one host in the cluster while # vm2 and vm4 are deployed on the other host in the cluster. This # can be done using host's tags & service offerings with host tags # Steps: # 1.Enable Maintenance on one of host on which VPCVR is present # Validations: # 1. Successfully push the host into maintenance mode. # 2. VMs present on the above host should successfully migrate to the # other host present in the cluster Host.update(self.apiclient, id=self.hosts[0].id, hosttags="hosttag1,hosttag2") Host.update(self.apiclient, id=self.hosts[1].id, hosttags="hosttag1,hosttag2") self.validate_vm_deployment() self.debug("Stop the host on which the VPC virtual router is running") try: Host.enableMaintenance(self.apiclient, id=self.vpcvr.hostid) except Exception as e: self.fail("Failed to enable maintenance mode on host: %s" % e) self.debug("Check if all instances belonging to the account are up again?") routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True) self.assertEqual(isinstance(routers, list), True, "List routers shall return a valid VPCVR for account") router = routers[0] try: timeout = self.services["timeout"] self.debug("Timeout Value %d : " % timeout) while True: list_router_response = Router.list(self.apiclient, id=router.id, state="Running") if list_router_response is not None: break elif timeout == 0: raise Exception("Router state should be running after migration") time.sleep(self.services["sleep"]) timeout = timeout - 1 self.debug("Waiting for %d seconds - %d tries left" % (self.services["sleep"], timeout)) self.debug("Verified that the Router is in Running State") except Exception as e: self.fail("Failed to find the Router in Running state %s " % e) vms = VirtualMachine.list( self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True ) self.assertEqual(isinstance(vms, list), True, "VM response should return instances running for account") for vm in vms: self.assertEqual(vm.state, "Running", "Vm state should be running after migration") return
def test_03_RVR_Network_check_router_state(self): """ Test redundant router internals """ self.logger.debug("Starting test_03_RVR_Network_check_router_state...") hypervisor = self.testClient.getHypervisorInfo() self.logger.debug("Creating Network Offering with default egress FALSE") network_offering_egress_false = NetworkOffering.create( self.apiclient, self.services["nw_off_persistent_RVR_egress_false"], conservemode=True ) network_offering_egress_false.update(self.apiclient, state='Enabled') self.logger.debug("Creating network with network offering: %s" % network_offering_egress_false.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_false.id, zoneid=self.zone.id ) self.logger.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.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)] ) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network_offering_egress_false) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) 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.logger.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)" ) vals = ["MASTER", "BACKUP", "UNKNOWN"] cnts = [0, 0, 0] result = "UNKNOWN" for router in routers: if router.state == "Running": hosts = list_hosts( self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list host returns a valid list" ) host = hosts[0] if hypervisor.lower() in ('vmware', 'hyperv'): result = str(get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, "sh /opt/cloud/bin/checkrouter.sh ", hypervisor=hypervisor )) else: try: host.user, host.passwd = get_host_credentials( self.config, host.ipaddress) result = str(get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cloud/bin/checkrouter.sh " )) except KeyError: self.skipTest( "Marvin configuration has no host credentials to\ check router services") if result.count(vals[0]) == 1: cnts[vals.index(vals[0])] += 1 if cnts[vals.index('MASTER')] != 1: self.fail("No Master or too many master routers found %s" % cnts[vals.index('MASTER')]) return
def test_03_RVR_Network_check_router_state(self): """ Test redundant router internals """ self.logger.debug("Starting test_03_RVR_Network_check_router_state...") hypervisor = self.testClient.getHypervisorInfo() self.logger.debug("Creating Network Offering with default egress FALSE") network_offering_egress_false = NetworkOffering.create( self.apiclient, self.services["nw_off_persistent_RVR_egress_false"], conservemode=True ) network_offering_egress_false.update(self.apiclient, state='Enabled') self.logger.debug("Creating network with network offering: %s" % network_offering_egress_false.id) network = Network.create( self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=network_offering_egress_false.id, zoneid=self.zone.id ) self.logger.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.logger.debug("Deploying VM in account: %s" % self.account.name) virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, networkids=[str(network.id)] ) self.logger.debug("Deployed VM in network: %s" % network.id) self.cleanup.insert(0, network_offering_egress_false) self.cleanup.insert(0, network) self.cleanup.insert(0, virtual_machine) 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.logger.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 Primary and backup routers" ) self.assertEqual( len(routers), 2, "Length of the list router should be 2 (Backup & Primary)" ) vals = ["PRIMARY", "BACKUP", "UNKNOWN"] cnts = [0, 0, 0] result = "UNKNOWN" for router in routers: if router.state == "Running": hosts = list_hosts( self.apiclient, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid ) self.assertEqual( isinstance(hosts, list), True, "Check list host returns a valid list" ) host = hosts[0] if hypervisor.lower() in ('vmware', 'hyperv'): result = str(get_process_status( self.apiclient.connection.mgtSvr, 22, self.apiclient.connection.user, self.apiclient.connection.passwd, router.linklocalip, "sh /opt/cloud/bin/checkrouter.sh ", hypervisor=hypervisor )) else: try: host.user, host.passwd = get_host_credentials( self.config, host.ipaddress) result = str(get_process_status( host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cloud/bin/checkrouter.sh " )) except KeyError: self.skipTest( "Marvin configuration has no host credentials to\ check router services") if result.count(vals[0]) == 1: cnts[vals.index(vals[0])] += 1 if cnts[vals.index('PRIMARY')] != 1: self.fail("No Primary or too many primary routers found %s" % cnts[vals.index('PRIMARY')]) 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_restart_ntwk_with_cleanup(self): """Test restart RvR 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("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" ) return
def test_restart_ntwk_with_cleanup(self): """Test restart RvR 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("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") return
def test_restart_network_with_destroyed_masterVR(self): """Test restarting RvR network without cleanup after destroying master VR """ # 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. Destroy master VR # 5. restartNetwork cleanup=false # 6. Verify RVR status after network restart # 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( validateList(networks)[0], PASS, "List networks should return a valid response for created network" ) 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( validateList(vms)[0], PASS, "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( validateList(routers)[0], PASS, "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' and\ routers[1].redundantstate == 'BACKUP': master_router = routers[0] backup_router = routers[1] elif routers[1].redundantstate == 'MASTER' and \ routers[0].redundantstate == 'BACKUP': master_router = routers[1] backup_router = routers[0] else: self.fail("Both the routers in RVR are in BackupState") Router.stop( self.apiclient, id=master_router.id ) Router.destroy( self.apiclient, id=master_router.id ) masterVR = Router.list( self.apiclient, id=master_router.id ) self.assertIsNone(masterVR, "Router is not destroyed") new_master = Router.list( self.apiclient, id=backup_router.id ) self.assertEqual(validateList(new_master)[0], PASS, "Invalid response after vr destroy") self.assertEqual( new_master[0].redundantstate, "MASTER", "Backup didn't switch to Master after destroying Master VR" ) 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( validateList(routers)[0], PASS, "list router should return Master and backup routers afrer network restart" ) 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" ) if routers[0].redundantstate == 'MASTER' and\ routers[1].redundantstate == 'BACKUP': self.debug("Found master and backup VRs after network restart") elif routers[0].redundantstate == 'BACKUP' and \ routers[1].redundantstate == 'MASTER': self.debug("Found master and backup routers") else: self.fail("RVR is not in proper start after network restart") 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(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