Ejemplo n.º 1
0
def do_postflight(client: ssh_client.AsyncSshClient):
    """ Runs a script that will check if DC/OS is operational without needing to authenticate
    """
    postflight_script = """
T=900
if [ -f /opt/mesosphere/etc/dcos-diagnostics-runner-config.json ]; then
    for check_type in node-poststart cluster; do
        until OUT=$(sudo /opt/mesosphere/bin/dcos-shell /opt/mesosphere/bin/dcos-diagnostics check $check_type) \
                || [[ T -eq 0 ]]; do
            sleep 1
            let T=T-1
        done
        RETCODE=$?
        echo $OUT
        if [[ RETCODE -ne 0 ]]; then
            exit $RETCODE
        fi
        T=900
    done
else
    until OUT=$(sudo /opt/mesosphere/bin/./3dt --diag) || [[ T -eq 0 ]]; do
        sleep 1
        let T=T-1
    done
    RETCODE=$?
    for value in $OUT; do
        echo $value
    done
fi
exit $RETCODE
"""
    return client.run_command('run', [postflight_script])
Ejemplo n.º 2
0
def do_postflight(client: ssh_client.AsyncSshClient):
    """Runs a script that will check if DC/OS is operational without needing to authenticate

    It waits 20mins+ for the cluster poststart checks to succeed.
    See https://jira.mesosphere.com/browse/DCOS-41568.
    """
    postflight_script = """
function run_command_until_success() {
    # Run $@ until it exits 0 or until it has been tried 1200 times. Prints shell output and returns the status of the
    # last attempted run.
    cmd=$@
    max_runs=1200

    runs=$max_runs
    until out=$($cmd) || [[ runs -eq 0 ]]; do
        sleep 1
        let runs=runs-1
    done
    retcode=$?

    echo "$out"
    return $retcode
}

function run_checks() {
    # Run checks with the base command $@ until they succeed or the attempt limit has been reached. Prints shell output
    # and returns the status of the last attempted check run.
    check_cmd=$@

    for check_type in node-poststart cluster; do
        run_command_until_success $check_cmd $check_type
        check_status=$?
        if [[ check_status -ne 0 ]]; then
            break
        fi
    done

    return $check_status
}

if [ -f /opt/mesosphere/bin/dcos-check-runner ]; then
    # Cluster with dcos-check-runner available.
    run_checks sudo /opt/mesosphere/bin/dcos-shell /opt/mesosphere/bin/dcos-check-runner check
    RETCODE=$?
elif [ -f /opt/mesosphere/etc/dcos-diagnostics-runner-config.json ]; then
    # Older version cluster with dcos-diagnostics checks available.
    run_checks sudo /opt/mesosphere/bin/dcos-shell /opt/mesosphere/bin/dcos-diagnostics check
    RETCODE=$?
else
    # Even older version cluster without checks.
    run_command_until_success sudo /opt/mesosphere/bin/3dt --diag
    RETCODE=$?
fi
exit $RETCODE
"""
    return client.run_command('run', [postflight_script])
Ejemplo n.º 3
0
def do_preflight(client: ssh_client.AsyncSshClient, remote_script_path: str,
                 bootstrap_script_url: str):
    """ Runs preflight instructions against client
    remote_script_path: where the install script should be downloaded to on the remote host
    bootstrap_script_url: the URL where the install script will be pulled from
    """
    preflight_script_template = """
mkdir -p {remote_script_dir}
{download_cmd}
sudo bash {remote_script_path} --preflight-only master"""
    preflight_script = preflight_script_template.format(
        remote_script_dir=os.path.dirname(remote_script_path),
        download_cmd=' '.join(curl(bootstrap_script_url, remote_script_path)),
        remote_script_path=remote_script_path)
    return client.run_command('run', [preflight_script])