Ejemplo n.º 1
0
def install_network_test_vm(dut, name):
    if not have_fresh_vhd(NETWORK_TEST_OS_NAME):
        print 'HEADLINE: no fresh vhd for %s, building from scratch' % NETWORK_TEST_OS_NAME
        build_network_test_vm(dut, NETWORK_TEST_OS_NAME)
        soft_shutdown_guest(dut, NETWORK_TEST_OS_NAME, method='ssh')
        run(['xec-vm', '-n', NETWORK_TEST_OS_NAME, 'delete'], host=dut)

    assert have_fresh_vhd(NETWORK_TEST_OS_NAME) # won't work outside of CBG

    os_name, vm_name = name_split(name)
    assert os_name == NETWORK_TEST_OS_NAME, "Only %s is supported as a network test VM" % NETWORK_TEST_OS_NAME
    vm_uuid = install_guest(dut, guest=name, kind='vhd')
    configure_v4v_rules(dut, vm_name)
    soft_reboot_and_wait(dut, vm_name) # apply v4v rules

    return NetworkTestVM(dut, vm_uuid)
Ejemplo n.º 2
0
def install_network_test_vm(dut, name):
    if not have_fresh_vhd(NETWORK_TEST_OS_NAME):
        print 'HEADLINE: no fresh vhd for %s, building from scratch' % NETWORK_TEST_OS_NAME
        build_network_test_vm(dut, NETWORK_TEST_OS_NAME)
        soft_shutdown_guest(dut, NETWORK_TEST_OS_NAME, method='ssh')
        run(['xec-vm', '-n', NETWORK_TEST_OS_NAME, 'delete'], host=dut)

    assert have_fresh_vhd(NETWORK_TEST_OS_NAME)  # won't work outside of CBG

    os_name, vm_name = name_split(name)
    assert os_name == NETWORK_TEST_OS_NAME, "Only %s is supported as a network test VM" % NETWORK_TEST_OS_NAME
    vm_uuid = install_guest(dut, guest=name, kind='vhd')
    configure_v4v_rules(dut, vm_name)
    soft_reboot_and_wait(dut, vm_name)  # apply v4v rules

    return NetworkTestVM(dut, vm_uuid)
Ejemplo n.º 3
0
def futile_iso(dut, guest, os_name, build, domlist):
    """Return None or a reason why doing an ISO install on dut would be 
    futile"""
    with_tools_vhd = VHD_WITH_TOOLS_PATTERN % {'build':build, 'name': os_name,
                                           'encrypted':''}
    if exists(with_tools_vhd):
        return "have VHD with tools available"
    sans_tools_vhd = VHD_SANS_TOOLS_PATTERN % {'name': os_name, 'encrypted':''}
    if have_fresh_vhd(os_name):
        return "have fresh VHD available"
    if os_name in set(dom['name'] for dom in domlist):
        return "already have VM"
    try:
        check_free(dut, target_os=os_name)
    except InsufficientStorage:
        return "insufficient storage for new VM"
    except InsufficientMemory:
        return "insufficient memory for new VM"
Ejemplo n.º 4
0
def futile_iso(dut, guest, os_name, build, domlist):
    """Return None or a reason why doing an ISO install on dut would be 
    futile"""
    with_tools_vhd = VHD_WITH_TOOLS_PATTERN % {'build':build, 'name': os_name,
                                           'encrypted':''}
    if exists(with_tools_vhd):
        return "have VHD with tools available"
    sans_tools_vhd = VHD_SANS_TOOLS_PATTERN % {'name': os_name, 'encrypted':''}
    if have_fresh_vhd(os_name):
        return "have fresh VHD available"
    if os_name in set(dom['name'] for dom in domlist):
        return "already have VM"
    try:
        check_free(dut, target_os=os_name)
    except InsufficientStorage:
        return "insufficient storage for new VM"
    except InsufficientMemory:
        return "insufficient memory for new VM"
Ejemplo n.º 5
0
Archivo: ensure.py Proyecto: OpenXT/bvt
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)        
Ejemplo n.º 6
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)