Example #1
0
def read_boot_time(dut, build):
    boot_times = None
    print 'INFO: sending reboot'
    # The first boot time after a fresh install is much slower than the following
    wait_to_come_up(dut)
    run(['reboot'], host=dut)
    with time_limit(600, 'wait for sync up event'):
        while 1:
            try:
                print 'INFO: checking if', dut, 'is still up'
                check_up(dut)
            except Exception, exc:
                print 'INFO:', dut, 'is down', exc
                break
            else:
                print 'INFO:', dut, 'still up'
                sleep(1)
                print
        while 1:
            wait_to_come_up(dut, timeout=1200)
            log = grep_dut_log(dut, '/var/log/messages', UI_READY)
            
            boot_times = parse_sys_log(log)
            print 'INFO: boot times:', ' '.join(['%.2f' % t for t in boot_times])
            if len(boot_times) >= 2:
                break
            sleep(5)
Example #2
0
def get_status_report(dut,
                      port=22,
                      command='status-tool',
                      reason='unknown',
                      try_installer=False,
                      label='-platform'):
    """Use status-tool on XT box to generate a status report and rsync it back to 
        BVT machine for inspection"""

    try:
        wait_to_come_up(dut, timeout=10)
        out, exitcode = run(['/usr/bin/' + command],
                            timeout=600,
                            host=dut,
                            ignore_failure=True)
        print 'STATUS_REPORT: made status report reason', reason, 'exit code', \
            exitcode
        out2 = out[out.find(' '.join(MAGIC)):]
        spl = out2.split()
        if spl[:2] != MAGIC or len(spl) != 4:
            print 'STATUS_REPORT: unexpected status-tool output', out
        else:
            report = spl[-2]
            print 'STATUS_REPORT: downloading', report
            report_loc = store_client_artifact(dut, report, 'status-reports',
                                               label + POSTFIX)
            print 'INFO: created status report', report_loc
            return (report_loc)
    except (SubprocessError, TimeoutError):
        print 'INFO: unable to connect'
        raise
Example #3
0
def get_status_report(dut, port=22, command = 'status-tool', 
                        reason='unknown', try_installer=False,
                        label='-platform'):
    """Use status-tool on XT box to generate a status report and rsync it back to 
        BVT machine for inspection"""

    try:
        wait_to_come_up(dut, timeout=10)
        out, exitcode = run(['/usr/bin/'+command], timeout=600, host=dut, ignore_failure=True)
        print 'STATUS_REPORT: made status report reason', reason, 'exit code', \
            exitcode
        out2 = out[out.find(' '.join(MAGIC)):]
        spl = out2.split()
        if spl[:2] != MAGIC  or len(spl)!=4:
            print 'STATUS_REPORT: unexpected status-tool output', out
        else:
            report = spl[-2]
            print 'STATUS_REPORT: downloading', report
            report_loc = store_client_artifact(dut, report, 'status-reports', 
                                               label+POSTFIX)
            print 'INFO: created status report', report_loc
            return (report_loc)
    except (SubprocessError, TimeoutError):
        print 'INFO: unable to connect'
        raise 
Example #4
0
File: soak.py Project: OpenXT/bvt
def soak_up( dut):
    """Turn on dut"""
    set_s0(dut)
    wait_to_come_up(dut)
    build = get_build(dut)
    print 'SOAK:', 'found build', build 
    print 'SOAK:', 'making sure dom0 is okay by testing networking' 
    network_test(dut, 'all')
    print 'SOAK:', 'in power state s0' 
Example #5
0
def soak_up(dut):
    """Turn on dut"""
    set_s0(dut)
    wait_to_come_up(dut)
    build = get_build(dut)
    print 'SOAK:', 'found build', build
    print 'SOAK:', 'making sure dom0 is okay by testing networking'
    network_test(dut, 'all')
    print 'SOAK:', 'in power state s0'
Example #6
0
def hostShutdown(machine,vms,steps,build,test_path,caller):
    log(1,'Host Shutdown')
    tslib.forcepowerstate(machine, 'on', vms)
    power_control.xenmgr_shutdown(machine)
    sleep(30)
    power_control.set_s0(machine)
    wait_to_come_up(machine, timeout=15)
    windows_transitions.vm_poweron(machine)
    log(2)
