David Caro has uploaded a new change for review.

Change subject: Added db upgrade job
......................................................................

Added db upgrade job

I had to add also some extra files:

* support to upgrade from or to a branch
* whitelist scripts, triggers, builder and publisher
* generic gerrit scm

Change-Id: Iae2aaf97d330757441872586aa844ab07cd42f36
Signed-off-by: David Caro <dcaro...@redhat.com>
---
A jobs/confs/groovy-scripts/whitelist-filter.groovy
A jobs/confs/shell-scripts/ovirt-engine_upgrade-db.cleanup.sh
A jobs/confs/shell-scripts/ovirt-engine_upgrade-db.sh
A jobs/confs/shell-scripts/whitelist-filter.sh
A jobs/confs/yaml/builders/ovirt-engine_upgrade-db.yaml
A jobs/confs/yaml/builders/whitelist.yaml
A jobs/confs/yaml/jobs/ovirt-engine/ovirt-engine_upgrade-db.yaml
A jobs/confs/yaml/publishers/whitelist.yaml
A jobs/confs/yaml/scms/gerrit.yaml
A jobs/confs/yaml/templates/engine-upgrade-db.yaml
M jobs/confs/yaml/triggers/gerrit.yaml
11 files changed, 272 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/06/34706/1

diff --git a/jobs/confs/groovy-scripts/whitelist-filter.groovy 
b/jobs/confs/groovy-scripts/whitelist-filter.groovy
new file mode 100644
index 0000000..90f93c3
--- /dev/null
+++ b/jobs/confs/groovy-scripts/whitelist-filter.groovy
@@ -0,0 +1,5 @@
+//Set proper status when user not in whitelist
+import hudson.model.*
+if(manager.logContains(".*NOT FOUND IN THE WHITELIST.*")) {
+  manager.build.setResult(Result.NOT_BUILT)
+}
diff --git a/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.cleanup.sh 
b/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.cleanup.sh
new file mode 100644
index 0000000..c5795d3
--- /dev/null
+++ b/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.cleanup.sh
@@ -0,0 +1,6 @@
+#!/bin/bash -x
+echo "shell-scripts/ovirt-engine_upgrade-db.cleanup.sh"
+
+DBNAME="${{JOB_NAME//[\/=]/_}}_${{BUILD_NUMBER}}"
+echo "Dropping db  ${{DBNAME}}"
+sudo -u postgres dropdb "$DBNAME"
diff --git a/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.sh 
b/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.sh
new file mode 100644
index 0000000..b34bb97
--- /dev/null
+++ b/jobs/confs/shell-scripts/ovirt-engine_upgrade-db.sh
@@ -0,0 +1,71 @@
+#!/bin/bash -xe
+echo "shell-scripts/ovirt-engine_upgrade-db.sh"
+#
+# Parameters:
+#
+# test-branch
+#   Branch that is being tested (the one that was not chekced out by jenkins)
+#
+# action
+#   If we are upgrading from test-branch or to test-branch, accepts the strings
+#   'to' and 'from'
+#
+
+TEST_BRANCH="{test-branch}"
+ACTION="{action}"
+ACTION="${{ACTION?No action passed}}"
+
+cd "$WORKSPACE"/ovirt-engine
+
+### get current HEAD ###
+cur_head="$(git rev-parse HEAD)"
+
+if [[ "$ACTION"  == 'from' ]]; then
+    git reset --hard "origin/$TEST_BRANCH"
+    git clean -dxf
+fi
+
+### create db #####
+DBNAME="${{JOB_NAME//[\/=]/_}}_${{BUILD_NUMBER}}"
+
+echo "INFO::CREATING DATABASE"
+sudo -u postgres createdb \
+    "$DBNAME" \
+    -e \
+    -E UTF8 \
+    --lc-collate en_US.UTF8 \
+    --lc-ctype en_US.UTF8 \
+    -T template0 \
+    -O engine \
+> /dev/null
+echo "INFO::DATABASE CREATED"
+
+# make sure we have user and access
+
+echo "INFO::POPULATING DATABASE"
+./packaging/dbscripts/schema.sh \
+    -c apply \
+    -u engine \
+    -d "$DBNAME"
+echo "INFO::DATABASE POPULATED"
+
+### upgrade ####
+cd "$WORKSPACE"/ovirt-engine
+if [[ "$ACTION"  == 'from' ]]; then
+    git reset --hard "$cur_head"
+else
+    git reset --hard origin/"$TEST_BRANCH"
+fi
+git clean -dxf
+
+echo "INFO::Verifying that upgrade script is re-entrant ..."
+./packaging/dbscripts/schema.sh \
+    -c apply \
+    -u engine \
+    -d "$DBNAME"
+
+#Go back o original code, just in case
+git reset --hard "$cur_head"
+git clean -dxf
+
+exit 0
diff --git a/jobs/confs/shell-scripts/whitelist-filter.sh 
b/jobs/confs/shell-scripts/whitelist-filter.sh
new file mode 100644
index 0000000..8f6589f
--- /dev/null
+++ b/jobs/confs/shell-scripts/whitelist-filter.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+echo "shell-scripts/whitelist-filter.sh"
+#
+# Fails the build if it was triggered by a non-whitelisted commiter
+#
+
+# Check whitelist
+if ! [[ -z "$GERRIT_PATCHSET_UPLOADER_EMAIL" ]] \
+    && [[ "@redhat.com" != "${{GERRIT_PATCHSET_UPLOADER_EMAIL: -11}}" ]] \
+    && ! egrep -q \
+             -e "^$GERRIT_PATCHSET_UPLOADER_EMAIL\$" \
+             jenkins-whitelist/jenkins-whitelist.txt; then
+   echo "USER $GERRIT_PATCHSET_UPLOADER_EMAIL NOT FOUND IN THE WHITELIST, NOT 
RUNNING"
+   exit 1
+fi
diff --git a/jobs/confs/yaml/builders/ovirt-engine_upgrade-db.yaml 
b/jobs/confs/yaml/builders/ovirt-engine_upgrade-db.yaml
new file mode 100644
index 0000000..9f0eebd
--- /dev/null
+++ b/jobs/confs/yaml/builders/ovirt-engine_upgrade-db.yaml
@@ -0,0 +1,18 @@
+# Upgrades the engine database from one branch to another
+#
+# The original branch should be already in the $WORKSPACE/ovirt-engine
+# directory, probably using the scm plugin
+#
+# Prameters:
+#
+# test-branch
+#
+#   branch to upgrade to or from, will use it's HEAD
+#
+# action
+#   What to do with the test branch, update from or to it (values: to|from)
+#
+- builder:
+    name: ovirt-engine_upgrade-db
+    builders:
+      - shell: !include-raw shell-scripts/ovirt-engine_upgrade-db.sh
diff --git a/jobs/confs/yaml/builders/whitelist.yaml 
b/jobs/confs/yaml/builders/whitelist.yaml
new file mode 100644
index 0000000..eace730
--- /dev/null
+++ b/jobs/confs/yaml/builders/whitelist.yaml
@@ -0,0 +1,11 @@
+# Fails the build if the commiter is not in the whitelist, does
+# nothing otherwise or if not started by gerrit.
+#
+# You should use the whitelist publisher and a whitelist aware trigger
+# to get the full functionality (set status as aborted, and send a
+# message to gerrit)
+#
+- builder:
+    name: whitelist
+    builders:
+        - shell: !include-raw shell-scripts/whitelist-filter.sh
diff --git a/jobs/confs/yaml/jobs/ovirt-engine/ovirt-engine_upgrade-db.yaml 
b/jobs/confs/yaml/jobs/ovirt-engine/ovirt-engine_upgrade-db.yaml
new file mode 100644
index 0000000..9579031
--- /dev/null
+++ b/jobs/confs/yaml/jobs/ovirt-engine/ovirt-engine_upgrade-db.yaml
@@ -0,0 +1,19 @@
+#
+# Upgrade from or to test-version
+#
+- project:
+    name: ovirt-engine_upgrade-db
+    project:
+      - ovirt-engine
+    trigger:
+      - merged
+    version:
+      - master:
+          branch: 'master'
+    test-version:
+      - 3.5:
+          test-branch: 'ovirt-engine-3.5'
+    action:
+      - from
+    jobs:
+      - 'ovirt-engine_{version}_upgrade-db-{action}-{test-version}_{trigger}'
diff --git a/jobs/confs/yaml/publishers/whitelist.yaml 
b/jobs/confs/yaml/publishers/whitelist.yaml
new file mode 100644
index 0000000..2c8e856
--- /dev/null
+++ b/jobs/confs/yaml/publishers/whitelist.yaml
@@ -0,0 +1,4 @@
+- publisher:
+    name: whitelist
+    publishers:
+        - groovy-postbuild: !include-raw groovy-scripts/whitelist-filter.groovy
diff --git a/jobs/confs/yaml/scms/gerrit.yaml b/jobs/confs/yaml/scms/gerrit.yaml
new file mode 100644
index 0000000..c6c257f
--- /dev/null
+++ b/jobs/confs/yaml/scms/gerrit.yaml
@@ -0,0 +1,23 @@
+# Gerrit aware scm
+#
+# Parameters:
+#
+# project
+#   Name of the project to clone
+#
+- scm:
+    name: gerrit
+    scm:
+      - git:
+          url: 'git://gerrit.ovirt.org/{project}.git'
+          branches:
+            - $GERRIT_BRANCH
+          basedir: '{project}'
+          scm-name: '{project}'
+          name: ''
+          refspec: $GERRIT_REFSPEC
+          choosing-strategy: gerrit
+          use-author: true
+          skip-tag: true
+          prune: true
+          wipe-workspace: false
diff --git a/jobs/confs/yaml/templates/engine-upgrade-db.yaml 
b/jobs/confs/yaml/templates/engine-upgrade-db.yaml
new file mode 100644
index 0000000..3036702
--- /dev/null
+++ b/jobs/confs/yaml/templates/engine-upgrade-db.yaml
@@ -0,0 +1,53 @@
+#
+# Parameters:
+#
+# version
+#   Version tag of the job, as 3.5, 3.4, master...
+#
+# to-version
+#   Version tag to upgrade to, usually version + 1
+#
+# trigger
+#   Type of trigger event, should be created or merged (to trigger on
+#   patchset created or patchset merged respectively)
+#
+# branch
+#   Full name of the branch to build from, for example ovirt-3.5
+#
+# test-branch
+#   Full name of the destination branch to upsgreade to ro from, for
+#   example ovirt-3.6
+#
+# trigger-files
+#    regext for the files this job should trigger on
+#
+# action
+#    What to do with test-branch, upgrade from or to it (values: from|to)
+#
+- job-template:
+    name: 'ovirt-engine_{version}_upgrade-db-{action}-{test-version}_{trigger}'
+    parameters:
+      - gerrit-params:
+          branch: '{branch}'
+    scm:
+      - gerrit:
+          project: 'ovirt-engine'
+      - jenkins:
+          branch: master
+    triggers:
+      - on-patch-{trigger}-with-files-whitelist:
+          project: 'ovirt-engine'
+          branch: '{branch}'
+          files: '.*/packaging/dbscripts/.*'
+    builders:
+      - whitelist
+      - ovirt-engine_upgrade-db:
+          test-branch: '{test-branch}'
+          action: '{action}'
+    publishers:
+      - whitelist
+      - post-tasks:
+          - matches:
+              - log-text: '.*INFO::DATABASE CREATED.*'
+                operator: AND
+            script: !include-raw 
shell-scripts/ovirt-engine_upgrade-db.cleanup.sh
diff --git a/jobs/confs/yaml/triggers/gerrit.yaml 
b/jobs/confs/yaml/triggers/gerrit.yaml
index f161194..2756a47 100644
--- a/jobs/confs/yaml/triggers/gerrit.yaml
+++ b/jobs/confs/yaml/triggers/gerrit.yaml
@@ -55,3 +55,50 @@
                   file-paths:
                     - compare-type: REG_EXP
                       pattern: '{files}'
