X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=scripts%2Flttng-modules%2Fmaster.groovy;h=20b2f48712eaca740946e86132c14800c05606d0;hb=417251718144a9f5ab350abe6a15aca660819ab9;hp=74d885c299ada4dea08407f0edd5e1404789619a;hpb=f3d8604b477b84631d624aed305afdd944ffa5c6;p=lttng-ci.git diff --git a/scripts/lttng-modules/master.groovy b/scripts/lttng-modules/master.groovy index 74d885c..20b2f48 100644 --- a/scripts/lttng-modules/master.groovy +++ b/scripts/lttng-modules/master.groovy @@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 - Michael Jeanson + * Copyright (C) 2016-2017 - Michael Jeanson * * 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 @@ -23,20 +23,44 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib.Ref -class kVersion implements Comparable { +class InvalidKVersionException extends Exception { + public InvalidKVersionException(String message) { + super(message) + } +} + +class EmptyKVersionException extends Exception { + public EmptyKVersionException(String message) { + super(message) + } +} + +class VanillaKVersion implements Comparable { - Integer major = 0; - Integer majorB = 0; - Integer minor = 0; - Integer patch = 0; - Integer rc = Integer.MAX_VALUE; + Integer major = 0 + Integer majorB = 0 + Integer minor = 0 + Integer patch = 0 + Integer rc = Integer.MAX_VALUE - kVersion() {} + VanillaKVersion() {} - kVersion(version) { + VanillaKVersion(version) { this.parse(version) } + static VanillaKVersion minKVersion() { + return new VanillaKVersion("v0.0.0") + } + + static VanillaKVersion maxKVersion() { + return new VanillaKVersion("v" + Integer.MAX_VALUE + ".0.0") + } + + static VanillaKVersion factory(version) { + return new VanillaKVersion(version) + } + def parse(version) { this.major = 0 this.majorB = 0 @@ -44,9 +68,13 @@ class kVersion implements Comparable { this.patch = 0 this.rc = Integer.MAX_VALUE + if (!version) { + throw new EmptyKVersionException("Empty kernel version") + } + def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/ if (!match) { - throw new Exception("Invalid kernel version: ${version}") + throw new InvalidKVersionException("Invalid kernel version: ${version}") } Integer offset = 0; @@ -79,21 +107,36 @@ class kVersion implements Comparable { return this.rc != Integer.MAX_VALUE } - @Override int compareTo(kVersion o) { + // Return true if both version are of the same stable branch + Boolean isSameStable(VanillaKVersion o) { + if (this.major != o.major) { + return false + } + if (this.majorB != o.majorB) { + return false + } + if (this.minor != o.minor) { + return false + } + + return true + } + + @Override int compareTo(VanillaKVersion o) { if (this.major != o.major) { - return Integer.compare(this.major, o.major); + return Integer.compare(this.major, o.major) } if (this.majorB != o.majorB) { - return Integer.compare(this.majorB, o.majorB); + return Integer.compare(this.majorB, o.majorB) } if (this.minor != o.minor) { - return Integer.compare(this.minor, o.minor); + return Integer.compare(this.minor, o.minor) } if (this.patch != o.patch) { - return Integer.compare(this.patch, o.patch); + return Integer.compare(this.patch, o.patch) } if (this.rc != o.rc) { - return Integer.compare(this.rc, o.rc); + return Integer.compare(this.rc, o.rc) } // Same version @@ -120,13 +163,152 @@ class kVersion implements Comparable { } } +class UbuntuKVersion implements Comparable { + + Integer major = 0 + Integer minor = 0 + Integer patch = 0 + Integer umajor = 0 + Integer uminor = 0 + String suffix = "" + Boolean isLTS = false + + UbuntuKVersion() {} + + UbuntuKVersion(version) { + this.parse(version) + } + + static UbuntuKVersion minKVersion() { + return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0") + } + + static UbuntuKVersion maxKVersion() { + return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0") + } + + static UbuntuKVersion factory(version) { + return new UbuntuKVersion(version) + } + + def parse(version) { + this.major = 0 + this.minor = 0 + this.patch = 0 + this.umajor = 0 + this.uminor = 0 + this.suffix = ""; + this.isLTS = false + + if (!version) { + throw new EmptyKVersionException("Empty kernel version") + } + + //'Ubuntu-lts-4.8.0-27.29_16.04.1', + //'Ubuntu-4.4.0-70.91', + def match = version =~ /^Ubuntu-(lts-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/ + if (!match) { + throw new InvalidKVersionException("Invalid kernel version: ${version}") + } + + this.isLTS = match.group(1) != null + + // Major + this.major = Integer.parseInt(match.group(2)) + + // Minor + this.minor = Integer.parseInt(match.group(3)) + + // Patch level + this.patch = Integer.parseInt(match.group(4)) + + // Ubuntu major + this.umajor = Integer.parseInt(match.group(5)) + + // Ubuntu minor + this.uminor = Integer.parseInt(match.group(6)) + + if (match.group(7) != null) { + this.suffix = match.group(7) + } + } + + // Return true if this version is a release candidate + Boolean isRC() { + return false + } + + // Return true if both version are of the same stable branch + Boolean isSameStable(UbuntuKVersion o) { + if (this.isLTS != o.isLTS) { + return false + } + if (this.major != o.major) { + return false + } + if (this.minor != o.minor) { + return false + } + if (this.patch != o.patch) { + return false + } + + return true + } + + @Override int compareTo(UbuntuKVersion o) { + if (this.major != o.major) { + return Integer.compare(this.major, o.major) + } + if (this.minor != o.minor) { + return Integer.compare(this.minor, o.minor) + } + if (this.patch != o.patch) { + return Integer.compare(this.patch, o.patch) + } + if (this.umajor != o.umajor) { + return Integer.compare(this.umajor, o.umajor) + } + if (this.uminor != o.uminor) { + return Integer.compare(this.uminor, o.uminor) + } + if (this.isLTS != o.isLTS) { + if (o.isLTS) { + return 1 + } else { + return -1 + } + } + + // Same version + return 0; + } + + String toString() { + String vString = "Ubuntu-" + + if (this.isLTS) { + vString = vString.concat("lts-") + } + + vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}") + + return vString + } +} + // Retrieve parameters of the current build def mversion = build.buildVariableResolver.resolve('mversion') def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild') def kgitrepo = build.buildVariableResolver.resolve('kgitrepo') -def kverfloor = new kVersion(build.buildVariableResolver.resolve('kverfloor')) +def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor') +def kverceil_raw = build.buildVariableResolver.resolve('kverceil') +def kverfilter = build.buildVariableResolver.resolve('kverfilter') +def uversion = build.buildVariableResolver.resolve('uversion') def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob')) +def currentJobName = build.project.getFullDisplayName() + // Get the out variable def config = new HashMap() @@ -134,8 +316,6 @@ def bindings = getBinding() config.putAll(bindings.getVariables()) def out = config['out'] -def jlc = new jenkins.model.JenkinsLocationConfiguration() -def jenkinsUrl = jlc.url // Get tags from git repository def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call(); @@ -143,17 +323,80 @@ def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call(); // Get kernel versions to build def kversions = [] def kversionsRC = [] -for (ref in refs) { - def match = ref.getName() =~ /^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/ +def matchStrs = [] +def blacklist = [] +def kversionFactory = "" + +if (uversion != null) { + kversionFactory = new UbuntuKVersion() + switch (uversion) { + case 'bionic': + matchStrs = [ + ~/^refs\/tags\/(Ubuntu-4\.15\.0-\d{1,3}?\.[\d]+)$/, + ] + break + + case 'xenial': + matchStrs = [ + ~/^refs\/tags\/(Ubuntu-4\.4\.0-\d{1,3}?\.[\d]+)$/, + ~/^refs\/tags\/(Ubuntu-lts-4\.8\.0-.*_16\.04\.\d+)$/, + ~/^refs\/tags\/(Ubuntu-lts-4\.10\.0-.*_16\.04\.\d+)$/, + ~/^refs\/tags\/(Ubuntu-lts-4\.15\.0-.*_16\.04\.\d+)$/, + ] + + blacklist = [ + 'Ubuntu-lts-4.10.0-7.9_16.04.1', + ] + break + + case 'trusty': + matchStrs = [ + ~/^refs\/tags\/(Ubuntu-3\.13\.0-[\d\.]+)$/, + ~/^refs\/tags\/(Ubuntu-lts-.*_14\.04\.\d+)$/, + ] + break + + default: + println "Unsupported Ubuntu version: ${uversion}" + throw new InterruptedException() + break + } +} else { + // Vanilla + kversionFactory = new VanillaKVersion() + matchStrs = [ + ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/, + ] +} - if (match) { - def v = new kVersion(match.group(1)) +// Parse kernel versions +def kverfloor = "" +try { + kverfloor = kversionFactory.factory(kverfloor_raw) +} catch (EmptyKVersionException e) { + kverfloor = kversionFactory.minKVersion() +} - if (v >= kverfloor) { - if (v.isRC()) { - kversionsRC.add(v) - } else { - kversions.add(v) +def kverceil = "" +try { + kverceil = kversionFactory.factory(kverceil_raw) +} catch (EmptyKVersionException e) { + kverceil = kversionFactory.maxKVersion() +} + +// Build a sorted list of versions to build +for (ref in refs) { + for (matchStr in matchStrs) { + def match = ref.getName() =~ matchStr + if (match && !blacklist.contains(match.group(1))) { + def v = kversionFactory.factory(match.group(1)) + + if ((v >= kverfloor) && (v < kverceil)) { + if (v.isRC()) { + kversionsRC.add(v) + } else { + kversions.add(v) + } } } } @@ -162,12 +405,35 @@ for (ref in refs) { kversions.sort() kversionsRC.sort() +switch (kverfilter) { + case 'stable-head': + // Keep only the head of each stable branch + println('Filter kernel versions to keep only the latest point release of each stable branch.') + + for (i = 0; i < kversions.size(); i++) { + def curr = kversions[i] + def next = i < kversions.size() - 1 ? kversions[i + 1] : null + + if (next != null) { + if (curr.isSameStable(next)) { + kversions.remove(i) + i-- + } + } + } + break + + default: + // No filtering of kernel versions + println('No kernel versions filtering selected.') + break +} + // If the last RC version is newer than the last stable, add it to the build list -if (kversionsRC.last() > kversions.last()) { +if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) { kversions.add(kversionsRC.last()) } -// Debug println "Building the following kernel versions:" for (k in kversions) { println k @@ -182,6 +448,7 @@ def allBuilds = [] def ongoingBuild = [] def failedRuns = [] def isFailed = false +def similarJobQueued = 0; // Loop while we have kernel versions remaining or jobs running while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { @@ -190,7 +457,7 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { def kversion = kversions.pop() def job_params = [ new StringParameterValue('mversion', mversion), - new StringParameterValue('kversion', kversion.toString()), + new StringParameterValue('ktag', kversion.toString()), new StringParameterValue('kgitrepo', kgitrepo), ] @@ -205,7 +472,7 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size() try { - Thread.sleep(5000) + Thread.sleep(10000) } catch(e) { if (e in InterruptedException) { build.setResult(hudson.model.Result.ABORTED) @@ -215,6 +482,13 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { } } + // Abort job if a newer instance is queued + similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName} + if ( similarJobQueued > 0 ) { + build.setResult(hudson.model.Result.ABORTED) + throw new InterruptedException() + } + def i = ongoingBuild.iterator() while ( i.hasNext() ) { currentBuild = i.next() @@ -225,7 +499,7 @@ while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { // Print results def matrixParent = currentBuild.get() allBuilds.add(matrixParent) - def kernelStr = matrixParent.buildVariableResolver.resolve("kversion") + def kernelStr = matrixParent.buildVariableResolver.resolve("ktag") println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}" // Process child runs of matrixBuild @@ -251,19 +525,17 @@ for (failedRun in failedRuns) { println "---Build report---" for (b in allBuilds) { - def kernelStr = b.buildVariableResolver.resolve("kversion") + def kernelStr = b.buildVariableResolver.resolve("ktag") println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}" -} - -// Clean all builds -// TODO: Delete only builds generated from this job run -for (b in job.getBuilds()) { - b.delete() + // Cleanup builds + try { + b.delete() + } catch (all) {} } // Mark this build failed if any child build has failed if (isFailed) { - build.getExecutor().interrupt(Result.FAILURE) + build.setResult(hudson.model.Result.FAILURE) } // EOF