Example #7
0
def reboot(dut, timeout=600, managed=True):
    """Reboot dut by running shutdown, and wait for it to come back"""
    if managed:
        platform_transition(dut, 'reboot')
    else:
        print "INFO: sending reboot"
        run(['reboot'], host=dut) #wait=False
    wait_to_go_down(dut)                  # wait for host to go down
    wait_to_come_up(dut, timeout=timeout) # wait for host to boot
    print "DEBUG: host is up"
Example #8
0
File: XCXT.py Project: OpenXT/bvt
def tpmsetup(machine,vms,steps,build,test_path,caller):
    r = run(['tpm-setup'], host=machine)
    tslib.cmdResponse(r, 'tpm-setup')
    if 'TPM setup successful -- please reboot!' not in r or 'fail' in r:
        tslib.pauseToDebug("TPM setup - FAILED") 
    else:
        power_control.platform_transition(machine, 'reboot')
        wait_to_go_down(machine)
        tslib.interact(machine, "At the TPM protection screen, enter password and choose to reseal the device")
        wait_to_come_up(machine) 
Example #9
0
def reboot(dut, timeout=600, managed=True):
    """Reboot dut by running shutdown, and wait for it to come back"""
    if managed:
        platform_transition(dut, 'reboot')
    else:
        print "INFO: sending reboot"
        run(['reboot'], host=dut)  #wait=False
    wait_to_go_down(dut)  # wait for host to go down
    wait_to_come_up(dut, timeout=timeout)  # wait for host to boot
    print "DEBUG: host is up"
Example #10
0
def tpmsetup(machine, vms, steps, build, test_path, caller):
    r = run(['tpm-setup'], host=machine)
    tslib.cmdResponse(r, 'tpm-setup')
    if 'TPM setup successful -- please reboot!' not in r or 'fail' in r:
        tslib.pauseToDebug("TPM setup - FAILED")
    else:
        power_control.platform_transition(machine, 'reboot')
        wait_to_go_down(machine)
        tslib.interact(
            machine,
            "At the TPM protection screen, enter password and choose to reseal the device"
        )
        wait_to_come_up(machine)
Example #11
0
def hostSleep(machine,vms,steps,build,test_path,caller):
    log(1,'Host Sleep')
    if caller == 'PVM': tslib.hdx_switch(machine, 1, vms)
    if caller == 'SVM': tslib.hdx_switch(machine, 0, vms)
    if caller == 'noVM': tslib.forcepowerstate(machine, 'off', vms)
    else: tslib.forcepowerstate(machine, 'on', vms)
    sleep(5)
    power_control.xenmgr_sleep(machine)
    sleep(30)
    power_control.set_s0(machine)
    wait_to_come_up(machine, timeout=15)
    if caller != 'noVM': windows_transitions.wait_for_vms(machine,vms,timeout=15)
    log(2)
Example #12
0
def store_installer_status_report(dut, reason='unknown'):
    """Make a status report using the installer"""
    build_doc = mongodb.get_autotest().builds.find_one(
        {'branch':'master'}, sort=[('build_time', mongodb.DESCENDING)])
    print 'STATUS_REPORT: chose installer of %(_id)s on %(branch)s' % build_doc
    default_build = str(build_doc['_id'])
    print 'STATUS_REPORT: getting installer status report reason', reason
    set_pxe_build(dut, default_build, 'ssh')
    power_cycle(dut, pxe=True)
    wait_to_come_up(dut, timeout=600)
    print 'STAUTS_REPORT: connected to port 22'
    return store_status_report( dut, port=22,
                                command='status-report', reason=reason,
                                try_installer=False, label='-installer')
Example #13
0
def reboot_test(dut, hours):
    duration = float(hours)*60*60
    print 'INFO: reboot loop duration', duration, 'seconds'
    start = time.time()
    cycles = 0
    while cycles == 0 or time.time() - start < duration:
        cycles += 1
        print 'INFO:cycle', cycles
        wait_to_come_up(dut)        #Wait for host to boot
        print 'HEADLINE: dom0 on',dut,'looks fine',
        print (time.time()-start)/3600.0,'hours into test'
        print 'INFO: sending reboot'
        run(['reboot'], host=dut)
        wait_to_go_down(dut)        #Wait for host to go down
