Exemple #1
0
def have_accelerated_graphics(dut, domain, vm_address=None, timeout=10):
    """Test if domain on dut is a PVM"""
    if vm_address is None:
        vm_address = wait_for_windows(dut, domain, timeout=timeout)
    if (not call_exec_daemon('fileExists', ['C:\\Users\\bvt\\devcon.exe'],
                             host=vm_address)):
        call_exec_daemon('fetchFile', [
            'http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe',
            'C:\\Users\\bvt\\devcon.exe'
        ],
                         host=vm_address,
                         timeout=timeout)
        run_via_exec_daemon(['C:\\Users\\bvt\\devcon.exe', '/auto', '.'],
                            host=vm_address,
                            timeout=timeout)
    displays = run_via_exec_daemon(
        ['C:\\Users\\bvt\\i386\\devcon.exe listclass Display'],
        host=vm_address,
        timeout=timeout)
    #Status of onboard display driver. Should be disabled or have a problem if
    #AMD/Nvidia drivers are in place
    status = run_via_exec_daemon(
        ['C:\\Users\\bvt\\i386\\devcon.exe status PCI\VEN_1234*'],
        host=vm_address,
        timeout=timeout).split('\n')
    print 'INFO: accelerated graphics output', repr(displays)
    return ('problem' in status[2] or 'disabled' in status[2]) and \
        ('Standard VGA Graphics' not in displays) and \
        ('No devices' not in displays)
Exemple #2
0
def vm_reinstate_hibernate(dut, who='all'):
    """used to reinstate hibernate after vm_sleep_self call"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            call_exec_daemon('run', [r'powercfg -h on'], vmip)
def install_dev_certs(dut, dev, domain, vm_address):
    """Installing dev certs is critical to properly installing tools
        on 64 bit machines."""
    try:
        run_via_exec_daemon(['bcdedit', '/set', 'testsigning', 'on'],
                            host=vm_address)
        reboot_windows(dut, domain, vm_address)
        wait_for_windows(dut, domain['name'])
        username = get_username(dut, domain, vm_address, 'windows')
        call_exec_daemon('fetchFile', [
            'http://openxt.ainfosec.com/certificates/windows/developer.cer',
            'C:\\Users\\%s\\developer.cer' % username
        ],
                         host=vm_address,
                         timeout=300)
        run_via_exec_daemon([
            'certutil -addstore -f "Root" C:\\Users\\%s\\developer.cer' %
            username
        ],
                            host=vm_address)
        run_via_exec_daemon([
            'certutil -addstore -f "TrustedPublisher" C:\\Users\\%s\\developer.cer'
            % username
        ],
                            host=vm_address)
    except Exception:
        print "ERROR: Failure to install developer certs."
        print_exc()
        raise DevCertFailureException()
Exemple #4
0
def vm_reinstate_hibernate(dut,who='all'):
    """used to reinstate hibernate after vm_sleep_self call"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut,domain['name'])
            call_exec_daemon('run', [r'powercfg -h on'], vmip)
Exemple #5
0
def is_windows_up(host, timeout=60):
    """Return true if windows is up on vm_address"""
    try:
        call_exec_daemon('windowsVersion', [], host=host, timeout=timeout)
    except (TimeoutError, error):
        return False 
    else: return True
Exemple #6
0
def ensure_stable(vm_address, interval, timeout=600, description=None, method="exec_daemon"):
    """Ensure that vm_address is continuaully up for interval"""
    assert method in ['exec_daemon', "ssh"]
    last_down = time()
    start = time()
    last_out = time()
    reached = False
    while 1:
        delta = time() - last_down
        run_time = time() - start
        if delta > interval:
            print 'HEADLINE: VM at', vm_address, description, 'has been stable for', delta
            return
        if run_time > timeout:
            args = (time() - last_out, timeout, vm_address, description)
            if reached:
                raise SystemUnstable(*args)
            else:
                raise SystemUnreachable(*args)
        try:
            if method == "exec_daemon":
                call_exec_daemon('windowsVersion', [], host=vm_address, timeout=60)
            elif method == "ssh":
                run(['true'], host=vm_address, timeout=60, check_host_key=False)
            else:
                raise Exception("Unkonwn method %s" % method)
        except Exception, exc:
            last_down = time()
        else:
            delta = time() - last_down
            print 'WAIT_FOR_SYSTEM: stable for', delta, 'of', interval, 'seconds'
            last_out = time()
            reached = True
        sleep(1)
