<commit_before>#!/bin/bash
#
# This script installs development and QA tools for Fuel.
#

set -e

TOP_DIR=$(cd $(dirname "$0") && pwd)

source ${TOP_DIR}/helpers/functions.sh

print_usage() {
    echo "Usage: ${0##*/} [-h]"
    echo "Options:"
    echo "  -h: print this usage message and exit"
}

check_root() {
    local user=$(/usr/bin/id -u)
    if [ ${user} -ne 0 ]; then
        error "Only the superuser (uid 0) can use this script."
        exit 1
    fi
}

parse_arguments() {
    while getopts ":h" opt; do
        case ${opt} in
            h)
                print_usage
                exit 0
                ;;
            *)
                error "An invalid option has been detected."
                print_usage
                exit 1
        esac
    done
}

init_variables() {
    USER_NAME=developer
    USER_HOME=/home/${USER_NAME}
    DEST=${DEST:-/opt/stack}
    VIRTUALENV_DIR=${DEST}/.venv

    PIP_SECURE_LOCATION="https://raw.github.com/pypa/pip/master/contrib/get-pip.py"
    TMP="`dirname \"$0\"`"
    TMP="`( cd \"${TMP}\" && pwd )`"

    mkdir -p ${DEST}
}

install_system_requirements() {
    message "Enable default CentOS repos"
    yum -y reinstall centos-release  # enable default CentOS repos

    message "Installing system requirements"
    yum -y install gcc
    yum -y install zlib-devel
    yum -y install sqlite-devel
    yum -y install readline-devel
    yum -y install bzip2-devel
    yum -y install libgcrypt-devel
    yum -y install openssl-devel
    yum -y install libffi-devel
    yum -y install libxml2-devel
    yum -y install libxslt-devel
}

install_python_27() {
    message "Installing Python 2.7"
    TMP="`mktemp -d`"
    cd ${TMP}
    wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
    tar xzf Python-2.7.8.tgz
    cd Python-2.7.8
    ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
    make altinstall

    message "Installing pip and virtualenv for Python 2.7"
    GETPIPPY_FILE="`mktemp`"
    wget -O ${GETPIPPY_FILE} ${PIP_SECURE_LOCATION}
    python2.7 ${GETPIPPY_FILE}

    pip2.7 install -U tox
    pip2.7 install -U virtualenv
}

setup_virtualenv() {
    message "Setup virtualenv in ${VIRTUALENV_DIR}"
    virtualenv -p python2.7 ${VIRTUALENV_DIR}
}

activate_virtualenv() {
    source ${VIRTUALENV_DIR}/bin/activate
}

init_cluster_variables() {
    message "Initializing cluster variables"
    CONTROLLER_HOST_ID="`fuel node | grep controller | awk '{print $1}'`"
    CONTROLLER_HOST="node-${CONTROLLER_HOST_ID}"
    message "Controller host: ${CONTROLLER_HOST}"

    export OS_AUTH_URL=http://${CONTROLLER_HOST}:5000/v2.0/
    export OS_AUTH_URL_v3=http://${CONTROLLER_HOST}:5000/v3.0/
    export OS_USERNAME=admin
    export OS_PASSWORD=<PASSWORD>
    export OS_TENANT_NAME=admin

    ADMIN_URL="`keystone catalog --service identity | grep adminURL | awk '{print $4}'`"
    MGMT_IP="`echo ${ADMIN_URL} | sed 's/[\/:]/ /g' | awk '{print $2}'`"
    MGMT_CIDR="`echo ${MGMT_IP} | awk -F '.' '{print $1 "." $2 "." $3 ".0/24"}'`"

    message "Keystone admin URL: ${ADMIN_URL}"
    message "Calculated mgmt network CIDR: ${MGMT_CIDR}"

    message "Adding route to mgmt network"
    ip ro add ${MGMT_CIDR} dev eth0 || true

    # fix permissions on fuel client
    chmod o+r /etc/fuel/client/config.yaml
}

install_rally() {
    message "Installing Rally into ${DEST}"
    cd ${DEST}
    RALLY_DIR=${DEST}/rally
    rm -rf ${RALLY_DIR}
    git clone git://git.openstack.org/stackforge/rally.git
    cd ${RALLY_DIR}
    ${VIRTUALENV_DIR}/bin/pip install -U pbr
    ${VIRTUALENV_DIR}/bin/python setup.py install
    RALLY_CONFIGURATION_DIR="/etc/rally"
    RALLY_DATABASE_DIR="${VIRTUALENV_DIR}/database"
    mkdir -p /etc/rally
    chmod -R o+w /etc/rally
    message "Rally installed into ${RALLY_DIR}"
}