Example #14
0
def get_xc_config(dut, timeout=60):
    """Get config information for XC running on dut or throw exception"""
    print 'GET_XC_CONFIG: connect to', dut
    wait_to_come_up(dut, timeout=timeout, installer_okay=False)
    non_comment = compile('\\A[^#].+ = .+')
    lines = run(['cat', '/etc/xenclient.conf'],
                timeout=timeout,
                host=dut,
                line_split=True)
    line_pairs = [
        split_value_definition(line) for line in lines
        if non_comment.match(line)
    ]
    return dict((key, value) for (key, value) in line_pairs)
Example #15
0
def old_reboot_test( machine, hours):
    duration = float(hours)*60*60
    print 'INFO: reboot loop duration',duration,'seconds'
    start = time.time()
    cycles = 0
    while cycles ==0 or time.time() - start < duration:
        cycles += 1
        print 'INFO: cycle',cycles
        with connection.wait_to_come_up(machine) as sh_dut:
            out,_ = sh_dut.verified_launch('df')
            for line in out.split('\n'):
                match = re.search('([0-9]+)% (/[a-zA-Z/]*)', line)
                if match is None: continue
                percent= int(match.group(1))
                mount = match.group(2)
                print 'INFO:',percent,'% for',mount
                # After a fresh install: 93% for /
                if percent > 95:
                    raise PartitionTooFull(mount,'is now',percent,'% full')
            print 'HEADLINE: dom0 on',machine,'looks fine',
            print (time.time()-start)/3600.0,'hours into test'
            print 'INFO: sending reboot'
            sh_dut.verified_launch('reboot')
            print 'INFO: sleeping to allow reboot to happen'
            time.sleep(10)
        with wait_to_come_up(machine) as sh_dut: pass
Example #16
0
def try_get_build_number_branch(dut, timeout=60):
    """Get build number and branch running on dut or throw exception"""
    print 'GETBUILD: connect to', dut
    wait_to_come_up(dut, timeout=timeout, installer_okay=False)
    issue = run(['cat', '/etc/issue'], timeout=timeout, host=dut)
    branch = None
    matchbr = search(r'build_branch\s*=\s*([0-9a-zA-Z\-]+)', issue)
    match = search(r'build\s*=\s*([0-9a-zA-Z\-]+)', issue)
    if match is None:
        raise UnrecongisedEtcIssue(issue)
    if matchbr:
        branch = matchbr.group(1)
    else:
        branch = 'master'
    print 'GETBUILD: detected build', match.group(1), branch, 'on', dut
    return match.group(1), branch
Example #17
0
def try_get_build_number_branch(dut, timeout=60):
    """Get build number and branch running on dut or throw exception"""
    print 'GETBUILD: connect to', dut
    wait_to_come_up(dut, timeout=timeout, installer_okay=False)
    issue = run(['cat','/etc/issue'], timeout=timeout, host=dut)
    branch = None
    matchbr = search(r'build_branch\s*=\s*([0-9a-zA-Z\-]+)', issue)
    match = search(r'build\s*=\s*([0-9a-zA-Z\-]+)', issue)
    if match is None:
        raise UnrecongisedEtcIssue(issue)
    if matchbr:
        branch = matchbr.group(1)
    else: 
        branch = 'master'
    print 'GETBUILD: detected build', match.group(1), branch, 'on', dut
    return match.group(1), branch
Example #18
0
def store_status_report(dut,
                        port=22,
                        command='status-tool',
                        reason='unknown',
                        try_installer=False,
                        label='-platform'):
    """Make a status report and store it on the artifacts server"""
    print 'INFO: getting status report from', dut, 'reason ' + str(reason)
    set_pxe_build(dut, action='boot')
    try:
        set_pxe_s0(dut)
    except NoPowerControl:
        pass
    try:
        wait_to_come_up(dut, timeout=10)
        out, exitcode = run(['/usr/bin/' + command],
                            timeout=600,
                            host=dut,
                            ignore_failure=True)

        print 'STATUS_REPORT: made status report reason', reason, 'exit code', \
            exitcode
        out2 = out[out.find(' '.join(MAGIC)):]
        spl = out2.split()
        if spl[:2] != MAGIC or len(spl) != 4:
            print 'STATUS_REPORT: unexpected status-tool output', out
        else:
            report = spl[-2]
            print 'STATUS_REPORT: downloading', report
            report_loc = store_client_artifact(dut, report, 'status-reports',
                                               label + POSTFIX)
            print 'INFO: created status report', report_loc
            set_pxe_build(dut, action='boot')

            return (report_loc)
    except (SubprocessError, TimeoutError):
        print 'INFO: unable to connect'
        if try_installer:
            print 'INFO: trying installer status report'
            try:
                return store_installer_status_report(
                    dut, reason='unable to connect when geting ' + reason)
            finally:
                set_pxe_build(dut, None, 'boot')
        else:
            raise
