From 340153465d80637fa84c47d176e1c18de506eb94 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 20 May 2016 12:15:58 +0200 Subject: [PATCH] Copied the testing framework from develop. --- .travis.yml | 7 +++ tests/Dockerfile | 95 ++++++++++++++++++++++++++++++++++++++++ tests/install_console.py | 36 +++++++++++++++ tests/test.sh | 52 ++++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 .travis.yml create mode 100644 tests/Dockerfile create mode 100755 tests/install_console.py create mode 100755 tests/test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..7d8bae0b5b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +sudo: required + +services: + - docker + +script: + - docker run --rm -t -v "$TRAVIS_BUILD_DIR:/tmp/pandorafms" pandorafms/pandorafms-base /tmp/pandorafms/tests/test.sh diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000000..b43b9b7f22 --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,95 @@ +FROM centos:centos6 +MAINTAINER Pandora FMS Team + +RUN { \ + echo '[EPEL]'; \ + echo 'name = CentOS Epel'; \ + echo 'baseurl = http://dl.fedoraproject.org/pub/epel/6/x86_64'; \ + echo 'enabled=1'; \ + echo 'gpgcheck=0'; \ +} > /etc/yum.repos.d/extra_repos.repo + +RUN { \ + echo '[artica_pandorafms]'; \ + echo 'name=CentOS6 - PandoraFMS official repo'; \ + echo 'baseurl=http://artica.es/centos6'; \ + echo 'gpgcheck=0'; \ + echo 'enabled=1'; \ +} > /etc/yum.repos.d/pandorafms.repo + +RUN yum -y update; yum clean all; + +# Generic dependencies +RUN yum install -y \ + firefox + python-pip + xorg-x11-server-Xvfb +RUN pip install pyvirtualdisplay +RUN pip install selenium + +# Pandora FMS Console dependencies +RUN yum install -y \ + git \ + httpd \ + cronie \ + ntp \ + openldap \ + anytermd \ + nfdump \ + wget \ + curl \ + openldap \ + plymouth \ + xterm \ + php \ + php-gd \ + graphviz \ + php-mysql \ + php-pear-DB \ + php-pear \ + php-pdo \ + php-mbstring \ + php-ldap \ + php-snmp \ + php-ldap \ + php-common \ + php-zip \ + nmap \ + xprobe2 \ + mysql-server \ + mysql + +# Pandora FMS Server dependencies +RUN yum install -y \ + git \ + cronie \ + ntp \ + wget \ + curl \ + xterm \ + postfix \ + wmic \ + perl-HTML-Tree \ + perl-DBI \ + perl-DBD-mysql \ + perl-libwww-perl \ + perl-XML-Simple \ + perl-XML-SAX \ + perl-NetAddr-IP \ + net-snmp \ + net-tools \ + perl-IO-Socket-INET6 \ + perl-Socket6 \ + nmap \ + sudo \ + xprobe2 \ + make \ + perl-CPAN \ + perl-JSON \ + net-snmp-perl \ + perl-Time-HiRes \ + perl-XML-Twig \ + perl-Encode-Locale \ + net-snmp \ + net-snmp-utils + diff --git a/tests/install_console.py b/tests/install_console.py new file mode 100755 index 0000000000..f186605c84 --- /dev/null +++ b/tests/install_console.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# Script to install the Pandora FMS Console. +import os +from pyvirtualdisplay import Display +from selenium import webdriver + +# Are we running headless? +if ('DISPLAY' not in os.environ): + display = Display(visible=0, size=(800, 600)) + display.start() + +# Go to the installation page. +browser = webdriver.Firefox() +browser.implicitly_wait(5) +browser.get('http://localhost/pandora_console/install.php') +assert("Pandora FMS - Installation Wizard" in browser.title) + +# Accept the license agreement. +browser.find_element_by_xpath("//*[@id='step11']/img").click() +browser.find_element_by_xpath("//*[@id='install_box']/form/div/input").click() + +# Fill-in the configuration form. +browser.find_element_by_xpath("//*[@id='step3']/img").click() +browser.find_element_by_name("pass").send_keys("pandora") +browser.find_element_by_id("step4").click() + +# Complete the installation. +browser.implicitly_wait(300) # The installation is going to take a long time. +browser.find_element_by_xpath("//*[@id='step5']/img").click() +browser.implicitly_wait(5) +assert("Installation complete" in browser.page_source) + +# Clean-up +browser.quit() +if ('DISPLAY' not in os.environ): + display.stop() diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000000..85b192eb89 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,52 @@ +#!/bin/bash +SOURCE_DIR="/tmp/pandorafms" + +################################################ +# Check the exit status of the last run command. +# Exits if it different from 0. +################################################ +function check { + MESSAGE=$1 + RC=$2 + if [ $RC == 0 ]; then + echo ">$MESSAGE... [OK]" + else + echo ">$MESSAGE... [ERR $RC]" + exit 1 + fi +} + +# Start the required services. +service mysqld start && /usr/bin/mysqladmin -u root password 'pandora' +check "Starting the MySQL Server" $? +service httpd start +check "Starting the Apache Web Server" $? + +# Install the Pandora FMS Console. +cd /tmp/pandorafms/pandora_console && chmod +x pandora_console_install && yes | ./pandora_console_install --install +check "Installing the Pandora FMS Console" $? + +# Create the Pandora FMS database. +cd /tmp/pandorafms/tests && chmod +x install_console.py && ./install_console.py +check "Creating the Pandora FMS Database" $? + +# Build and install the Pandora FMS Server. +cd /tmp/pandorafms/pandora_server && perl Makefile.PL && make && make test +check "Building the Pandora FMS Server" $? +cd /tmp/pandorafms/pandora_server && chmod +x pandora_server_installer && ./pandora_server_installer --install +check "Installing the Pandora FMS Server" $? +sed -i -e 's/^dbuser.*/dbuser root/' /etc/pandora/pandora_server.conf + +# Install the Pandora FMS Agent. +cd /tmp/pandorafms/pandora_agents/unix && chmod +x pandora_agent_installer && ./pandora_agent_installer --install +check "Installing the Pandora FMS Agent" $? + +# Start Pandora FMS services. +service tentacle_serverd start +check "Starting the Tentacle Server" $? +service pandora_server start +check "Starting the Pandora FMS Server" $? +service pandora_agent_daemon start +check "Starting the Pandora FMS Agent" $? + +exit 0