def testShutdown(self): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-21 11 : 06 Description : Make sure the shutdown operation can take effect in certain time - 6s; ''' dom = self.__startVM() VM.shutdown(dom.UUIDString()) for i in range(3): sleep(2) if not dom.isActive(): break self.assertFalse(dom.isActive())
def __createVM(self): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-21 10 : 49 Description : Make sure there is always a VM called 'test' Delete the VM first if it exists, and then create another VM called 'test'. ''' _id = '103adb75-f41a-4dae-8bdc-c61e92c85e58' name = self.name memory = 1024 vcpu = 2 mac = '' diskDir = '/home/res/images/test.qcow2' isoDir = '/home/res/iso/CentOS-7.1.iso' bridgeSrc = 'ovs0' try: self.__deleteVM(self.name) except: pass log.debug("After deletion, now let's create a new one.") return VM.create(_id, name, memory, vcpu, mac, diskDir, isoDir, bridgeSrc)
def __startVM(self): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-21 11 : 01 Description : Start a VM by its name and meantime return its domain object for further use. ''' try: self.__shutoffVM(self.name) except: pass dom = VM.conn.lookupByName(self.name) uuidstr = dom.UUIDString() VM.start(uuidstr) return dom
def testReboot(self): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-21 11 : 08 Description : Detect two states changes from up to down then from down to up. ''' try: self.__startVM(self.name) except: pass dom_id0 = self.__get_vm_id(self.name) log.debug(dom_id0) _id = VM.conn.lookupByName(self.name).UUIDString() log.debug("reboot" + _id) VM.reboot(str(_id)) dom_id1 = self.__get_vm_id(self.name) log.debug(dom_id1) self.assertTrue(dom_id1 > dom_id0)