URL: https://github.com/SSSD/sssd/pull/796 Author: pbrezina Title: #796: ci: enable sssd-ci for 1-16 branch Action: synchronized
To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/796/head:pr796 git checkout pr796
From 9a6cf5f5a3218c378c968cc4932152c7a2614fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com> Date: Fri, 29 Mar 2019 11:10:18 +0100 Subject: [PATCH] ci: enable sssd-ci for 1-16 branch Fedora 28 is the latest version containing 1.16 so I think it is fine to not run the test against Fedora 29+. Besides this change this patch contains files from master without change. --- Jenkinsfile | 235 +++++++++++++++++++++++++++++++ contrib/test-suite/README.md | 38 +++++ contrib/test-suite/run-client.sh | 37 +++++ contrib/test-suite/run.sh | 100 +++++++++++++ 4 files changed, 410 insertions(+) create mode 100644 Jenkinsfile create mode 100644 contrib/test-suite/README.md create mode 100755 contrib/test-suite/run-client.sh create mode 100755 contrib/test-suite/run.sh diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000..092033839a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,235 @@ +/** + * Remember that the build failed because one of the untrusted files were + * modified. + */ +untrusted = false + +/** + * SSSD CI. + * + * This class hold SSSD CI settings and defines several helper methods + * that helps reducing code duplication. Unfortunately, it does not + * seem to be possible to run those methods directly from the pipeline + * as CI.MethodName() as it produces 'Expected a symbol' error therefore + * functions outside this class scope must be defined as well. These functions + * can be then called directly from the pipeline. + */ +class CI { + /** + * Absolute path to directory that holds the workspace on Jenkins slave. + */ + public static String BaseDir = '/home/fedora' + + /** + * Github status context name that is visible in pull request statuses. + */ + public static String GHContext = 'sssd-ci' + + /** + * URL that will be opened when user clicks on 'details' on 'sssd-ci' status. + */ + public static String GHUrl = 'https://pagure.io/SSSD/sssd' + + /** + * URL that will be opened when user clicks on 'details' on specific + * build status (e.g. sssd-ci/fedora28). + */ + public static String AWS = 'https://s3.eu-central-1.amazonaws.com/sssd-ci' + + /** + * Path to SSSD Test Suite on Jenkins slave. + */ + public static String SuiteDir = this.BaseDir + '/sssd-test-suite' + + /** + * Workaround for https://issues.jenkins-ci.org/browse/JENKINS-39203 + * + * At this moment if one stage in parallel block fails, failure branch in + * post block is run in all stages even though they might have been successful. + * + * We remember result of test stages in this variable so we can correctly + * report a success or error even if one of the stages that are run in + * parallel failed. + */ + public static def Results = [:] + + /** + * Mark build as successfull. + */ + public static def BuildSuccessful(build) { + this.Results[build] = "success" + } + + /** + * Return true if the build was successful. + */ + public static def IsBuildSuccessful(build) { + return this.Results[build] == "success" + } + + /** + * Send commit status to Github for sssd-ci context. + */ + public static def Notify(ctx, status, message) { + ctx.githubNotify status: status, + context: this.GHContext, + description: message, + targetUrl: this.GHUrl + } + + /** + * Send commit status to Github for specific build (e.g. sssd-ci/fedora28). + */ + public static def NotifyBuild(ctx, status, message) { + ctx.githubNotify status: status, + context: String.format('%s/%s', this.GHContext, ctx.env.TEST_SYSTEM), + description: message, + targetUrl: String.format( + '%s/%s/%s/%s/index.html', + this.AWS, + ctx.env.BRANCH_NAME, + ctx.env.BUILD_ID, + ctx.env.TEST_SYSTEM + ) + } + + /** + * Run tests. TEST_SYSTEM environment variable must be defined. + */ + public static def RunTests(ctx) { + this.NotifyBuild(ctx, 'PENDING', 'Build is in progress.') + + ctx.sh String.format( + './sssd/contrib/test-suite/run.sh %s %s %s %s', + "${ctx.env.WORKSPACE}/sssd", + "${this.SuiteDir}", + "${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}", + "${this.BaseDir}/configs/${ctx.env.TEST_SYSTEM}.json" + ) + + this.BuildSuccessful(ctx.env.TEST_SYSTEM) + } + + /** + * Archive artifacts and notify Github about build result. + */ + public static def WhenCompleted(ctx) { + ctx.archiveArtifacts artifacts: "artifacts/**", allowEmptyArchive: true + ctx.sh String.format( + "${this.BaseDir}/scripts/archive.sh %s %s %s", + ctx.env.TEST_SYSTEM, + "${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}", + "${ctx.env.BRANCH_NAME}/${ctx.env.BUILD_ID}" + ) + ctx.sh "rm -fr ${ctx.env.WORKSPACE}/artifacts/${ctx.env.TEST_SYSTEM}" + + if (this.IsBuildSuccessful(ctx.env.TEST_SYSTEM)) { + this.NotifyBuild(ctx, 'SUCCESS', 'Success.') + return + } + + this.NotifyBuild(ctx, 'FAILURE', 'Build failed.') + } + + /** + * Notify Github that the build was aborted. + */ + public static def WhenAborted(ctx) { + this.NotifyBuild(ctx, 'ERROR', 'Aborted.') + } +} + +/** + * CI class methods cannot be called directly from the pipeline as it + * yield 'Expected a symbol' error for some reason. This is a workaround + * for this issue. + */ +def CI_RunTests() { CI.RunTests(this) } +def CI_Post() { CI.WhenCompleted(this) } +def CI_Aborted() { CI.WhenAborted(this) } +def CI_Notify(status, message) { CI.Notify(this, status, message) } + +pipeline { + agent none + options { + timeout(time: 10, unit: 'HOURS') + checkoutToSubdirectory('sssd') + } + stages { + stage('Prepare') { + steps { + CI_Notify('PENDING', 'Running tests.') + } + } + stage('Read trusted files') { + steps { + readTrusted './contrib/test-suite/run.sh' + readTrusted './contrib/test-suite/run-client.sh' + } + post { + failure { + script { + untrusted = true + } + } + } + } + stage('Run Tests') { + parallel { + stage('Test on Fedora 28') { + agent {label "sssd-ci"} + environment { TEST_SYSTEM = "fedora28" } + steps { CI_RunTests() } + post { + always { CI_Post() } + aborted { CI_Aborted() } + } + } + stage('Test on Fedora 29') { + agent {label "sssd-ci"} + environment { TEST_SYSTEM = "fedora29" } + steps { CI_RunTests() } + post { + always { CI_Post() } + aborted { CI_Aborted() } + } + } + stage('Test on Fedora 30') { + agent {label "sssd-ci"} + environment { TEST_SYSTEM = "fedora30" } + steps { CI_RunTests() } + post { + always { CI_Post() } + aborted { CI_Aborted() } + } + } + stage('Test on Fedora Rawhide') { + agent {label "sssd-ci"} + environment { TEST_SYSTEM = "fedora-rawhide" } + steps { CI_RunTests() } + post { + always { CI_Post() } + aborted { CI_Aborted() } + } + } + } + } + } + post { + failure { + script { + if (untrusted) { + CI_Notify('ERROR', 'Untrusted files were modified.') + } else { + CI_Notify('FAILURE', 'Some tests failed.') + } + } + } + aborted { + CI_Notify('ERROR', 'Builds were aborted.') + } + success { + CI_Notify('SUCCESS', 'All tests succeeded.') + } + } +} diff --git a/contrib/test-suite/README.md b/contrib/test-suite/README.md new file mode 100644 index 0000000000..576d12d286 --- /dev/null +++ b/contrib/test-suite/README.md @@ -0,0 +1,38 @@ +# Run SSSD Test Suite + +Script `run.sh` will run all available SSSD test on a set of virtual machines created by vagrant. These virtual machines are part of separate project located at `https://github.com/SSSD/sssd-test-suite`. + +## Automated Testing + +These test are run automatically when you submit a Pull Request to SSSD project. Status report together with logs will be available in the Pull Request when testing is finished. + +## Steps to run the tests manually + +1. Checkout `https://github.com/SSSD/sssd-test-suite` +2. Configure and setup SSSD test suite per instructions located at project readme. +3. Make sssd-test-suite use already provisioned boxes (either manually created or maintained by SSSD team at https://app.vagrantup.com/sssd-vagrant). +4. Run `run.sh`, please note that this script will call `vagrant destroy` and it will thus destroy your existing guests. + +``` +run.sh SSSD-SOURCE-DIR TEST-SUITE-DIR ARTIFACTS-DIR CONFIG-FILE + SSSD-SOURCE-DIR Path to SSSD source directory. + TEST-SUITE-DIR Path to sssd-test-suite_dir directory. + ARTIFACTS-DIR Path to directory where artifacts should be stored. + CONFIG-FILE Path to sssd-test-suite_dir configuration file to use. +``` + +At this moment only `client` guest is required. We need to expand our test cases to test agains FreeIPA and Active Directory. + +## SSSD CI Architecture + +Jenkins master polls github for new branches and pull requests. When it discovers new pull request or branch or changes to existing pull request or branch it will allocate a jenkins agent and executes pipeline defined in `./Jenkinsfile` (in SSSD source) on this agent. + +The pipeline executes `./contrib/test-suite/run.sh` and archives logs when testing is finished. Script `./contrib/test-suite/run.sh` prepares sssd-test-suite, starts the vagrant machines and copy SSSD source code to the client machine. Then it calls `./contrib/test-suite/run-client.sh` on the client machine which runs continuous integration tests. + +### Extending current tests +To extend current testing capabilities, modify `./contrib/test-suite/run.sh` and `./contrib/test-suite/run-client.sh` to new requirements. These files can be modified by anyone but are considered untrusted from contributor that is not an administrator of SSSD repository. This means that if a public contributor submits a pull request that changes those files, Jenkins will refuse to run tests. + +### Adding additional distribution to test on +You need to modify `./Jenkinsfile`. Simply copy, paste and amend existing Fedora 28 stage. This file is also considered untrusted so only administrators can modify it within a pull request. + +You also need to extend `sssd-test-suite` and prepare vagrant boxes for this distro. diff --git a/contrib/test-suite/run-client.sh b/contrib/test-suite/run-client.sh new file mode 100755 index 0000000000..3b9eb606fa --- /dev/null +++ b/contrib/test-suite/run-client.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# DO NOT RUN THIS MANUALLY +# + +sssd_source="/shared/sssd" +artifacts_dir="/shared/artifacts" + +archive-artifacts() { + echo "Archiving artifacts..." + + cp -f $sssd_source/ci-*.log $artifacts_dir + cp -f $sssd_source/ci-build-debug/ci-*.log $artifacts_dir + cp -f $sssd_source/ci-build-debug/test-suite.log $artifacts_dir +} + +success-or-die() { + ret=$1 + msg=$2 + if [ $ret -eq 0 ]; then + return 0 + fi + + echo $msg + archive-artifacts + + exit $ret +} + +cd $sssd_source + +echo "[1/1] Running Continuous Integration Tests" +./contrib/ci/run --moderate --no-deps +success-or-die $? "CI Failed!" + +archive-artifacts +exit 0 diff --git a/contrib/test-suite/run.sh b/contrib/test-suite/run.sh new file mode 100755 index 0000000000..bb4c06f59e --- /dev/null +++ b/contrib/test-suite/run.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +print-usage() { + cat <<EOF +Run SSSD Continuous Integration Tests +Make sure to checkout and setup https://github.com/SSSD/sssd-test-suite + +run.sh SSSD-SOURCE-DIR TEST-SUITE-DIR ARTIFACTS-DIR CONFIG-FILE + SSSD-SOURCE-DIR Path to SSSD source directory. + TEST-SUITE-DIR Path to sssd-test-suite_dir directory. + ARTIFACTS-DIR Path to directory where artifacts should be stored. + CONFIG-FILE Path to sssd-test-suite_dir configuration file to use. +EOF +} + +print-help-if-asked() { + while test $# -gt 0 + do + case "$1" in + --help) + print-usage ; exit 0 + ;; + -h) print-usage ; exit 0 + ;; + -?) print-usage ; exit 0 + ;; + esac + shift + done +} + +success-or-die() { + if [ $1 -ne 0 ]; then + echo $2 + exit 1 + fi +} + +print-help-if-asked "$@" +if [[ $# -ne 4 ]]; then + print-usage + exit 1 +fi + +sssd_source=$1 +suite_dir=$2 +artifacts_dir=$3 +config=$4 + +guest_source="/shared/sssd" +guest_artifacts="/shared/artifacts" + +# Currently only client machine is needed. +guests="client" + +run-vagrant() { + VAGRANT_CWD="$suite_dir" \ + SSSD_TEST_SUITE_RSYNC="$sssd_source:$guest_source" \ + SSSD_TEST_SUITE_SSHFS="$artifacts_dir:$guest_artifacts" \ + SSSD_TEST_SUITE_CONFIG="$config" \ + vagrant "$@" +} + +start-guest() { + # This may fail if guest's box was not yet downloaded. We will ignore it. + run-vagrant destroy $1 &> /dev/null + + run-vagrant box update $1 + success-or-die $? "Unable to update guest: $1" + + run-vagrant up $1 + success-or-die $? "Unable to start guest: $1" +} + +stop-guest() { + run-vagrant halt $1 + success-or-die $? "Unable to halt guest: $1" +} + +echo "[1/5] Creating $artifacts_dir" +mkdir -p "$artifacts_dir" +success-or-die $? "Unable to create directory: $artifacts_dir" + +echo "[2/5] Updating sssd-test-suite" +git -C "$suite_dir" pull --rebase +success-or-die $? "Unable to rebase sssd-test-suite at: $suite_dir" + +echo "[3/5] Preparing vagrant machines" +for guest in $guests; do + start-guest $guest +done + +echo "[4/5] Running tests" +run-vagrant ssh client -- "$guest_source/contrib/test-suite/run-client.sh" +success-or-die $? "SSSD Test Suite Failed: $?" + +echo "[5/5] Shutdown machines" +for guest in $guests; do + stop-guest $guest +done
_______________________________________________ sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org