test suite for nginx
This commit is contained in:
parent
7aaf603481
commit
bb1d535e5f
6 changed files with 264 additions and 10 deletions
|
|
@ -3,5 +3,4 @@ CMD=python -m avocado run --filter-by-tags=-WIP $(MODULE_LINT) *.py
|
|||
|
||||
#
|
||||
all:
|
||||
generator
|
||||
$(CMD)
|
||||
|
|
|
|||
|
|
@ -12,18 +12,12 @@ testdependecies:
|
|||
- curl
|
||||
module:
|
||||
docker:
|
||||
start: "docker run --rm -p 80:80 nginx"
|
||||
start: "docker run -it -p 80:80 -p 443:443"
|
||||
source: https://github.com/container-images/nginx.git
|
||||
container: docker.io/modularitycontainers/nginx
|
||||
container: nginx
|
||||
rpm:
|
||||
start: systemctl start nginx
|
||||
stop: systemctl stop nginx
|
||||
status: systemctl status nginx
|
||||
repos:
|
||||
- http://mirror.vutbr.cz/fedora/releases/25/Everything/x86_64/os/
|
||||
test:
|
||||
processrunning:
|
||||
- 'ls /proc/*/exe -alh | grep nginx'
|
||||
testhost:
|
||||
basic:
|
||||
- 'curl localhost | grep "Welcome to nginx!"'
|
||||
- http://mirror.vutbr.cz/fedora/releases/26/Everything/x86_64/os/
|
||||
|
|
|
|||
62
tests/configuration.py
Normal file
62
tests/configuration.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#!/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: Rado Pitonak <rpitonak@redhat.com>
|
||||
#
|
||||
|
||||
from avocado import main
|
||||
import time
|
||||
from avocado.core import exceptions
|
||||
from moduleframework import module_framework
|
||||
|
||||
|
||||
class ConfigurationCheck(module_framework.AvocadoTest):
|
||||
"""
|
||||
:avocado: enable
|
||||
"""
|
||||
|
||||
def testConfChange(self):
|
||||
"""
|
||||
Test change the root directory in the configuration file of running nginx.
|
||||
Then nginx is reloaded and should load website from new root directory.
|
||||
"""
|
||||
|
||||
self.start()
|
||||
conf_path = "/etc/nginx/nginx.conf"
|
||||
|
||||
content = "<html><body><h1>Nginx is running in container!</h1></body></html>"
|
||||
root = "/tmp/app-root"
|
||||
|
||||
# create website for testing
|
||||
self.run("mkdir {}".format(root))
|
||||
self.run("echo '{}' >> {}/index.html".format(content, root))
|
||||
|
||||
# change the root directory inside conf file
|
||||
self.run("sed -i 's/root.*$/root \/tmp\/app-root\/;/g' {}".format(conf_path))
|
||||
self.run("nginx -s reload")
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
# request content from host
|
||||
self.assertIn('{}\n'.format(content), self.runHost("curl 127.0.0.1:80").stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
56
tests/rpmvalidator.py
Normal file
56
tests/rpmvalidator.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/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: Jan Scotka <jscotka@redhat.com>
|
||||
#
|
||||
|
||||
from avocado import main
|
||||
from moduleframework import module_framework
|
||||
|
||||
|
||||
class ExampleRpmValidation(module_framework.AvocadoTest):
|
||||
"""
|
||||
:avocado: enable
|
||||
"""
|
||||
fhs_base_paths = [
|
||||
'/bin',
|
||||
'/boot',
|
||||
'/dev',
|
||||
'/etc',
|
||||
'/home',
|
||||
'/lib',
|
||||
'/lib64',
|
||||
'/media',
|
||||
'/mnt',
|
||||
'/opt',
|
||||
'/proc',
|
||||
'/root',
|
||||
'/run',
|
||||
'/sbin',
|
||||
'/sys',
|
||||
'/srv',
|
||||
'/tmp',
|
||||
'/usr/bin'
|
||||
]
|
||||
|
||||
def testPaths(self):
|
||||
self.start()
|
||||
for directory in self.fhs_base_paths:
|
||||
self.run("test -d %s" % directory)
|
||||
63
tests/sanity1.py
Normal file
63
tests/sanity1.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#!/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: Rado Pitonak <rpitonak@redhat.com>
|
||||
#
|
||||
|
||||
from avocado import main
|
||||
from avocado.core import exceptions
|
||||
from moduleframework import module_framework
|
||||
|
||||
|
||||
class SanityCheck1(module_framework.AvocadoTest):
|
||||
"""
|
||||
:avocado: enable
|
||||
"""
|
||||
|
||||
def test1(self):
|
||||
"""
|
||||
Simple sanity test
|
||||
"""
|
||||
|
||||
self.start()
|
||||
self.run("ls / | grep bin")
|
||||
|
||||
def test2Version(self):
|
||||
"""
|
||||
Check if nginx is installed in correct version
|
||||
"""
|
||||
|
||||
version = "1."
|
||||
self.start()
|
||||
|
||||
# For some reason, nginx -v spits out the version number to stderr
|
||||
self.run("nginx -v 2>&1 | grep {}".format(version))
|
||||
|
||||
def test3ServiceRunning(self):
|
||||
"""
|
||||
Check if nginx is running
|
||||
"""
|
||||
|
||||
self.start()
|
||||
self.run('ls /proc/*/exe -alh | grep nginx')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
80
tests/sanity2.py
Normal file
80
tests/sanity2.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#!/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: Rado Pitonak <rpitonak@redhat.com>
|
||||
#
|
||||
|
||||
from avocado import main
|
||||
from avocado.core import exceptions
|
||||
from moduleframework import module_framework
|
||||
import time
|
||||
|
||||
|
||||
class SanityCheck2(module_framework.AvocadoTest):
|
||||
"""
|
||||
:avocado: enable
|
||||
"""
|
||||
|
||||
def test1Port80(self):
|
||||
"""
|
||||
Request to localhost inside the container to make sure that server running on port 80
|
||||
"""
|
||||
|
||||
self.start()
|
||||
time.sleep(2)
|
||||
self.run("curl 127.0.0.1:80")
|
||||
|
||||
def test2WebsiteContent(self):
|
||||
"""
|
||||
Check if nginx display correct content
|
||||
"""
|
||||
|
||||
content = "<html><body><h1>Nginx is running in container!</h1></body></html>"
|
||||
root = "/usr/share/nginx/"
|
||||
|
||||
self.start()
|
||||
|
||||
# create simple static website inside the container
|
||||
self.run("touch {}/html/index.html".format(root))
|
||||
self.run("echo '{}' >> {}/html/index.html".format(content, root))
|
||||
|
||||
# compare content returned by request from host with original content
|
||||
self.assertIn('{}\n'.format(content), self.runHost("curl 127.0.0.1:80").stdout)
|
||||
|
||||
def test3Port443(self):
|
||||
"""
|
||||
Test configure server to listen also on port 443 and make request from host.
|
||||
"""
|
||||
|
||||
conf_path = "/etc/nginx/nginx.conf"
|
||||
self.start()
|
||||
time.sleep(2)
|
||||
|
||||
# Make the server listen on port 443.
|
||||
self.run("sed -i 's/server {}$/ server {} listen 443;/g' {}".format("{", "{", conf_path))
|
||||
# reload nginx to apply changes
|
||||
self.run("nginx -s reload")
|
||||
time.sleep(5)
|
||||
|
||||
self.runHost("curl 127.0.0.1:443")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue