First set of tests

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
This commit is contained in:
Petr "Stone" Hracek 2017-04-04 13:09:58 +02:00
commit 37a4778475
5 changed files with 129 additions and 0 deletions

3
Makefile Normal file
View file

@ -0,0 +1,3 @@
test:
cd tests; make

11
tests/Makefile Normal file
View file

@ -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

38
tests/config.yaml Normal file
View file

@ -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'

26
tests/my-haproxy.cfg Normal file
View file

@ -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

51
tests/simpleTest.py Normal file
View file

@ -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 <psklenar@redhat.com>
#
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)