Beispiel #1
0
def wait_for_guest(host, guest, method=None, timeout=600):
    """Return address for guest on host, checking that it is responding
    and retrying as necessary"""
    if method is None:
        method = get_default_exec_method(host, guest)
    assert method in ['exec_daemon', "ssh"]
    print 'WAIT_FOR_SYSTEM: contacting', guest, 'using', method
    _, name = name_split(guest)
    start = time()
    run(['xec-vm', '-n', name, 'switch'], host=host)
    def check_running():
        """check VM is running"""
        count = 0
        while(1):
            out = run(['xec-vm', '-n', name, 'get', 'state'], word_split=True, host=host)
            print 'WAIT_FOR_SYSTEM: VM', name, 'state', out[0]
            if out[0] == 'stopped':
                if count > 4: raise SystemStoppedWhileWaitingForSystem(out, guest, host)
                else: count+=1
                sleep(2)
            else: break

    def get_address():
        """get address for VM """
        check_running()
        return domain_address(host, guest, timeout=5)

    address = retry(get_address, 'get %s address on %s' % (guest, host),
                    timeout=timeout, propagate=[SystemStoppedWhileWaitingForSystem])
    delta = time() - start
    rtimeout = max(30, int(timeout - delta))
    print 'WAIT_FOR_SYSTEM: remainining timeout', rtimeout, 'of', timeout
    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
    def check_ssh_access():
        """Check that VM is available over ssh"""
        check_running()
        run(['echo', 'test succeeded'], host=address, timeout=60, check_host_key=False)
        print 'WAIT_FOR_SYSTEM: ssh command execution succeeded'
    if method == "exec_daemon":
        try:
            ver = retry(check_windows_version,
                        description='run windowsVersion on '+host+' '+guest,
                        timeout=rtimeout,
                        propagate=[SystemStoppedWhileWaitingForSystem])
        except error:
            raise UnableToContactGuestService(host, guest, timeout, error)
        print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
            'replied with windows version', ver, 'from address', address
    elif method == "ssh":
        retry(check_ssh_access,
          description='run ssh check on '+host+' '+guest,
          timeout=rtimeout,
          propagate=[SystemStoppedWhileWaitingForSystem])
        print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
            'ssh test succeed on', address
    return address
Beispiel #2
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
Beispiel #3
0
def sleep_dom0(host, guest):
    #depending on the status changing of the host before it sleep might fail first time
    retry(lambda: run(['xec-vm', '-n', guest, 'sleep'], host=host),
          description='xec-vm sleep on VM',
          timeout=120)
    is_asleep(host, guest)
    """Wake Vm up"""
    vm_resume(host, guest)
    if is_acpi_state(host, guest, 3):
        raise VMResumeFailure()
Beispiel #4
0
def get_vhd_from_url(host, url):
    """Return the path to the vhd. If it doesn't exist, bvt will download it from
       the provided url"""
    split = url.split('/')
    name = split[len(split)-1]
    job = specify(host=host)
    _, result = run(['ls', '/storage/disks/'+name], host=host, ignore_failure=True)
    if result > 0:
        retry(lambda: job(['wget', '-q', '-O', '/storage/disks/'+name, url], timeout=3600), timeout=7200, description='download'+url)
    return '/storage/disks/'+name
Beispiel #5
0
Datei: run.py Projekt: OpenXT/bvt
def verify_connection(host, user, timeout=60, check_host_key=False):
    """Verify that we can connect to host as user"""
    def go():
        run(['true'], verify=False, host=host, user=user, timeout=5, check_host_key=check_host_key)
    try:
        retry(go, 'run true on '+host, timeout=timeout)
    except AssertionError:
        raise
    except Exception,exc:
        print 'RUN: first stage verify failed with', exc
Beispiel #6
0
def wait_for_tftp(dut_ip, predicate):
    """Wait for predicate to hold for the last file accessed
    by dut_ip"""
    _, tftp_before = last_tftp_file(dut_ip)
    def check_tftp():
        """Check TFTP server activtiy"""
        last_file, tftp_after = last_tftp_file(dut_ip)
        print 'TFTPWAIT:', tftp_after, 'was', tftp_before, 'last', last_file
        if tftp_after == tftp_before or not predicate(last_file):
            raise NoTFTPActivityTimeout(tftp_before, tftp_after, last_file)

    retry(check_tftp, timeout=360.0, catch=[NoTFTPActivityTimeout],
          description='wait for TFTP')