install_tempest() {
    message "Installing Tempest into ${DEST}"
    cd ${DEST}
    TEMPEST_DIR="${DEST}/tempest"
    rm -rf ${TEMPEST_DIR}
    git clone git://git.openstack.org/openstack/tempest.git
    cd ${TEMPEST_DIR}
    ${VIRTUALENV_DIR}/bin/python setup.py install
    mkdir -p /etc/tempest
    chmod -R o+w /etc/tempest
    cp ${TOP_DIR}/helpers/tempest.sh ${VIRTUALENV_DIR}/bin/tempest
    cp ${TOP_DIR}/helpers/sync.sh ${VIRTUALENV_DIR}/bin/sync
    cp ${TOP_DIR}/helpers/functions.sh ${VIRTUALENV_DIR}/bin/
    cp ${TOP_DIR}/helpers/shouldfail ${DEST}/
    message "Tempest installed into ${TEMPEST_DIR}"

    message "Downloading necessary resources"
    TEMPEST_FILES="${VIRTUALENV_DIR}/files"
    mkdir ${TEMPEST_FILES}

    CIRROS_VERSION=${CIRROS_VERSION:-"0.3.2"}
    CIRROS_IMAGE_URL="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz"
    wget -O ${TEMPEST_FILES}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz ${CIRROS_IMAGE_URL}
    cd ${TEMPEST_FILES}
    tar xzf cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz
}

configure_rally() {
    message "Configuring Rally"

    mkdir -p ${RALLY_DATABASE_DIR} ${RALLY_CONFIGURATION_DIR}
    sed 's|#connection=<None>|connection=sqlite:///'${RALLY_DATABASE_DIR}'/rally.sqlite|' \
        ${RALLY_DIR}/etc/rally/rally.conf.sample > ${RALLY_CONFIGURATION_DIR}/rally.conf
    ${VIRTUALENV_DIR}/bin/rally-manage db recreate
    chmod -R go+w ${RALLY_DATABASE_DIR}

    RALLY_CLUSTER_FILE="`mktemp`"
    cat > ${RALLY_CLUSTER_FILE} << EOF
{
    "type": "ExistingCloud",
    "endpoint": {
        "auth_url": "http://${CONTROLLER_HOST}:5000/v2.0/",
        "username": "admin",
        "password": "<PASSWORD>",
        "tenant_name": "admin"
    }
}
EOF

    ${VIRTUALENV_DIR}/bin/rally deployment create --filename=${RALLY_CLUSTER_FILE} --name=SkyNet
    ${VIRTUALENV_DIR}/bin/rally use deployment --name SkyNet
    ${VIRTUALENV_DIR}/bin/rally deployment check
}

configure_user() {
    message "Creating and configuring user ${USER_NAME}"

    useradd -m ${USER_NAME}<commit_msg>Update Rally config to align with the master code<commit_after>#!/bin/bash
#
# This script installs development and QA tools for Fuel.
#

set -e

TOP_DIR=$(cd $(dirname "$0") && pwd)

source ${TOP_DIR}/helpers/functions.sh

print_usage() {
    echo "Usage: ${0##*/} [-h]"
    echo "Options:"
    echo "  -h: print this usage message and exit"
}

check_root() {
    local user=$(/usr/bin/id -u)
    if [ ${user} -ne 0 ]; then
        error "Only the superuser (uid 0) can use this script."
        exit 1
    fi
}

parse_arguments() {
    while getopts ":h" opt; do
        case ${opt} in
            h)
                print_usage
                exit 0
                ;;
            *)
                error "An invalid option has been detected."
                print_usage
                exit 1
        esac
    done
}

init_variables() {
    USER_NAME=developer
    USER_HOME=/home/${USER_NAME}
    DEST=${DEST:-/opt/stack}
    VIRTUALENV_DIR=${DEST}/.venv

    PIP_SECURE_LOCATION="https://raw.github.com/pypa/pip/master/contrib/get-pip.py"
    TMP="`dirname \"$0\"`"
    TMP="`( cd \"${TMP}\" && pwd )`"

    mkdir -p ${DEST}
}

install_system_requirements() {
    message "Enable default CentOS repos"
    yum -y reinstall centos-release  # enable default CentOS repos

    message "Installing system requirements"
    yum -y install gcc
    yum -y install zlib-devel
    yum -y install sqlite-devel
    yum -y install readline-devel
    yum -y install bzip2-devel
    yum -y install libgcrypt-devel
    yum -y install openssl-devel
    yum -y install libffi-devel
    yum -y install libxml2-devel
    yum -y install libxslt-devel
}

install_python_27() {
    message "Installing Python 2.7"
    TMP="`mktemp -d`"
    cd ${TMP}
    wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
    tar xzf Python-2.7.8.tgz
    cd Python-2.7.8
    ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
    make altinstall

    message "Installing pip and virtualenv for Python 2.7"
    GETPIPPY_FILE="`mktemp`"
    wget -O ${GETPIPPY_FILE} ${PIP_SECURE_LOCATION}
    python2.7 ${GETPIPPY_FILE}

    pip2.7 install -U tox
    pip2.7 install -U virtualenv
}

setup_virtualenv() {
    message "Setup virtualenv in ${VIRTUALENV_DIR}"
    virtualenv -p python2.7 ${VIRTUALENV_DIR}
}

activate_virtualenv() {
    source ${VIRTUALENV_DIR}/bin/activate
}