def launch_installer(dut, guest, vm_address, traditional, tools_iso_drive):
    """Launch installer, grab logs and reboot the required number of times"""

    width = get_width(vm_address)
    domain = find_domain(dut, guest)
    try:
        if traditional:
            print 'INFO: running tools installer'
            # TODO: use an in if construct to make this clearer
            run_via_exec_daemon([(XENSETUP_PATH_PATTERN % tools_iso_drive),
                                 '/S', '/norestart'],
                                timeout=3600,
                                host=vm_address)
            command2 = [(XENCLIENT_TOOLS_PATTERN[width] % tools_iso_drive),
                        '/passive', '/norestart', '/L*v', TOOLS_LOG_FILE]
            print 'INFO: running install stage 2', command2
            exitcode, _ = run_via_exec_daemon(command2,
                                              timeout=3600,
                                              host=vm_address,
                                              ignore_failure=True)
            print 'INFO: XenClientTools.msi exited with code', exitcode

            if exitcode not in [0, 3010]:
                raise UnableToInstallTools('unexpected exit code', exitcode,
                                           'from XenClientTools.msi')
        else:
            unattended_bat = UNATTENDED_PATH_PATTERN % (tools_iso_drive)
            call_exec_daemon('run', [unattended_bat, TOOLS_LOG_FILE],
                             host=vm_address)
            wait_for_guest_to_start(dut, domain['name'])

    finally:
        for sub_old, sub_new in [(None, None), ('.txt', '*.msi.txt')]:
            globp = (TOOLS_LOG_FILE if sub_old is None else
                     TOOLS_LOG_FILE.replace(sub_old, sub_new))
            print 'INFO: searching for logs matching', globp
            for globo in call_exec_daemon('globPattern', [globp],
                                          host=vm_address):
                print 'INFO: reading glob', globo
                try:
                    logf = call_exec_daemon('readFile', [globo],
                                            host=vm_address)
                except Fault, exc:
                    print 'INFO: got', exc, 'reading', TOOLS_LOG_FILE
                else:
                    log = ''.join(x for x in logf.data
                                  if ord(x) > 0 and ord(x) < 128 and x != '\r')
                    print 'INFO: read', TOOLS_LOG_FILE, 'size', len(log)
                    okay = False
                    for line in log.split('\n'):
                        if line:
                            print 'TOOLS:', globo, line
                        if 'Installation completed successfully' in line:
                            okay = True
                    del log
                    del logf
                if traditional and globo == TOOLS_LOG_FILE and not okay:
                    raise UnableToInstallTools(
                        'no success line in log file from XenClientTools')
Exemple #8
0
def test_graphics(vm_address, dut, domain):
    """Set 3D theme so we know pass through is working"""
    # TODO: check windows version properly
    if 'win7' not in domain:
        return
    call_exec_daemon('createFile', ['C:\\set_theme.vbs', CHANGE_THEME_VBS],
                     host=vm_address)
    run_via_exec_daemon(['C:\\set_theme.vbs'], host=vm_address)
Exemple #9
0
 def obtain():
     """Unpack devcon"""
     call_exec_daemon('fetchFile', [
         'http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe',
         'C:\\devcon.exe'
     ],
                      host=vm_address,
                      timeout=timeout)
Exemple #10
0
def test_graphics(vm_address, dut, domain):
    """Set 3D theme so we know pass through is working"""
    # TODO: check windows version properly
    if 'win7' not in domain:  
        return
    call_exec_daemon('createFile', ['C:\\set_theme.vbs', CHANGE_THEME_VBS], 
                     host=vm_address)
    run_via_exec_daemon(['C:\\set_theme.vbs'], host=vm_address)
Exemple #11
0
def is_windows_up(host, timeout=60):
    """Return true if windows is up on vm_address"""
    try:
        call_exec_daemon('windowsVersion', [], host=host, timeout=timeout)
    except (TimeoutError, error):
        return False
    else:
        return True
