From f2bd502cdc1f3d7b8338b64df272b139dcf02e04 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 9 May 2016 20:31:33 +0000 Subject: [PATCH] Carry volume ID from build_image through ISO to manifest --- server/build_image.py | 22 +++++++++++++++++----- server/build_manifest.py | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/server/build_image.py b/server/build_image.py index c954f72..bc03e3b 100755 --- a/server/build_image.py +++ b/server/build_image.py @@ -54,6 +54,11 @@ parser.add_argument( dest='source_iso', action='store', required=True) +parser.add_argument( + '--volume-id', + dest='volume_id', + action='store', + required=True) FLAGS = parser.parse_args() @@ -92,7 +97,7 @@ class ImageBuilder(object): 'loopback.cfg': 'boot/grub/loopback.cfg', } - def __init__(self, source_iso, image_dir, archive, arch, release, modules, kernel_args): + def __init__(self, source_iso, image_dir, archive, arch, release, modules, kernel_args, volume_id=None): self._source_iso = source_iso self._image_dir = image_dir self._archive = archive @@ -100,6 +105,7 @@ class ImageBuilder(object): self._release = release self._modules = modules or [] self._kernel_args = kernel_args or [] + self._volume_id = volume_id self._ico_server_path = os.path.dirname(sys.argv[0]) @@ -275,10 +281,15 @@ class ImageBuilder(object): def _CreateISO(self, union_path, timestamp): dest_iso = os.path.join(self._image_dir, '%d.iso' % timestamp) - self._Exec( - 'grub-mkrescue', + args = [ '--output=%s' % dest_iso, - union_path) + '--', + ] + if self._volume_id: + args.extend(['-V', self._volume_id]) + args.append(union_path) + + self._Exec('grub-mkrescue', *args) return dest_iso def _BuildImage(self): @@ -333,7 +344,8 @@ def main(): FLAGS.arch, FLAGS.release, FLAGS.modules, - FLAGS.kernel_args) + FLAGS.kernel_args, + FLAGS.volume_id) builder.BuildImage() diff --git a/server/build_manifest.py b/server/build_manifest.py index fef112d..a058168 100755 --- a/server/build_manifest.py +++ b/server/build_manifest.py @@ -5,6 +5,7 @@ import hashlib import json import os import re +import subprocess import sys import time @@ -37,6 +38,7 @@ FLAGS = parser.parse_args() class ManifestBuilder(object): _FILE_REGEX = re.compile('^(?P\d+)\.iso$') + _VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P.+)$', re.MULTILINE) _BUF_SIZE = 2 ** 16 def __init__(self, image_dir, old_manifest): @@ -55,6 +57,15 @@ class ManifestBuilder(object): except FileNotFoundError: return {} + def _GetVolumeID(self, path): + isoinfo = subprocess.check_output([ + 'isoinfo', + '-d', + '-i', path, + ]) + match = self._VOLUME_ID_REGEX.search(isoinfo) + return match.group('volume_id').decode('ascii') + def BuildManifest(self): ret = { 'timestamp': int(time.time()), @@ -77,7 +88,11 @@ class ManifestBuilder(object): image.update(old_image) continue - with open(os.path.join(self._image_dir, filename), 'rb') as fh: + image_path = os.path.join(self._image_dir, filename) + + image['volume_id'] = self._GetVolumeID(image_path) + + with open(image_path, 'rb') as fh: hash_obj = hashlib.sha256() while True: data = fh.read(self._BUF_SIZE)