Beispiel #7
0
def get_vhd_from_url(host, url):
    """Return the path to the vhd. If it doesn't exist, bvt will download it from
       the provided url"""
    split = url.split('/')
    name = split[len(split) - 1]
    job = specify(host=host)
    _, result = run(['ls', '/storage/disks/' + name],
                    host=host,
                    ignore_failure=True)
    if result > 0:
        retry(lambda: job(['wget', '-q', '-O', '/storage/disks/' + name, url],
                          timeout=3600),
              timeout=7200,
              description='download' + url)
    return '/storage/disks/' + name
Beispiel #8
0
def wait_for_tftp(dut_ip, predicate):
    """Wait for predicate to hold for the last file accessed
    by dut_ip"""
    _, tftp_before = last_tftp_file(dut_ip)

    def check_tftp():
        """Check TFTP server activtiy"""
        last_file, tftp_after = last_tftp_file(dut_ip)
        print 'TFTPWAIT:', tftp_after, 'was', tftp_before, 'last', last_file
        if tftp_after == tftp_before or not predicate(last_file):
            raise NoTFTPActivityTimeout(tftp_before, tftp_after, last_file)

    retry(check_tftp,
          timeout=360.0,
          catch=[NoTFTPActivityTimeout],
          description='wait for TFTP')
Beispiel #9
0
def wait_for_ip_address(mac, timeout=7200, description=None):
    """Return IP address for mac, waiting for it if necessary"""
    return retry(lambda: mac_to_ip_address(mac, timeout, description),
                 'find IP address',
                 catch=[NoDHCPLease],
                 timeout=timeout,
                 pace=10.0)
Beispiel #10
0
def verify_connection(host, user, timeout=60, check_host_key=False):
    """Verify that we can connect to host as user"""
    def go():
        run(['true'],
            verify=False,
            host=host,
            user=user,
            timeout=5,
            check_host_key=check_host_key)

    try:
        retry(go, 'run true on ' + host, timeout=timeout)
    except AssertionError:
        raise
    except Exception, exc:
        print 'RUN: first stage verify failed with', exc
Beispiel #11
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
Beispiel #12
0
def download_image(dut, kind, guest, dest_file, url=None):
    """Download a standard BVT image"""
    # wget fails if target exists, so make sure it doesn't
    if kind == 'with_tools':
        build = get_build(dut)
    else:
        build = None
    print 'INSTALL_GUEST: downloading', url, 'as', dest_file
    job = specify(host=dut)
    job(['rm', '-f', dest_file])
    watcher = Process(target=watch_space, args=(dut, '/storage'))
    watcher.start()
    print 'INFO: downloading', url, 'to', dest_file
    retry(lambda: job(['wget', '-q', '-O', dest_file, url], timeout=3600),
          timeout=7200, description='download '+url)
    watcher.terminate()
    size = job(['ls', '-l', dest_file], word_split=True)[4]
    print 'INFO: downloaded', size, 'byte', url.split('/')[-1]
Beispiel #13
0
def download_image(dut, kind, guest, dest_file, url=None):
    """Download a standard BVT image"""
    # wget fails if target exists, so make sure it doesn't
    if kind == 'with_tools':
        build = get_build(dut)
    else:
        build = None
    print 'INSTALL_GUEST: downloading', url, 'as', dest_file
    job = specify(host=dut)
    job(['rm', '-f', dest_file])
    watcher = Process(target=watch_space, args=(dut, '/storage'))
    watcher.start()
    print 'INFO: downloading', url, 'to', dest_file
    retry(lambda: job(['wget', '-q', '-O', dest_file, url], timeout=3600),
          timeout=7200, description='download '+url)
    watcher.terminate()
    size = job(['ls', '-l', dest_file], word_split=True)[4]
    print 'INFO: downloaded', size, 'byte', url.split('/')[-1]
Beispiel #14
0
def get_build_number_branch(dut, timeout=60):
    """Get build number and branch running on 'dut' or None if that cannot be determined"""
    print 'GETBUILD: determining the Xen Client version installed on', dut
    try:
        build = retry(lambda: try_get_build_number_branch(dut, timeout=timeout),
              timeout=timeout,
              description='get build on '+dut)
    except (TimeoutError, SubprocessError, InstallerRunning), exc:
        print 'GETBUILD: error', repr(exc)
        return
