示例#1
0
def generate_pxelinux_includes(output_directory, builds, releases, args,
                               verbose=False):
    """Generate files in output_directory for builds and releases"""
    menuset = classify_builds(builds, args.branch_menu)
    latestdir = join(output_directory, 'latestbuilds')
    if not isdir(latestdir):
        mkdir(latestdir)
    menu, labels = generate_menu(menuset, len(releases), len(builds),
                                 args.branch_menu, args.bvt_results_url)
    atomic_write(join(latestdir, 'automenu.inc'), menu)
    buildseq = releases + [labels[label] for label in sorted(labels.keys())
                           ] + list(reversed(builds))
    seen = {}
    buildsequ = []
    for pbuild in buildseq:
        build = populate(pbuild, args.netboot_url, args.autoinstall_url)
        if build['alias'] in seen:
            print 'WARNING: found', build['alias'], 'at',
            print build['build_directory'], 'and',
            print seen[build['alias']]['build_directory'],
            print 'so ignoring new location'
            continue
        assert build['alias'] not in seen, (build, seen[build['alias']])
        seen[build['alias']] = build
        buildsequ.append(build)
    if verbose:
        print 'INFO: autogen.inc will have', len(buildseq),
        print 'sections'
    atomic_write(join(latestdir, 'autogen.inc'),
                 ('# autogenerated on %s at %s by genpxe; do not edit!\n' % (
                   gethostname(), asctime()))+
                 (''.join(generate_pxelinux_cfg(build) for build in buildsequ)))
示例#2
0
def set_pxe_build(dut,
                  build=None,
                  release=None,
                  action='install',
                  mac_address=None,
                  build_url=None):
    """Set dut to do action using build when it PXE boots"""
    assert dut
    print 'PXE_INSTALL:', action, 'for', release or build, 'on', dut
    if action == 'boot':
        print 'PXE_INSTALL: booting'
        assert build is None

    print 'PXE_INSTALL: setting PXE auto-run build for', dut, 'to', \
        release or build
    autopxe = pxe_filename(dut, mac_address)
    if exists(autopxe):
        unlink(autopxe)
    print 'INFO: pxe file location is', autopxe
    if build is None and release is None:
        print 'INFO: removing PXE file'
        if exists(autopxe):
            unlink(autopxe)
        return
    ansdir_tftp = join('autotest', dut)
    ansdir = join(PXE_DIR, ansdir_tftp)
    partial_build_info = select_build(build, release)
    if build_url:
        partial_build_info['NETBOOT_URL'] = build_url
    partial_build_info['TFTP_PATH'] = ansdir_tftp + '/@netboot@'
    build_info = populate(partial_build_info)

    print 'INFO: installing from', build_info['build_directory']
    print 'PXE_INSTALL: build info', build_info
    netboot, variant = select_variant(build_info)

    print 'INFO: answer file TFTP directory path', ansdir_tftp
    atomic_write(autopxe,
                 'default ' + build_info['alias'] +
                 ('-u' if action == 'upgrade' else '') + '\n' +
                 generate_pxelinux_cfg(build_info),
                 verbose=True)
    with file(autopxe, 'r') as fin:
        for line in fin.readlines():
            print 'PXE: PXE line', line
    write_netboot(build_info,
                  ansdir,
                  kind=variant,
                  ansfile_filter=lambda x: INSTALLER_STATUS_REPORT
                  if action == 'ssh' else x.replace(
                      '</postinstall>', ANSWERFILE_AMT_ENDING % get_bus(dut)
                      if secondary_nic_equipped(dut) else ANSWERFILE_ENDING),
                  ansfile_glob='*.ans')
    with file(ansdir + '/' + netboot + '/network.ans', 'r') as fin:
        for line in fin.readlines():
            print 'PXE: answerfile line', line
    return build_info
