Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
def clean_old_vhds():
    """Clean up old VHDs"""
    references = set()

    builddir = VHD_WITH_TOOLS_PATTERN[:VHD_WITH_TOOLS_PATTERN.find('%')-1]
    builddocs = get_autotest().builds.find(
        {}, sort=[('build_time', DESCENDING)], limit=5)
    recentbuilds = [bd['_id'] for bd in builddocs]
    builds = listdir(builddir)
    for name in builds:
        if name not in recentbuilds:
            fname = builddir + '/'+ name
            print 'delete', fname
            run(['rm', '-rf', fname], ignore_failure=True)
    
    for (dirpath, dirnames, filenames) in walk('/home/xc_vhds/dev_vhds'):
        for name in filenames:
            full = dirpath+'/'+name
            if not islink(full):
                continue
            references.add(readlink(full))

    print 'INFO: have references to', len(references), 'VHDs'
    for (dirpath, dirnames, filenames) in \
            walk('/home/xc_bvt_output/archive-vhds'):
        for name in filenames:
            full = dirpath+'/'+name
            if full not in references:
                print 'INFO: deleting unreferenced', full
                try:
                    unlink(full)
                except OSError:
                    pass
Beispiel #4
0
def disableSnapshot(machine, vms, steps, build, test_path, caller):
    dummy = str(random.randint(10000, 20000))
    vm_address = str(domain_address(machine, vms))
    r = run(['xec-vm', '-n', vms, '--disk', '1', 'get', 'snapshot'],
            host=machine)
    if 'temporary' in r:
        tslib.forcepowerstate(machine, 'off', vms)
        r = run(
            ['xec-vm', '-n', vms, '--disk', '1', 'set', 'snapshot', 'none'],
            host=machine)
        tslib.cmdResponse(r,
                          'xec-vm -n ' + vms + ' --disk 1 set snapshot none')
        snapshot = run(['xec-vm', '-n', vms, '--disk', '1', 'get', 'snapshot'],
                       host=machine)
        tslib.cmdResponse(r, 'xec-vm -n ' + vms + ' --disk 1 get snapshot')
        if 'none' not in snapshot:
            tslib.pauseToDebug("xec failed to disable snapshot")
        windows_transitions.vm_poweron(machine, vms)
        for i in range(2):
            windows_transitions.vm_reboot_dom0(machine, vms)
    res = run_via_exec_daemon(
        ['mkdir', 'C:\\Users\\Administrator\\Desktop\\' + dummy],
        host=vm_address,
        wait=True)
    windows_transitions.vm_reboot_dom0(machine, vms)
    res = run_via_exec_daemon(['dir', 'C:\\Users\\Administrator\\Desktop\\'],
                              host=vm_address,
                              wait=True)
    if dummy not in res:
        tslib.pauseToDebug("Snapshot disabled: Old folders lost after reboot")
Beispiel #5
0
def set_boot_order(host,name,order):
    #would check exclusive, but makes an easy check
    valid_boot = ['c','d','n']
    for letter in order:
        if letter not in valid_boot:
            raise InvalidBootOption()
    run(['xec-vm', '-n', name, 'set', 'boot', order], host=host)
Beispiel #6
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 #7
0
def ensure_stable(vm_address, interval, timeout=600, description=None, method="exec_daemon"):
    """Ensure that vm_address is continuaully up for interval"""
    assert method in ['exec_daemon', "ssh"]
    last_down = time()
    start = time()
    last_out = time()
    reached = False
    while 1:
        delta = time() - last_down
        run_time = time() - start
        if delta > interval:
            print 'HEADLINE: VM at', vm_address, description, 'has been stable for', delta
            return
        if run_time > timeout:
            args = (time() - last_out, timeout, vm_address, description)
            if reached:
                raise SystemUnstable(*args)
            else:
                raise SystemUnreachable(*args)
        try:
            if method == "exec_daemon":
                call_exec_daemon('windowsVersion', [], host=vm_address, timeout=60)
            elif method == "ssh":
                run(['true'], host=vm_address, timeout=60, check_host_key=False)
            else:
                raise Exception("Unkonwn method %s" % method)
        except Exception, exc:
            last_down = time()
        else:
            delta = time() - last_down
            print 'WAIT_FOR_SYSTEM: stable for', delta, 'of', interval, 'seconds'
            last_out = time()
            reached = True
        sleep(1)