Beispiel #15
0
def get_build_number_branch(dut, timeout=60):
    """Get build number and branch running on 'dut' or None if that cannot be determined"""
    print 'GETBUILD: determining the Xen Client version installed on', dut
    try:
        build = retry(
            lambda: try_get_build_number_branch(dut, timeout=timeout),
            timeout=timeout,
            description='get build on ' + dut)
    except (TimeoutError, SubprocessError, InstallerRunning), exc:
        print 'GETBUILD: error', repr(exc)
        return
Beispiel #16
0
def sleep_vm_windows(host, guest):
    vm_sleep_self(host, who=guest)
    #due to use of exec-daemon in vm_sleep_self, can take time for it to finish

    if retry(lambda: is_asleep(host, guest),
             description='checking if VM is asleep yet',
             timeout=120):
        pass
    vm_resume(host, guest)
    vm_reinstate_hibernate(host, who=guest)
    """windows sleep commands like to go to hibernate instead, so after we done we need to reinstate them"""
Beispiel #17
0
def call_exec_daemon(command, args=list(), host=None, timeout=60, why=''):
    """Invoke the exec daemon with args on host.

    (Use domain_address to get a suitable host parameter
    """
    assert host is not None
    def inner():
        with time_limit(timeout, 
                        'call %s%r on %s %s' % (command, args, host, why)):
            print 'RUN: calling', command, 'arguments', args, 'on', host
            proxy = ServerProxy(EXEC_DAEMON_URL_FORMAT % (host))
            return getattr(proxy, command)(*args)
    return retry(inner, 'call exec daemon  on '+repr(host)+' '+why, timeout=timeout,
          catch=[error])
Beispiel #18
0
def wait_to_come_up(host, timeout=120, installer_okay=False):
    """Return once host is up and responding to ssh, or thrown
    an exception on timeout"""

    if installer_okay:
        mdb = mongodb.get_autotest()
        dut_doc = mdb.duts.find_one({'name': host})
        if dut_doc.get('num-nics'):
            if dut_doc['num-nics'] == 2:
                host = host + '-amt'
    out = retry(lambda: check_up(host, installer_okay),
                description='run true on ' + host + ' to see if it is up',
                timeout=timeout)

    print 'WAIT_TO_COME_UP:', host, 'responded with up time', out[:-1]
Beispiel #19
0
def wait_to_come_up(host, timeout=120, installer_okay=False):
    """Return once host is up and responding to ssh, or thrown
    an exception on timeout"""
    
    if installer_okay:
        mdb = mongodb.get_autotest()
        dut_doc = mdb.duts.find_one({'name': host})
        if dut_doc.get('num-nics'):
            if dut_doc['num-nics'] == 2: 
                host = host+'-amt' 
    out = retry(lambda: check_up(host, installer_okay),
          description='run true on '+host+' to see if it is up',
          timeout=timeout)

    print 'WAIT_TO_COME_UP:', host, 'responded with up time', out[:-1]
Beispiel #20
0
def call_exec_daemon(command, args=list(), host=None, timeout=60, why=''):
    """Invoke the exec daemon with args on host.

    (Use domain_address to get a suitable host parameter
    """
    assert host is not None

    def inner():
        with time_limit(timeout,
                        'call %s%r on %s %s' % (command, args, host, why)):
            print 'RUN: calling', command, 'arguments', args, 'on', host
            proxy = ServerProxy(EXEC_DAEMON_URL_FORMAT % (host))
            return getattr(proxy, command)(*args)

    return retry(inner,
                 'call exec daemon  on ' + repr(host) + ' ' + why,
                 timeout=timeout,
                 catch=[error])
Beispiel #21
0
def list_vms(dut, timeout=10):
    # not all the dbus objects appear at once so shortly after xenmgr starts
    # xec-vm can fail
    stdout_capture = retry(
            lambda: run(['xec-vm'], timeout=timeout, host=dut),
            description = 'list VMs',
            timeout=timeout, catch=[SubprocessError])
    lines = [lstrip(line.split('|')) for line in stdout_capture.split('\n')]
    domains = [dict(zip ( ['dom_id', 'name', 'uuid', 'status'], line)) for
               line in lines[1:-1]]
    print 'DOMAINS:', domains
    domains2 = []
    for domain in domains:
        if domain.get('name', '') == '': 
            if not domain.get('dom_id',''). startswith('-'*5):
                print 'DOMAINS:', 'filtered out bogus looking', domain
        else:
            domains2.append(domain)
    return domains2