Example #19
0
def do_test(dut, test_case, build, result_id, source_directory):
    """Run test_case on dut using build"""
    if test_case['trigger'] != 'platform install':
        wait_to_come_up(dut)

    handles = [
        handle for handle, human in test_names.ordering if human in test_case
    ]
    handle = handles[0] if handles else None

    arg_dict = {}
    guest = test_case.get('guest')
    for name, value in test_case['arguments']:
        if value == '$(DUT)':
            valuep = dut
        elif value == '$(GUEST)':
            valuep = test_case['guest']
        elif value == '$(OS_NAME)':
            if guest is None:
                valuep = 'dom0'
            else:
                valuep = dict(test_names.ordering).get(guest, guest)
        elif value == '$(RELEASE)':
            valuep = None
        elif value == '$(BUILD)':
            valuep = build
        elif value == '$(PRESERVE_DATABASE)':
            valuep = False
        elif value == '$(SOURCE_DIRECTORY)':
            valuep = source_directory
        elif value == '$(SYNCH_URL)':
            valuep = 'autoxt1.cam.xci-test.com'
        elif value == '$(ENCRYPT_VHD)':
            valuep = False
        elif value == '$(RESULT_ID)':
            valuep = result_id
        elif value == '$(UPDATE_BRANCH)':
            valuep = extract_branch(build)
        elif value == '$(UPDATE_BUILD)':
            valuep = build
        else:
            valuep = value
        arg_dict[name] = valuep
    test_case['function'](**arg_dict)
Example #20
0
File: launch.py Project: OpenXT/bvt
def do_test(dut, test_case, build, result_id, source_directory):
    """Run test_case on dut using build"""
    if test_case['trigger'] != 'platform install':
        wait_to_come_up(dut)
    
    handles = [handle for handle, human in test_names.ordering if 
               human in test_case]
    handle = handles[0] if handles else None
    
    arg_dict = {}
    guest = test_case.get('guest')
    for name, value in test_case['arguments']:
        if value == '$(DUT)':
            valuep = dut
        elif value  == '$(GUEST)':
            valuep = test_case['guest']
        elif value == '$(OS_NAME)':
            if guest is None:
                valuep = 'dom0'
            else: 
                valuep = dict(test_names.ordering).get(guest, guest)
        elif value == '$(RELEASE)':
            valuep = None
        elif value == '$(BUILD)':
            valuep = build
        elif value == '$(PRESERVE_DATABASE)':
            valuep = False
        elif value == '$(SOURCE_DIRECTORY)':
            valuep = source_directory
        elif value == '$(SYNCH_URL)':
            valuep = 'autoxt1.cam.xci-test.com'
        elif value == '$(ENCRYPT_VHD)':
            valuep = False
        elif value == '$(RESULT_ID)':
            valuep = result_id
        elif value == '$(UPDATE_BRANCH)':
            valuep = extract_branch(build)
        elif value == '$(UPDATE_BUILD)':
            valuep = build
        else:
            valuep = value
        arg_dict[name] = valuep
    test_case['function'](**arg_dict)
Example #21
0
def store_installer_status_report(dut, reason='unknown'):
    """Make a status report using the installer"""
    build_doc = mongodb.get_autotest().builds.find_one({'branch': 'master'},
                                                       sort=[
                                                           ('build_time',
                                                            mongodb.DESCENDING)
                                                       ])
    print 'STATUS_REPORT: chose installer of %(_id)s on %(branch)s' % build_doc
    default_build = str(build_doc['_id'])
    print 'STATUS_REPORT: getting installer status report reason', reason
    set_pxe_build(dut, default_build, 'ssh')
    power_cycle(dut, pxe=True)
    wait_to_come_up(dut, timeout=600)
    print 'STAUTS_REPORT: connected to port 22'
    return store_status_report(dut,
                               port=22,
                               command='status-report',
                               reason=reason,
                               try_installer=False,
                               label='-installer')
