Exemple #1
0
def have_driver(host, section, name):
    """Does host have driver name in section?"""
    try:

        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)

        retry(obtain, 'download devcon', timeout=60)
        run_via_exec_daemon(['C:\\devcon.exe', '/auto', '.'],
                            host=vm_address,
                            timeout=timeout)
        drivers = run_via_exec_daemon(
            ['C:\\devcon\\i386\\devcon.exe', 'listclass', section],
            timeout=60,
            host=host)
        print 'TOOLS: have', section, 'drivers', drivers
        print 'INFO:', 'found' if name in drivers else 'did not find', name
        return name in drivers
    except SubprocessError:
        pass
    return False
Exemple #2
0
def disableSnapshot(machine, vms, steps, build, test_path, caller):
    dummy = str(random.randint(10000, 20000))
    vm_address = str(domain_address(machine, vms))
    r = run(['xec-vm', '-n', vms, '--disk', '1', 'get', 'snapshot'],
            host=machine)
    if 'temporary' in r:
        tslib.forcepowerstate(machine, 'off', vms)
        r = run(
            ['xec-vm', '-n', vms, '--disk', '1', 'set', 'snapshot', 'none'],
            host=machine)
        tslib.cmdResponse(r,
                          'xec-vm -n ' + vms + ' --disk 1 set snapshot none')
        snapshot = run(['xec-vm', '-n', vms, '--disk', '1', 'get', 'snapshot'],
                       host=machine)
        tslib.cmdResponse(r, 'xec-vm -n ' + vms + ' --disk 1 get snapshot')
        if 'none' not in snapshot:
            tslib.pauseToDebug("xec failed to disable snapshot")
        windows_transitions.vm_poweron(machine, vms)
        for i in range(2):
            windows_transitions.vm_reboot_dom0(machine, vms)
    res = run_via_exec_daemon(
        ['mkdir', 'C:\\Users\\Administrator\\Desktop\\' + dummy],
        host=vm_address,
        wait=True)
    windows_transitions.vm_reboot_dom0(machine, vms)
    res = run_via_exec_daemon(['dir', 'C:\\Users\\Administrator\\Desktop\\'],
                              host=vm_address,
                              wait=True)
    if dummy not in res:
        tslib.pauseToDebug("Snapshot disabled: Old folders lost after reboot")