Beispiel #22
0
def list_vms(dut, timeout=10):
    # not all the dbus objects appear at once so shortly after xenmgr starts
    # xec-vm can fail
    stdout_capture = retry(lambda: run(['xec-vm'], timeout=timeout, host=dut),
                           description='list VMs',
                           timeout=timeout,
                           catch=[SubprocessError])
    lines = [lstrip(line.split('|')) for line in stdout_capture.split('\n')]
    domains = [
        dict(zip(['dom_id', 'name', 'uuid', 'status'], line))
        for line in lines[1:-1]
    ]
    print 'DOMAINS:', domains
    domains2 = []
    for domain in domains:
        if domain.get('name', '') == '':
            if not domain.get('dom_id', '').startswith('-' * 5):
                print 'DOMAINS:', 'filtered out bogus looking', domain
        else:
            domains2.append(domain)
    return domains2
Beispiel #23
0
def archive_vhd(dut,
                guest,
                have_tools=None,
                replace=True,
                artifact_name='archive-vhds',
                publish=True):
    """Archive the VHD image of guest on dut. have_tools should
    be set iff the XenClient tools are installed for that VHD (since we
    use a separate directory with a symlink name including the build number
    for VHDs with tools"""
    if ARTIFACTS_ROOT is None:
        print 'INFO: artifacts storage disabled'
        return
    domain = find_domain(dut, guest)
    vhd_path = get_disk_path(dut, domain)
    disk_uuid = get_disk_uuid(dut, vhd_path)
    disk_key = get_disk_key(dut, disk_uuid)
    print 'NOTE: disk uuid', disk_uuid, 'key', disk_key
    if have_tools is None:
        from src.testcases.install_tools import tools_install_problems
        have_tools = False if tools_install_problems(dut, guest) else True

    build = get_build(dut)
    key_postfix = (('.' + ','.join(disk_key[:-4].split(',')[1:]))
                   if disk_key else '')
    postfix = '.' + domain['name'] + key_postfix + (
        ('.tools.' + build) if have_tools else '.st') + '.vhd'
    print 'HEADLINE: VHD postfix will be', postfix
    info = dict(domain, build=build, encrypted=key_postfix)
    if publish:
        base_file = (VHD_WITH_TOOLS_PATTERN
                     if have_tools else VHD_SANS_TOOLS_PATTERN) % (info)
        if islink(base_file):
            if not replace:
                print 'ARCHIVE_VHD: already have', base_file
                return
        elif isfile(base_file):
            raise UnexpectedFile(base_file)

    print 'ARCHIVE_VHD: domain state', domain
    if domain['status'] not in ['paused', 'stopped']:
        raise VmIsRunning()
    print 'ARCHIVE_VHD: vhd at', vhd_path

    transfers = {}

    if disk_key:
        keydest = retry(lambda: store_client_artifact(
            dut, disk_key, artifact_name, postfix + '.key'),
                        description='store filesystem',
                        timeout=3600,
                        pace=60)
        transfers[keydest] = base_file + '.key'
    vhddest = store_client_artifact(dut, vhd_path, artifact_name, postfix)
    transfers[vhddest] = base_file
    sha = run(['sha256sum', vhddest], timeout=600).split()[0] + '\n'
    shafile = store_memory_artifact(sha, artifact_name, postfix + '.sha256')
    assert isfile(shafile)
    transfers[shafile] = base_file + '.sha256'
    for destfile in transfers.keys():
        assert isfile(destfile)
    if publish:
        for dest, base_file in transfers.items():
            print 'HEADLINE: publishing', base_file, 'to', dest
            parent = split(base_file)[0]
            umask(0000)
            if not isdir(parent):
                run(['mkdir', '-p', parent])
            run(['ln', '-sf', dest, base_file])
        clean_old_vhds()
    return dest