Exemple #12
0
def launch_installer(dut, guest, vm_address, traditional, tools_iso_drive):
    """Launch installer, grab logs and reboot the required number of times"""

    width = get_width(vm_address)
    domain = find_domain(dut, guest)
    try:
        if traditional:
            print 'INFO: running tools installer'
            # TODO: use an in if construct to make this clearer
            run_via_exec_daemon([(XENSETUP_PATH_PATTERN % tools_iso_drive),
                                 '/S', '/norestart'], timeout=3600, 
                                host=vm_address)
            command2 = [(XENCLIENT_TOOLS_PATTERN[width] % tools_iso_drive),
                        '/passive', '/norestart', '/L*v', TOOLS_LOG_FILE]
            print 'INFO: running install stage 2', command2
            exitcode, _ = run_via_exec_daemon(command2,
                timeout=3600, host=vm_address, ignore_failure=True)
            print 'INFO: XenClientTools.msi exited with code', exitcode

            if exitcode not in [0, 3010]:
                raise UnableToInstallTools(
                    'unexpected exit code', exitcode,
                    'from XenClientTools.msi')
        else:
            unattended_bat = UNATTENDED_PATH_PATTERN % (tools_iso_drive)
            call_exec_daemon('run', [unattended_bat, TOOLS_LOG_FILE],
                             host=vm_address)
            wait_for_guest_to_start(dut, domain['name'])

    finally:
        for sub_old, sub_new in [(None, None), ('.txt', '*.msi.txt')]:
            globp = (TOOLS_LOG_FILE if sub_old is None else
                     TOOLS_LOG_FILE.replace(sub_old, sub_new))
            print 'INFO: searching for logs matching', globp
            for globo in call_exec_daemon('globPattern', [globp],
                                          host=vm_address):
                print 'INFO: reading glob', globo
                try:
                    logf = call_exec_daemon('readFile', [globo],
                                            host=vm_address)
                except Fault, exc:
                    print 'INFO: got', exc, 'reading', TOOLS_LOG_FILE
                else:
                    log = ''.join(x for x in logf.data if ord(x) > 0 and
                                  ord(x) < 128 and x != '\r')
                    print 'INFO: read', TOOLS_LOG_FILE, 'size', len(log)
                    okay = False
                    for line in log.split('\n'):
                        if line:
                            print 'TOOLS:', globo, line
                        if 'Installation completed successfully' in line:
                            okay = True
                    del log
                    del logf
                if traditional and globo == TOOLS_LOG_FILE and not okay:
                    raise UnableToInstallTools(
                        'no success line in log file from XenClientTools')
Exemple #13
0
def vm_sleep_self(dut, who='all'):
    """sleep vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            print "turning off hibernate :" + str(call_exec_daemon(command='run', args=[r'powercfg -h off'], host=vmip, timeout=60))
            sleep(4)
            call_exec_daemon('run', [r'C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState sleep'], vmip)
Exemple #14
0
def vm_shutdown_self(dut, who='all'):
    """shutdown vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            call_exec_daemon('run', ['shutdown -s'], host=vmip, timeout=60)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Exemple #15
0
def vm_shutdown_self(dut, who='all'):
    """shutdown vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            call_exec_daemon('run', ['shutdown -s'], host=vmip, timeout=60)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Exemple #16
0
def vm_hibernate_self(dut, who='all'):
    """hibernate vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            call_exec_daemon('run', [r'C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState hibernate'], host=vmip, timeout=60)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Exemple #17
0
def check_vm_status(machine):
        can_connect = []
        f=1
        domlist = domains.list_vms(machine)
        for domain in domlist:
            if (domain['name']!='uivm'):
                try:
                    call_exec_daemon('dir',host = machine)
                except Exception, e:
                    print 'POWER:', 'trying to connect to exec daemon',e
                    f=0
Exemple #18
0
def check_vm_status(machine):
    can_connect = []
    f = 1
    domlist = domains.list_vms(machine)
    for domain in domlist:
        if (domain['name'] != 'uivm'):
            try:
                call_exec_daemon('dir', host=machine)
            except Exception, e:
                print 'POWER:', 'trying to connect to exec daemon', e
                f = 0
Exemple #19
0
def soft_shutdown_guest(host, guest, timeout=DEFAULT_SHUTDOWN_TIMEOUT, method="exec_daemon"):
    """Shutdown guest using platform-specific method"""
    if is_stopped(host, guest):
        return True
    vm_address = domain_address(host, guest, timeout=5)
    if method == "exec_daemon":
        call_exec_daemon('shutdown', host=vm_address, timeout=20)
    elif method == "ssh":
        run(['shutdown', '-h', 'now'], host=vm_address, timeout=20, check_host_key=False)
    else:
        raise Exception("Unknown method %s" % method)
    wait_for_shutdown(host, guest, timeout=timeout)
    return True
