Browse Source

[Stresstests] Adds vagrant thing

Ask Solem 9 năm trước cách đây
mục cha
commit
15edb778de

+ 125 - 0
funtests/stress/run/Vagrantfile

@@ -0,0 +1,125 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
+VAGRANTFILE_API_VERSION = "2"
+
+Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
+  # All Vagrant configuration is done here. The most common configuration
+  # options are documented and commented below. For a complete reference,
+  # please see the online documentation at vagrantup.com.
+
+  # Every Vagrant virtual environment requires a box to build off of.
+  config.vm.box = "ubuntu/trusty64"
+
+  config.vm.provision :shell, path: "provision/provision.sh",
+    privileged: true
+
+  # Disable automatic box update checking. If you disable this, then
+  # boxes will only be checked for updates when the user runs
+  # `vagrant box outdated`. This is not recommended.
+  # config.vm.box_check_update = false
+
+  # Create a forwarded port mapping which allows access to a specific port
+  # within the machine from a port on the host machine. In the example below,
+  # accessing "localhost:8080" will access port 80 on the guest machine.
+  # config.vm.network "forwarded_port", guest: 80, host: 8080
+
+  # Create a private network, which allows host-only access to the machine
+  # using a specific IP.
+  config.vm.network "private_network", ip: "192.168.33.123"
+
+  # Create a public network, which generally matched to bridged network.
+  # Bridged networks make the machine appear as another physical device on
+  # your network.
+  # config.vm.network "public_network"
+
+  # If true, then any SSH connections made will enable agent forwarding.
+  # Default value: false
+  # config.ssh.forward_agent = true
+
+  # Share an additional folder to the guest VM. The first argument is
+  # the path on the host to the actual folder. The second argument is
+  # the path on the guest to mount the folder. And the optional third
+  # argument is a set of non-required options.
+  # config.vm.synced_folder "../data", "/vagrant_data"
+
+  # Provider-specific configuration so you can fine-tune various
+  # backing providers for Vagrant. These expose provider-specific options.
+  # Example for VirtualBox:
+  #
+  config.vm.provider "virtualbox" do |vb|
+  #   # Don't boot with headless mode
+  #   vb.gui = true
+  #
+  #   # Use VBoxManage to customize the VM. For example to change memory:
+    vb.customize ["modifyvm", :id, "--memory", "1024"]
+  end
+  #
+  # View the documentation for the provider you're using for more
+  # information on available options.
+
+  # Enable provisioning with CFEngine. CFEngine Community packages are
+  # automatically installed. For example, configure the host as a
+  # policy server and optionally a policy file to run:
+  #
+  # config.vm.provision "cfengine" do |cf|
+  #   cf.am_policy_hub = true
+  #   # cf.run_file = "motd.cf"
+  # end
+  #
+  # You can also configure and bootstrap a client to an existing
+  # policy server:
+  #
+  # config.vm.provision "cfengine" do |cf|
+  #   cf.policy_server_address = "10.0.2.15"
+  # end
+
+  # Enable provisioning with Puppet stand alone.  Puppet manifests
+  # are contained in a directory path relative to this Vagrantfile.
+  # You will need to create the manifests directory and a manifest in
+  # the file default.pp in the manifests_path directory.
+  #
+  # config.vm.provision "puppet" do |puppet|
+  #   puppet.manifests_path = "manifests"
+  #   puppet.manifest_file  = "site.pp"
+  # end
+
+  # Enable provisioning with chef solo, specifying a cookbooks path, roles
+  # path, and data_bags path (all relative to this Vagrantfile), and adding
+  # some recipes and/or roles.
+  #
+  # config.vm.provision "chef_solo" do |chef|
+  #   chef.cookbooks_path = "../my-recipes/cookbooks"
+  #   chef.roles_path = "../my-recipes/roles"
+  #   chef.data_bags_path = "../my-recipes/data_bags"
+  #   chef.add_recipe "mysql"
+  #   chef.add_role "web"
+  #
+  #   # You may also specify custom JSON attributes:
+  #   chef.json = { :mysql_password => "foo" }
+  # end
+
+  # Enable provisioning with chef server, specifying the chef server URL,
+  # and the path to the validation key (relative to this Vagrantfile).
+  #
+  # The Opscode Platform uses HTTPS. Substitute your organization for
+  # ORGNAME in the URL and validation key.
+  #
+  # If you have your own Chef Server, use the appropriate URL, which may be
+  # HTTP instead of HTTPS depending on your configuration. Also change the
+  # validation key to validation.pem.
+  #
+  # config.vm.provision "chef_client" do |chef|
+  #   chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
+  #   chef.validation_key_path = "ORGNAME-validator.pem"
+  # end
+  #
+  # If you're using the Opscode platform, your validator client is
+  # ORGNAME-validator, replacing ORGNAME with your organization name.
+  #
+  # If you have your own Chef Server, the default validation client name is
+  # chef-validator, unless you changed the configuration.
+  #
+  #   chef.validation_client_name = "ORGNAME-validator"
+end

+ 12 - 0
funtests/stress/run/provision/celeryd-init.config

@@ -0,0 +1,12 @@
+CELERYD_NODES="worker1"
+CELERY_BIN="/usr/local/bin/celery"
+CELERY_APP="stress"
+CELERYD_CHDIR="/opt/devel/celery/funtests/stress"
+#CELERYD_OPTS=""
+CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
+CELERYD_PID_FILE="/var/run/celery/%n.pid"
+
+CELERYD_USER="celery"
+CELERYD_GROUP="celery"
+
+CELERY_CREATE_DIRS=1

