Example #1
0
        def shutdown_vm(val, max_time = 30):
            stime = time.time()
            conn, user, passwd, ip, name = val
            res = False

            if is_host_alive(ip):
                print "Power off {0}:{1}".format(name, ip)
                cmd = SSHCMDExecutor(ip, username, passwd)
                cmd.exec_simple(*('sudo poweroff'.split()))
            
            print "wait while {0}:{1} stop pinging".format(name, ip)
            
            while time.time() - stime < max_time:
                if not is_host_alive(ip):
                    res = True
                    break

            if time.time() - stime > max_time and not res:
                print "Timeouted {0}:{1}. Destory it".format(name, ip)
            else:
                print "{0}:{1} don't responce on ping anymore. Destory it".format(name, ip)

            try:
                vm = conn.lookupByName(name)
                update_net_from_storage(vm)
            except libvirt.libvirtError:
                pass
            else:
                vm.destroy()
                
            return True
Example #2
0
def test_vm_starts():
    """
    starts vm
    creates folder on it with ssh
    and checks
    """
    vm = VM("oneiric")
    with vm.start():
        cmd = SSHCMDExecutor(vm.ip, vmuser, vmpass)
        cmd.exec_simple("mkdir /%s" % some_dir)
        tdirname = os.path.join(vm.fs.mpoint, some_dir)
        ok_(os.path.exists(tdirname))