Exemple #20
0
def install_tools(dut, guest):
    """Install tools on guest on dut"""
    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    print 'INSTALL_TOOLS: installing tools on', domain
    vm_address = wait_for_windows(dut, guest)
    print 'HEADLINE: contacted', guest, 'and checking for tools'
    if tools_install_problems(dut, guest) is None:
        raise ToolsAlreadyInstalled(dut, guest, vm_address)

    install_dotnet(dut, vm_address, guest)

    tools_iso_drive = make_tools_iso_available(dut, vm_address, guest,
                                               domain)
    print 'HEADLINE: tools ISO available on', tools_iso_drive

    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    ensure_stable(vm_address, 30, description=guest+' on '+dut)
    unattended_bat = UNATTENDED_PATH_PATTERN % (tools_iso_drive)
    print 'INFO: checking for %s on tools CD' % (unattended_bat)
    traditional = not call_exec_daemon('fileExists', [unattended_bat],
                                       host=vm_address)
    # TODO: do we need prompt remover on XP for new (non-traditional) installer?
    attended = traditional or 'xp' in guest
    prompt_remover_control = None

    install_dev_certs(dut, guest, domain, vm_address)

    if attended:
        prompt_remover_control = (start_prompt_remover(vm_address))
        # TODO: run ensure_stable unconditinally i.e. for unattend install as well
        ensure_stable(vm_address, 60, description=guest+' on '+dut)
        print 'INFO: prompt remover started'
    try:
        if not tools_install_problems(dut, guest):
            print 'INFO: tools install already okay for', dut, guest
        else:
            launch_installer(dut, guest, vm_address, traditional,
                             tools_iso_drive)
    finally:
        if attended:
            stop_prompt_remover(prompt_remover_control, vm_address)
    print 'INSTALL_TOOLS:', domain, 'tools installation complete'
    ensure_stable(vm_address, 30, description=guest+' on '+dut)
    print call_exec_daemon('ps', [], host=vm_address)
    problems = tools_install_problems(dut, guest)
    if problems:
        print 'HEADLINE:', problems
        raise UnableToInstallTools(problems)
    print 'HEADLINE: tools installed correctly on', guest, 'at', vm_address
def install_tools(dut, guest):
    """Install tools on guest on dut"""
    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    print 'INSTALL_TOOLS: installing tools on', domain
    vm_address = wait_for_windows(dut, guest)
    print 'HEADLINE: contacted', guest, 'and checking for tools'
    if tools_install_problems(dut, guest) is None:
        raise ToolsAlreadyInstalled(dut, guest, vm_address)

    install_dotnet(dut, vm_address, guest)

    tools_iso_drive = make_tools_iso_available(dut, vm_address, guest, domain)
    print 'HEADLINE: tools ISO available on', tools_iso_drive

    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    ensure_stable(vm_address, 30, description=guest + ' on ' + dut)
    unattended_bat = UNATTENDED_PATH_PATTERN % (tools_iso_drive)
    print 'INFO: checking for %s on tools CD' % (unattended_bat)
    traditional = not call_exec_daemon('fileExists', [unattended_bat],
                                       host=vm_address)
    # TODO: do we need prompt remover on XP for new (non-traditional) installer?
    attended = traditional or 'xp' in guest
    prompt_remover_control = None

    install_dev_certs(dut, guest, domain, vm_address)

    if attended:
        prompt_remover_control = (start_prompt_remover(vm_address))
        # TODO: run ensure_stable unconditinally i.e. for unattend install as well
        ensure_stable(vm_address, 60, description=guest + ' on ' + dut)
        print 'INFO: prompt remover started'
    try:
        if not tools_install_problems(dut, guest):
            print 'INFO: tools install already okay for', dut, guest
        else:
            launch_installer(dut, guest, vm_address, traditional,
                             tools_iso_drive)
    finally:
        if attended:
            stop_prompt_remover(prompt_remover_control, vm_address)
    print 'INSTALL_TOOLS:', domain, 'tools installation complete'
    ensure_stable(vm_address, 30, description=guest + ' on ' + dut)
    print call_exec_daemon('ps', [], host=vm_address)
    problems = tools_install_problems(dut, guest)
    if problems:
        print 'HEADLINE:', problems
        raise UnableToInstallTools(problems)
    print 'HEADLINE: tools installed correctly on', guest, 'at', vm_address