Beispiel #8
0
def clean_old_vhds():
    """Clean up old VHDs"""
    references = set()

    builddir = VHD_WITH_TOOLS_PATTERN[:VHD_WITH_TOOLS_PATTERN.find('%') - 1]
    builddocs = get_autotest().builds.find({},
                                           sort=[('build_time', DESCENDING)],
                                           limit=5)
    recentbuilds = [bd['_id'] for bd in builddocs]
    builds = listdir(builddir)
    for name in builds:
        if name not in recentbuilds:
            fname = builddir + '/' + name
            print 'delete', fname
            run(['rm', '-rf', fname], ignore_failure=True)

    for (dirpath, dirnames, filenames) in walk('/home/xc_vhds/dev_vhds'):
        for name in filenames:
            full = dirpath + '/' + name
            if not islink(full):
                continue
            references.add(readlink(full))

    print 'INFO: have references to', len(references), 'VHDs'
    for (dirpath, dirnames, filenames) in \
            walk('/home/xc_bvt_output/archive-vhds'):
        for name in filenames:
            full = dirpath + '/' + name
            if full not in references:
                print 'INFO: deleting unreferenced', full
                try:
                    unlink(full)
                except OSError:
                    pass
Beispiel #9
0
def nilfvm(machine, vms, steps, build, test_path, caller):
    tslib.forcepowerstate(machine, 'off', vms)
    r = run([
        'cd', '/storage/nilfvm', 'nilfvm-create',
        '--rootfs=nilfvm-rootfs.i686.cpio.bz2', '--size=256',
        '--config=service-nilfvm'
    ],
            host=machine)
    tslib.cmdResponse(
        r,
        'nilfvm-create --rootfs=nilfvm-rootfs.i686.cpio.bz2 --size=256 --config=service-nilfvm'
    )
    vm_uuid = run(['xec-vm', '-n', vms, 'get', 'uuid'], host=machine)
    vm_uuid = vm_uuid.rstrip('\n')
    tslib.cmdResponse(vm_uuid, 'xec-vm -n ' + vms + ' get uuid')
    r = run(['xec-vm', '-u', vm_uuid, 'set', 'track-dependencies', 'true'],
            host=machine)
    tslib.cmdResponse(r,
                      'xec-vm -u ' + vm_uuid + ' set track-dependencies true')
    nilfvm_uuid = run(['xec-vm', '-n', nilfvm01, 'get', 'uuid'], host=machine)
    r = run([
        'xec-vm', '-u', vm_uuid, '--nic', '0', 'set', 'backend-uuid',
        nilfvm_uuid
    ],
            host=machine)
    tslib.cmdResponse(
        r, 'xec-vm -u ' + vm_uuid + ' --nic 0 set backend-uuid ' + nilfvm_uuid)
Beispiel #10
0
def test_enforce_encrypted_disks(dut):
    vm = create_guest(dut, "enforce_enc_disks", "windows")
    try:
        SIZE = 1 # size of virtual disk for test, in MB

        # 1. Ensure vm is shut-down
        guest_shutdown(dut, vm)

        # 2. Add an encrypted disk.  Start and stop VM
        vhd = run(['xec', 'create-vhd', str(SIZE)], host=dut, timeout=600).strip()
        vm_disk = run(['xec-vm', '-u', guest_uuid(dut, vm), 'add-disk'], host=dut).strip()
        run(['xec', '-o', vm_disk, 'attach-vhd', vhd], host=dut)
        run(['xec', '-o', vm_disk, 'generate-crypto-key', '256'], host=dut, timeout=600)
        guest_start(dut, vm)
        guest_shutdown(dut, vm)

        # 3. Replace encrypted disk with an unencrypted one.  Verify VM does not start.
        run(['rm', '-f', vhd], host = dut)
        run(['vhd-util', 'create', '-n', vhd, '-s', str(SIZE)], host = dut)

        try:
            guest_start(dut, vm)
        except:
            pass
        else:
            raise VMStartedAfterTampering

    finally:
        guest_destroy(dut, vm)
        guest_delete(dut, vm)
Beispiel #11
0
def set_boot_order(host, name, order):
    #would check exclusive, but makes an easy check
    valid_boot = ['c', 'd', 'n']
    for letter in order:
        if letter not in valid_boot:
            raise InvalidBootOption()
    run(['xec-vm', '-n', name, 'set', 'boot', order], host=host)