Beispiel #24
0
def wait_for_guest(host, guest, method=None, timeout=600):
    """Return address for guest on host, checking that it is responding
    and retrying as necessary"""
    if method is None:
        method = get_default_exec_method(host, guest)
    assert method in ['exec_daemon', "ssh"]
    print 'WAIT_FOR_SYSTEM: contacting', guest, 'using', method
    _, name = name_split(guest)
    start = time()
    run(['xec-vm', '-n', name, 'switch'], host=host)

    def check_running():
        """check VM is running"""
        count = 0
        while (1):
            out = run(['xec-vm', '-n', name, 'get', 'state'],
                      word_split=True,
                      host=host)
            print 'WAIT_FOR_SYSTEM: VM', name, 'state', out[0]
            if out[0] == 'stopped':
                if count > 4:
                    raise SystemStoppedWhileWaitingForSystem(out, guest, host)
                else:
                    count += 1
                sleep(2)
            else:
                break

    def get_address():
        """get address for VM """
        check_running()
        return domain_address(host, guest, timeout=5)

    address = retry(get_address,
                    'get %s address on %s' % (guest, host),
                    timeout=timeout,
                    propagate=[SystemStoppedWhileWaitingForSystem])
    delta = time() - start
    rtimeout = max(30, int(timeout - delta))
    print 'WAIT_FOR_SYSTEM: remainining timeout', rtimeout, 'of', timeout

    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

    def check_ssh_access():
        """Check that VM is available over ssh"""
        check_running()
        run(['echo', 'test succeeded'],
            host=address,
            timeout=60,
            check_host_key=False)
        print 'WAIT_FOR_SYSTEM: ssh command execution succeeded'

    if method == "exec_daemon":
        try:
            ver = retry(check_windows_version,
                        description='run windowsVersion on ' + host + ' ' +
                        guest,
                        timeout=rtimeout,
                        propagate=[SystemStoppedWhileWaitingForSystem])
        except error:
            raise UnableToContactGuestService(host, guest, timeout, error)
        print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
            'replied with windows version', ver, 'from address', address
    elif method == "ssh":
        retry(check_ssh_access,
              description='run ssh check on ' + host + ' ' + guest,
              timeout=rtimeout,
              propagate=[SystemStoppedWhileWaitingForSystem])
        print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
            'ssh test succeed on', address
    return address
Beispiel #25
0
def ensure(dut, guest, busy_stop=True):
    """Ensure guest is installed with tools on dut.
    If busy_stop is true and then shut down other VMs to make more memory"""
    print 'INFO: contacting and determining build on', dut
    build = try_get_build(dut)
    os_name, name = name_split(guest)
    try:
        print 'INFO: looking for domain', guest
        domain1 = find_domain(dut, guest)
    except CannotFindDomain:
        print 'INFO:', guest, 'does not exist yet'
    else:
        print 'INFO: found domain', domain1
        if domain1['status'] != 'running':
            print 'INFO: starting', guest
            vm_address = start_vm(dut, guest, busy_stop=busy_stop)
        else:
            print 'INFO: contacting', guest
            vm_address = wait_for_guest(dut, name)
        problems = tools_install_problems(dut, guest)
        if problems is None:
            print 'HEADLINE: already have suitable VM with tools'
            maybe_kill_prompt_remover(dut, guest, vm_address)
            return vm_address
        else:
            print 'HEADLINE: already have', guest, 'but', problems
            install_tools(dut, guest)
            maybe_kill_prompt_remover(dut, guest, vm_address)
            return vm_address

    if VHD_WITH_TOOLS_PATTERN:
        with_tools_vhd = VHD_WITH_TOOLS_PATTERN % {
            'build': build,
            'name': os_name,
            'encrypted': ''
        }
        suitable = exists(with_tools_vhd)
    else:
        print 'INFO: set VHD_WITH_TOOLS_PATTERN to enable use of VHDs with tools installed'
        suitable = False
    if suitable:
        age = (time() - (stat(with_tools_vhd).st_ctime)) / (24 * 60 * 60.0)
        print 'INFO: found prepared VHD', with_tools_vhd, 'which is', age, 'days old'
        if age > MAXIMUM_VHD_AGE_DAYS:
            print 'INFO: not using ready made VHD since it is', age, 'days old'
            valid = False
        else:
            valid = True
    else:
        valid = False
    if valid:
        print 'HEADLINE: have ready made VHD at', with_tools_vhd
        vhd_path_callback = lambda vhd_path: download_image(
            dut, 'with_tools', os_name, vhd_path)
        vm_address2 = create_vm(dut,
                                guest,
                                vhd_path_callback=vhd_path_callback)
        problem = retry(lambda: tools_install_problems(dut, guest),
                        description='determine whether tools are installed',
                        catch=[error])
        if problem is not None:
            raise ToolsNotInstalledInImage(with_tools_vhd, problem)
        maybe_kill_prompt_remover(dut, guest, vm_address2)
        return vm_address2
    sans_tools_vhd = VHD_SANS_TOOLS_PATTERN % {
        'name': os_name,
        'encrypted': ''
    }
    kind2 = 'vhd' if have_fresh_vhd(os_name) else 'iso'
    install_guest(dut, guest, kind2, busy_stop=True)
    install_tools(dut, guest)
