diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ab7c1d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM registry.fedoraproject.org/fedora:26 + +# dhcp-server image + +LABEL MAINTAINER Dominika Hodovska, Red Hat + +LABEL summary="DHCP (Dynamic Host Configuration Protocol) server container" \ + name="dhcp-server" \ + version="1.0" \ + Release="1" \ + architecture="$ARCH" \ + com.redhat.component=$NAME \ + usage="# docker run --net=host -v /etc/dhcp/:/etc/dhcp -v /var/lib/dhcpd:/var/lib/dhcpd --name dhcp f26/dhcp-server" \ + help="Runs dhcp server which reads network configuration from host." \ + description="dhcp-server provides network configuration for dhcp-clients" \ + vendor="Fedora Project" \ + org.fedoraproject.component="dhcp-server" \ + authoritative-source-url="registry.fedoraproject.org" \ + io.k8s.description="dhcp-server provides network configuration for dhcp-clients" \ + io.k8s.display-name="dhcp-server" \ + io.openshift.tags="dhcp" + +ADD repos/dhcp-server-module.repo /etc/yum.repos.d/ +ADD files/dhcpd.sh /dhcpd + +RUN microdnf install dhcp-server && microdnf clean all && \ + chmod 755 /dhcpd + +VOLUME ['/etc/dhcp', '/etc/dhcp'] ['/var/lib/dhcpd', '/var/lib/dhcpd'] + +CMD ["/dhcpd", "-d", "--no-pid"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1cedf3a --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +IMAGE_NAME = dhcp-server + +MODULEMDURL=file://dhcp-server.yaml + +default: run + +build: + docker build --tag=$(IMAGE_NAME) . + +run: build + docker run -d $(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/files/dhcpd.sh b/files/dhcpd.sh new file mode 100644 index 0000000..edb0f40 --- /dev/null +++ b/files/dhcpd.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ ! -f /etc/dhcp/dhcpd.conf ]; then + echo "Not configured to listen on any interfaces!" + echo "see https://github.com/container-images/dhcp-server for reference" + exit 1 +fi + +if [ ! -f /var/lib/dhcpd/dhcpd.leases ]; then + touch /var/lib/dhcpd/dhcpd.leases +fi + +exec /usr/sbin/dhcpd $@ diff --git a/repos/dhcp-server-module.repo b/repos/dhcp-server-module.repo new file mode 100644 index 0000000..f8b0c87 --- /dev/null +++ b/repos/dhcp-server-module.repo @@ -0,0 +1,5 @@ +[dhcp-server-module] +name=dhcp-server module repository +baseurl=https://kojipkgs.fedoraproject.org/repos/module-f4faa83efb729898-build/latest/x86_64/ +enabled=1 +gpgcheck=0 diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..d023886 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,7 @@ +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..e1e6f65 --- /dev/null +++ b/tests/config.yaml @@ -0,0 +1,32 @@ +document: modularity-testing +version: 1 + +name: dhcp-server +modulemd-url: http://pkgs.fedoraproject.org/cgit/modules/dhcp-server.git/plain/dhcp-server.yaml +source: https://github.com/container-images/dhcp-server +packages: + rpms: + - dhcp-server + +testdependencies: + rpms: + - dhcp-client + +module: + docker: + start: "docker run -it --net=host -v /etc/dhcp/:/etc/dhcp:Z -v /var/lib/dhcpd:/var/lib/dhcpd:Z" + labels: + description: 'Provides the ISC DHCP server' + setup: modprobe dummy; + ip address add 1.2.3.4/24 dev dummy0; + ip link set dev dummy0 up; + echo "subnet 1.2.3.0 netmask 255.255.255.0 {{ range 1.2.3.20 1.2.3.30; }}" > /etc/dhcp/dhcpd.conf; + cleanup: rmmod dummy + container: docker.io/dhodovsk/dhcp-server + rpm: + start: systemctl start dhcpd + stop: systemctl stop dhcpd + status: systemctl status dhcpd + repos: + - http://download.englab.brq.redhat.com/pub/fedora/releases/25/Everything/x86_64/os/ + - https://kojipkgs.fedoraproject.org/repos/module-136b2919f615964c/latest/x86_64 \ No newline at end of file diff --git a/tests/sanity.py b/tests/sanity.py new file mode 100644 index 0000000..1cb6e9c --- /dev/null +++ b/tests/sanity.py @@ -0,0 +1,42 @@ +#!/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: Dominika Hodovska +# + +from moduleframework import module_framework +import socket + + +class dhcpdTests(module_framework.AvocadoTest): + """ + :avocado: enable + """ + def testPorts(self): + + self.start() + #set the right dhclient flag instead of this sleep hack + self.runHost('killall dhclient') + self.runHost('[ $(ip address | grep dummy0 | grep 1.2.3 | wc -l) == 1 ]', shell=True) + self.runHost('/usr/sbin/dhclient dummy0') + self.runHost('sleep 10') + self.runHost('[ $(ip address | grep dummy0 | grep 1.2.3 | wc -l) == 2 ]', shell=True) + self.runHost('killall dhclient') + self.stop() diff --git a/tests/sanity.pyc b/tests/sanity.pyc new file mode 100644 index 0000000..e82bab9 Binary files /dev/null and b/tests/sanity.pyc differ