Beispiel #12
0
def set_iso_0(host, guest, iso):
    """sets what iso is held in the 0 disk slot of a VM"""
    run([
        'xec-vm', '-n', guest, '--disk', '0', 'set', 'phys-path',
        '/storage/isos/' + iso
    ],
        host=host)
Beispiel #13
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'
Beispiel #14
0
def add_vhd(host, name, size=80000):
    #returns the path to the disk
    run([
        'vhd-util', 'create', '-n', '/storage/disks/' + name, '-s',
        str(size)
    ],
        host=host)
    return '/storage/disks/' + name
Beispiel #15
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'
Beispiel #16
0
 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'
Beispiel #17
0
def set_disk_snapshot(host, guest, disknum, snapshot):
    #should be none or temporary
    if snapshot != 'none' and snapshot != 'temporary':
        raise BadEnumValue()
    run([
        'xec-vm', '-n', guest, '--disk', disknum, 'set', 'snapshot', snapshot
    ],
        host=host)
Beispiel #18
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')
Beispiel #19
0
def vm_reboot_dom0(dut, who='all'):
    """reboot vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'reboot'], host=dut)
            vmip = domains.domain_address(dut, domain['name'])
            wait_for_windows_to_go_down(vmip)
            wait_for_windows_to_come_up(vmip)
Beispiel #20
0
def shutdown_domain(dut, vm_uuid):
    """Attempt to cleanly shut down a VM.  Requires tools to be installed."""
    run(['xec-vm', '-u', vm_uuid, 'shutdown'], host=dut, timeout=600)
    for _ in range(30):
        sleep(5)
        state = run(['xec-vm', '-u', vm_uuid, 'get', 'state'], host=dut, timeout=600)
        if state.strip() == 'stopped':
            return
    raise VMFailedToShutDown
Beispiel #21
0
def vm_reboot_dom0(dut, who='all'):
    """reboot vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'reboot'], host=dut)
            vmip = domains.domain_address(dut, domain['name'])
            wait_for_windows_to_go_down(vmip)
            wait_for_windows_to_come_up(vmip)
Beispiel #22
0
def vm_hibernate_dom0(dut, who='all'):
    """hibernate vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'hibernate'], host=dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Beispiel #23
0
def get_disk_key(dut, disk_uuid):
    key_dir = run(['xec', 'get', 'platform-crypto-key-dirs'], 
                  host=dut, word_split=True)[0]
    disk_keys = [join(key_dir, key) for key in 
                 run(['ls', key_dir], word_split=True, host=dut)
                 if key.startswith(disk_uuid)]
    if len(disk_keys) > 1:
        raise MultipleDiskKeys(disk_keys, dut, guest, disk_uuid)
    return disk_keys[0] if disk_keys else None
Beispiel #24
0
def install_python(dut):
    _, ec= run(['python', '--version'], host=dut, ignore_failure=True)
    if ec == 0:
        print 'INFO: python already installed'
        return
    print 'INFO: copying python files on target'
    run(['scp', '-r', abspath(split(split(__file__)[0])[0])+'/pyxc', 'root@'+dut+':/root'])
    print 'INFO: launching python installer'
    run(['/root/pyxc/pysetup'], host=dut, timeout=3600)
Beispiel #25
0
def enableusbPassthrough(machine,vms,steps,build,test_path,caller):
    (vendor_id1,device_id1,vendor_id2,device_id2) = getDeviceID(machine,vms,steps,build,test_path,caller)
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'add-pt-rule','0x0c03',vendor_id1,device_id1], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n vms add-pt-rule 0x0c03'+vendor_id1+' '+device_id1)
    r = run(['xec-vm','-n',vms,'add-pt-rule','0x0c03',vendor_id2,device_id2], host=machine)    
    tslib.cmdResponse(r, 'xec-vm -n vms add-pt-rule 0x0c03'+vendor_id2+' '+device_id2)
    windows_transitions.vm_poweron(machine, vms)
    tslib.interact(machine, "Perform VM reboot if required. Plugin a usb device and verify if the device is passed through to the VM")
Beispiel #26
0
def vm_poweroff(dut, who='all'):
    """force poweroff a VM from domo"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'destroy'], host=dut, timeout=20)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Beispiel #27
