From 37a4778475d76dc06d08b387262bc33ccf879727 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 4 Apr 2017 13:09:58 +0200 Subject: [PATCH] First set of tests Signed-off-by: Petr "Stone" Hracek --- Makefile | 3 +++ tests/Makefile | 11 ++++++++++ tests/config.yaml | 38 +++++++++++++++++++++++++++++++++ tests/my-haproxy.cfg | 26 ++++++++++++++++++++++ tests/simpleTest.py | 51 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 Makefile create mode 100644 tests/Makefile create mode 100644 tests/config.yaml create mode 100644 tests/my-haproxy.cfg create mode 100644 tests/simpleTest.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e5b204a --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +test: + cd tests; make diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..fe6691f --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,11 @@ +MODULE_LINT=/usr/lib/python2.7/site-packages/moduleframework/modulelint.py +CMD=python -m avocado run --filter-by-tags=-WIP $(MODULE_LINT) *.py *.sh + +# +check-docker: + MODULE=docker $(CMD) + +check-rpm: + MODULE=rpm $(CMD) + +all: check-docker check-rpm diff --git a/tests/config.yaml b/tests/config.yaml new file mode 100644 index 0000000..4801984 --- /dev/null +++ b/tests/config.yaml @@ -0,0 +1,38 @@ +document: modularity-testing +version: 1 +name: haproxy +modulemd-url: https://raw.githubusercontent.com/container-images/haproxy/master/haproxy.yaml +service: + port: 80 +packages: + rpms: + - haproxy +testdependecies: + rpms: + - nc +module: + docker: + start: "docker run -it -p 8077:80 -v $(pwd)/local-haproxy.cfg:/etc/haproxy/haproxy.cfg:Z" + labels: + description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments." + io.k8s.description: "HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments." + source: https://github.com/container-images/haproxy + container: docker.io/modularitycontainers/haproxy + rpm: + start: sed -i 's/bind\*/bind :8077/' $(pwd)/local-haproxy.cfg; + cp $(pwd)/local-haproxy.cfg /etc/haproxy/haproxy.cfg; + semanage port -a -t http_port_t -p tcp 8001; + semanage port -a -t http_port_t -p tcp 8000; + semanage port -a -t http_port_t -p tcp 8077; + sleep 4; + systemctl start haproxy + stop: systemctl stop haproxy + status: systemctl status haproxy + repos: + - http://mirror.vutbr.cz/fedora/releases/25/Everything/x86_64/os/ + - https://phracek.fedorapeople.org/haproxy-module-repo/ + test: + processrunning: + - 'ls /proc/*/exe -alh | grep haproxy' + + diff --git a/tests/my-haproxy.cfg b/tests/my-haproxy.cfg new file mode 100644 index 0000000..3e1e8a4 --- /dev/null +++ b/tests/my-haproxy.cfg @@ -0,0 +1,26 @@ +# Example from http://www.haproxy.org/download/1.3/examples/antidos.cfg + +# This configuration is meant to be installed in front of an existing web +# server that needs some DoS protection. We assume that the web server has been +# moved to port 8080 on the loopback, and that haproxy 1.3.18 is running on +# port 80. Note that Apache will have to be configured to get the client's IP +# address from the X-Forwarded-For header (mod_rpaf can do that). + +global + daemon + maxconn 256 + +defaults + mode http + timeout connect 5000ms + timeout client 50000ms + timeout server 50000ms + +frontend http-in + bind :80 + default_backend servers + +backend servers + server server1 127.0.0.1:8000 maxconn 32 + server server2 127.0.0.1:8001 maxconn 32 + diff --git a/tests/simpleTest.py b/tests/simpleTest.py new file mode 100644 index 0000000..b473c00 --- /dev/null +++ b/tests/simpleTest.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# This Modularity Testing Framework helps you to write tests for modules +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# he Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Authors: Petr Sklenar +# + +from moduleframework import module_framework +import os + + +class simpleTests(module_framework.AvocadoTest): + """ + :avocado: enable + """ + def setUp(self): + super(self.__class__, self).setUp() + self.runHost('docker pull docker.io/httpd') + self.runHost('docker run --name http_name_8000 -d -p 8000:80 docker.io/httpd') + self.runHost('docker run --name http_name_8001 -d -p 8001:80 docker.io/httpd') + global myip + myip = self.runHost('hostname -i').stdout.strip() + + def tearDown(self): + super(self.__class__, self).tearDown() + self.runHost('docker stop http_name_8000') + self.runHost('docker stop http_name_8001') + self.runHost('docker rm http_name_8000') + self.runHost('docker rm http_name_8001') + + def testAssertIn(self): + self.runHost(('sed s/127.0.0.1/{}/ my-haproxy.cfg > local-haproxy.cfg').format(myip), shell = True) + self.start() + self.assertIn('It works!',self.runHost('curl localhost:8077', shell = True).stdout) +