From fbde3269acc576d32b6e44b66c5f65b62230da28 Mon Sep 17 00:00:00 2001 From: James Molet Date: Oct 19 2018 14:02:30 +0000 Subject: PR testing --- diff --git a/Jenkinsfile b/Jenkinsfile index 8c1641c..8300faa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -109,168 +109,6 @@ node('fedora-28') { ) } } -node('docker') { - checkout scm - stage('Build Docker container') { - unarchive mapping: ['mock-result/f28/': '.'] - def f28_rpm = findFiles(glob: 'mock-result/f28/**/*.noarch.rpm')[0] - def appversion = sh(returnStdout: true, script: """ - rpm2cpio ${f28_rpm} | \ - cpio --quiet --extract --to-stdout ./usr/lib/python3\\*/site-packages/greenwave\\*.egg-info/PKG-INFO | \ - awk '/^Version: / {print \$2}' - """).trim() - /* Git builds will have a version like 0.3.2.dev1+git.3abbb08 following - * the rules in PEP440. But Docker does not let us have + in the tag - * name, so let's munge it here. */ - appversion = appversion.replace('+', '-') - docker.withRegistry( - 'https://docker-registry.engineering.redhat.com/', - 'docker-registry-factory2-builder-sa-credentials') { - /* Note that the docker.build step has some magic to guess the - * Dockerfile used, which will break if the build directory (here ".") - * is not the final argument in the string. */ - def image = docker.build "factory2/greenwave:internal-${appversion}", "--build-arg greenwave_rpm=$f28_rpm --build-arg cacert_url=https://password.corp.redhat.com/RH-IT-Root-CA.crt ." - /* Pushes to the internal registry can sometimes randomly fail - * with "unknown blob" due to a known issue with the registry - * storage configuration. So we retry up to 3 times. */ - retry(3) { - image.push() - } - } - /* Build and push the same image with the same tag to quay.io, but without the cacert. */ - docker.withRegistry( - 'https://quay.io/', - 'quay-io-factory2-builder-sa-credentials') { - def image = docker.build "factory2/greenwave:${appversion}", "--build-arg greenwave_rpm=$f28_rpm ." - image.push() - } - /* Save container version for later steps (this is ugly but I can't find anything better...) */ - writeFile file: 'appversion', text: appversion - archiveArtifacts artifacts: 'appversion' - } -} - -node('fedora-28') { - checkout scm - - /* Install packages needed by the functional tests. */ - sh 'sudo dnf -y install python3-pytest python3-requests python3-sqlalchemy python3-gunicorn' - - /* Also need to install Greenwave's dependencies, since we are running it - * locally not in Openshift for now. */ - sh 'sudo dnf -y builddep greenwave.spec' - - def openshiftHost = 'greenwave-test.cloud.upshift.engineering.redhat.com' - def buildTag = "${env.BUILD_TAG}".replace('jenkins-','') - def waiverdbURL = "waiverdb-test-${buildTag}-web-${openshiftHost}" - def resultsdbURL = "resultsdb-test-${buildTag}-api-${openshiftHost}" - - def resultsdbRepo = 'https://pagure.io/taskotron/resultsdb/raw/develop/f/openshift' - def resultsdbTemplate = 'resultsdb-test-template.yaml' - sh "curl ${resultsdbRepo}/${resultsdbTemplate} > openshift/${resultsdbTemplate}" - - def waiverdbRepo = 'https://pagure.io/waiverdb/raw/master/f/openshift' - def waiverdbTemplate = 'waiverdb-test-template.yaml' - sh "curl ${waiverdbRepo}/${waiverdbTemplate} > openshift/${waiverdbTemplate}" - - stage('Perform functional tests') { - openshift.withCluster('Upshift') { - openshift.withCredentials('upshift-greenwave-test-jenkins-credentials') { - openshift.withProject('greenwave-test') { - def rtemplate = readYaml file: 'openshift/resultsdb-test-template.yaml' - // TODO: move this image to the factory2 project in the docker registry - def resultsdbImage = 'docker-registry.engineering.redhat.com/csomh/resultsdb:latest' - def resultsdbModels = openshift.process( - rtemplate, - '-p', "TEST_ID=${buildTag}", - '-p', "RESULTSDB_IMAGE=${resultsdbImage}", - '-p', "RESULTSDB_ADDITIONAL_RESULT_OUTCOMES=\"('RUNNING','QUEUED')\"" - ) - def wtemplate = readYaml file: 'openshift/waiverdb-test-template.yaml' - def waiverdbModels = openshift.process( - wtemplate, - '-p', "TEST_ID=${buildTag}", - '-p', 'WAIVERDB_APP_VERSION=latest', - '-p', "RESULTSDB_API_URL=${resultsdbURL}", - '-p', "WAIVERDB_REPLICAS=1" - ) - def environment_label = "test-${buildTag}" - try { - openshift.create(resultsdbModels) - openshift.create(waiverdbModels) - echo "Waiting for pods with label environment=${environment_label} to become Ready" - def pods = openshift.selector('pods', ['environment': environment_label]) - timeout(10) { - pods.untilEach(5) { - def conds = it.object().status.conditions - for (int i = 0; i < conds.size(); i++) { - if (conds[i].type == 'Ready' && conds[i].status == 'True') { - return true - } - } - return false - } - } - - def route_hostname = waiverdbURL - echo "Fetching CA chain for https://${route_hostname}/" - def ca_chain = sh(returnStdout: true, script: """openssl s_client \ - -connect ${route_hostname}:443 \ - -servername ${route_hostname} -showcerts < /dev/null | \ - awk 'BEGIN {first_cert=1; in_cert=0}; - /BEGIN CERTIFICATE/ { if (first_cert == 1) first_cert = 0; else in_cert = 1 }; - { if (in_cert) print }; - /END CERTIFICATE/ { in_cert = 0 }'""") - writeFile(file: "${env.WORKSPACE}/ca-chain.crt", text: ca_chain) - echo "Wrote CA certificate chain to ${env.WORKSPACE}/ca-chain.crt" - - withEnv(["GREENWAVE_CONFIG=${env.WORKSPACE}/conf/settings.py.example" - ,"PYTHONPATH=." - ,"REQUESTS_CA_BUNDLE=${env.WORKSPACE}/ca-chain.crt" - ,"WAIVERDB_TEST_URL=https://${waiverdbURL}/" - ,"RESULTSDB_TEST_URL=https://${resultsdbURL}/"]) { - sh 'py.test-3 -v --junitxml=junit-functional-tests.xml functional-tests/' - } - junit 'junit-functional-tests.xml' - } finally { - /* Extract logs for debugging purposes */ - openshift.selector('deploy,pods', ['environment': environment_label]).logs() - /* Tear down everything we just created */ - openshift.selector('dc,deploy,configmap,secret,svc,route', - ['environment': environment_label]).delete() - } - } - } - } - } -} - -node('docker') { - checkout scm - if (scmVars.GIT_BRANCH == 'origin/master') { - stage('Tag "latest".') { - unarchive mapping: ['appversion': 'appversion'] - def appversion = readFile('appversion').trim() - docker.withRegistry( - 'https://docker-registry.engineering.redhat.com/', - 'docker-registry-factory2-builder-sa-credentials') { - def image = docker.image("factory2/greenwave:internal-${appversion}") - /* Pushes to the internal registry can sometimes randomly fail - * with "unknown blob" due to a known issue with the registry - * storage configuration. So we retry up to 3 times. */ - retry(3) { - image.push('latest') - } - } - docker.withRegistry( - 'https://quay.io/', - 'quay-io-factory2-builder-sa-credentials') { - def image = docker.image("factory2/greenwave:${appversion}") - image.push('latest') - } - } - } -} } // end of timestamps } catch (e) {