Beispiel #26
0
def archive_vhd(dut, guest, have_tools=None, replace=True, 
                artifact_name = 'archive-vhds', publish=True):
    """Archive the VHD image of guest on dut. have_tools should
    be set iff the XenClient tools are installed for that VHD (since we
    use a separate directory with a symlink name including the build number
    for VHDs with tools"""
    if ARTIFACTS_ROOT is None:
        print 'INFO: artifacts storage disabled'
        return
    domain = find_domain(dut, guest)
    vhd_path = get_disk_path(dut, domain)
    disk_uuid = get_disk_uuid(dut, vhd_path)
    disk_key = get_disk_key(dut, disk_uuid)
    print 'NOTE: disk uuid', disk_uuid, 'key', disk_key
    if have_tools is None:
        from src.testcases.install_tools import tools_install_problems
        have_tools = False if tools_install_problems(dut, guest) else True

    build = get_build(dut)
    key_postfix = (('.'+','.join(disk_key[:-4].split(',')[1:])) if
                   disk_key else '')
    postfix = '.'+domain['name']+ key_postfix + (
        ('.tools.'+build) if have_tools else '.st')+'.vhd'
    print 'HEADLINE: VHD postfix will be', postfix
    info = dict(domain, build=build, encrypted=key_postfix)
    if publish:
        base_file = (VHD_WITH_TOOLS_PATTERN if have_tools else 
                     VHD_SANS_TOOLS_PATTERN) % (info)
        if islink(base_file):
            if not replace:
                print 'ARCHIVE_VHD: already have', base_file
                return
        elif isfile(base_file):
            raise UnexpectedFile(base_file)

    print 'ARCHIVE_VHD: domain state', domain
    if domain['status'] not in ['paused', 'stopped']:
        raise VmIsRunning()
    print 'ARCHIVE_VHD: vhd at', vhd_path

    transfers = {}

    if disk_key:
        keydest = retry(lambda: store_client_artifact(
                dut, disk_key, artifact_name, postfix+'.key'),
                        description = 'store filesystem', timeout=3600, pace=60)
        transfers[keydest] = base_file + '.key'
    vhddest = store_client_artifact(dut, vhd_path, artifact_name, postfix)
    transfers[vhddest] = base_file
    sha = run(['sha256sum', vhddest], timeout=600).split()[0]+'\n'
    shafile = store_memory_artifact(sha, artifact_name, postfix+'.sha256')
    assert isfile(shafile)
    transfers[shafile] =  base_file + '.sha256'
    for destfile in transfers.keys():
        assert isfile(destfile)
    if publish:
        for dest, base_file in transfers.items():
            print 'HEADLINE: publishing', base_file, 'to', dest
            parent = split(base_file)[0]
            umask(0000)
            if not isdir(parent):
                run(['mkdir', '-p', parent])
            run(['ln', '-sf', dest, base_file])
        clean_old_vhds()
    return dest