Exemple #22
0
def vm_hibernate_self(dut, who='all'):
    """hibernate vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            call_exec_daemon('run', [
                r'C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState hibernate'
            ],
                             host=vmip,
                             timeout=60)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
def get_msi_versions(vm_address):
    """Return the MSI version installed (e.g. "6.2.14883") or
    None if no MSI is installed"""
    content = """
import _winreg, sys
versions = {}
for base in [
  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"]:
    try:
       uninstall = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, base)
    except WindowsError:
       continue   
    try:
       i = 0
       while 1:
           sub = _winreg.EnumKey(uninstall, i)
           subk = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, base+'\\'+sub)
           j = 0
           progname = version = None
           try:
               while 1:
                   name, value, _ = _winreg.EnumValue(subk, j)
                   if name == 'DisplayName':
                        progname = value
                   if name == 'DisplayVersion':
                        version = value
                   #print >>sys.stderr, i,j, sub, 'entry', name, value
                   j += 1
           except WindowsError:
               pass
           if progname:
               versions[progname] = version
           i += 1
    except WindowsError:
        pass
print versions
""".replace('\\', '\\\\')
    call_exec_daemon('createFile', ['C:\\list_installed_programs.py', content],
                     host=vm_address)
    try:
        versions = eval(
            run_via_exec_daemon(['C:\\list_installed_programs.py'],
                                host=vm_address))
        print 'INSTALL_TOOLS: versions installed=', versions
    finally:
        call_exec_daemon('removeFile', ['C:\\list_installed_programs.py'],
                         host=vm_address)
        pass
    return versions
Exemple #24
0
def install_dev_certs(dut, dev, domain, vm_address):
    """Installing dev certs is critical to properly installing tools
        on 64 bit machines."""
    try:
        run_via_exec_daemon(['bcdedit','/set', 'testsigning', 'on'], host=vm_address)
        reboot_windows(dut, domain, vm_address)
        wait_for_windows(dut, domain['name'])
        username = get_username(dut,domain,vm_address,'windows')
        call_exec_daemon('fetchFile', ['http://openxt.ainfosec.com/certificates/windows/developer.cer', 'C:\\Users\\%s\\developer.cer'% username], host=vm_address, timeout=300)
        run_via_exec_daemon(['certutil -addstore -f "Root" C:\\Users\\%s\\developer.cer'% username], host=vm_address)
        run_via_exec_daemon(['certutil -addstore -f "TrustedPublisher" C:\\Users\\%s\\developer.cer'% username], host=vm_address)
    except Exception:
        print "ERROR: Failure to install developer certs."
        print_exc()
        raise DevCertFailureException()
Exemple #25
0
def vm_sleep_self(dut, who='all'):
    """sleep vm/vms from within the VM"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            print "turning off hibernate :" + str(
                call_exec_daemon(command='run',
                                 args=[r'powercfg -h off'],
                                 host=vmip,
                                 timeout=60))
            sleep(4)
            call_exec_daemon('run', [
                r'C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState sleep'
            ], vmip)
Exemple #26
0
def get_msi_versions(vm_address):
    """Return the MSI version installed (e.g. "6.2.14883") or
    None if no MSI is installed"""
    content = """
import _winreg, sys
versions = {}
for base in [
  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
  "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"]:
    try:
       uninstall = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, base)
    except WindowsError:
       continue   
    try:
       i = 0
       while 1:
           sub = _winreg.EnumKey(uninstall, i)
           subk = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, base+'\\'+sub)
           j = 0
           progname = version = None
           try:
               while 1:
                   name, value, _ = _winreg.EnumValue(subk, j)
                   if name == 'DisplayName':
                        progname = value
                   if name == 'DisplayVersion':
                        version = value
                   #print >>sys.stderr, i,j, sub, 'entry', name, value
                   j += 1
           except WindowsError:
               pass
           if progname:
               versions[progname] = version
           i += 1
    except WindowsError:
        pass
print versions
""".replace('\\', '\\\\')
    call_exec_daemon('createFile', ['C:\\list_installed_programs.py', content],
                     host=vm_address)
    try:
        versions = eval(run_via_exec_daemon(['C:\\list_installed_programs.py'],
                                            host=vm_address))
        print 'INSTALL_TOOLS: versions installed=', versions
    finally:
        call_exec_daemon('removeFile', ['C:\\list_installed_programs.py'], host=vm_address)
        pass
    return versions