示例#3
0
def set_pxe_build(dut, build=None, release=None, action='install', mac_address=None,
                  build_url=None):
    """Set dut to do action using build when it PXE boots"""
    assert dut
    print 'PXE_INSTALL:', action, 'for', release or build, 'on', dut
    if action == 'boot':
        print 'PXE_INSTALL: booting'
        assert build is None

    print 'PXE_INSTALL: setting PXE auto-run build for', dut, 'to', \
        release or build
    autopxe = pxe_filename(dut, mac_address)
    if exists(autopxe):
        unlink(autopxe)
    print 'INFO: pxe file location is', autopxe
    if build is None and release is None:
        print 'INFO: removing PXE file'
        if exists(autopxe):
            unlink(autopxe)
        return
    ansdir_tftp = join('autotest', dut) 
    ansdir = join(PXE_DIR, ansdir_tftp)
    partial_build_info = select_build(build, release)
    if build_url:
        partial_build_info['NETBOOT_URL'] = build_url
    partial_build_info['TFTP_PATH'] = ansdir_tftp+'/@netboot@'
    build_info = populate(partial_build_info)

    print 'INFO: installing from', build_info['build_directory']
    print 'PXE_INSTALL: build info', build_info
    netboot, variant = select_variant(build_info)

    print 'INFO: answer file TFTP directory path', ansdir_tftp
    atomic_write(autopxe, 'default '+build_info['alias']+('-u' if action=='upgrade' else '') +'\n'+
                 generate_pxelinux_cfg(build_info), verbose=True)
    with file(autopxe, 'r') as fin:
        for line in fin.readlines():
            print 'PXE: PXE line', line
    write_netboot(build_info, ansdir,
                  kind=variant,
                  ansfile_filter=
                  lambda x: INSTALLER_STATUS_REPORT if
                    action == 'ssh' else
                      x.replace('</postinstall>', ANSWERFILE_AMT_ENDING % get_bus(dut) 
                                            if secondary_nic_equipped(dut)
                                            else ANSWERFILE_ENDING),
                  ansfile_glob='*.ans')
    with file(ansdir+'/'+netboot+'/network.ans', 'r') as fin:
        for line in fin.readlines():
            print 'PXE: answerfile line', line
    return build_info
示例#4
0
def main():
    """Entry point"""
    args = get_args()
    if args.build_output:
        if not isdir(args.build_output):
            print 'ERROR:', args.build_output, 'not found'
            exit(1)
        build = populate(inspect_build(args.build_output, None)[0],
                         args.netboot_url, args.autoinstall_url)

        write_netboot(build, args.output_directory,
                      pretend=not args.apply) 
        check_call(['rsync', '-raP', args.build_output+'/repository/',
                    args.output_directory])
        atomic_write(join(args.output_directory, 'pxelinux.cfg'),
                     ('#autogenerated by genpxe at %s\n' % (asctime()))+
                     generate_pxelinux_cfg(build) +
                     '\nlabel local\n  localboot 0\ndefault=build\nprompt 1\n')
        return
    if args.verbose:
        print 'INFO: scanning builds'
    builds = order_by('build_number', scan_builds(args.scan_directory,
                                                  verbose=args.verbose))
    if args.verbose:
        print 'INFO: found', len(builds), 'builds'
    if args.verbose:
        print 'INFO: scanning releases'

    releases = order_by('alias', scan_releases(args.releases_directory))
    if args.clean_old_netboots:
        clean_old_netboots(args.output_directory, builds+releases,
                           verbose=args.verbose, pretend=not args.apply)
    if args.generate_netboots:
        count = len(releases+builds)
        if args.verbose:
            print 'INFO: updating netboot material for', count,
            print 'builds'
        for build in releases + builds:
            write_netboot(populate(build, args.netboot_url,
                                   args.autoinstall_url),
                          join(args.output_directory, 'builds',
                               build['branch'], build['tag']),
                          pretend=not args.apply)
    if args.generate_pxelinux_includes:
        generate_pxelinux_includes(args.output_directory, builds, releases,
                                   args, verbose=args.verbose)