+
+- trigger:
+    name: on-patch-created-with-files-whitelist
+    triggers:
+      - gerrit:
+            trigger-on-patchset-uploaded-event: true
+            escape-quotes: true
+            projects:
+                - project-compare-type: 'PLAIN'
+                  project-pattern: '{project}'
+                  branches:
+                    - branch-compare-type: 'PLAIN'
+                      branch-pattern: '{branch}'
+                  file-paths:
+                    - compare-type: REG_EXP
+                      pattern: '{files}'
+            notbuilt-message: |
+              To avoid overloading the infrastructure, a whitelist for
+              running gerrit triggered jobs has been set in place, if
+              you feel like you should be in it, please contact infra at
+              ovirt dot org.
+            skip-vote:
+              notbuilt: true
+
+
+- trigger:
+    name: on-patch-merged-with-files-whitelist
+    triggers:
+      - gerrit:
+            trigger-on-change-merged-event: true
+            escape-quotes: true
+            projects:
+                - project-compare-type: 'PLAIN'
+                  project-pattern: '{project}'
+                  branches:
+                    - branch-compare-type: 'PLAIN'
+                      branch-pattern: '{branch}'
+                  file-paths:
+                    - compare-type: REG_EXP
+                      pattern: '{files}'
+            notbuilt-message: |
+              To avoid overloading the infrastructure, a whitelist for
+              running gerrit triggered jobs has been set in place, if
+              you feel like you should be in it, please contact infra at
+              ovirt dot org.
+            skip-vote:
+              notbuilt: true


-- 
To view, visit http://gerrit.ovirt.org/34706
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae2aaf97d330757441872586aa844ab07cd42f36
Gerrit-PatchSet: 1
Gerrit-Project: jenkins
Gerrit-Branch: master
Gerrit-Owner: David Caro <dcaro...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to