init_cluster_variables() {
    message "Initializing cluster variables"
    CONTROLLER_HOST_ID="`fuel node | grep controller | awk '{print $1}'`"
    CONTROLLER_HOST="node-${CONTROLLER_HOST_ID}"
    message "Controller host: ${CONTROLLER_HOST}"

    export OS_AUTH_URL=http://${CONTROLLER_HOST}:5000/v2.0/
    export OS_AUTH_URL_v3=http://${CONTROLLER_HOST}:5000/v3.0/
    export OS_USERNAME=admin
    export OS_PASSWORD=<PASSWORD>
    export OS_TENANT_NAME=admin

    ADMIN_URL="`keystone catalog --service identity | grep adminURL | awk '{print $4}'`"
    MGMT_IP="`echo ${ADMIN_URL} | sed 's/[\/:]/ /g' | awk '{print $2}'`"
    MGMT_CIDR="`echo ${MGMT_IP} | awk -F '.' '{print $1 "." $2 "." $3 ".0/24"}'`"

    message "Keystone admin URL: ${ADMIN_URL}"
    message "Calculated mgmt network CIDR: ${MGMT_CIDR}"

    message "Adding route to mgmt network"
    ip ro add ${MGMT_CIDR} dev eth0 || true

    # fix permissions on fuel client
    chmod o+r /etc/fuel/client/config.yaml
}

install_rally() {
    message "Installing Rally into ${DEST}"
    cd ${DEST}
    RALLY_DIR=${DEST}/rally
    rm -rf ${RALLY_DIR}
    git clone git://git.openstack.org/stackforge/rally.git
    cd ${RALLY_DIR}
    ${VIRTUALENV_DIR}/bin/pip install -U pbr
    ${VIRTUALENV_DIR}/bin/python setup.py install
    RALLY_CONFIGURATION_DIR="/etc/rally"
    RALLY_DATABASE_DIR="${VIRTUALENV_DIR}/database"
    mkdir -p /etc/rally
    chmod -R o+w /etc/rally
    message "Rally installed into ${RALLY_DIR}"
}

install_tempest() {
    message "Installing Tempest into ${DEST}"
    cd ${DEST}
    TEMPEST_DIR="${DEST}/tempest"
    rm -rf ${TEMPEST_DIR}
    git clone git://git.openstack.org/openstack/tempest.git
    cd ${TEMPEST_DIR}
    ${VIRTUALENV_DIR}/bin/python setup.py install
    mkdir -p /etc/tempest
    chmod -R o+w /etc/tempest
    cp ${TOP_DIR}/helpers/tempest.sh ${VIRTUALENV_DIR}/bin/tempest
    cp ${TOP_DIR}/helpers/sync.sh ${VIRTUALENV_DIR}/bin/sync
    cp ${TOP_DIR}/helpers/functions.sh ${VIRTUALENV_DIR}/bin/
    cp ${TOP_DIR}/helpers/shouldfail ${DEST}/
    message "Tempest installed into ${TEMPEST_DIR}"

    message "Downloading necessary resources"
    TEMPEST_FILES="${VIRTUALENV_DIR}/files"
    mkdir ${TEMPEST_FILES}

    CIRROS_VERSION=${CIRROS_VERSION:-"0.3.2"}
    CIRROS_IMAGE_URL="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz"
    wget -O ${TEMPEST_FILES}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz ${CIRROS_IMAGE_URL}
    cd ${TEMPEST_FILES}
    tar xzf cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz
}

configure_rally() {
    message "Configuring Rally"

    mkdir -p ${RALLY_DATABASE_DIR} ${RALLY_CONFIGURATION_DIR}
    sed 's|#connection=<None>|connection=sqlite:///'${RALLY_DATABASE_DIR}'/rally.sqlite|' \
        ${RALLY_DIR}/etc/rally/rally.conf.sample > ${RALLY_CONFIGURATION_DIR}/rally.conf
    ${VIRTUALENV_DIR}/bin/rally-manage db recreate
    chmod -R go+w ${RALLY_DATABASE_DIR}

    RALLY_CLUSTER_FILE="`mktemp`"
    cat > ${RALLY_CLUSTER_FILE} << EOF
{
    "type": "ExistingCloud",
    "auth_url": "http://${CONTROLLER_HOST}:5000/v2.0/",
    "region_name": "RegionOne",
    "endpoint_type": "public",
    "admin_port": 35357,
    "admin": {
        "username": "admin",
        "password": "<PASSWORD>",
        "tenant_name": "admin"
    }
}
EOF

    ${VIRTUALENV_DIR}/bin/rally deployment create --filename=${RALLY_CLUSTER_FILE} --name=SkyNet
    ${VIRTUALENV_DIR}/bin/rally use deployment --name SkyNet
    ${VIRTUALENV_DIR}/bin/rally deployment check
}

configure_user() {
    message "Creating and configuring user ${USER_NAME}"

    useradd -m ${USER_NAME}
{'fraction_non_alphanumeric': 0.14298854419265825, 'fraction_numerical': 0.013964378292499373, 'mean_word_length': 3.0666439986399183, 'pattern_counts': {'":': 17, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1909266', 'n_tokens_mistral': 4693, 'n_tokens_neox': 4391, 'n_words': 925}