0
def disableusbPassthrough(machine,vms,steps,build,test_path,caller):
    (vendor_id1,device_id1,vendor_id2,device_id2) = getDeviceID(machine,vms,steps,build,test_path,caller)
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'delete-pt-rule','0x0c03',vendor_id1,device_id1], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n vms delete-pt-rule 0x0c03'+vendor_id1+' '+device_id1)
    r = run(['xec-vm','-n',vms,'delete-pt-rule','0x0c03',vendor_id2,device_id2], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n vms delete-pt-rule 0x0c03'+vendor_id2+' '+device_id2)
    windows_transitions.vm_poweron(machine, vms)
    tslib.interact(machine, "Plugin a usb device and verify that it is not passed through to the VM")
Beispiel #28
0
def vm_shutdown_dom0(dut, who='all'):
    """shutdown vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'shutdown'], host=dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Beispiel #29
0
def disableStartOnBoot(machine,vms,steps,build,test_path,caller):
    print "INFO: Disabling autoboot for ",vms," VM"
    r = run(['xec-vm','-n',vms,'set','start-on-boot','false'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n '+vms+' set start-on-boot false')
    print "INFO: Rebooting host"
    power_control.reboot(machine)
    r = run(['xec-vm','-n',vms,'get','state'], host=machine)
    if 'stopped' not in r: tslib.pauseToDebug("VM started with XC boot and this is not expected")
    else: print 'INFO:',vms,'did not start on XC boot'
Beispiel #30
0
def audioPassthrough(machine,vms,steps,build,test_path,caller):
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'add-pt-rule','0x0403','any','any'], host=machine)
    tslib.cmdResponse(r,'xec-vm -n <vmname> add-pt-rule 0x0403 any any')
    windows_transitions.vm_poweron(machine, vms)
    r = run(['xec-vm','-n',vms,'list-pt-pci-devices'], host=machine)
    tslib.cmdResponse(r,'xec-vm -n '+vms+' list-pt-pci-devices')
    tslib.interact(machine, "Verify if the o/p of list-pt-pci-devices is as expected")
    tslib.interact(machine, "Verify from the VM that a new audio device is detected. Install driver and proceed")
Beispiel #31
0
def one_operation_logged(options, recording):
    try:
        mdb = mongodb.get_autotest()
        dut_document = mdb.duts.find_one({'name':options.machine})

        for job in mdb.jobs.find():
            control_pid = job.get('control_pid')
            if ((control_pid is None or 
                not os.path.isdir('/proc/'+str(control_pid))) and
                job.get('status', '').startswith('running')):
                mdb.jobs.update({'_id': job['_id']},
                                {'$set': {
                            'status': \
                                'control process '+str(control_pid)+
                            ' disppeared without clearing up'}})
        print 'TESTLAUNCH: experiment override', dut_document.get('experiment')

        job = get_job(mdb, options.machine)
        if job:
            print 'INFO: Doing Job'
            def update_job(field, value):
                """Update one field in job"""
                mdb.jobs.update({'_id':job['_id']}, 
                                {'$set': {field: value}})
            def set_status(status):
                """Update mongo status"""
                update_job('status', status)
            set_status('running')
            update_job('launch_time', time.time())
            update_job('control_pid', os.getpid())
            update_job('control_machine', gethostname())
            update_job('dut', options.machine)
            print 'I should run', job, 'on', options.machine
            command_line = list(job['command']) + [ '-m', options.machine]
            print 'running', command_line, 'with', job['timeout'], \
                'seconds timeout'
            def show(output):
                """show stderr"""
                for line in output.splitlines():
                    print line
                    make_log_entry(line, job_id=job['_id'],
                                   dut=options.machine)
            def finish(status, exc=None):
                """Mark test as finished"""
                set_status(status)
                if exc:
                    update_job('failure', str(exc))
                update_job('finish_time', time.time())
            try:
                run(command_line, timeout=job['timeout'],
                    output_callback=show, error_callback=show)
                finish('completed')
            except SubprocessError, exc:
                finish('failed (non zero exit code)', exc)
            except TimeoutError, exc:
                finish('failed (timed out)', exc)
Beispiel #32
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"
Beispiel #33
0
def vm_sleep_dom0(dut, who='all'):
    """sleep vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'sleep'], host=dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            wait_for_windows_to_go_down(vmip)
Beispiel #34
0
def store_local_artifact(local_file, section, postfix):
    """Copy local_file to artifact storage in specific section with
    postifx"""
    segments = make_segments(section, postfix)
    destination = ARTIFACTS_NFS_PATH + '/'.join(segments)
    parent = os.path.split(destination)[0]
    os.umask(0000)
    run(['mkdir', '-p', parent])
    run(['cp', local_file, destination], timeout=3600)
    return destination
