[gnome-ostree] build/qa: Make disk generation work



commit f8fbb82e80ed6c5d6b4e55c5ec852b4a12d93a79
Author: Colin Walters <walters verbum org>
Date:   Mon Jan 28 17:15:44 2013 -0500

    build/qa: Make disk generation work
    
    The main change here is that we have it read the last build, and use
    those exact revisions.

 Makefile-ostbuild.am                               |    2 +-
 .../builtins/{qa_build_disks.js => build_disks.js} |   51 +++++++++++----
 src/ostbuild/js/builtins/qa_make_disk.js           |   43 +-------------
 src/ostbuild/js/builtins/qa_pull_deploy.js         |    3 +-
 src/ostbuild/js/libqa.js                           |   64 ++++++++++++++++++-
 src/ostbuild/js/main.js                            |    2 +-
 6 files changed, 102 insertions(+), 63 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index c36bfcb..ef0ef1f 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -61,9 +61,9 @@ jsostbuiltinsdir=$(jsostbuilddir)/builtins
 jsostbuiltins_DATA= \
 	src/ostbuild/js/builtins/autobuilder.js \
 	src/ostbuild/js/builtins/build.js \
+	src/ostbuild/js/builtins/build_disks.js \
 	src/ostbuild/js/builtins/checkout.js \
 	src/ostbuild/js/builtins/git_mirror.js \
-	src/ostbuild/js/builtins/qa_build_disks.js \
 	src/ostbuild/js/builtins/qa_make_disk.js \
 	src/ostbuild/js/builtins/qa_pull_deploy.js \
 	src/ostbuild/js/builtins/qa_smoketest.js \
diff --git a/src/ostbuild/js/builtins/qa_build_disks.js b/src/ostbuild/js/builtins/build_disks.js
similarity index 58%
rename from src/ostbuild/js/builtins/qa_build_disks.js
rename to src/ostbuild/js/builtins/build_disks.js
index 41be72c..dccafeb 100644
--- a/src/ostbuild/js/builtins/qa_build_disks.js
+++ b/src/ostbuild/js/builtins/build_disks.js
@@ -27,22 +27,33 @@ const Builtin = imports.builtin;
 const ArgParse = imports.argparse;
 const ProcUtil = imports.procutil;
 const LibQA = imports.libqa;
+const JsonDB = imports.jsondb;
 const Config = imports.config;
 const JsonUtil = imports.jsonutil;
 const GuestFish = imports.guestfish;
 
 const loop = GLib.MainLoop.new(null, true);
 
