Exemple #1
0
def do_iteration(i, options):
    """Do one iteration of the test loop"""
    set_experiment_install_flag(
        options.machine,
        (options.install_first or not options.soak_power_level) and (i == 1))

    try:
        mdb = mongodb.get_autotest()
        dutdoc = mdb.duts.find_one({'name': options.machine})
    except NoMongoHost:
        dutdoc = {'write': True}
    write = (dutdoc if dutdoc else {}).get('write')
    test_parameters = {
        'dut': options.machine,
        'record': options.record,
        #'status_report_mode': STATUS_REPORTS_ALWAYS if
        # options.diagnostic_status_report else STATUS_REPORTS_NEVER,
        'stash_guests': options.guest,
        'verbose': options.verbose,
        'stash_on_failure': options.stash_on_failure,
        'reinstall_on_failure': options.reinstall_on_failure
    }

    def trigger_tests(condition, guest=None):
        """Trigger test cases matching condition for guest"""
        for test_case in test_cases.TEST_CASES:
            if test_case.get('trigger') == condition:
                run_test(test_parameters, test_case, options, guest)

    trigger_tests('first')
    if write:
        trigger_tests('platform install')

    trigger_tests('build ready')
    trigger_tests('soakup')
    trigger_tests('platform ready')
    trigger_tests('stress')
    trigger_tests('regression')
    for guest in options.guest if options.guest else []:
        try:
            find_domain(options.machine, guest)
            have_domain = True
        except CannotFindDomain:
            have_domain = False
        print 'check for domain', guest, 'returned', have_domain
        write_guest = options.rebuild_vms or write or not have_domain
        if write_guest:
            trigger_tests('VM install', guest)
        domain = find_domain(options.machine, guest)
        if domain['status'] == 'stopped':
            run(['xec-vm', '-n', domain['name'], 'start'],
                host=options.machine,
                timeout=600)
        if write_guest:
            trigger_tests('VM configure', guest)
            trigger_tests('VM accelerate', guest)
        trigger_tests('VM ready', guest)
    trigger_tests('soakdown')
Exemple #2
0
def do_iteration(i, options):
    """Do one iteration of the test loop"""
    set_experiment_install_flag(options.machine, 
                                (options.install_first or not 
                                 options.soak_power_level) and (i == 1))

    try:
        mdb = mongodb.get_autotest()
        dutdoc = mdb.duts.find_one({'name':options.machine}) 
    except NoMongoHost:
        dutdoc = {'write':True}
    write = (dutdoc if dutdoc else {}).get('write')
    test_parameters = {
        'dut':options.machine, 'record': options.record,
        #'status_report_mode': STATUS_REPORTS_ALWAYS if 
        # options.diagnostic_status_report else STATUS_REPORTS_NEVER,
        'stash_guests' : options.guest, 'verbose' : options.verbose,
        'stash_on_failure'  : options.stash_on_failure,
        'reinstall_on_failure' : options.reinstall_on_failure}
    def trigger_tests(condition, guest=None):
        """Trigger test cases matching condition for guest"""
        for test_case in test_cases.TEST_CASES:
            if test_case.get('trigger') == condition:
                run_test(test_parameters, test_case, options, guest)
    trigger_tests('first')        
    if write:
        trigger_tests('platform install')

    trigger_tests('build ready')
    trigger_tests('soakup')
    trigger_tests('platform ready')
    trigger_tests('stress')
    trigger_tests('regression')
    for guest in options.guest if options.guest else []:
        try:
            find_domain(options.machine, guest)
            have_domain = True
        except CannotFindDomain:
            have_domain = False
        print 'check for domain', guest, 'returned', have_domain
        write_guest = options.rebuild_vms or write or not have_domain 
        if write_guest:
            trigger_tests('VM install', guest)
        domain = find_domain(options.machine, guest)
        if domain['status'] == 'stopped':
            run(['xec-vm', '-n', domain['name'], 'start'], 
                host=options.machine, timeout=600)
        if write_guest:
            trigger_tests('VM configure', guest)
            trigger_tests('VM accelerate', guest)
        trigger_tests('VM ready', guest)
    trigger_tests('soakdown')