Beispiel #35
0
def store_local_artifact(local_file, section, postfix):
    """Copy local_file to artifact storage in specific section with
    postifx"""
    segments = make_segments(section, postfix)
    destination = ARTIFACTS_NFS_PATH+'/'.join(segments)
    parent = os.path.split(destination)[0]
    os.umask(0000)
    run(['mkdir', '-p', parent])
    run(['cp', local_file, destination], timeout=3600)
    return destination
Beispiel #36
0
def vm_sleep_dom0(dut, who='all'):
    """sleep vm/vms from dom0"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'sleep'], host=dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            vmip = domains.domain_address(dut, domain['name'])
            wait_for_windows_to_go_down(vmip)
Beispiel #37
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"
Beispiel #38
0
def disableStubdom(machine,vms,steps,build,test_path,caller):
    status = run(['xec-vm','-n',vms,'get','stubdom'], host=machine)
    if 'false' in status:
         print "INFO: stubdom is already disabled, exiting.."
         exit()
    count = xenopslistcount(machine,vms)
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'set','stubdom','false'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n'+vms+'set stubdom false')
    windows_transitions.vm_poweron(machine, vms)
    if not checkStubdom(machine,vms,count,1): tslib.pauseToDebug("qemu is either not running in dom0 or service VM have not stopped")
Beispiel #39
0
def shutdown_domain(dut, vm_uuid):
    """Attempt to cleanly shut down a VM.  Requires tools to be installed."""
    run(['xec-vm', '-u', vm_uuid, 'shutdown'], host=dut, timeout=600)
    for _ in range(30):
        sleep(5)
        state = run(['xec-vm', '-u', vm_uuid, 'get', 'state'],
                    host=dut,
                    timeout=600)
        if state.strip() == 'stopped':
            return
    raise VMFailedToShutDown
Beispiel #40
0
def store_memory_artifact(content, section, postfix):
    """Store content on artifact server in section with postfix"""
    # it might be nice to avoid copying in store_local_artifact
    segments = make_segments(section, postfix)
    destination = ARTIFACTS_NFS_PATH+'/'.join(segments)
    parent = os.path.split(destination)[0]
    run(['mkdir', '-p', parent])
    fileobj = file(destination, 'wb')
    fileobj.write(content)
    fileobj.close()
    return destination
Beispiel #41
0
def check_mounts(dut):
    """Check mounts are as expected on dut"""
    writefile(FILE_PATH, BASH_SCRIPT, host=dut)
    run(['chmod', '+x', FILE_PATH], host=dut)
    out = run([FILE_PATH], host=dut)
    for line in out.split('\n'):
        print 'INFO:', line
    print 'INFO: mount checking completed cleanly'
    mtab = run(['mount'], host=dut)
    found = 'on /config' in mtab
    print 'INFO: /config', 'IS' if found else 'NOT', 'mounted'
Beispiel #42
0
def store_memory_artifact(content, section, postfix):
    """Store content on artifact server in section with postfix"""
    # it might be nice to avoid copying in store_local_artifact
    segments = make_segments(section, postfix)
    destination = ARTIFACTS_NFS_PATH + '/'.join(segments)
    parent = os.path.split(destination)[0]
    run(['mkdir', '-p', parent])
    fileobj = file(destination, 'wb')
    fileobj.write(content)
    fileobj.close()
    return destination
 def check_service(service):
     while (not tools_service(service, vm_address)):
         sleep(20)
     print 'INFO: Found %s service running.' % service
     print 'INFO: doing reboot'
     reboot_windows(dut, domain, vm_address)
     print 'INFO: done reboot, waiting for VM to come back up'
     run(['xec-vm', '-n', domain['name'], 'switch'], host=dut)
     print 'INFO: waiting for windows to boot'
     wait_for_windows(dut, guest)
     print 'HEADLINE: done reboot'
Beispiel #44
0
 def check_service(service):
     while (not tools_service(service, vm_address)):
         sleep(20)
     print 'INFO: Found %s service running.' % service
     print 'INFO: doing reboot'
     reboot_windows(dut, domain, vm_address)
     print 'INFO: done reboot, waiting for VM to come back up'
     run(['xec-vm', '-n', domain['name'], 'switch'], host=dut)
     print 'INFO: waiting for windows to boot'
     wait_for_windows(dut, guest)
     print 'HEADLINE: done reboot'
Beispiel #45
0
def vm_poweroff(dut, who='all'):
    """force poweroff a VM from domo"""
    domlist = find_guest_vms(dut)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            run(['xec-vm', '-n', domain['name'], 'destroy'],
                host=dut,
                timeout=20)
    for domain in domlist:
        if who == 'all' or domain['name'] == who:
            wait_for_guest_to_go_down(dut, domain['name'])
Beispiel #46
0
def check_mounts(dut):
    """Check mounts are as expected on dut"""
    writefile(FILE_PATH, BASH_SCRIPT, host=dut)
    run(['chmod', '+x', FILE_PATH], host=dut)
    out = run([FILE_PATH], host=dut)
    for line in out.split('\n'):
        print 'INFO:', line
    print 'INFO: mount checking completed cleanly'
    mtab = run(['mount'], host=dut)
    found = 'on /config' in mtab
    print 'INFO: /config', 'IS' if found else 'NOT', 'mounted'
Beispiel #47
0
def get_disk_key(dut, disk_uuid):
    key_dir = run(['xec', 'get', 'platform-crypto-key-dirs'],
                  host=dut,
                  word_split=True)[0]
    disk_keys = [
        join(key_dir, key)
        for key in run(['ls', key_dir], word_split=True, host=dut)
        if key.startswith(disk_uuid)
    ]
    if len(disk_keys) > 1:
        raise MultipleDiskKeys(disk_keys, dut, guest, disk_uuid)
    return disk_keys[0] if disk_keys else None
Beispiel #48
0
def checkTPM(machine, vms, steps, build, test_path, caller):
    r = run(['cryptsetup', 'luksDump', '/dev/xenclient/config'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
    f = 0
    for i in [1, 7]:
        if 'Key Slot ' + str(i) + ': ENABLED' not in r: f = 1
    for i in [0, 2, 3, 4, 5, 6]:
        if 'Key Slot ' + str(i) + ': DISABLED' not in r: f = 1
    if f: tslib.pauseToDebug("Command response is not as expected")

    r = run(['cat', '$(find', '/sys/', '-name', 'pcrs)'], host=machine)
    tslib.cmdResponse(r, 'cat $(find /sys/ -name pcrs)')
Beispiel #49
0
def checkTPM(machine,vms,steps,build,test_path,caller):
    r = run(['cryptsetup','luksDump','/dev/xenclient/config'], host=machine)
    tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
    f=0
    for i in [1,7]:
        if 'Key Slot '+str(i)+': ENABLED' not in r: f=1
    for i in [0,2,3,4,5,6]:
        if 'Key Slot '+str(i)+': DISABLED' not in r: f=1
    if f: tslib.pauseToDebug("Command response is not as expected")
     
    r = run(['cat','$(find','/sys/','-name','pcrs)'], host=machine)     
    tslib.cmdResponse(r, 'cat $(find /sys/ -name pcrs)')
Beispiel #50
0
def disableStartOnBoot(machine, vms, steps, build, test_path, caller):
    print "INFO: Disabling autoboot for ", vms, " VM"
    r = run(['xec-vm', '-n', vms, 'set', 'start-on-boot', 'false'],
            host=machine)
    tslib.cmdResponse(r, 'xec-vm -n ' + vms + ' set start-on-boot false')
    print "INFO: Rebooting host"
    power_control.reboot(machine)
    r = run(['xec-vm', '-n', vms, 'get', 'state'], host=machine)
    if 'stopped' not in r:
        tslib.pauseToDebug("VM started with XC boot and this is not expected")
    else:
        print 'INFO:', vms, 'did not start on XC boot'
Beispiel #51
0
def policyAudio(machine,vms,steps,build,test_path,caller):
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'set','policy-audio-access','false'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n '+vms+' set policy-audio-access false')
    windows_transitions.vm_poweron(machine, vms)
    tslib.interact(machine, "Play audio on the test VM and ensure that it fails") 

    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm','-n',vms,'set','policy-audio-access','true'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n '+vms+' set policy-audio-access true')
    windows_transitions.vm_poweron(machine, vms)
    tslib.interact(machine, "Play audio on the test VM and ensure that audio plays")
Beispiel #52
0
def stubdomStatusDom(machine,vm):    # checks if subdom is running in dom0
    domid = run(['xec-vm','-n',vm,'get','domid'], host=machine)
    print 'INFO: domid of ',vm,' is ',domid
    r = run(['ps','-ef'], host=machine)
    r = string.split(r,'\n')
    l = []
    for line in r:
         if 'qemu' in line: l.append(line)
    tslib.cmdResponse('\n'.join(l), 'ps aux | grep qemu')
    searchStr = ('-d '+domid).rstrip('\n')
    if searchStr in ' '.join(l): return 1
    else: return 0
Beispiel #53
0
def nilfvm(machine,vms,steps,build,test_path,caller):
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['cd','/storage/nilfvm','nilfvm-create','--rootfs=nilfvm-rootfs.i686.cpio.bz2','--size=256','--config=service-nilfvm'], host=machine)
    tslib.cmdResponse(r, 'nilfvm-create --rootfs=nilfvm-rootfs.i686.cpio.bz2 --size=256 --config=service-nilfvm')
    vm_uuid = run(['xec-vm','-n',vms,'get','uuid'], host=machine)
    vm_uuid = vm_uuid.rstrip('\n')
    tslib.cmdResponse(vm_uuid, 'xec-vm -n '+vms+' get uuid')
    r = run(['xec-vm','-u',vm_uuid,'set','track-dependencies','true'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -u '+vm_uuid+' set track-dependencies true')
    nilfvm_uuid = run(['xec-vm','-n',nilfvm01,'get','uuid'], host=machine)
    r = run(['xec-vm','-u',vm_uuid,'--nic','0','set','backend-uuid',nilfvm_uuid], host=machine)
    tslib.cmdResponse(r, 'xec-vm -u '+vm_uuid+' --nic 0 set backend-uuid '+nilfvm_uuid)
Beispiel #54
0
def stubdomStatusDom(machine, vm):  # checks if subdom is running in dom0
    domid = run(['xec-vm', '-n', vm, 'get', 'domid'], host=machine)
    print 'INFO: domid of ', vm, ' is ', domid
    r = run(['ps', '-ef'], host=machine)
    r = string.split(r, '\n')
    l = []
    for line in r:
        if 'qemu' in line: l.append(line)
    tslib.cmdResponse('\n'.join(l), 'ps aux | grep qemu')
    searchStr = ('-d ' + domid).rstrip('\n')
    if searchStr in ' '.join(l): return 1
    else: return 0
Beispiel #55
0
def start_logging(dut):
    print 'INFO:', 'kill old dbus monitors'
    run(KILL_DBUS_MONITOR, host=dut) 
    
    print 'INFO:', 'enable dbus eavesdrop' 
    run(['echo "'+ALLOW_EAVESDROP+'" > /storage/eaves.sh'], host=dut, shell=True)
    run(['/storage/eaves.sh'], host=dut)
    
    print 'INFO:', 'reload dbus config' 
    run(DBUS_CMD+['ReloadConfig'], host=dut)

    print 'INFO:', 'start dbus logging' 
    run(['dbus-monitor', '--system', '>', '%s&'% DBUS_LOG], host=dut)
Beispiel #56
0
def forcepowerstate(machine, reqstate, vm_name='all'):
    domlist = find_guest_vms(machine)
    for domain in domlist:
        if (vm_name == 'all' or vm_name == domain['name']):
            pow_state = get_vm_powerstate(machine, domain['name'])
            pow_state = pow_state.rstrip('\n')
            if (reqstate == 'on'):
                if (pow_state != 'running'):
                    start_vm(machine, domain['name'])
            elif (reqstate == 'off'):
                if (pow_state == 'running'):
                    run(['xec-vm', '-n', domain['name'], 'shutdown'],
                        host=machine)
Beispiel #57
0
def enableStubdom(machine, vms, steps, build, test_path, caller):
    status = run(['xec-vm', '-n', vms, 'get', 'stubdom'], host=machine)
    if 'true' in status:
        print "INFO: stubdom is already enabled, exiting.."
        exit()
    count = xenopslistcount(machine, vms)
    tslib.forcepowerstate(machine, 'off', vms)
    r = run(['xec-vm', '-n', vms, 'set', 'stubdom', 'true'], host=machine)
    tslib.cmdResponse(r, 'xec-vm -n' + vms + 'set stubdom true')
    windows_transitions.vm_poweron(machine, vms)
    if not checkStubdom(machine, vms, count, 0):
        tslib.pauseToDebug(
            "qemu is either running in dom0 or service VM have not started")