diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d07338 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM baseruntime/baseruntime:latest + +COPY repos/* /etc/yum.repos.d/ + +RUN microdnf --nodocs --enablerepo httpd install httpd && \ + microdnf clean all + +EXPOSE 8080 + + +CMD exec /usr/sbin/httpd -D FOREGROUND diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed9c92e --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +IMAGE_NAME = httpd + +MODULEMDURL=file://httpd.yaml + +default: run + +build: + docker build --tag=$(IMAGE_NAME) . + +run: build + docker run -it -p 80:80 $(IMAGE_NAME) + +test: build + cd tests; MODULE=docker MODULEMD=$(MODULEMDURL) URL="docker=$(IMAGE_NAME)" make all + cd tests; MODULE=rpm MODULEMD=$(MODULEMDURL) URL="docker=$(IMAGE_NAME)" make all diff --git a/repos/fedora.repo b/repos/fedora.repo new file mode 100644 index 0000000..f86d71c --- /dev/null +++ b/repos/fedora.repo @@ -0,0 +1,5 @@ +[fedora] +name=fedora +baseurl=https://mirrors.nic.cz/fedora/linux/development/26/Everything/x86_64/os/ +enabled=0 + diff --git a/repos/httpd.repo b/repos/httpd.repo new file mode 100644 index 0000000..f0ab60f --- /dev/null +++ b/repos/httpd.repo @@ -0,0 +1,4 @@ +[httpd] +name=httpd +baseurl=https://kojipkgs.fedoraproject.org/repos/module-httpd-master-20170314081857-build/latest/x86_64/ +enabled=0 diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..8fd8ae7 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,6 @@ +MODULE_LINT=/usr/share/moduleframework/tools/modulelint.py +CMD=python -m avocado run --filter-by-tags=-WIP $(MODULE_LINT) *.py + +# +all: + $(CMD) diff --git a/tests/config.yaml b/tests/config.yaml new file mode 100644 index 0000000..2766b1f --- /dev/null +++ b/tests/config.yaml @@ -0,0 +1,17 @@ +document: modularity-testing +version: 1 +name: httpd +modulemd-url: https://src.fedoraproject.org/git/modules/httpd.git/plain/httpd.yaml +service: + port: 8080 +packages: + rpms: + - httpd +module: + docker: + start: "docker run -it -p 80:80 -p 443:443" + container: httpd + rpm: + start: exec /usr/sbin/httpd -D FOREGROUND + repos: + - http://mirror.vutbr.cz/fedora/releases/26/Everything/x86_64/os/ diff --git a/tests/microdnfinside.py b/tests/microdnfinside.py new file mode 100644 index 0000000..479487d --- /dev/null +++ b/tests/microdnfinside.py @@ -0,0 +1,35 @@ +#!/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 +# + +from moduleframework import module_framework +import os + + +class microDNFTest(module_framework.AvocadoTest): + """ + :avocado: enable + """ + + def testInstallMicroDNFEmpty(self): + self.start() + self.assertIn("Transaction: (empty)",self.run("microdnf install microdnf", ignore_status=True).stdout) diff --git a/tests/rpmvalidator.py b/tests/rpmvalidator.py new file mode 100644 index 0000000..8dc7541 --- /dev/null +++ b/tests/rpmvalidator.py @@ -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 +# + +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) diff --git a/tests/sanity1.py b/tests/sanity1.py new file mode 100644 index 0000000..03ece7f --- /dev/null +++ b/tests/sanity1.py @@ -0,0 +1,44 @@ +#!/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 +# + +from avocado import main +from avocado.core import exceptions +from moduleframework import module_framework +class SanityCheck1(module_framework.AvocadoTest): + """ + :avocado: enable + """ + + def test1(self): + self.start() + self.run("ls / | grep bin") + + # check if httpd is installed in the right version. + def test2HttpdVersion(self): + version = "2.4" + self.start() + self.run("httpd -v | grep {}".format(version)) + + +if __name__ == '__main__': + main() diff --git a/tests/sanity2.py b/tests/sanity2.py new file mode 100644 index 0000000..9e633ea --- /dev/null +++ b/tests/sanity2.py @@ -0,0 +1,69 @@ +#!/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 +# + +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): + self.start() + time.sleep(2) + self.run("curl 127.0.0.1:80") + + # test with simple static website + def test2WebContent(self): + content = "

Httpd is running in container!

" + root = "/var/www/" + + self.start() + self.run("touch {}/html/index.html".format(root)) + self.run("echo '{}' >> {}/html/index.html".format(content, root)) + + self.assertIn('{}\n'.format(content), self.runHost("curl 127.0.0.1:80").stdout) + + def test3Port443(self): + conf_path = "/etc/httpd/conf" + httpd = "/usr/sbin/httpd" + + self.start() + time.sleep(2) + try: + self.run("cat {}/httpd.conf | grep 'Listen 443'".format(conf_path)) + except: + # add 'Listen 443' to httpd.conf manually + self.run("echo 'Listen 443' >> {}/httpd.conf ".format(conf_path)) + # restart httpd to apply changes from httpd.conf + self.run("exec {} -k graceful".format(httpd)) + finally: + time.sleep(2) + self.runHost("curl 127.0.0.1:443") + +if __name__ == '__main__': + main() diff --git a/tests/simpleTest.py b/tests/simpleTest.py new file mode 100644 index 0000000..780e387 --- /dev/null +++ b/tests/simpleTest.py @@ -0,0 +1,47 @@ +#!/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 +# + +from moduleframework import module_framework +import os + + +class simpleTests(module_framework.AvocadoTest): + """ + :avocado: enable + """ + + def testPath(self): + print ">>>>>>>>>>>>>> ", module_framework.__file__ + print ">>>>>>>>>>>>>> ", __file__ + + def testAssertIn(self): + self.start() + self.assertIn("sbin", self.run("ls /").stdout) + + def testInsideModule(self): + self.start() + self.assertEqual("a", self.run("echo a").stdout.strip()) + + def testCommandOnHost(self): + self.start() + self.assertEqual("a", self.runHost("echo a").stdout.strip())