Exemple #27
0
def compile(vm_address, name, program):
    """Generate an EXE on vm_address"""
    target_file = 'C:\\install\\'+name+'.au3'    
    call_exec_daemon('unpackTarball', 
                     ['http://autotest.cam.xci-test.com/bin/autoit.tar.gz',
                      'C:\\'], host=vm_address)
    run_via_exec_daemon(['del', target_file], timeout=600, host=vm_address)
    call_exec_daemon('createFile', [target_file, program], host=vm_address)
    target_exe  = target_file.replace('.au3', '.exe')
    run_via_exec_daemon(['taskkill', '/IM', target_exe.split('\\')[-1]], 
                        timeout=600, ignore_failure=True, host=vm_address)
    run_via_exec_daemon(['del', target_exe], timeout=600, host=vm_address)
    run_via_exec_daemon(['C:\\install\\autoit3\\aut2exe\\aut2exe.exe', '/in',
                        target_file, '/out', target_exe], timeout=600,
                        host=vm_address)
    return target_exe
def get_width(vm_address):
    """Return CPU width of vm_addresss"""
    try:
        result = call_exec_daemon('getEnvVar', ['ProgramFiles(x86)'],
                                  host=vm_address)
    except Fault:
        return 32
    else:
        return 64 if '\\' in result else 32
Exemple #29
0
def get_width(vm_address):
    """Return CPU width of vm_addresss"""
    try:
        result = call_exec_daemon('getEnvVar', ['ProgramFiles(x86)'],
                                  host=vm_address)
    except Fault:
        return 32
    else:
        return 64 if '\\' in result else 32
Exemple #30
0
def soft_shutdown_guest(host,
                        guest,
                        timeout=DEFAULT_SHUTDOWN_TIMEOUT,
                        method="exec_daemon"):
    """Shutdown guest using platform-specific method"""
    if is_stopped(host, guest):
        return True
    vm_address = domain_address(host, guest, timeout=5)
    if method == "exec_daemon":
        call_exec_daemon('shutdown', host=vm_address, timeout=20)
    elif method == "ssh":
        run(['shutdown', '-h', 'now'],
            host=vm_address,
            timeout=20,
            check_host_key=False)
    else:
        raise Exception("Unknown method %s" % method)
    wait_for_shutdown(host, guest, timeout=timeout)
    return True
Exemple #31
0
def ensure_stable(vm_address,
                  interval,
                  timeout=600,
                  description=None,
                  method="exec_daemon"):
    """Ensure that vm_address is continuaully up for interval"""
    assert method in ['exec_daemon', "ssh"]
    last_down = time()
    start = time()
    last_out = time()
    reached = False
    while 1:
        delta = time() - last_down
        run_time = time() - start
        if delta > interval:
            print 'HEADLINE: VM at', vm_address, description, 'has been stable for', delta
            return
        if run_time > timeout:
            args = (time() - last_out, timeout, vm_address, description)
            if reached:
                raise SystemUnstable(*args)
            else:
                raise SystemUnreachable(*args)
        try:
            if method == "exec_daemon":
                call_exec_daemon('windowsVersion', [],
                                 host=vm_address,
                                 timeout=60)
            elif method == "ssh":
                run(['true'],
                    host=vm_address,
                    timeout=60,
                    check_host_key=False)
            else:
                raise Exception("Unkonwn method %s" % method)
        except Exception, exc:
            last_down = time()
        else:
            delta = time() - last_down
            print 'WAIT_FOR_SYSTEM: stable for', delta, 'of', interval, 'seconds'
            last_out = time()
            reached = True
        sleep(1)
