summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaghavendra Talur <rtalur@redhat.com>2015-11-24 18:18:01 +0530
committerRaghavendra Talur <rtalur@redhat.com>2015-12-28 00:50:36 -0800
commit78305ce9604329250dd4a9f2335587957d71c701 (patch)
tree5222b7e08cc23fd62b7deeb221812a0c111451d8
parent7ab8a1a3f4510a284b1686302624ec4252c95a6f (diff)
tests: Introduce a Vagrant VM based test environment
This introduces a mechanism using which a developer could easily test the Gluster code in a VM environment. Also, it will help bring uniformity in the environments used by various developers. How to use: 1. git checkout -b custom-branch-name 2. Make changes 3. Execute ./run-tests-in-vagrant.sh What happens in the background: 1. A new directory is created: tests/vagrant/vagrant-custom-branch-name It will serve as the Vagrant dir which has the Vagrantfile and related ansible playbooks. The VM is started using Vagrant and provisioned using ansible. 2. The source dir is recursively copied over to the VM under /home/vagrant/glusterfs. 3. Gluster is source installed in VM. What happens in the foreground: 1. run-tests.sh is executed in VM using ssh and output is displayed in the same terminal with option to use ctrl-c to interrupt the test midway. The VM would still persist and you could ssh into it. Also, you can checkout a different branch elsewhere and execute run-tests-in-vagrant.sh there to get another VM which would execute tests on that code. If you wish to make some changes in the code, you could: a. Change the code in host and run the script again to repeat the whole process. OR b. vagrant ssh into the VM and make the changes in the VM. Co-authored-by: Kaushal M <kaushal@redhat.com> Co-authored-by: Michael Adam <obnox@samba.org> Change-Id: Ic87801172c8b614cdecbdf2a765e1b3370a5faf7 BUG: 1291537 Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Raghavendra Talur <rtalur@redhat.com> Reviewed-on: http://review.gluster.org/12753 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Niels de Vos <ndevos@redhat.com>
-rw-r--r--glusterfs.spec.in1
-rwxr-xr-xrun-tests-in-vagrant.sh126
-rw-r--r--tests/vagrant/vagrant-template/Vagrantfile50
-rw-r--r--tests/vagrant/vagrant-template/roles/daemon-services/tasks/main.yml3
-rw-r--r--tests/vagrant/vagrant-template/roles/install-pkgs/tasks/main.yml76
-rw-r--r--tests/vagrant/vagrant-template/roles/iptables/tasks/main.yml3
-rw-r--r--tests/vagrant/vagrant-template/roles/mock-user/tasks/main.yml3
-rw-r--r--tests/vagrant/vagrant-template/roles/prepare-brick/tasks/main.yml6
-rw-r--r--tests/vagrant/vagrant-template/roles/selinux/tasks/main.yml3
-rw-r--r--tests/vagrant/vagrant-template/setup.yml11
10 files changed, 282 insertions, 0 deletions
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index 4dc4852..3281ee9 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -1107,6 +1107,7 @@ fi
%{_prefix}/share/glusterfs/run-tests.sh
%{_prefix}/share/glusterfs/tests
%exclude %{_prefix}/share/glusterfs/tests/basic/rpm.t
+%exclude %{_prefix}/share/glusterfs/tests/vagrant
%if ( 0%{!?_without_ocf:1} )
%files resource-agents
diff --git a/run-tests-in-vagrant.sh b/run-tests-in-vagrant.sh
new file mode 100755
index 0000000..00ec99a
--- /dev/null
+++ b/run-tests-in-vagrant.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+###############################################################################
+# TODO: Provide an option parser; may be getopts. #
+# TODO: Allow subset of tests to be executed when VM starts. #
+# TODO: Provide option to destroy the VM. #
+###############################################################################
+
+function force_location()
+{
+ current_dir=$(dirname $0);
+
+ if [ ! -f ${current_dir}/tests/vagrant/vagrant-template/Vagrantfile ]; then
+ echo "Aborting."
+ echo
+ echo "The tests/vagrant subdirectory seems to be missing."
+ echo
+ echo "Please correct the problem and try again."
+ echo
+ exit 1
+ fi
+}
+
+function vagrant_check()
+{
+ vagrant -v;
+
+ if [ $? -ne 0 ]; then
+ echo "Aborting"
+ echo "Vagrant not found. Please install Vagrant and try again."
+ exit 1
+ else
+ echo "Found Vagrant, continuing...."
+ echo
+ fi
+}
+
+function ansible_check()
+{
+ ansible --version;
+
+ if [ $? -ne 0 ]; then
+ echo "Aborting"
+ echo "Ansible not found. Please install Ansible and try again."
+ exit 1
+ else
+ echo "Found Ansible, continuing...."
+ echo
+ fi
+}
+
+force_location
+
+echo "Testing for Vagrant...."
+vagrant_check
+echo
+echo
+
+echo "Testing for Ansible...."
+ansible_check
+echo
+echo
+
+BRANCHNAME=`git rev-parse --abbrev-ref HEAD`
+echo "Copying tests/vagrant/vagrant-template dir to tests/vagrant/$BRANCHNAME"
+mkdir -p tests/vagrant/$BRANCHNAME
+cp -R tests/vagrant/vagrant-template/* tests/vagrant/$BRANCHNAME
+echo "Change dir to vagrant dir: tests/vagrant/$BRANCHNAME"
+cd tests/vagrant/$BRANCHNAME
+echo "Working directory is $PWD"
+echo
+echo
+
+echo "Doing vagrant up...."
+vagrant up || { echo "vagrant up failed, exiting...."; exit 1; }
+echo
+echo
+
+
+echo "Vagrant up successfull"
+echo
+echo
+
+
+vagrant ssh-config > ssh_config
+
+echo "Copying source code from host machine to VM"
+rsync -az -e "ssh -F ssh_config" "../../../." vagrant-testVM:/home/vagrant/glusterfs
+#scp -r -F ssh_config "./../../../." vagrant-testVM:/home/vagrant/glusterfs
+echo "Copied."
+echo
+echo
+
+vagrant ssh -c 'cd /home/vagrant/glusterfs ; ./autogen.sh' -- -t
+echo
+echo
+
+vagrant ssh -c 'cd /home/vagrant/glusterfs ; \
+ CFLAGS="-g -O0 -Werror -Wall -Wno-error=cpp -Wno-error=maybe-uninitialized" \
+ ./configure \
+ --prefix=/usr \
+ --exec-prefix=/usr \
+ --bindir=/usr/bin \
+ --sbindir=/usr/sbin \
+ --sysconfdir=/etc \
+ --datadir=/usr/share \
+ --includedir=/usr/include \
+ --libdir=/usr/lib64 \
+ --libexecdir=/usr/libexec \
+ --localstatedir=/var \
+ --sharedstatedir=/var/lib \
+ --mandir=/usr/share/man \
+ --infodir=/usr/share/info \
+ --libdir=/usr/lib64 \
+ --enable-debug' -- -t
+echo
+echo
+
+
+vagrant ssh -c 'cd /home/vagrant/glusterfs; sudo make install' -- -t
+echo
+echo
+
+vagrant ssh -c 'cd /home/vagrant/glusterfs; sudo ./run-tests.sh' -- -t
+echo
+echo
diff --git a/tests/vagrant/vagrant-template/Vagrantfile b/tests/vagrant/vagrant-template/Vagrantfile
new file mode 100644
index 0000000..fda113f
--- /dev/null
+++ b/tests/vagrant/vagrant-template/Vagrantfile
@@ -0,0 +1,50 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure("2") do |config|
+ config.vm.define "vagrant-testVM" do |testvm|
+ testvm.vm.box = "fedora/23-cloud-base"
+ testvm.vm.hostname = "vagrant-testVM"
+ #testvm.ssh.insert_key = false
+ testvm.vm.synced_folder ".", "/vagrant", disabled: true
+
+
+ # Define basic config for VM, memory, cpu, storage pool
+ testvm.vm.provider "libvirt" do |lv|
+ lv.storage_pool_name = "default"
+ lv.memory = 1024
+ lv.cpus = 1
+
+
+ # We need a brick partition, lets have a 5G disk for that.
+ # If you need more bricks, just add more letters to the
+ # string below.
+ "b".split("").each do |i|
+ lv.storage :file,
+ #:path => "",
+ #:allow_existing => "",
+ :device => "vd#{i}",
+ :size => "5G",
+ :type => "qcow2",
+ :bus => "virtio",
+ :cache => "default"
+ end
+ end
+
+ # Let's provision
+
+ # Some packages are required for ansible dnf module to work
+ # so install them using shell inline
+ testvm.vm.provision "shell", inline: "sudo dnf install -y python-dnf", run: "always"
+ testvm.vm.provision "shell", inline: "sudo dnf install -y libselinux-python", run: "always"
+ testvm.vm.provision "shell", inline: "sudo dnf install -y libsemanage-python", run: "always"
+
+ # Now onto the main provisioning
+ testvm.vm.provision "ansible", run: "always" do |setup|
+ setup.verbose = "v"
+ setup.playbook = "setup.yml"
+ end
+
+ end
+end
+
diff --git a/tests/vagrant/vagrant-template/roles/daemon-services/tasks/main.yml b/tests/vagrant/vagrant-template/roles/daemon-services/tasks/main.yml
new file mode 100644
index 0000000..98d077b
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/daemon-services/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- name: stop and disable kernel nfs
+ service: name=nfs-server state=stopped enabled=no
diff --git a/tests/vagrant/vagrant-template/roles/install-pkgs/tasks/main.yml b/tests/vagrant/vagrant-template/roles/install-pkgs/tasks/main.yml
new file mode 100644
index 0000000..a6656b6
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/install-pkgs/tasks/main.yml
@@ -0,0 +1,76 @@
+---
+- name: install deltarpm
+ dnf: name=deltarpm state=present
+
+- name: update system
+ shell: dnf update -y
+
+- name: install other packages
+ dnf: name={{ item }} state=present
+ with_items:
+ - attr
+ - autoconf
+ - automake
+ - bison
+ - cmockery2
+ - cmockery2-devel
+ - cifs-utils
+ - dbench
+ - dos2unix
+ - e2fsprogs
+ - findutils
+ - flex
+ - fuse-devel
+ - fuse-libs
+ - gcc
+ - gdb
+ - git
+ - glib2-devel
+ - hostname
+ - libacl-devel
+ - libaio-devel
+ - libattr-devel
+ - libibverbs-devel
+ - librdmacm-devel
+ - libtool
+ - libxml2-devel
+ - lvm2-devel
+ - make
+ - man-db
+ - mock
+ - net-tools
+ - nfs-utils
+ - openssh-server
+ - openssl-devel
+ - perl-Test-Harness
+ - pkgconfig
+ - procps-ng
+ - psmisc
+ - python-devel
+ - python-devel
+ - python-eventlet
+ - python-netifaces
+ - python-paste-deploy
+ - python-setuptools
+ - python-simplejson
+ - python-sphinx
+ - python-webob
+ - pyxattr
+ - readline-devel
+ - rpm-build
+ - screen
+ - strace
+ - supervisor
+ - systemtap-sdt-devel
+ - sqlite-devel
+ - samba*
+ - userspace-rcu-devel
+ - vim
+ - wget
+ - which
+ - xfsprogs
+ - yajl-devel
+
+- name: Erase gluster packages, keep dependencies; we will source install
+ shell: rpm -ev --nodeps `rpm -qa | grep ^gluster`
+ ignore_errors: True
diff --git a/tests/vagrant/vagrant-template/roles/iptables/tasks/main.yml b/tests/vagrant/vagrant-template/roles/iptables/tasks/main.yml
new file mode 100644
index 0000000..768cb0e
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/iptables/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- name: disable iptables, need to add specific rules later
+ shell: iptables -F
diff --git a/tests/vagrant/vagrant-template/roles/mock-user/tasks/main.yml b/tests/vagrant/vagrant-template/roles/mock-user/tasks/main.yml
new file mode 100644
index 0000000..c8e1209
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/mock-user/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- name: Add mock user; required for rpm.t
+ user: name=mock group=mock
diff --git a/tests/vagrant/vagrant-template/roles/prepare-brick/tasks/main.yml b/tests/vagrant/vagrant-template/roles/prepare-brick/tasks/main.yml
new file mode 100644
index 0000000..6b3f6b8
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/prepare-brick/tasks/main.yml
@@ -0,0 +1,6 @@
+---
+- name: Format backend
+ filesystem: fstype=xfs dev=/dev/vdb
+
+- name: Add entry to fstab and mount
+ mount: name=/d src=/dev/vdb fstype=xfs state=mounted
diff --git a/tests/vagrant/vagrant-template/roles/selinux/tasks/main.yml b/tests/vagrant/vagrant-template/roles/selinux/tasks/main.yml
new file mode 100644
index 0000000..c9ba961
--- /dev/null
+++ b/tests/vagrant/vagrant-template/roles/selinux/tasks/main.yml
@@ -0,0 +1,3 @@
+---
+- name: Allow gfapi in Samba to bind to other ports than well known smb ports
+ seboolean: name=samba_load_libgfapi state=yes persistent=yes
diff --git a/tests/vagrant/vagrant-template/setup.yml b/tests/vagrant/vagrant-template/setup.yml
new file mode 100644
index 0000000..691c7af
--- /dev/null
+++ b/tests/vagrant/vagrant-template/setup.yml
@@ -0,0 +1,11 @@
+---
+- hosts: all
+ sudo: true
+ roles:
+ - install-pkgs
+ - prepare-brick
+ - mock-user
+ - selinux
+ - iptables
+ - daemon-services
+