def setUpClass(cls): cls.testClient = super(TestVPCHostMaintenance, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() cls._cleanup = [] cls.hosts = [] cls.vpcSupported = True cls.hypervisor = cls.testClient.getHypervisorInfo() if cls.hypervisor.lower() in ['hyperv']: cls.vpcSupported = False return cls.services = 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.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.services["mode"] = cls.zone.networktype cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) cls._cleanup.append(cls.vpc_off) cls.vpc_off.update(cls.api_client, state='Enabled') cls.hosts = Host.list(cls.api_client, zoneid=cls.zone.id, listall=True, type='Routing') if isinstance(cls.hosts, list): for host in cls.hosts: Host.enableMaintenance(cls.api_client, id=host.id) timeout = cls.services["timeout"] while True: time.sleep(cls.services["sleep"]) hosts_states = Host.list(cls.api_client, id=host.id, listall=True) if hosts_states[ 0].resourcestate == 'PrepareForMaintenance': # Wait for sometimetill host goes in maintenance state time.sleep(cls.services["sleep"]) elif hosts_states[0].resourcestate == 'Maintenance': time.sleep(cls.services["sleep"]) break elif timeout == 0: raise unittest.SkipTest( "Failed to enable maintenance mode on %s" % host.name) timeout = timeout - 1 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_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(TestVPCHostMaintenance, 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 cls.services["mode"] = cls.zone.networktype cls.vpc_off = VpcOffering.create( cls.api_client, cls.services["vpc_offering"] ) cls.vpc_off.update(cls.api_client, state='Enabled') cls.hosts = Host.list( cls.api_client, zoneid=cls.zone.id, listall=True, type='Routing' ) if isinstance(cls.hosts, list): for host in cls.hosts: Host.enableMaintenance( cls.api_client, id=host.id ) timeout = cls.services["timeout"] while True: time.sleep(cls.services["sleep"]) hosts_states = Host.list( cls.api_client, id=host.id, listall=True ) if hosts_states[ 0].resourcestate == 'PrepareForMaintenance': # Wait for sometimetill host goes in maintenance state time.sleep(cls.services["sleep"]) elif hosts_states[0].resourcestate == 'Maintenance': time.sleep(cls.services["sleep"]) break elif timeout == 0: raise unittest.SkipTest( "Failed to enable maintenance mode on %s" % host.name) timeout = timeout - 1 cls._cleanup = [ cls.vpc_off ] 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 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