示例#1
0
def _check_continuous_activity_window():
    cmd = '%s --no-color next' % APP_INVOKE
    sched = DEFAULT_NEXT_SCHEDULE
    rng = ''
    defValue = config.default_continuous_range
    if not defValue:
        if config.is_canonical_machine:
            defValue = "0400 to 2200"
        else:
            defValue = '*'
    print('''
Continuous builds can be constrained to an activity window so that during off
hours, system resources can be used elsewhere. This is important if you plan to
run performance tests, among other things.
''')
    rng = sadm_prompt.prompt('Hours for running continuous sandboxes (e.g., 0100 to 2200; "*" = all)', defValue)
    if rng and (rng == '*' or rng == 'all'):
        rng = ''
    config.schedule_continuous_manually = sadm_prompt.prompt_bool('\nSchedule continuous sandboxes manually?', _get_prompt_bool_repr(config.schedule_continuous_manually))
    if not config.schedule_continuous_manually:
        # Remove any manually-scheduled, continuous sandboxes from the schedule.
        unschedule = [sb for sb in Sandbox.list() if (sb.get_sandboxtype().get_should_schedule() and sb.schedule)]
        for sb in unschedule:
            sb.schedule = None
            sb.applySchedule()
    # Only allow overriding standard interval on non-canonical machines.
    if not config.is_canonical_machine:
        if config.continuous_interval:
            # Make sure we only have the interval part, not the range.
            sched = str(Schedule(config.continuous_interval))
        sched = sadm_prompt.prompt('\nIf idle, start next continuous sandbox ("never" to disable)', sched)
    # Again, make sure we only have the interval part.
    if sched:
        sched = Schedule(sched)
        if sched.is_periodic():
            sched = 'every ' + sched.every
        else:
            sched = 'never'
    else:
        sched = DEFAULT_NEXT_SCHEDULE
    # Add the range part on, regardless of where the interval came from.
    if rng:
        if sched != 'never':
            sched += ", " + rng
        else:
            rng = ''
    sched = Schedule(sched)
    Schedule.apply_to_arbitrary_command(cmd, 'run next continuous sandbox', sched, removeOnly=(config.schedule_continuous_manually))
    if rng:
        rng = '%s to %s' % (sched.range[0], sched.range[1])
    if not rng:
        print('''
Performance tests are disallowed on this box, since unconstrained continuous
builds might invalidate results.
''')
    config.default_continuous_range = rng
示例#2
0
def _check_remoting_info():
    if sadm_prompt.prompter.get_mode() == sadm_prompt.AUTOCONFIRM_MODE:
        return
    if not config.needs_remoting_info():
        return
    descr = buildinfo.BuildInfo()
    remoteInfo = ''
    print('''
Machines that automate sandbox operations should be remotely accessible for
configuration and troubleshooting purposes. Please provide the following
information to facilitate this.
''')
    config.username_for_remote_access = sadm_prompt.prompt('Username for remote login', config.username_for_remote_access)
    config.ipaddr = sadm_prompt.prompt('IP address', config.ipaddr)
    config.ssh_port = sadm_prompt.prompt('Port for ssh', config.ssh_port)
    config.remote_desktop_port = sadm_prompt.prompt('Port for remote desktop', config.remote_desktop_port)
    config.remoting_instructions = sadm_prompt.prompt('''
Other instructions for accessing this machine remotely (such as where to get the password etc.)''', config.remoting_instructions)
    if config.ssh_port:
        remoteInfo += 'ssh to %s:%s as %s\n' % (config.ipaddr, config.ssh_port, config.username_for_remote_access)
    if config.remote_desktop_port:
        remoteInfo += 'remote desktop to %s:%s\n' % (config.ipaddr, config.remote_desktop_port)
    if config.remoting_instructions:
        remoteInfo += '%s' % config.remoting_instructions
    build_machines = tempfile.mkdtemp()
    wr = vcs.get_working_repository()
    vcs.checkout(os.path.join(wr.master_reporoot, 'BuildMachines').replace('\\','/'), build_machines)
    if os.name == 'nt':
        site = os.environ['COMPUTERNAME'].lower()
    else:
        site = os.environ['HOSTNAME'].lower()
    fldr = os.path.join(build_machines, site)
    if not os.path.isdir(fldr):
        os.makedirs(fldr)
    fp = open(os.path.join(fldr, REMOTE_INFO_FILE), 'w')
    fp.write(remoteInfo)
    fp.close()
    vcs.add(build_machines)
    try:
        vcs.checkin(build_machines, 'Update remote info for %s' % site, quiet=True)
    except:
        pass
示例#3
0
def _check_perf_test_config():
    rng = config.default_continuous_range
    if not rng:
        return
    print('''
In order to run performance tests, you must be prepared to save result data
in a JDBC database. Normally, the db is on db1.example.com, the
''')
    defValue = config.perf_log_db_url
    if defValue == STD_PERFTEST_DBURL:
        defValue = 'std'
    x = sadm_prompt.prompt('URL for perf test db ("std", custom value, or "none" to disable)', defValue)
    if x:
        if x == 'std':
            x = STD_PERFTEST_DBURL
        elif x.find('%s') == -1:
            x = None
    changed = (str(config.perf_log_db_url) != str(x))
    config.perf_log_db_url = x
    if x:
        x = sadm_prompt.prompt('Password for perf test db', config.perf_log_password)
        if x != config.perf_log_password:
            changed = True
            config.perf_log_password = x
    if changed:
        if config.perf_log_password and config.perf_log_db_url:
            if os.name == 'nt':
                printc('You need to manually set an environment variable:', WARNING_COLOR)
                print('    PERFLOG_URL=%s' % (config.perf_log_db_url % config.perf_log_password))
            else:
                printc('You need to add this line to ~/.bashrc and/or crontab:', WARNING_COLOR)
                print('    export PERFLOG_URL="%s"' % (config.perf_log_db_url % config.perf_log_password))
        else:
            if os.name == 'nt':
                printc('You need to manually undefine the PERFLOG_URL environment variable.', WARNING_COLOR)
            else:
                printc('You need to remove the export PERFLOG_URL= line from ~/.bashrc and/or crontab.', WARNING_COLOR)