+ 187 - 0
funtests/stress/run/provision/provision.sh

@@ -0,0 +1,187 @@
+#!/bin/bash
+
+echo "------------ HELLO ---------------"
+
+APT_SOURCES_LST="/etc/apt/sources.list.d/"
+
+DEVEL_DIR="/opt/devel"
+
+WGET="wget"
+RABBITMQCTL="rabbitmqctl"
+
+RABBITMQ_APT_URL="http://www.rabbitmq.com/debian/"
+RABBITMQ_APT_VER="testing main"
+RABBITMQ_APT_KEY="https://www.rabbitmq.com/rabbitmq-signing-key-public.asc"
+RABBITMQ_DEB="rabbitmq-server"
+
+RABBITMQ_USERNAME="testing"
+RABBITMQ_PASSWORD="t3s71ng"
+RABBITMQ_VHOST="/testing"
+
+REDIS_DEB="redis-server"
+REDIS_CONF="/etc/redis/redis.conf"
+
+GIT_ROOT="${DEVEL_DIR}"
+
+GITHUB_ROOT="https://github.com/"
+CELERY_GITHUB_USER="celery"
+CELERY_USER="celery"
+CELERY_GROUP="celery"
+CELERY_DIR="${GIT_ROOT}/celery"
+CELERY_FUNTESTS="${CELERY_DIR}/funtests/stress"
+CELERY_CONFIG_SRC="${CELERY_FUNTESTS}/run/provision/celeryd-init.config"
+CELERY_CONFIG_DST="/etc/default/celeryd"
+
+
+die () {
+    echo $*
+    exit 1
+}
+
+# --- grent
+
+add_real_user () {
+    user_shell=${3:-/bin/bash}
+    addgroup $2
+    echo creating user "$1 group='$2' shell='${user_shell}'"
+    echo | adduser -q "$1" --shell="${user_shell}"   \
+            --ingroup="$2"                           \
+            --disabled-password  1>/dev/null 2>&1
+    id "$1" || die "Not able to create user"
+}
+
+for_user_makedir () {
+    mkdir "$2"
+    chown "$1" "$2"
+    chmod 0755 "$2"
+}
+
+# --- directories
+
+make_directories () {
+    mkdir -p "${DEVEL_DIR}"
+}
+
+
+# --- apt
+
+apt_update() {
+    apt-get update
+}
+
+add_apt_source () {
+    echo "deb $1" >> "${APT_SOURCES_LST}/rabbitmq.list"
+}
+
+add_apt_key() {
+    "$WGET" --quiet -O - "$1" | apt-key add -
+}
+
+apt_install () {
+    apt-get install -y "$1"
+}
+
+# --- rabbitmq
+
+rabbitmq_add_user () {
+    "$RABBITMQCTL" add_user "$1" "$2"
+}
+
+rabbitmq_add_vhost () {
+    "$RABBITMQCTL" add_vhost "$1"
+}
+
+rabbitmq_set_perm () {
+    "$RABBITMQCTL" set_permissions -p $1 $2 '.*' '.*' '.*'
+}
+
+install_rabbitmq() {
+    add_apt_source "${RABBITMQ_APT_URL} ${RABBITMQ_APT_VER}"
+    add_apt_key "${RABBITMQ_APT_KEY}"
+    apt_update
+    apt_install "${RABBITMQ_DEB}"
+
+    rabbitmq_add_user "${RABBITMQ_USERNAME}" "${RABBITMQ_PASSWORD}"
+    rabbitmq_add_vhost "${RABBITMQ_VHOST}"
+    rabbitmq_set_perm "${RABBITMQ_VHOST}" "${RABBITMQ_USERNAME}"
+}
+
+# --- redis
+
+restart_redis () {
+    service redis-server restart
+}
+
+
+install_redis () {
+    apt_install "${REDIS_DEB}"
+    sed -i 's/^bind .*$/#bind 127.0.0.1/' "${REDIS_CONF}"
+    restart_redis
+}
+
+# --- git
+
+install_git () {
+    apt_install git
+}
+
+
+github_clone () {
+    (cd "${GIT_ROOT}"; git clone "${GITHUB_ROOT}/${1}/${2}")
+    chown "${CELERY_USER}" "${CELERY_DIR}"
+    ls -l /opt/devel/celery
+}
+
+
+# --- pip
+
+pip_install () {
+    pip install -U "$1"
+}
+
+install_pip () {
+    apt_install python-setuptools
+    easy_install pip
+    pip_install virtualenv
+}
+
+# --- celery
+
+restart_celery () {
+    service celeryd restart
+}
+
+
+install_celery_service () {
+    cp "${CELERY_DIR}/extra/generic-init.d/celeryd" /etc/init.d/
+    chmod +x "/etc/init.d/celeryd"
+    update-rc.d celeryd defaults
+    cp "${CELERY_CONFIG_SRC}" "${CELERY_CONFIG_DEST}"
+    update-rc.d celeryd enable
+    restart_celery
+}
+
+install_celery () {
+    pip_install celery
+    add_real_user "${CELERY_USER}" "${CELERY_GROUP}"
+    echo github_clone "'${CELERY_GITHUB_USER}'" "'celery'"
+    github_clone "${CELERY_GITHUB_USER}" celery
+    (cd ${CELERY_DIR}; pip install -r requirements/dev.txt);
+    (cd ${CELERY_DIR}; python setup.py develop);
+    install_celery_service
+}
+
+
+# --- MAIN
+
+provision () {
+    make_directories
+    apt_update
+    install_git
+    install_rabbitmq
+    install_redis
+    install_pip
+    install_celery
+}
+
+provision