-const QaBuildDisks = new Lang.Class({
-    Name: 'QaBuildDisks',
+const BuildDisks = new Lang.Class({
+    Name: 'BuildDisks',
     Extends: Builtin.Builtin,
 
     DESCRIPTION: "Generate disk images",
 
     execute: function(args, loop, cancellable) {
         this._initPrefix(null);
-	      this._buildDataPath = this.workdir.get_child(this.prefix + '-buildresult.json');
-	      this._buildData = JsonUtil.loadJson(this._buildDataPath, cancellable);
+
+	      this.imageDir = this.workdir.get_child('images').get_child(this.prefix);
+	      this.currentImageLink = this.imageDir.get_child('current');
+	      this.previousImageLink = this.imageDir.get_child('previous');
+        GSystem.file_ensure_directory(this.imageDir, true, cancellable);
+
+	      let buildresultDir = this.workdir.get_child('builds').get_child(this.prefix);
+	      let builddb = new JsonDB.JsonDB(buildresultDir);
+
+        let latestPath = builddb.getLatestPath();
+        let buildVersion = builddb.parseVersionStr(latestPath.get_basename());
+        this._buildData = builddb.loadFromPath(latestPath, cancellable);
 
 	      let targets = this._buildData['targets'];
 
@@ -51,29 +62,41 @@ const QaBuildDisks = new Lang.Class({
 	      // assumption that the trees are relatively close, so we avoid
 	      // copying data via libguestfs repeatedly.
 	      let defaultTarget = this._buildData['snapshot']['default-target'];
+        let defaultRevision = this._buildData['targets'][defaultTarget];
 	      this._defaultDiskPath = this._diskPathForTarget(defaultTarget, false);
 
+        let tmppath = this._defaultDiskPath.get_parent().get_child(this._defaultDiskPath.get_basename() + '.tmp');
+        GSystem.shutil_rm_rf(tmppath, cancellable);
+
 	      if (!this._defaultDiskPath.query_exists(null)) {
-	          ProcUtil.runSync(['ostbuild', 'qa-make-disk', this._defaultDiskPath.get_path()],
-                             cancellable);
-	      }
+            LibQA.createDisk(tmppath, cancellable);
+	      } else {
+            LibQA.copyDisk(this._defaultDiskPath, tmppath, cancellable);
+        }
 
         let osname = this._buildData['snapshot']['osname'];
 
-	      ProcUtil.runSync(['ostbuild', 'qa-pull-deploy', this._defaultDiskPath.get_path(),
-			                    this.repo.get_path(), osname, defaultTarget],
+	      ProcUtil.runSync(['ostbuild', 'qa-pull-deploy', tmppath.get_path(),
+			                    this.repo.get_path(), osname, defaultTarget, defaultRevision],
 			                   cancellable, { logInitiation: true });
+        
+        GSystem.file_rename(tmppath, this._defaultDiskPath, cancellable);
 
         for (let targetName in targets) {
 	          if (targetName == defaultTarget)
 		            continue;
+            let targetRevision = this._buildData['targets'][targetName];
 	          let diskPath = this._diskPathForTarget(targetName, true);
-            GSystem.shutil_rm_rf(diskPath, cancellable);
-	          LibQA.createDiskSnapshot(this._defaultDiskPath, diskPath, cancellable);
-	          ProcUtil.runSync(['ostbuild', 'qa-pull-deploy', diskPath.get_path(), 
-			                        this.repo.get_path(), osname, targetName],
+            tmppath = diskPath.get_parent().get_child(diskPath.get_basename() + '.tmp');
+            GSystem.shutil_rm_rf(tmppath, cancellable);
+	          LibQA.createDiskSnapshot(this._defaultDiskPath, tmppath, cancellable);
+	          ProcUtil.runSync(['ostbuild', 'qa-pull-deploy', tmppath.get_path(), 
+			                        this.repo.get_path(), osname, targetName, targetRevision],
 			                       cancellable, { logInitiation: true });
 	      }
+
+        GSystem.file_linkcopy(latestPath, imageDir.get_child(latestPath.get_basename()),
+                              Gio.FileCopyFlags.OVERWRITE, cancellable);
     },
 
     _diskPathForTarget: function(targetName, isSnap) {
@@ -84,6 +107,6 @@ const QaBuildDisks = new Lang.Class({
 	      } else {
 	          suffix = '-disk.qcow2';
         }
-	      return this.workdir.get_child(this.prefix + '-' + squashedName + suffix);
+	      return this.imageDir.get_child(this.prefix + '-' + squashedName + suffix);
     }
 });
diff --git a/src/ostbuild/js/builtins/qa_make_disk.js b/src/ostbuild/js/builtins/qa_make_disk.js
index a68fec8..7fecbef 100644
--- a/src/ostbuild/js/builtins/qa_make_disk.js
+++ b/src/ostbuild/js/builtins/qa_make_disk.js
@@ -46,48 +46,7 @@ const QaMakeDisk = new Lang.Class({
 
         let tmppath = path.get_parent().get_child(path.get_basename() + '.tmp');
         GSystem.shutil_rm_rf(tmppath, cancellable);
-        let sizeMb = 8 * 1024;
-        let bootsizeMb = 200;
-        let swapsizeMb = 64;
-
-        let guestfishProcess;
-        
-        ProcUtil.runSync(['qemu-img', 'create', '-f', 'qcow2', tmppath.get_path(), '' + sizeMb + 'M'], cancellable);
-        let makeDiskCmd = 'launch\n\
-part-init /dev/vda mbr\n\
-blockdev-getsize64 /dev/vda\n\
-blockdev-getss /dev/vda\n';
-        let gf = new GuestFish.GuestFish(tmppath, {partitionOpts: [], readWrite: true});
-        let lines = gf.run(makeDiskCmd, cancellable);
-        if (lines.length != 2)
-            throw new Error("guestfish returned unexpected output lines (" + lines.length + ", expected 2");
-        let diskBytesize = parseInt(lines[0]);
-        let diskSectorsize = parseInt(lines[1]);
-        print(Format.vprintf("bytesize: %s sectorsize: %s", [diskBytesize, diskSectorsize]));
-        let bootsizeSectors = bootsizeMb * 1024 / diskSectorsize * 1024;
-        let swapsizeSectors = swapsizeMb * 1024 / diskSectorsize * 1024;
-        let rootsizeSectors = diskBytesize / diskSectorsize - bootsizeSectors - swapsizeSectors - 64;
-        let bootOffset = 64;
-        let swapOffset = bootOffset + bootsizeSectors;
-        let rootOffset = swapOffset + swapsizeSectors;
-        let endOffset = rootOffset + rootsizeSectors;
-
-        let partconfig = Format.vprintf('launch\n\
-part-add /dev/vda p %s %s\n\
-part-add /dev/vda p %s %s\n\
-part-add /dev/vda p %s %s\n\
-mkfs ext4 /dev/vda1\n\
-set-e2label /dev/vda1 gnostree-boot\n\
-mkswap-L gnostree-swap /dev/vda2\n\
-mkfs ext4 /dev/vda3\n\
-set-e2label /dev/vda3 gnostree-root\n\
-mount /dev/vda3 /\n\
-mkdir /boot\n\
-', [bootOffset, swapOffset - 1,
-    swapOffset, rootOffset - 1,
-    rootOffset, endOffset - 1]);
-        print("partition config: ", partconfig);
-        lines = gf.run(partconfig, cancellable);
+        LibQA.createDisk(tmppath, cancellable);
         GSystem.file_rename(tmppath, path, cancellable);
         print("Created: " + path.get_path());
     }
diff --git a/src/ostbuild/js/builtins/qa_pull_deploy.js b/src/ostbuild/js/builtins/qa_pull_deploy.js
index 837ff48..e562fa5 100644
--- a/src/ostbuild/js/builtins/qa_pull_deploy.js
+++ b/src/ostbuild/js/builtins/qa_pull_deploy.js
@@ -41,6 +41,7 @@ const QaPullDeploy = new Lang.Class({
         this.parser.addArgument('srcrepo');
         this.parser.addArgument('osname');
         this.parser.addArgument('target');
+        this.parser.addArgument('revision');
     },
 
     execute: function(args, loop, cancellable) {
@@ -55,7 +56,7 @@ const QaPullDeploy = new Lang.Class({
         gfmnt.mount(this._mntdir, cancellable);
         try {
             LibQA.pullDeploy(this._mntdir, Gio.File.new_for_path(args.srcrepo),
-                             args.osname, args.target, cancellable);
+                             args.osname, args.target, args.revision, cancellable);
         } finally {
             gfmnt.umount(cancellable);
         }
diff --git a/src/ostbuild/js/libqa.js b/src/ostbuild/js/libqa.js
index 429ac91..0bd0136 100644
--- a/src/ostbuild/js/libqa.js
+++ b/src/ostbuild/js/libqa.js
@@ -39,11 +39,61 @@ function newReadWriteMount(diskpath, cancellable) {
     return [gfmnt, mntdir];
 }
 
+function createDisk(diskpath, cancellable) {
+    let sizeMb = 8 * 1024;
+    let bootsizeMb = 200;
+    let swapsizeMb = 64;
+
+    let guestfishProcess;
+    
+    ProcUtil.runSync(['qemu-img', 'create', '-f', 'qcow2', diskpath.get_path(), '' + sizeMb + 'M'], cancellable);
+    let makeDiskCmd = 'launch\n\
+part-init /dev/vda mbr\n\
+blockdev-getsize64 /dev/vda\n\
+blockdev-getss /dev/vda\n';
+    let gf = new GuestFish.GuestFish(diskpath, {partitionOpts: [], readWrite: true});
+    let lines = gf.run(makeDiskCmd, cancellable);
+    if (lines.length != 2)
+        throw new Error("guestfish returned unexpected output lines (" + lines.length + ", expected 2");
+    let diskBytesize = parseInt(lines[0]);
+    let diskSectorsize = parseInt(lines[1]);
+    print(Format.vprintf("bytesize: %s sectorsize: %s", [diskBytesize, diskSectorsize]));
+    let bootsizeSectors = bootsizeMb * 1024 / diskSectorsize * 1024;
+    let swapsizeSectors = swapsizeMb * 1024 / diskSectorsize * 1024;
+    let rootsizeSectors = diskBytesize / diskSectorsize - bootsizeSectors - swapsizeSectors - 64;
+    let bootOffset = 64;
+    let swapOffset = bootOffset + bootsizeSectors;
+    let rootOffset = swapOffset + swapsizeSectors;
+    let endOffset = rootOffset + rootsizeSectors;
+
+    let partconfig = Format.vprintf('launch\n\
+part-add /dev/vda p %s %s\n\
+part-add /dev/vda p %s %s\n\
+part-add /dev/vda p %s %s\n\
+mkfs ext4 /dev/vda1\n\
+set-e2label /dev/vda1 gnostree-boot\n\
+mkswap-L gnostree-swap /dev/vda2\n\
+mkfs ext4 /dev/vda3\n\
+set-e2label /dev/vda3 gnostree-root\n\
+mount /dev/vda3 /\n\
+mkdir /boot\n\
+', [bootOffset, swapOffset - 1,
+    swapOffset, rootOffset - 1,
+    rootOffset, endOffset - 1]);
+    print("partition config: ", partconfig);
+    gf.run(partconfig, cancellable);
+}
+
 function createDiskSnapshot(diskpath, newdiskpath, cancellable) {
     ProcUtil.runSync(['qemu-img', 'create', '-f', 'qcow2', '-o', 'backing_file=' + diskpath.get_path(),
 		      newdiskpath.get_path()], cancellable);
 }
 
+function copyDisk(srcpath, destpath, cancellable) {
+    ProcUtil.runSync(['qemu-img', 'convert', '-O', 'qcow2', srcpath.get_path(),
+		      destpath.get_path()], cancellable);
+}
+
 function getQemuPath() {
     let fallbackPaths = ['/usr/libexec/qemu-kvm']
     let qemuPathString = GLib.find_program_in_path('qemu-kvm');
@@ -176,7 +226,7 @@ function _getInitramfsPath(mntdir, kernelRelease) {
     return path;
 };
 
-function pullDeploy(mntdir, srcrepo, osname, target, cancellable) {
+function pullDeploy(mntdir, srcrepo, osname, target, revision, cancellable) {
     let bootdir = mntdir.get_child('boot');
     let ostreedir = mntdir.get_child('ostree');
     let ostree_osdir = ostreedir.resolve_relative_path('deploy/' + osname);
@@ -202,13 +252,19 @@ function pullDeploy(mntdir, srcrepo, osname, target, cancellable) {
     // or the like.
     GSystem.shutil_rm_rf(ostree_osdir, cancellable);
 
+    let revOrTarget;
+    if (revision)
+	revOrTarget = revision;
+    else
+	revOrTarget = target;
+    
     ProcUtil.runSync(adminCmd.concat(['os-init', osname]), cancellable,
                      {logInitiation: true, env: adminEnv});
     ProcUtil.runSync(['ostree', '--repo=' + ostreedir.get_child('repo').get_path(),
-                      'pull-local', srcrepo.get_path(), target], cancellable,
+                      'pull-local', srcrepo.get_path(), revOrTarget], cancellable,
                      {logInitiation: true, env: adminEnv});
-
-    ProcUtil.runSync(adminCmd.concat(['deploy', '--no-kernel', osname, target]), cancellable,
+    
+    ProcUtil.runSync(adminCmd.concat(['deploy', '--no-kernel', osname, target, revOrTarget]), cancellable,
                      {logInitiation: true, env: adminEnv});
     ProcUtil.runSync(adminCmd.concat(['update-kernel', '--no-bootloader', osname]), cancellable,
                      {logInitiation: true, env: adminEnv});
diff --git a/src/ostbuild/js/main.js b/src/ostbuild/js/main.js
index d4a8fcd..ae92800 100755
--- a/src/ostbuild/js/main.js
+++ b/src/ostbuild/js/main.js
@@ -25,9 +25,9 @@ const BUILTINS = ['autobuilder',
                   'git-mirror',
                   'resolve',
                   'build',
+                  'build-disks',
                   'shell',
                   'qa-make-disk',
-                  'qa-build-disks',
 		  'qa-pull-deploy',
 		  'qa-smoketest'];
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]