#2 Adds tests according to the CI
Merged 5 months ago by cipherboy. Opened 10 months ago by ssahani.
rpms/ ssahani/freeradius tests  into  master

Adds tests according to the CI
Susant Sahani • 10 months ago  

@@ -0,0 +1,36 @@ 

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/freeradius

+ #   Description: Test if freeradius authentication workd ok

+ #   Author: Susant Sahani<susant@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ export TEST=/CoreOS/freeradius

+ export TESTVERSION=1.0

+ BUILT_FILES=

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE

+ .PHONY: all install download clean

+ run: $(FILES) build

+ 	./runtest.sh

+ build: $(BUILT_FILES)

+ 	test -x runtest.sh || chmod a+x runtest.sh

+ clean:

+ 	rm -f *~ $(BUILT_FILES)

+ include /usr/share/rhts/lib/rhts-make.include

+ $(METADATA): Makefile

+ 	@echo "Owner:           Susant Sahani<susant@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     Test if the ABI hasn't changed" >> $(METADATA)

+ 	@echo "Type:            Sanity" >> $(METADATA)

+ 	@echo "TestTime:        5m" >> $(METADATA)

+ 	@echo "RunFor:          freeradius" >> $(METADATA)

+ 	@echo "Requires:        freeradius" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 	@echo "Releases:        -Fedora 28" >> $(METADATA)

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,3 @@ 

+ PURPOSE of /CoreOS/freeradius

+ Description: tests for freeradius

+ Author: Susant Sahani<susant@redhat.com>

@@ -0,0 +1,2 @@ 

+ fedora-ci Cleartext-Password := "password"

+        Reply-Message = "Hello, %{User-Name}"

@@ -0,0 +1,6 @@ 

+ client localhost {

+      ipaddr = 127.0.0.1

+      secret = testing123

+      require_message_authenticator = no

+      nastype = other

+ }

@@ -0,0 +1,68 @@ 

+ #!/usr/bin/env python3

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   Description: Tests for freeradius

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ 

+ import errno

+ import os

+ import sys

+ import time

+ import unittest

+ import subprocess

+ import signal

+ import shutil

+ import psutil

+ import socket

+ 

+ RADIUSD_PID_FILE='/var/run/radiusd/radiusd.pid'

+ 

+ def setUpModule():

+     """Initialize the environment, and perform sanity checks on it."""

+ 

+     if shutil.which('radiusd') is None:

+         raise OSError(errno.ENOENT, 'radiusd not found')

+ 

+     if shutil.which('radtest') is None:

+         raise OSError(errno.ENOENT, 'radtest not found')

+ 

+     if subprocess.call(['systemctl', 'is-active', '--quiet',

+                         'radiusd.service']) == 0:

+         raise unittest.SkipTest('radiusd.service is already active')

+ 

+ def tearDownModule():

+         pass

+ 

+ class GenericUtilities():

+     """Provide a set of utility functions start stop daemons. write config files etc """

+ 

+     def StartRadiusServer(self):

+         """Start radiusd"""

+         subprocess.check_output(['systemctl', 'start', 'radiusd'])

+ 

+     def StopRadiusServer(self):

+         """stop radiusd"""

+         subprocess.check_output(['systemctl', 'stop', 'radiusd'])

+ 

+ class RadiousTests(unittest.TestCase, GenericUtilities):

+ 

+     def setUp(self):

+         self.StartRadiusServer()

+ 

+     def tearDown(self):

+         self.StopRadiusServer()

+ 

+     def test_radius_plaintext_auth(self):

+         time.sleep(1)

+         output=subprocess.check_output(['radtest', 'fedora-ci', 'password', '127.0.0.1',  '100', 'testing123']).rstrip().decode('utf-8')

+         print(output)

+ 

+         self.assertRegex(output, "Received Access-Accept")

+         self.assertRegex(output, "Reply-Message = \"Hello, fedora-ci\"")

+ 

+ if __name__ == '__main__':

+     unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,

+                                                      verbosity=3))

@@ -0,0 +1,49 @@ 

+ #!/bin/bash

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   runtest.sh of freeradius

+ #   Description:  RADIUS server

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="freeradius"

+ 