Exemple #3
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)
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 #5
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 #6
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 #7
0
def standby_windows(vm_address):
    """Put windows VM at vm_address into standby."""
    print 'HEADLINE: runing powerprof.dll SetSupsendState Standby',
    print 'which we think actually hibernates the VM'
    run_via_exec_daemon(['C:\\Windows\\System32\\rundll32.exe', 
                         'powrprof.dll,SetSuspendState', 'Standby'], 
                        host=vm_address, wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #8
0
def hibernate_windows(vm_address):
    """Put windows VM at vm_address into standby."""
    run_via_exec_daemon([
        'C:\\Windows\\System32\\rundll32.exe', 'powrprof.dll,SetSuspendState',
        'Hibernate'
    ],
                        host=vm_address,
                        wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #9
0
def kill_prompt_remover(vm_address):
    """Kill the prompt remover"""
    try:
        run_via_exec_daemon(['taskkill', '/IM',
                             'prompt_remover_generated.exe'],
                            host=vm_address, ignore_failure=True)
    except error, exc:
        print 'INSTALL_TOOLS: ignoring socket error', exc, \
            'killing prompt remover'
Exemple #10
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')
def kill_prompt_remover(vm_address):
    """Kill the prompt remover"""
    try:
        run_via_exec_daemon(
            ['taskkill', '/IM', 'prompt_remover_generated.exe'],
            host=vm_address,
            ignore_failure=True)
    except error, exc:
        print 'INSTALL_TOOLS: ignoring socket error', exc, \
            'killing prompt remover'
Exemple #12
0
def standby_windows(vm_address):
    """Put windows VM at vm_address into standby."""
    print 'HEADLINE: runing powerprof.dll SetSupsendState Standby',
    print 'which we think actually hibernates the VM'
    run_via_exec_daemon([
        'C:\\Windows\\System32\\rundll32.exe', 'powrprof.dll,SetSuspendState',
        'Standby'
    ],
                        host=vm_address,
                        wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #13
0
def loop_run_program(target_exe, vm_address):
    """Run process in loop"""
    while 1:
        print 'INSTALL_TOOLS: starting', target_exe, 'on', vm_address

        try:
            run_via_exec_daemon([target_exe], host=vm_address,
                                timeout=24*60*60)
        except Exception, exc:
            print 'failed with', exc
        sleep(5)
def loop_run_program(target_exe, vm_address):
    """Run process in loop"""
    while 1:
        print 'INSTALL_TOOLS: starting', target_exe, 'on', vm_address

        try:
            run_via_exec_daemon([target_exe],
                                host=vm_address,
                                timeout=24 * 60 * 60)
        except Exception, exc:
            print 'failed with', exc
        sleep(5)
Exemple #15
0
def get_architecture(host,guest):
   if not is_acpi_state(host,guest,0):
       guest_start(host,guest)
       guest_switch(host,guest)
       wait_for_guest(host,guest)
   os = get_system_type(host,guest)

   if os == 'windows':
       unparsed = run_via_exec_daemon(['systeminfo'], host=domain_address(host,guest),line_split=True)
       for line in unparsed:
           if "System Type" in line:
               correct_line = line.split(" ")
               break
       if correct_line == None:
           print "ERR: Architecture not returned"
           raise InformationCollectionFailure()
       temp = correct_line
       correct_line = None
       for seg in temp:
           if any(char.isdigit() for char in seg):
               correct_line = seg
               break
       if correct_line == None:
           print "ERR: Architecture not returned"
           raise InformaitonCollectionFailure()
       Arch = re.sub("\D", "", correct_line)
       return Arch.strip()

   elif os == 'linux':
       return run(['uname','-m'],host=domain_address(host,guest),ignore_failure=True)[0].strip() 
   else:
       raise UnexpectedOs() 
Exemple #16
0
def odtd_install_guest(dut, guest='st_xp', kind='iso'):
    print 'HEADLINE: installing',guest,'on',dut,'from',kind
    sdir = '/storage/isos' 
    dest_file = (sdir+'/st_'+guest+'.'+kind)
    install_guest.download_image(dut, kind, guest, dest_file)
    rubyd = ('{"name"=>"%s", '
                 '"image_path"=>"images\\/vms/000_XenClient_h32bit_256.png", '
                 '"config.memory"=>"1024", "cd"=>"st_%s.iso", '
                 '"description"=>"%s", '
                 '"config.vcpus"=>"1", '
                 '"wired_network"=>"bridged"}' % (guest,guest,guest))
    vmid_raw = run(['xec', 'create', rubyd], host=dut)
    full_vmid = vmid_raw.split()[0]
    short_vmid = full_vmid.split('/')[-1].replace('_','-')
    vhdid_raw = run(['xec', '-o', full_vmid, '-i', 'com.citrix.xenclient.xenmgr.vm addEmptyDisk', '40'], host=dut)  
    vhdid = vhdid_raw.split()[0]
    run(['xec', '-o', full_vmid, '-i', 'com.citrix.xenclient.xenmgr.vm', 'setDisk', vhdid, 'device', 'hda'], host=dut) 
    run(['db-read /vm/', short_vmid, '/config/disk/', vhdid, '/path'], host=dut) 
    vm_address = start_vm(dut, guest, timeout=start_timeout, busy_stop=busy_stop)
    print 'INSTALL_GUEST: start_vm returned, address', vm_address
    ensure_stable(vm_address, 30, description = guest + ' on '+dut)
    print 'INSTALL_GUEST: VM stable'
    print 'INSTALL_GUEST: dir c: replied with %d bytes' % (
        len(run_via_exec_daemon(['dir', 'C:\\'], host=vm_address)))
    return vm_address
Exemple #17
0
def guest_disk_count(host, guest):
    """function to get the count of 'disks' the guest sees"""
    total_disk_count = 0
    os = get_system_type(host, guest)
    if os == 'windows':
        unparsed = run_via_exec_daemon([
            'echo', 'list', 'disk', '|', 'diskpart', '|', 'find', '"Disk"',
            '|', 'find', '"Online"'
        ],
                                       host=domain_address(host,
                                                           guest,
                                                           timeout=5),
                                       line_split=True)
        #necessary as windows sometimes puts random blank lines at the end
        print "DEBUG: " + ',,'.join(unparsed)
        for entry in unparsed:
            if "Disk" in entry:
                total_disk_count += 1
    elif os == 'linux':
        unparsed = run(['lsblk', '-l', '-o', 'NAME,TYPE'],
                       host=domain_address(host, guest, timeout=5),
                       timeout=20,
                       check_host_key=False,
                       line_split=True)
        for entry in unparsed:
            if "disk" in entry:
                total_disk_count += 1
    else:
        raise UnexpectedOs()

    print "DEBUG: returning guest: \"%s\" has %d disks" % (guest,
                                                           total_disk_count)
    return total_disk_count
def get_running_services(vm_address):
    """Return the set of services running on vm_address"""
    services = set([
        ' '.join(line) for line in run_via_exec_daemon(
            ['net', 'start'], split=True, host=vm_address)[2:-4]
    ])
    print 'INSTALL_TOOLS: services running', sorted(services)
    return services
Exemple #19
0
def have_driver(host, section, name):
    """Does host have driver name in section?"""
    try:
        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)
        retry(obtain, 'download devcon', timeout=60)
        run_via_exec_daemon(['C:\\devcon.exe', '/auto', '.'], host=vm_address,timeout=timeout)
        drivers = run_via_exec_daemon(['C:\\devcon\\i386\\devcon.exe', 
                                       'listclass', 
                                       section], timeout=60, host=host)
        print 'TOOLS: have',section, 'drivers', drivers
        print 'INFO:', 'found' if name in drivers else 'did not find', name
        return name in drivers
    except SubprocessError:
        pass
    return False
Exemple #20
0
def get_running_services(vm_address):
    """Return the set of services running on vm_address"""
    services = set([
        ' '.join(line) for line in
        run_via_exec_daemon(['net', 'start'], split=True,
                            host=vm_address)[2:-4]])
    print 'INSTALL_TOOLS: services running', sorted(services)
    return services
Exemple #21
0
def disableSnapshot(machine,vms,steps,build,test_path,caller):
    dummy = str(random.randint(10000,20000))
    vm_address = str(domain_address(machine, vms))
    r = run(['xec-vm','-n',vms,'--disk','1','get','snapshot'], host=machine)
    if 'temporary' in r:
        tslib.forcepowerstate(machine, 'off', vms)
        r = run(['xec-vm','-n',vms,'--disk','1','set','snapshot','none'], host=machine)
        tslib.cmdResponse(r, 'xec-vm -n '+vms+' --disk 1 set snapshot none')
        snapshot = run(['xec-vm','-n',vms,'--disk','1','get','snapshot'], host=machine)
        tslib.cmdResponse(r, 'xec-vm -n '+vms+' --disk 1 get snapshot')
        if 'none' not in snapshot: tslib.pauseToDebug("xec failed to disable snapshot")
        windows_transitions.vm_poweron(machine, vms)
        for i in range(2): windows_transitions.vm_reboot_dom0(machine, vms) 
    res = run_via_exec_daemon(['mkdir','C:\\Users\\Administrator\\Desktop\\'+dummy],host=vm_address, wait=True)
    windows_transitions.vm_reboot_dom0(machine, vms)
    res = run_via_exec_daemon(['dir','C:\\Users\\Administrator\\Desktop\\'],host=vm_address, wait=True)       
    if dummy not in res: tslib.pauseToDebug("Snapshot disabled: Old folders lost after reboot")         
Exemple #22
0
def install_dotnet(dut, vm_address, guest):
    """Install dotnet on guest """
    ensure_stable(vm_address, 5, description=guest+' on '+dut)
    if is_dotnet_installed(vm_address):
        print 'INFO: already have .NET installed'
        return
    domain = find_domain(dut, guest)
    print 'HEADLINE: installing .NET'

    try:
        tools_iso_drive = make_tools_iso_available(dut, vm_address, guest, domain)
        run_via_exec_daemon(['%s:\\windows\\dotNetFx40_Full_x86_x64.exe' %tools_iso_drive, '/passive'], timeout=3600, 
                            host=vm_address)
    except (error, Fault):
        wait_for_windows(dut, guest)
    except SubprocessError, exc:
        if exc.args[0] == 3010:
            print 'INFO: dotnet installer indicated reboot required'
Exemple #23
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
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
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 #26
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_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 #28
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 #29
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 #30
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 #31
0
def guest_disk_count(host,guest):
    """function to get the count of 'disks' the guest sees"""
    total_disk_count = 0
    os = get_system_type(host,guest)
    if os == 'windows':
        unparsed = run_via_exec_daemon(['echo', 'list', 'disk', '|', 'diskpart','|','find','"Disk"','|','find','"Online"'],host=domain_address(host, guest, timeout=5),line_split=True)
        #necessary as windows sometimes puts random blank lines at the end
        print "DEBUG: "+',,'.join(unparsed)
        for entry in unparsed:
            if "Disk" in entry:
                total_disk_count += 1
    elif os == 'linux':
        unparsed = run(['lsblk','-l','-o','NAME,TYPE'], host=domain_address(host, guest, timeout=5), timeout=20, check_host_key=False, line_split=True)
        for entry in unparsed:
            if "disk" in entry:
                total_disk_count += 1
    else:
        raise UnexpectedOs() 

    print "DEBUG: returning guest: \"%s\" has %d disks" % (guest,total_disk_count)
    return total_disk_count
Exemple #32
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 #33
0
def odtd_install_guest(dut, guest='st_xp', kind='iso'):
    print 'HEADLINE: installing', guest, 'on', dut, 'from', kind
    sdir = '/storage/isos'
    dest_file = (sdir + '/st_' + guest + '.' + kind)
    install_guest.download_image(dut, kind, guest, dest_file)
    rubyd = ('{"name"=>"%s", '
             '"image_path"=>"images\\/vms/000_XenClient_h32bit_256.png", '
             '"config.memory"=>"1024", "cd"=>"st_%s.iso", '
             '"description"=>"%s", '
             '"config.vcpus"=>"1", '
             '"wired_network"=>"bridged"}' % (guest, guest, guest))
    vmid_raw = run(['xec', 'create', rubyd], host=dut)
    full_vmid = vmid_raw.split()[0]
    short_vmid = full_vmid.split('/')[-1].replace('_', '-')
    vhdid_raw = run([
        'xec', '-o', full_vmid, '-i',
        'com.citrix.xenclient.xenmgr.vm addEmptyDisk', '40'
    ],
                    host=dut)
    vhdid = vhdid_raw.split()[0]
    run([
        'xec', '-o', full_vmid, '-i', 'com.citrix.xenclient.xenmgr.vm',
        'setDisk', vhdid, 'device', 'hda'
    ],
        host=dut)
    run(['db-read /vm/', short_vmid, '/config/disk/', vhdid, '/path'],
        host=dut)
    vm_address = start_vm(dut,
                          guest,
                          timeout=start_timeout,
                          busy_stop=busy_stop)
    print 'INSTALL_GUEST: start_vm returned, address', vm_address
    ensure_stable(vm_address, 30, description=guest + ' on ' + dut)
    print 'INSTALL_GUEST: VM stable'
    print 'INSTALL_GUEST: dir c: replied with %d bytes' % (len(
        run_via_exec_daemon(['dir', 'C:\\'], host=vm_address)))
    return vm_address
Exemple #34
0
def get_architecture(host, guest):
    if not is_acpi_state(host, guest, 0):
        guest_start(host, guest)
        guest_switch(host, guest)
        wait_for_guest(host, guest)
    os = get_system_type(host, guest)

    if os == 'windows':
        unparsed = run_via_exec_daemon(['systeminfo'],
                                       host=domain_address(host, guest),
                                       line_split=True)
        for line in unparsed:
            if "System Type" in line:
                correct_line = line.split(" ")
                break
        if correct_line == None:
            print "ERR: Architecture not returned"
            raise InformationCollectionFailure()
        temp = correct_line
        correct_line = None
        for seg in temp:
            if any(char.isdigit() for char in seg):
                correct_line = seg
                break
        if correct_line == None:
            print "ERR: Architecture not returned"
            raise InformaitonCollectionFailure()
        Arch = re.sub("\D", "", correct_line)
        return Arch.strip()

    elif os == 'linux':
        return run(['uname', '-m'],
                   host=domain_address(host, guest),
                   ignore_failure=True)[0].strip()
    else:
        raise UnexpectedOs()
Exemple #35
0
def shutdown_windows(vm_address):
    """Shutdown windows VM at vm_addresss, and return once it is down"""
    run_via_exec_daemon(['shutdown', '-s'], 
                        host=vm_address, wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #36
0
def shutdown_windows(vm_address):
    """Shutdown windows VM at vm_addresss, and return once it is down"""
    run_via_exec_daemon(['shutdown', '-s'], host=vm_address, wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #37
0
def get_username(host, guest, addr, os):
    if os == 'windows':
        return run_via_exec_daemon(['whoami'],
                                   host=addr).split('\\')[1].strip('\n')
Exemple #38
0
def reboot_windows(dut, domain, vm_address):
    run_via_exec_daemon(['shutdown', '-f', '-r', '-t', '00'],
                        host=vm_address,
                        wait=False)
    wait_for_domid_change(dut, domain['name'], domain['dom_id'])
Exemple #39
0
def reboot_windows(dut, domain, vm_address):
    run_via_exec_daemon(['shutdown', '-f', '-r', '-t', '00'], host=vm_address, wait=False)
    wait_for_domid_change(dut, domain['name'], domain['dom_id'])
Exemple #40
0
def hibernate_windows(vm_address):
    """Put windows VM at vm_address into standby."""
    run_via_exec_daemon(['C:\\Windows\\System32\\rundll32.exe', 
                         'powrprof.dll,SetSuspendState', 'Hibernate'], 
                        host=vm_address, wait=False)
    wait_for_windows_to_go_down(vm_address)
Exemple #41
0
def get_username(host,guest,addr,os):
    if os == 'windows':
        return run_via_exec_daemon(['whoami'], host=addr).split('\\')[1].strip('\n')