Exemple #3
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
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 #6
0
def install_tools(dut, guest):
    """Install tools on guest on dut"""
    if not isfile(XC_TOOLS_ISO, host=dut):
        raise ToolsIsoMissing(dut, XC_TOOLS_ISO)
    os, name = name_split(guest)
    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    return _proxy_call(dut, name, 'install_tools', dut, name)
Exemple #7
0
def wait_for_shutdown(host, guest, timeout=DEFAULT_SHUTDOWN_TIMEOUT):
    start_time = time()
    while time() - start_time < timeout:
        domain = find_domain(host, guest)
        if domain['status'] == 'stopped': 
            return True
        sleep(5)
    raise TimeoutError()
Exemple #8
0
def reboot_windows_vm(dut, domain):
    """Triger a reboot of guest"""
    _, name = name_split(domain)
    domain = find_domain(dut, name)
    print 'INFO: rebooting guest', domain
    run(['xec-vm', '-n', name, 'reboot'], host=dut)
    wait_for_domid_change(dut, name, domain['dom_id'])
    print 'INFO: reboot of', domain, 'completed'
Exemple #9
0
def wait_for_shutdown(host, guest, timeout=DEFAULT_SHUTDOWN_TIMEOUT):
    start_time = time()
    while time() - start_time < timeout:
        domain = find_domain(host, guest)
        if domain['status'] == 'stopped':
            return True
        sleep(5)
    raise TimeoutError()
Exemple #10
0
def reboot_windows_vm(dut, domain):
    """Triger a reboot of guest"""
    _, name = name_split(domain)
    domain = find_domain(dut, name)
    print 'INFO: rebooting guest', domain
    run(['xec-vm', '-n', name, 'reboot'], host=dut)
    wait_for_domid_change(dut, name, domain['dom_id'])
    print 'INFO: reboot of', domain, 'completed'
Exemple #11
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 #12
0
def run_v4v(dut, guest, args):
    status = find_domain(dut, guest)
    domaddr = domid_to_dotted(int(status['dom_id']))
    all_args = [
        'sshv4v', '-oStrictHostKeyChecking=no',
        '-oUserKnownHostsFile=/dev/null', domaddr
    ]
    all_args.extend(args)
    return run(space_escape(all_args), host=dut)
Exemple #13
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_guest(dut, guest, method='ssh')
    print 'HEADLINE: contacted', guest, 'and checking for tools'
    if tools_install_problems(dut, guest) is None: 
        raise ToolsAlreadyInstalled(dut, guest, vm_address)
    print 'INSTALL_TOOLS: installing prequisitives', domain
    install_prerequisites(vm_address)
    # there are some graphics gliches if tools installed on non-upgraded system
    print 'INSTALL_TOOLS: running upgrade', domain
    run_upgrade(vm_address)
    print 'INSTALL_TOOLS: upgrade done', domain
    soft_reboot_and_wait(dut, guest) # reboot after ugprade
    mount_point = make_tools_iso_available(dut, vm_address, guest, 
                                               domain)
    domain = find_domain(dut, guest)
    start_vm_if_not_running(dut, domain['name'])
    print 'HEADLINE: tools ISO available on', mount_point
    ensure_stable(vm_address, 30, description=guest+' on '+dut, method='ssh')
    tools_installer = "%s/linux/install.sh" % mount_point
    result = run([tools_installer], host=vm_address, timeout=300, check_host_key=False)
    print 'INSTALL_TOOLS:', domain, 'tools installation complete'
    print 'INSTALL_TOOLS: output was', result
    print 'INSTALL_TOOLS: rebooting', result
    soft_reboot_and_wait(dut, guest) # reboot after ugprade
    print 'INSTALL_TOOLS: reboot completed', result
    ensure_stable(vm_address, 30, description=guest+' on '+dut, method='ssh')
    problems = tools_install_problems(dut, guest)
    if problems:
        print 'HEADLINE:', problems
        raise UnableToInstallTools(problems)
    print 'HEADLINE: tools installed correctly on', guest, 'at', vm_address
    if ARCHIVE_TOOLS_INSTALLED_VHDS:
        soft_shutdown_guest(dut, guest, timeout=600, method="ssh")
        archive_vhd(dut, guest, have_tools=True, replace=False)
    start_vm_if_not_running(dut, guest)