Example #22
0
File: XCXT.py Project: OpenXT/bvt
def editfs(machine,vms,steps,build,test_path,caller):
    r = run(['mount','-o','rw,remount','/'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
    r = run(['touch','/testfolder1'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')

    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    tslib.interact(machine, "At the TPM protection screen, choose shutdown. Ensure that machine shutsdown")

    power_control.set_s0(machine)
    tslib.interact(machine, "At the TPM protection screen, choose continue. Enter the wrong password 3 times. Ensure that machine shutsdown")

    power_control.set_s0(machine)
    tslib.interact(machine, "At the TPM protection screen, choose continue. Enter the correct password. Choose not to reseal the device")
    wait_to_come_up(machine)

    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    tslib.interact(machine, "Ensure that TPM protection screen is shown, enter password and choose to reseal the device")
    wait_to_come_up(machine)

    print "Rebooting the device to check if reseal has taken effect. TPM screen should not be seen anymore"
    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    wait_to_come_up(machine)
Example #23
0
def store_status_report(dut, port=22, command = 'status-tool', 
                        reason='unknown', try_installer=False,
                        label='-platform'):
    """Make a status report and store it on the artifacts server"""
    print 'INFO: getting status report from', dut, 'reason '+str(reason)
    set_pxe_build( dut, action='boot')
    try:
        set_pxe_s0(dut)
    except NoPowerControl:
        pass
    try:
        wait_to_come_up(dut, timeout=10)
        out, exitcode = run(['/usr/bin/'+command], timeout=600, host=dut, ignore_failure=True)
        
        print 'STATUS_REPORT: made status report reason', reason, 'exit code', \
            exitcode
        out2 = out[out.find(' '.join(MAGIC)):]
        spl = out2.split()
        if spl[:2] != MAGIC  or len(spl)!=4:
            print 'STATUS_REPORT: unexpected status-tool output', out
        else:
            report = spl[-2]
            print 'STATUS_REPORT: downloading', report
            report_loc = store_client_artifact(dut, report, 'status-reports', 
                                               label+POSTFIX)
            print 'INFO: created status report', report_loc
            set_pxe_build( dut, action='boot')

            return (report_loc)
    except (SubprocessError, TimeoutError):
        print 'INFO: unable to connect'
        if try_installer:
            print 'INFO: trying installer status report'
            try:
                return store_installer_status_report(
                    dut, reason='unable to connect when geting '+reason)
            finally:
                set_pxe_build( dut, None, 'boot')
        else:
            raise
Example #24
0
def editfs(machine, vms, steps, build, test_path, caller):
    r = run(['mount', '-o', 'rw,remount', '/'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
    r = run(['touch', '/testfolder1'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')

    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    tslib.interact(
        machine,
        "At the TPM protection screen, choose shutdown. Ensure that machine shutsdown"
    )

    power_control.set_s0(machine)
    tslib.interact(
        machine,
        "At the TPM protection screen, choose continue. Enter the wrong password 3 times. Ensure that machine shutsdown"
    )

    power_control.set_s0(machine)
    tslib.interact(
        machine,
        "At the TPM protection screen, choose continue. Enter the correct password. Choose not to reseal the device"
    )
    wait_to_come_up(machine)

    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    tslib.interact(
        machine,
        "Ensure that TPM protection screen is shown, enter password and choose to reseal the device"
    )
    wait_to_come_up(machine)

    print "Rebooting the device to check if reseal has taken effect. TPM screen should not be seen anymore"
    power_control.platform_transition(machine, 'reboot')
    wait_to_go_down(machine)
    wait_to_come_up(machine)
Example #25
0
def pxe_install_xc(dut,
                   build=None,
                   release=None,
                   watch_tftp=None,
                   upgrade=False,
                   mac_address=None):
    """PXE install build on dut"""
    print 'HEADLINE:', 'upgrading' if upgrade else 'installing', \
        release or build, 'XT on', dut
    if watch_tftp is None:
        watch_tftp = 'autotest' in gethostname()
    if isdir(build):
        repository_directory = build + '/repository'
    else:
        build_info = select_build(build, release)
        netboot, variant = select_variant(build_info)
        repository_directory = build_info['build_directory'] + '/repository'
        if variant == 'kent':
            repository_directory += '-kent'
        print 'INFO: bi=', build_info, repository_directory

    with TemporaryWebServer(path=repository_directory) as web:
        out = urlopen(web.url + '/packages.main/XC-PACKAGES').read()
        print 'INFO: XC-PACKAGES is', repr(out)
        target_build_info = set_pxe_build(
            dut,
            build=build,
            release=release,
            action='upgrade' if upgrade else 'install',
            mac_address=mac_address,
            build_url=web.url)
        print 'PXE_INSTALL: set PXE server'
        if upgrade:
            try:
                platform_transition(dut, 'reboot')
            except SubprocessError:
                print 'HEADLINE: unable to contact', dut, 'to do clean shutodwn'
            else:
                wait_to_go_down(dut)
        power_cycle(dut, pxe=True)
        process = Process(target=watch, args=(dut, '/var/log/installer'))
        process.start()
        try:
            print 'PXE_INSTALL: waiting to come up in installer'
            print 'INFO: Waiting to come up in installer'
            print 'INFO: ', dut
            wait_to_come_up(dut, installer_okay=True, timeout=120)
            print 'INFO: passed wait to come up'
            if DEFAULT_POWER_CONTROL == 'AMT':
                if not is_installer_running(dut + '-amt', timeout=60):
                    raise PlatformCameUpInsteadOfInstaller(dut)
            else:
                if not is_installer_running(dut, timeout=60):
                    raise PlatformCameUpInsteadOfInstaller(dut)
            print 'HEADLINE: SSH response from installer'
            pxe_localboot(dut, mac_address)
            print 'INFO: set PXE back to default'
            wait_to_come_up(dut, installer_okay=False, timeout=300)
            print 'INFO: response from', dut
            if not isdir(build):
                found = get_build_number_branch(dut, timeout=3600)
            else:
                found = True
        finally:
            process.terminate()
    if found == True:
        pass
    elif found:
        bn, br = found
        print 'PXE_INSTALL:', dut, 'now has', bn, br, 'installed'
        tag = build if build else (
            target_build_info['tag']
            if target_build_info and target_build_info.get('tag') else None)
        if tag and (bn not in tag or br not in tag):
            raise UnexpectedInstallAfterInstallation('found=', bn, br,
                                                     'wanted=', build, 'on',
                                                     dut)
    else:
        raise UnableToContactAfterInstallation('wanted=', build, 'on', dut)
    print 'HEADLINE: succesfully', 'upgraded' if upgrade else 'installed', \
        (release or build), 'on', dut
Example #26
0
def vhdcompact_reboot(dut, guest, operation='pipe'):
    """Run vhdcmpact on dut for guest then reboot"""
    wait_to_come_up(dut)
    print 'VHDCOMPACT: connected to dut', dut, 'for', operation
    go = specify(host=dut)
    vm_address = wait_for_windows(dut, guest)
    go(['xec-vm', '-n', guest, 'shutdown'], timeout=600)
    print 'VHDCOMPACT:', 'shut down domain', guest
    if is_windows_up(vm_address):
        raise WindowsStillUp(dut, guest)
    result = 'vhdcompact not run'
    before = archive_vhd(dut,
                         guest,
                         artifact_name='before-vhdcompact',
                         have_tools=False,
                         publish=False)
    if before is None:
        raise CannotArchiveVHD(dut, guest)
    found = False
    disk = 0
    while 1:
        physical_path, stderr_log, exit_code = go(
            ['xec-vm', '-n', guest, '--disk',
             str(disk), 'get', 'phys-path'],
            stderr=True,
            ignore_failure=True)
        print 'VHDCOMPACT: physical path', physical_path, 'for', disk
        if exit_code != 0:
            assert 'does not exist' in stderr_log, (exit_code, stderr_log)
            break

        if physical_path.startswith('/storage/disks'):
            found = True
            break
        disk += 1

    assert ' ' not in physical_path
    pathe = physical_path.split()[0]
    if operation == 'inplace':
        print 'VHDCOMPACT:', 'found disk on ID', disk, \
            'path', pathe
        out = go(['vhdcompact', pathe], timeout=1800)
        if 'Already compacted' in out:
            result = 'already compacted'
        else:
            match = re.search(
                r'Size before\s+([0-9]+)\s+MB.\s+' +
                r'Size after\s+([0-9]+)\s+MB.' +
                r'\s+Reclaimed\s+([0-9]+)\s+MB', out)
            if match is None:
                raise UnexpectedVHDCompactOutput(out)
            result = 'compacted from %sMB to %sMB' % (match.group(1),
                                                      match.group(2))
        print 'VHDCOMPACT:', 'disk on ID', disk, 'path', \
            pathe, result
    elif operation == 'pipe':
        base = basename(split(pathe)[1]) + '.sync'
        devname = '/dev/mapper/' + base

        go([
            'vhd-dm-create', '--readonly', '--partitions', '--device-name',
            base, pathe
        ])
        try:
            go([
                'vhdcompact', '-c', '-p', '-r', '-m4', '-b', devname, pathe,
                '>', pathe + '.new'
            ],
               timeout=3600,
               shell=True)
        finally:
            go(['vhd-dm-remove', '--partitions', base])
        sizes = [
            int(go(['stat', '-c', '%s', pathe + postfix], split=True)[0][0])
            for postfix in ['', '.new']
        ]
        result = 'size went from %d to %d (%d%%)' % (sizes[0], sizes[1], (
            100.0 * (sizes[0] - sizes[1]) / sizes[0] if sizes[0] else 0))

        go(['mv', '-f', pathe, pathe + '.old'])
        go(['mv', pathe + '.new', pathe])
    elif operation == 'noop':
        pass
    else:
        raise UnimplementedOperation(operation)
    after = archive_vhd(dut,
                        guest,
                        artifact_name='after-vhdcompact',
                        have_tools=False,
                        publish=False)
    if after is None:
        raise CannotArchiveVHD(dut, guest)
    for command in ['start', 'switch']:
        go(['xec-vm', '-n', guest, command], timeout=600)

    try:
        wait_for_windows(dut, guest, timeout=600)
    except Exception, exc:
        print 'HEADLINE: vhdcompcat made VHD copy', before, 'into unbootable VHD copy', after
        raise UnableToConnectAfterVHDCompact(exc)
Example #27
0
def pxe_install_xc(dut, build=None, release=None, watch_tftp=None, upgrade=False,
                   mac_address=None):
    """PXE install build on dut"""
    print 'HEADLINE:', 'upgrading' if upgrade else 'installing', \
        release or build, 'XT on', dut
    if watch_tftp is None:
        watch_tftp = 'autotest' in gethostname()
    if isdir(build):
        repository_directory = build+'/repository'
    else:
        build_info = select_build(build, release)
        netboot, variant = select_variant(build_info)
        repository_directory = build_info['build_directory']+'/repository'
        if variant == 'kent':
            repository_directory += '-kent'
        print 'INFO: bi=', build_info, repository_directory

    with TemporaryWebServer(path=repository_directory) as web:
        out = urlopen(web.url+'/packages.main/XC-PACKAGES').read()
        print 'INFO: XC-PACKAGES is', repr(out)
        target_build_info = set_pxe_build(dut, build=build, release=release, 
                        action='upgrade' if upgrade else 'install',
                                            mac_address=mac_address,
                                            build_url = web.url)
        print 'PXE_INSTALL: set PXE server'
        if upgrade:
            try:
                platform_transition(dut, 'reboot')
            except SubprocessError:
                print 'HEADLINE: unable to contact', dut, 'to do clean shutodwn'
            else:
                wait_to_go_down(dut)
        power_cycle(dut, pxe=True)
        process = Process(target=watch, args=(dut, '/var/log/installer'))
        process.start()
        try:
            print 'PXE_INSTALL: waiting to come up in installer'
            print 'INFO: Waiting to come up in installer'
            print 'INFO: ', dut
            wait_to_come_up(dut, installer_okay=True, timeout=60)
            print 'INFO: passed wait to come up'
            if DEFAULT_POWER_CONTROL == 'AMT':
                if not is_installer_running(dut+'-amt', timeout=60):
                    raise PlatformCameUpInsteadOfInstaller(dut)
            else:
                if not is_installer_running(dut, timeout=60):
                    raise PlatformCameUpInsteadOfInstaller(dut)
            print 'HEADLINE: SSH response from installer'
            print 'INFO: set PXE back to default'
            wait_to_come_up(dut, installer_okay=False, timeout=300)
            print 'INFO: response from', dut
            if not isdir(build):
                found = get_build_number_branch(dut, timeout=3600)
            else:
                found = True
        finally:
            process.terminate()
    if found == True:
        pass
    elif found:
        bn, br= found
        print 'PXE_INSTALL:', dut, 'now has', bn, br, 'installed'
        tag = build if build else (target_build_info['tag'] if 
                                   target_build_info and target_build_info.get('tag') else None)
        if tag and (bn not in tag or br not in tag):
            raise UnexpectedInstallAfterInstallation(
                'found=', bn, br, 'wanted=', build, 'on', dut)
    else:
        raise UnableToContactAfterInstallation('wanted=',build,'on',dut)
    print 'HEADLINE: succesfully', 'upgraded' if upgrade else 'installed', \
        (release or build), 'on', dut
Example #28
0
def vhdcompact_reboot(dut, guest, operation='pipe'):
    """Run vhdcmpact on dut for guest then reboot"""
    wait_to_come_up(dut)
    print 'VHDCOMPACT: connected to dut', dut, 'for', operation 
    go = specify(host=dut)
    vm_address = wait_for_windows(dut, guest)
    go(['xec-vm', '-n', guest, 'shutdown'], timeout=600)
    print 'VHDCOMPACT:', 'shut down domain', guest 
    if is_windows_up(vm_address):
        raise WindowsStillUp(dut, guest)
    result = 'vhdcompact not run'
    before = archive_vhd(dut, guest, artifact_name = 'before-vhdcompact', 
                         have_tools=False, publish=False)
    if before is None:
        raise CannotArchiveVHD(dut, guest)
    found =  False
    disk = 0
    while 1:
        physical_path, stderr_log, exit_code = go(
            ['xec-vm', '-n', guest, '--disk', 
             str(disk), 'get', 'phys-path'], stderr=True, 
            ignore_failure=True)
        print 'VHDCOMPACT: physical path', physical_path, 'for', disk
        if exit_code != 0: 
            assert 'does not exist' in stderr_log, (exit_code, stderr_log)
            break
        
        if physical_path.startswith('/storage/disks'):
            found = True
            break
        disk += 1

    assert ' ' not in physical_path
    pathe = physical_path.split()[0]
    if operation == 'inplace':
        print 'VHDCOMPACT:', 'found disk on ID', disk, \
            'path', pathe 
        out = go(['vhdcompact', pathe], timeout=1800)
        if 'Already compacted' in out:
            result = 'already compacted'
        else:
            match = re.search(
                r'Size before\s+([0-9]+)\s+MB.\s+'+
                r'Size after\s+([0-9]+)\s+MB.'+
                r'\s+Reclaimed\s+([0-9]+)\s+MB', out)
            if match is None:
                raise UnexpectedVHDCompactOutput(out)
            result = 'compacted from %sMB to %sMB' % (
                match.group(1), match.group(2))
        print 'VHDCOMPACT:', 'disk on ID', disk, 'path', \
            pathe, result 
    elif operation == 'pipe':
        base = basename(split(pathe)[1])+'.sync'
        devname = '/dev/mapper/'+base

        go(['vhd-dm-create', '--readonly', '--partitions',
             '--device-name', base, pathe])
        try:
            go(['vhdcompact', '-c', '-p', '-r', '-m4', 
                '-b', devname, pathe, '>', pathe+'.new'],
                timeout=3600, shell=True)
        finally:
            go(['vhd-dm-remove', '--partitions', base])
        sizes = [int(go(['stat', '-c', '%s', pathe+postfix], 
                                 split=True)[0][0])
                 for postfix in ['', '.new']]
        result = 'size went from %d to %d (%d%%)' % (
            sizes[0], sizes[1], 
            (100.0*(sizes[0] - sizes[1]) / sizes[0] if 
             sizes[0] else 0))

        go(['mv', '-f', pathe, pathe+'.old'])
        go(['mv', pathe+'.new', pathe])
    elif operation == 'noop':
        pass
    else:
        raise UnimplementedOperation(operation)
    after = archive_vhd(dut, guest, artifact_name='after-vhdcompact', 
                        have_tools=False, publish=False)
    if after is None:
        raise CannotArchiveVHD(dut, guest)
    for command in ['start', 'switch']:
        go(['xec-vm', '-n', guest, command], timeout=600)

    try:
        wait_for_windows(dut, guest, timeout=600)
    except Exception, exc:
        print 'HEADLINE: vhdcompcat made VHD copy', before, 'into unbootable VHD copy', after
        raise  UnableToConnectAfterVHDCompact(exc)