+ RADIUS_CLIENT_CONF="/etc/raddb/clients.conf"

+ RADIUD_PALIN_TEXT_AUTH_FILE="/etc/raddb/mods-config/files/authorize"

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+         rlRun "systemctl stop firewalld" 0,5

+         rlRun "systemctl stop radiusd.service"

+         rlRun "setenforce 0"

+         rlFileBackup "$RADIUS_CLIENT_CONF"

+         rlFileBackup "$RADIUD_PALIN_TEXT_AUTH_FILE"

+ 

+         rlRun "cp freeradius-tests.py /usr/bin/"

+         rlRun "cp clients.conf $RADIUS_CLIENT_CONF"

+         rlRun "cp authorize $RADIUD_PALIN_TEXT_AUTH_FILE"

+         rlRun "systemctl daemon-reload"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "Starting radius auth tests ..."

+         rlRun "/usr/bin/python3 /usr/bin/freeradius-tests.py"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "rm /usr/bin/freeradius-tests.py"

+         rlRun "systemctl start firewalld" 0,5

+         rlRun "setenforce 1"

+         rlFileRestore

+         rlLog "freeradius tests done"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

+ 

+ rlGetTestState

file added
+12

@@ -0,0 +1,12 @@ 

+ - hosts: localhost

+   roles:

+     - role: standard-test-beakerlib

+       tags:

+       - classic

+       tests:

+       - auth-tests

+       required_packages:

+       - python3

+       - systemd

+       - freeradius

+       - freeradius-utils

Adds tests according to the CI

justification
Adds tests according to the CI wiki specifically the standard test interface in the spec.
The playbook includes Tier1 level test cases that have been tested in the following contexts and
is passing reliably: Classic. Test logs are stored in the artifacts directory.
The following steps are used to execute the tests using the standard test interface:

Test enveronment
Make sure you have installed packages from the spec

ansible-2.4.1.0-2.fc28.noarch
python2-dnf-2.7.5-1.fc28.noarch
libselinux-python-2.7-2.fc28.x86_64
standard-test-roles-2.5-1.fc28.noarch
Run tests for Classic
Snip of the example test run for Classic tests:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Test
:: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:21:19 ] :: [ LOG ] :: Starting radius auth tests ...
:: [ 16:21:19 ] :: [ LOG ] :: Starting radius auth tests ...
:: [ 16:21:19 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/freeradius-tests.py'
test_radius_plaintext_auth (main.RadiousTests) ... Sent Access-Request Id 17 from 0.0.0.0:49711 to 127.0.0.1:1812 length 79
User-Name = "fedora-ci"
User-Password = "password"
NAS-IP-Address = 192.168.225.189
NAS-Port = 100
Message-Authenticator = 0x00
Cleartext-Password = "password"
Received Access-Accept Id 17 from 127.0.0.1:1812 to 0.0.0.0:0 length 38
Reply-Message = "Hello, fedora-ci"
ok


Ran 1 test in 1.214s

OK
:: [ 16:21:20 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/freeradius-tests.py' (Expected 0, got 0)
:: [ 16:21:20 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/freeradius-tests.py' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 1s

rebased onto 7d27209

10 months ago

rebased onto bcef4f4

10 months ago

Thank you for the contribution, Susant!

I assume this is a part of a larger effort, which I'm not aware about. Could you please provide me with a link to a document describing the purpose and the overall means of this effort? Perhaps a link to that "CI wiki" and the "standard test interface in the spec"?

Thank you.

Thanks for looking in to this Nikolai . In short we are trying to automate test cases https://fedoraproject.org/wiki/CI
https://fedoraproject.org/wiki/CI/Tests

Whenever there is any PR is opened it will trigger the tests .
https://jenkins-continuous-infra.apps.ci.centos.org/blue/organizations/jenkins/fedora-rawhide-pr-pipeline/activity/

Thanks

This looks fine. I'll go ahead and merge this, but note that the tests are a bit basic. Better would be trying to enable the upstream test suite during build as it is more comprehensive than this test. Also nice would be trying to get a IPA + FreeRADIUS test in Fedora CI somewhere, but that'd be a lot more work.

Pull-Request has been merged by cipherboy

5 months ago