Exemple #14
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 #15
0
def stubdom_boot(dut, guest):
    """Test guest still boots on dut when running with studbom"""
    _, name = name_split(guest)
    vm_address = domain_address(dut, guest)
    run(['xec-vm', '-n', name, 'start'], host=dut)
    run(['xec-vm', '-n', name, 'switch'], host=dut)
    wait_for_windows_to_come_up(vm_address)
    shutdown_windows(vm_address)
    wait_for_vm_to_stop(dut, guest)
    status = find_domain(dut, guest)
    print 'INFO: domain status', status
    run(['xec-vm', '-n', name, 'set', 'cd', 'xc-tools.iso'], host=dut)
    run(['xec-vm', '-n', name, 'set', 'stubdom', 'true'], host=dut)
    print 'INFO: booting', guest, 'with stubdom'
    run(['xec-vm', '-n', name, 'start'], host=dut)
    run(['xec-vm', '-n', name, 'switch'], host=dut)
    wait_for_windows_to_come_up(vm_address)
    print 'HEADLINE: verified', guest, 'works with stubdom=true'
Exemple #16
0
def stubdom_boot(dut, guest):
    """Test guest still boots on dut when running with studbom"""
    _, name = name_split(guest)
    vm_address = domain_address(dut, guest)
    run(['xec-vm', '-n', name, 'start'], host=dut)
    run(['xec-vm', '-n', name, 'switch'], host=dut)
    wait_for_windows_to_come_up(vm_address)
    shutdown_windows(vm_address)
    wait_for_vm_to_stop(dut, guest)
    status = find_domain(dut, guest)
    print 'INFO: domain status', status
    run(['xec-vm', '-n', name, 'set', 'cd', 'xc-tools.iso'], host=dut)
    run(['xec-vm', '-n', name, 'set', 'stubdom', 'true'], host=dut)
    print 'INFO: booting', guest, 'with stubdom'
    run(['xec-vm', '-n', name, 'start'], host=dut)
    run(['xec-vm', '-n', name, 'switch'], host=dut)
    wait_for_windows_to_come_up(vm_address)
    print 'HEADLINE: verified', guest, 'works with stubdom=true'
Exemple #17
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
Exemple #18
0
def soft_reboot(dut, vm_name):
    domain = find_domain(dut, vm_name)
    print 'INFO: rebooting guest', domain
    vm_address = domain_address(dut, vm_name)
    run(['shutdown', '-r', 'now'], host=vm_address, check_host_key=False)
    wait_for_domid_change(dut, vm_name, domain['dom_id'])
Exemple #19
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)
Exemple #20
0
def is_stopped(host, guest):
    domain = find_domain(host, guest)
    if domain['status'] == 'stopped':
        return True
    return False
Exemple #21
0
def is_stopped(host, guest):
    domain = find_domain(host, guest)
    if domain['status'] == 'stopped': 
        return True
    return False
Exemple #22
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
Exemple #23
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)        
Exemple #24
0
def soft_reboot(dut, vm_name):
    domain = find_domain(dut, vm_name)
    print 'INFO: rebooting guest', domain
    vm_address = domain_address(dut, vm_name)
    run(['shutdown', '-r', 'now'], host=vm_address, check_host_key=False)
    wait_for_domid_change(dut, vm_name, domain['dom_id'])