Exemple #32
0
def start_prompt_remover(vm_address):
    """Start our interactive GUI prompt invoker, and return
    a control tuple suitable for stop_prompt_remover"""
    call_exec_daemon('unpackTarball', [None, 'C:\\'], host = vm_address)
    script = autoit_generator.install_tools_script
    for line in script.split('\n'):
        print 'AUTOIT:', line
    target_exe = autoit_generator.compile(vm_address,
                                          'prompt_remover_generated', script)
    autorun_dir = "C:\\docume~1\\admini~1\\startm~1\\Programs\\Startup"
    run_via_exec_daemon(['mkdir', autorun_dir], host=vm_address,
                        ignore_failure=True)
    autorun_promptremover_file = autorun_dir+'\\promptremove.bat'
    call_exec_daemon('createFile',
                     [autorun_promptremover_file, target_exe+'\r\n'],
                     host=vm_address)

    process = Process(target=loop_run_program, args=(target_exe, vm_address))
    process.start()
    return process, target_exe
Exemple #33
0
def is_dotnet_installed(vm_address):
    """Return true if the dot net version the tools require is installed"""
    try:
        value = call_exec_daemon('regLookup',  
                                 ['HKLM', DOTNET_4_KEY, DOTNET_4_NAME],
                                 host=vm_address)
    except Fault:
        print 'INFO: .NET key not found on', vm_address
        return False
    print 'INFO: .NET key found with value', value, 'on', vm_address
    return True
def start_prompt_remover(vm_address):
    """Start our interactive GUI prompt invoker, and return
    a control tuple suitable for stop_prompt_remover"""
    call_exec_daemon('unpackTarball', [None, 'C:\\'], host=vm_address)
    script = autoit_generator.install_tools_script
    for line in script.split('\n'):
        print 'AUTOIT:', line
    target_exe = autoit_generator.compile(vm_address,
                                          'prompt_remover_generated', script)
    autorun_dir = "C:\\docume~1\\admini~1\\startm~1\\Programs\\Startup"
    run_via_exec_daemon(['mkdir', autorun_dir],
                        host=vm_address,
                        ignore_failure=True)
    autorun_promptremover_file = autorun_dir + '\\promptremove.bat'
    call_exec_daemon('createFile',
                     [autorun_promptremover_file, target_exe + '\r\n'],
                     host=vm_address)

    process = Process(target=loop_run_program, args=(target_exe, vm_address))
    process.start()
    return process, target_exe
Exemple #35
0
def have_accelerated_graphics( dut, domain, vm_address=None, timeout=10):
    """Test if domain on dut is a PVM"""
    if vm_address is None:
        vm_address = wait_for_windows(dut, domain, timeout=timeout)
    if (not call_exec_daemon('fileExists', ['C:\\Users\\bvt\\devcon.exe'], host=vm_address)):
        call_exec_daemon('fetchFile',
            ['http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe', 'C:\\Users\\bvt\\devcon.exe'],
            host= vm_address, timeout=timeout)
        run_via_exec_daemon(
            ['C:\\Users\\bvt\\devcon.exe', '/auto', '.'], host=vm_address,
            timeout=timeout)
    displays = run_via_exec_daemon(
        ['C:\\Users\\bvt\\i386\\devcon.exe listclass Display'], host=vm_address,
        timeout=timeout)
    #Status of onboard display driver. Should be disabled or have a problem if 
    #AMD/Nvidia drivers are in place
    status = run_via_exec_daemon(
        ['C:\\Users\\bvt\\i386\\devcon.exe status PCI\VEN_1234*'], host=vm_address,
        timeout=timeout).split('\n')
    print 'INFO: accelerated graphics output', repr(displays)
    return ('problem' in status[2] or 'disabled' in status[2]) and \
        ('Standard VGA Graphics' not in displays) and \
        ('No devices' not in displays)
Exemple #36
0
def compile(vm_address, name, program):
    """Generate an EXE on vm_address"""
    target_file = 'C:\\install\\' + name + '.au3'
    call_exec_daemon(
        'unpackTarball',
        ['http://autotest.cam.xci-test.com/bin/autoit.tar.gz', 'C:\\'],
        host=vm_address)
    run_via_exec_daemon(['del', target_file], timeout=600, host=vm_address)
    call_exec_daemon('createFile', [target_file, program], host=vm_address)
    target_exe = target_file.replace('.au3', '.exe')
    run_via_exec_daemon(
        ['taskkill', '/IM', target_exe.split('\\')[-1]],
        timeout=600,
        ignore_failure=True,
        host=vm_address)
    run_via_exec_daemon(['del', target_exe], timeout=600, host=vm_address)
    run_via_exec_daemon([
        'C:\\install\\autoit3\\aut2exe\\aut2exe.exe', '/in', target_file,
        '/out', target_exe
    ],
                        timeout=600,
                        host=vm_address)
    return target_exe
