Carry volume ID from build_image through ISO to manifest

This commit is contained in:
Ian Gulliver
2016-05-09 20:31:33 +00:00
parent 29c310ba7b
commit f2bd502cdc
2 changed files with 33 additions and 6 deletions

View File

@@ -54,6 +54,11 @@ parser.add_argument(
dest='source_iso', dest='source_iso',
action='store', action='store',
required=True) required=True)
parser.add_argument(
'--volume-id',
dest='volume_id',
action='store',
required=True)
FLAGS = parser.parse_args() FLAGS = parser.parse_args()
@@ -92,7 +97,7 @@ class ImageBuilder(object):
'loopback.cfg': 'boot/grub/loopback.cfg', '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._source_iso = source_iso
self._image_dir = image_dir self._image_dir = image_dir
self._archive = archive self._archive = archive
@@ -100,6 +105,7 @@ class ImageBuilder(object):
self._release = release self._release = release
self._modules = modules or [] self._modules = modules or []
self._kernel_args = kernel_args or [] self._kernel_args = kernel_args or []
self._volume_id = volume_id
self._ico_server_path = os.path.dirname(sys.argv[0]) self._ico_server_path = os.path.dirname(sys.argv[0])
@@ -275,10 +281,15 @@ class ImageBuilder(object):
def _CreateISO(self, union_path, timestamp): def _CreateISO(self, union_path, timestamp):
dest_iso = os.path.join(self._image_dir, '%d.iso' % timestamp) dest_iso = os.path.join(self._image_dir, '%d.iso' % timestamp)
self._Exec( args = [
'grub-mkrescue',
'--output=%s' % dest_iso, '--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 return dest_iso
def _BuildImage(self): def _BuildImage(self):
@@ -333,7 +344,8 @@ def main():
FLAGS.arch, FLAGS.arch,
FLAGS.release, FLAGS.release,
FLAGS.modules, FLAGS.modules,
FLAGS.kernel_args) FLAGS.kernel_args,
FLAGS.volume_id)
builder.BuildImage() builder.BuildImage()

View File

@@ -5,6 +5,7 @@ import hashlib
import json import json
import os import os
import re import re
import subprocess
import sys import sys
import time import time
@@ -37,6 +38,7 @@ FLAGS = parser.parse_args()
class ManifestBuilder(object): class ManifestBuilder(object):
_FILE_REGEX = re.compile('^(?P<timestamp>\d+)\.iso$') _FILE_REGEX = re.compile('^(?P<timestamp>\d+)\.iso$')
_VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P<volume_id>.+)$', re.MULTILINE)
_BUF_SIZE = 2 ** 16 _BUF_SIZE = 2 ** 16
def __init__(self, image_dir, old_manifest): def __init__(self, image_dir, old_manifest):
@@ -55,6 +57,15 @@ class ManifestBuilder(object):
except FileNotFoundError: except FileNotFoundError:
return {} 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): def BuildManifest(self):
ret = { ret = {
'timestamp': int(time.time()), 'timestamp': int(time.time()),
@@ -77,7 +88,11 @@ class ManifestBuilder(object):
image.update(old_image) image.update(old_image)
continue 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() hash_obj = hashlib.sha256()
while True: while True:
data = fh.read(self._BUF_SIZE) data = fh.read(self._BUF_SIZE)