Beispiel #27
0
def sysmark_test( dut, domain, cd_drive='D'):
    con = (connect_to_exec_daemon.connect_to_windows_guest(
            session, dut,domain))
    
    iso = "/storage/isos/sysmark.iso"
    with connection.connect(host=dut, user='******') as sh_dut:    
        rc, _, _ = sh_dut.launch('ls '+iso)
        if rc != 0:
            sh_dut.verified_launch('wget http://autotest/sysmark_2004_se.iso -O '+iso,
                                         timeout=3600)
        if not exists(con, cd_drive+':\\setup.boot'):
            sh_dut.verified_launch(
                "db-cmd write /vm/"+domain['uuid']+"/config/disk/0/path "+iso)
            install_tools.wait_for_reboot( sh_dut, uuid=domain['uuid'],
                                                name=domain['name'])
    # Make the execdaemon actually start up again (sm2004se disables all
    # entries in the Run part of the registry)
    sed = r"c:\execdaemon.cmd"
    con.proxy.callRemote(
        'createFile', "C:\\docume~1\\admini~1\\startm~1\\Programs\\Startup"
                      "\\execdaemon.bat", sed)
    if  exists(con, r'C:\sm2004se\xen.iss'):
        print 'INFO: already have sm2004se management material'
    else:
        con.proxy.callRemote('unpackTarball', 
                                   'http://autotest/bin/sm2004se.tgz', 'C:\\')
        print 'INFO: unpacked sm2004se.tgz'
    
    if have_driver.have_driver(con, 'MEDIA' ,'Virtual Audio Cable'):
        print 'INFO: have virtual audio cable driver already installed'
    else:
        con.proxy.callRemote(
            'unpackTarball',
            'http://autotest.cam.xci-test.com/bin/devcon.tar.gz','C:\\')
        print 'INFO: unpacked devcon'
        con.verified_launch(
            'C:\\devcon\\i386\\devcon.exe install C:\\sm2004se\\vac\\vrtaucbl.inf '+
            'EuMusDesign_VAC_WDM', timeout=600)
    
    sysmd = r'C:\Program Files\BAPCo\SYSMark 2004 SE'
    sysmgrd = sysmd + r'\Benchmgr'
    sysmgrf = 'Sysmgr.exe'
    sysmgr = sysmgrd + '\\' + sysmgrf
    if not exists(con,sysmgr):
        bootmon = boot_monitor.BootMonitor(con)
        bootmon.get_first_boot_time()
        def record(f): test_failure.log_failure( f, 'installing sysmark')
        print 'INFO: waiting for quiescence before installing sysmark'
        sleep.sleep(300)
        print 'INFO: starting install'
        con.launch(
            cd_drive+':\\setup.exe -s -f1C:\\sm2004se\\xen.iss', timeout=3600).addErrback(
              record)
        retry.retry(
            check_boots(2, bootmon), 
            description='wait for Sysmark to be installed, indicated by reboots', 
            timeout=60*60*24, catch=[InsufficientReboots])
    else: assert 0
    assert exists(con,sysmgr)
    target_exe = (autoit_generator.compile(con, 'set_keyboard', 
                                                 autoit_generator.set_keyboard_layout))
    con.verified_launch(target_exe)
    bootmonr = boot_monitor.BootMonitor(con)
    con.launch('"'+sysmgr+'" STDSUITE=1 PROJNAME=XenRT')
    retry.retry(check_boots(3, bootmonr), 
                     description='wait for Sysmark to complete, indicated by reboots', 
                     timeout=60*60*6, catch=[InsufficientReboots])
    report = con.proxy.callRemote('readFile', sysmgrd+'\\Report\\XENRT.WMR')
    for line in report.split('\n'):
        print 'INFO: report',line
Beispiel #28
0
def ensure(dut, guest, busy_stop=True):
    """Ensure guest is installed with tools on dut.
    If busy_stop is true and then shut down other VMs to make more memory"""
    print 'INFO: contacting and determining build on', dut
    build = try_get_build(dut)
    os_name, name = name_split(guest)
    try:
        print 'INFO: looking for domain', guest
        domain1 = find_domain(dut, guest)
    except CannotFindDomain:
        print 'INFO:', guest, 'does not exist yet'
    else:
        print 'INFO: found domain', domain1
        if domain1['status'] != 'running':
            print 'INFO: starting', guest
            vm_address = start_vm(dut, guest, busy_stop=busy_stop)
        else:
            print 'INFO: contacting', guest
            vm_address = wait_for_guest(dut, name)
        problems = tools_install_problems(dut, guest)
        if problems is None:
            print 'HEADLINE: already have suitable VM with tools'
            maybe_kill_prompt_remover(dut, guest, vm_address)
            return vm_address
        else:
            print 'HEADLINE: already have', guest, 'but', problems
            install_tools(dut, guest)
            maybe_kill_prompt_remover(dut, guest, vm_address)
            return vm_address

    if VHD_WITH_TOOLS_PATTERN:
        with_tools_vhd = VHD_WITH_TOOLS_PATTERN % {'build':build, 'name': os_name, 
                                               'encrypted':''}
        suitable = exists(with_tools_vhd)
    else:
        print 'INFO: set VHD_WITH_TOOLS_PATTERN to enable use of VHDs with tools installed'
        suitable = False
    if suitable:
        age = (time() - (stat(with_tools_vhd).st_ctime)) / (24*60*60.0)
        print 'INFO: found prepared VHD', with_tools_vhd, 'which is', age, 'days old'
        if age > MAXIMUM_VHD_AGE_DAYS:
            print 'INFO: not using ready made VHD since it is', age, 'days old'
            valid = False
        else:
            valid = True
    else:
        valid = False
    if valid:
        print 'HEADLINE: have ready made VHD at', with_tools_vhd
        vhd_path_callback = lambda vhd_path: download_image(
            dut, 'with_tools', os_name, vhd_path)
        vm_address2 = create_vm(dut, guest, 
                                vhd_path_callback=vhd_path_callback)
        problem = retry(lambda: tools_install_problems(dut, guest),
              description='determine whether tools are installed',
              catch=[error])
        if problem is not None:
            raise ToolsNotInstalledInImage(with_tools_vhd, problem)
        maybe_kill_prompt_remover(dut, guest, vm_address2)
        return vm_address2
    sans_tools_vhd = VHD_SANS_TOOLS_PATTERN % {'name': os_name, 'encrypted': ''}
    kind2 = 'vhd' if have_fresh_vhd(os_name) else 'iso'
    install_guest(dut, guest, kind2, busy_stop=True)
    install_tools(dut, guest)        