Exemple #37
0
def find_tools_iso(host):
    """A tricky safety feature to make sure we install the right ISO """
    for path in TOOLS_ISO_FILES:
        for drive in [chr(ord('A') + n) for n in range(3, 26)]:
            try:
                full = drive + path
                print 'INSTALL_TOOLS: looking for', full, 'on', host
                ret = call_exec_daemon('fileExists', [full], host=host)
                if ret:
                    print 'INSTALL_TOOLS: found tools ISO on', drive, \
                        'return', ret
                    return drive
            except Fault:
                pass
    raise UnableToFindTools(TOOLS_ISO_FILES)
Exemple #38
0
def get_windows_iperf(host, destd='C:/iperf'):
    """Put iperf on host at destd"""
    iperf_local = '/tmp/iperf_win.zip'
    if not isfile(iperf_local):
        run([
            'wget', '--no-check-certificate', '-O', iperf_local,
            IPERF_WINDOWS_DOWNLOAD[0]
        ])
    sha256sum = run(['sha256sum', iperf_local], word_split=True)[0]
    if sha256sum != IPERF_WINDOWS_DOWNLOAD[1]:
        raise DidNotFindExpectedIperfBinary('have', sha256sum, 'want',
                                            IPERF_WINDOWS_DOWNLOAD)
    with ZipFile(iperf_local) as zipobj:
        tempd = mkdtemp(suffix='.iperf.tar')
        with tarfile.open(name=tempd + '/iperf.tar', mode='w') as tarobj:
            for zipinfo in zipobj.infolist():
                print 'TRANSFER: transferring %s (%dKB)' % (
                    zipinfo.filename, zipinfo.file_size / 1024)
                tarinfo = tarfile.TarInfo(zipinfo.filename)
                tarinfo.size = zipinfo.file_size
                tarobj.addfile(tarinfo, zipobj.open(zipinfo.filename))
        with TemporaryWebServer(tempd) as web:
            call_exec_daemon('unpackTarball',
                             [web.url + '/iperf.tar', 'C:/iperf'],
                             host=host)
        for zipinfo in zipobj.infolist():
            destf = destd + '/' + zipinfo.filename
            if zipinfo.file_size == 0:
                continue
            print 'TRANSFER: checking', destf, zipinfo.file_size
            have = call_exec_daemon('sha1Sum', [destf], host=host)
            want = sha1(zipobj.open(zipinfo.filename).read()).hexdigest()
            if have != want:
                raise IperfTransferError(destf, 'have', have, 'want', want)
            print 'TRANSFER: Correctly transferred', destf, 'hash', have
    return destd + '/iperf.exe'
Exemple #39
0
def find_tools_iso(host):
    """A tricky safety feature to make sure we install the right ISO """
    for path in TOOLS_ISO_FILES:
        for drive in [chr(ord('A')+n) for n in range(3, 26)]:
            try:
                full = drive+path
                print 'INSTALL_TOOLS: looking for', full, 'on', host
                ret = call_exec_daemon('fileExists', [full], host=host)
                if ret:
                    print 'INSTALL_TOOLS: found tools ISO on', drive, \
                        'return', ret
                    return drive
            except Fault: 
                pass
    raise UnableToFindTools(TOOLS_ISO_FILES)
Exemple #40
0
 def obtain():
     """Unpack devcon"""
     call_exec_daemon('fetchFile', ['http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe', 'C:\\devcon.exe'], host=vm_address, timeout=timeout)
Exemple #41
0
 def check_windows_version():
     """Check that VM is still running"""
     check_running()
     out = call_exec_daemon('windowsVersion', [], host=address, timeout=60)
     print 'WAIT_FOR_SYSTEM: windows version returned', out
Exemple #42
0
 def check_windows_version():
     """Check that VM is still running"""
     check_running()
     out = call_exec_daemon('windowsVersion', [], host=address, timeout=60)
     print 'WAIT_FOR_SYSTEM: windows version returned', out