示例#4
0
def _check_automated_builds():
    if not config.is_canonical_machine:
        config.build_queue_schedule = 'never'
    originalCfg = str(config.allow_official_builds) + config.build_queue_schedule
    if config.is_canonical_machine:
        print('''
On canonical build machines, official builds are allowed. However, some such
machines may not wish to do them, since they can complicate the scheduling of
continuous builds...
''')
        config.allow_official_builds = sadm_prompt.prompt_bool('Allow official builds?', _get_prompt_bool_repr(config.allow_official_builds))
    else:
        config.allow_official_builds = False
    email_list = ''
    if config.allow_official_builds:
        config.archiveRepo = sadm_prompt.prompt('\nArchive repo url', config.archiveRepo)
    if config.is_canonical_machine:
        config.build_queue_url = prompt('\nBase url for build queue', config.build_queue_url)
        queueSched = sadm_prompt.prompt('\nCheck build queue for new requests ("never" to disable)', config.build_queue_schedule)
        queueSched = Schedule(queueSched)
        email_list = sadm_prompt.prompt('\nEmails to notify of official build results (comma-separated)', config.email_list)
    else:
        queueSched = Schedule("never")
    if email_list:
        if type(email_list).__name__ == 'list':
            config.email_list = email_list
        else:
            config.email_list = [x for x in email_list.split(',').strip()]
            config.email_list.append(config.mailto)
    else:
        config.email_list = [config.mailto]
    newCfg = str(config.allow_official_builds) + str(queueSched)
    if newCfg != originalCfg:
        config.build_queue_schedule = str(queueSched)
        taskName = "check official build queue"
        cmd = '%s service' % APP_INVOKE
        Schedule.apply_to_arbitrary_command(cmd, taskName, queueSched, removeOnly=(not config.allow_official_builds))
示例#5
0
def _check_loc(config, prop_name, msg, validator=None, default_func=None):
    is_location = False
    current_val = getattr(config, prop_name)
    default_val = current_val
    if (not default_val) and default_func:
        default_val = default_func()
    while (not is_location):
        location = sadm_prompt.prompt(msg, default_val)
        if location and (location.lower() == 'none'):
            location = None
        if validator is None:
            is_location = make_dir(location)
        else:
            is_location = validator(location)
        if (not is_location):
            eprintc('%s is invalid.\n' % location, ERROR_COLOR)
    setattr(config, prop_name, location)
示例#6
0
def _check_canonical():
    if config.could_be_canonical_machine():
        print('''
Canonical build machines are managed by CM. They have a specific set of tools
installed (nothing extra), meet a minimal hardware spec, use standard
credentials and network config, and do nothing besides evaluate sandboxes.
When a build fails on a canonical build machine, the owner of the box and the
owner of the svn project cooperate to fix it. Many sadm settings are hard-coded
for such machines.
''')
        config.is_canonical_machine = sadm_prompt.prompt_bool('Treat this box as a canonical build machine?', _get_prompt_bool_repr(config.is_canonical_machine))
        if config.is_canonical_machine:
            config.auto_add_sandboxes = sadm_prompt.prompt_bool('Automatically add sandboxes?', _get_prompt_bool_repr(config.auto_add_sandboxes))
            config.branches_to_auto_add = sadm_prompt.prompt('Which branches would you like to add sandboxes from.(Give a list seperated by commas e.i. trunk,push_feature,... or all for all branches.)', config.branches_to_auto_add)
        else:
            config.auto_add_sandboxes = False
    else:
        config.is_canonical_machine = False
        config.auto_add_sandboxes = False
示例#7
0
def _check_whoami():
    email, code = run('bzr whoami', acceptFailure=True)
    if (not code) and email:
        m = _NAME_PLUS_ADDR_PAT.match(email)
        if m:
            email = m.group(2)
        else:
            m = _ADDR_ONLY_PAT.match(email)
            if m:
                email = m.group(1)
    if not email:
        config.mailto = sadm_prompt.prompt('\nYour email address?', config.mailto)
    else:
        config.mailto = email
    if config.mailto:
        if Schedule.mailto is None:
            Schedule.mailto = config.mailto
        # If we failed to get email from bzr, tell bzr about our identity as well.
        if code:
            run('bzr whoami %s' % email)
示例#8
0
def _check_role():
    print('''
Some sadm features are useful only on dedicated build machines. Others are
mainly interesting to developers. To simplify setup and program behaviors,
please choose the role that best describes this machine:

    dev      -- This is the primary machine of a developer or tester.
    devguest -- This is a VM hosted on a dev machine. It is used to test or
                cross-compile code developed on the dev machine.
    build    -- This machine is dedicated to automated builds. It may or may not
                be canonical.
    test     -- This machine is dedicated to automated testing. (Unlike a build
                machine, it may not have lots of compile tools installed, and
                should not service requests from the build queue.)
    custom   -- None of the above apply.
''')
    while True:
        machine_role = sadm_prompt.prompt('Machine role?', config.machine_role)
        if machine_role:
            machine_role = machine_role.strip().lower()
        if machine_role in ['custom','dev','devguest','build','test']:
            config.machine_role = machine_role
            return