Beispiel #29
0
def sysmark_test(dut, domain, cd_drive='D'):
    con = (connect_to_exec_daemon.connect_to_windows_guest(
        session, dut, domain))

    iso = "/storage/isos/sysmark.iso"
    with connection.connect(host=dut, user='******') as sh_dut:
        rc, _, _ = sh_dut.launch('ls ' + iso)
        if rc != 0:
            sh_dut.verified_launch(
                'wget http://autotest/sysmark_2004_se.iso -O ' + iso,
                timeout=3600)
        if not exists(con, cd_drive + ':\\setup.boot'):
            sh_dut.verified_launch("db-cmd write /vm/" + domain['uuid'] +
                                   "/config/disk/0/path " + iso)
            install_tools.wait_for_reboot(sh_dut,
                                          uuid=domain['uuid'],
                                          name=domain['name'])
    # Make the execdaemon actually start up again (sm2004se disables all
    # entries in the Run part of the registry)
    sed = r"c:\execdaemon.cmd"
    con.proxy.callRemote(
        'createFile', "C:\\docume~1\\admini~1\\startm~1\\Programs\\Startup"
        "\\execdaemon.bat", sed)
    if exists(con, r'C:\sm2004se\xen.iss'):
        print 'INFO: already have sm2004se management material'
    else:
        con.proxy.callRemote('unpackTarball',
                             'http://autotest/bin/sm2004se.tgz', 'C:\\')
        print 'INFO: unpacked sm2004se.tgz'

    if have_driver.have_driver(con, 'MEDIA', 'Virtual Audio Cable'):
        print 'INFO: have virtual audio cable driver already installed'
    else:
        con.proxy.callRemote(
            'unpackTarball',
            'http://autotest.cam.xci-test.com/bin/devcon.tar.gz', 'C:\\')
        print 'INFO: unpacked devcon'
        con.verified_launch(
            'C:\\devcon\\i386\\devcon.exe install C:\\sm2004se\\vac\\vrtaucbl.inf '
            + 'EuMusDesign_VAC_WDM',
            timeout=600)

    sysmd = r'C:\Program Files\BAPCo\SYSMark 2004 SE'
    sysmgrd = sysmd + r'\Benchmgr'
    sysmgrf = 'Sysmgr.exe'
    sysmgr = sysmgrd + '\\' + sysmgrf
    if not exists(con, sysmgr):
        bootmon = boot_monitor.BootMonitor(con)
        bootmon.get_first_boot_time()

        def record(f):
            test_failure.log_failure(f, 'installing sysmark')

        print 'INFO: waiting for quiescence before installing sysmark'
        sleep.sleep(300)
        print 'INFO: starting install'
        con.launch(cd_drive + ':\\setup.exe -s -f1C:\\sm2004se\\xen.iss',
                   timeout=3600).addErrback(record)
        retry.retry(check_boots(2, bootmon),
                    description=
                    'wait for Sysmark to be installed, indicated by reboots',
                    timeout=60 * 60 * 24,
                    catch=[InsufficientReboots])
    else:
        assert 0
    assert exists(con, sysmgr)
    target_exe = (autoit_generator.compile(
        con, 'set_keyboard', autoit_generator.set_keyboard_layout))
    con.verified_launch(target_exe)
    bootmonr = boot_monitor.BootMonitor(con)
    con.launch('"' + sysmgr + '" STDSUITE=1 PROJNAME=XenRT')
    retry.retry(
        check_boots(3, bootmonr),
        description='wait for Sysmark to complete, indicated by reboots',
        timeout=60 * 60 * 6,
        catch=[InsufficientReboots])
    report = con.proxy.callRemote('readFile', sysmgrd + '\\Report\\XENRT.WMR')
    for line in report.split('\n'):
        print 'INFO: report', line
Beispiel #30
0
def wait_for_ip_address(mac, timeout=7200, description=None):
    """Return IP address for mac, waiting for it if necessary"""
    return retry(lambda: mac_to_ip_address(mac, timeout, description), 
                 'find IP address',
                 catch=[NoDHCPLease], timeout=timeout, pace=10.0)