def migrate_router(self, router): """ Migrate the router """ self.debug("Checking if the host is available for migration?") hosts = Host.list(self.api_client, zoneid=self.zone.id, type='Routing') self.assertEqual( isinstance(hosts, list), True, "List hosts should return a valid list" ) if len(hosts) < 2: self.skipTest( "No host available for migration. Test requires atleast 2 hosts") # Remove the host of current VM from the hosts list hosts[:] = [host for host in hosts if host.id != router.hostid] host = hosts[0] self.debug("Validating if the network rules work properly or not?") self.debug("Migrating VM-ID: %s from %s to Host: %s" % ( router.id, router.hostid, host.id )) try: # Migrate the router cmd = migrateSystemVm.migrateSystemVmCmd() cmd.isAsync = "false" cmd.hostid = host.id cmd.virtualmachineid = router.id self.api_client.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate instance, %s" % e) self.debug("Waiting for Router mgiration ....") time.sleep(240) # 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" ) router.hostid = router_response[0].hostid self.assertEqual( router.hostid, host.id, "Migration to host %s failed. The router host is" "still %s" % (host.id, router.hostid)) 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 migrate_router(self, router): """ Migrate the router """ self.debug("Checking if the host is available for migration?") hosts = Host.list(self.api_client, zoneid=self.zone.id, type='Routing') self.assertEqual(isinstance(hosts, list), True, "List hosts should return a valid list") if len(hosts) < 2: self.skipTest( "No host available for migration. Test requires atleast 2 hosts" ) # Remove the host of current VM from the hosts list hosts[:] = [host for host in hosts if host.id != router.hostid] host = hosts[0] self.debug("Validating if the network rules work properly or not?") self.debug("Migrating VM-ID: %s from %s to Host: %s" % (router.id, router.hostid, host.id)) try: # Migrate the router cmd = migrateSystemVm.migrateSystemVmCmd() cmd.isAsync = "false" cmd.hostid = host.id cmd.virtualmachineid = router.id self.api_client.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate instance, %s" % e) self.debug("Waiting for Router mgiration ....") time.sleep(240) # 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") router.hostid = router_response[0].hostid self.assertEqual( router.hostid, host.id, "Migration to host %s failed. The router host is" "still %s" % (host.id, router.hostid)) 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_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