Skip to content

Commit

Permalink
Continue boximg chain implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Apr 17, 2015
1 parent f17edfa commit e588db6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 19 deletions.
2 changes: 1 addition & 1 deletion conduct/buildsteps/deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Debootstrap(BuildStep):
'distribution' : Parameter(type=str,
description='Desired distribution'),
# TODO: map archs? => system analyzer?
'arch' : Parameter(type=oneof('x86_64', 'i386', 'armel', 'armhf'),
'arch' : Parameter(type=str,
description='Desired architecture'),
'destdir' : Parameter(type=str,
description='Destination directory'),
Expand Down
11 changes: 10 additions & 1 deletion conduct/buildsteps/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
# *****************************************************************************

import re
from os import path

from conduct.buildsteps.base import BuildStep
Expand Down Expand Up @@ -82,7 +83,9 @@ class DevMapper(BuildStep):

outparameters = {
'mapped' : Parameter(type=list,
description='Created device files',)
description='Created device files',),
'loopdev' : Parameter(type=str,
description='Used loop device',)
}

def run(self):
Expand All @@ -92,12 +95,18 @@ def run(self):
# request a proper formated list of devs
out = systemCall('kpartx -v -l -s %s' % self.dev, log=self.log)

# store loop dev
self.loopdev = re.findall('(/dev/.*?) ', out)[0]

# store created device file paths
self.mapped = []
for line in out.splitlines():
devFile = line.rpartition(':')[0].strip()
self.mapped.append(path.join('/dev/mapper', devFile))

self.log.info('Loop device: %s' % self.loopdev)
self.log.info('Mapped devices: %s' % ', '.join(self.mapped))

def cleanup(self):
systemCall('kpartx -v -d -s %s' % self.dev,
log=self.log)
23 changes: 23 additions & 0 deletions conduct/buildsteps/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
from conduct.util import systemCall, ensureDirectory, mount, umount
from conduct.param import Parameter, oneof, listof, Referencer


class WriteFile(BuildStep):
parameters = {
'path' : Parameter(type=str,
description='Path to target file'),
'content' : Parameter(type=str,
description='Content wo write'),
'append' : Parameter(type=bool,
description='Append to the file '
'(if existing)',
default=False),
}

def run(self):
ensureDirectory(path.dirname(self.path))

openMode = 'a' if self.append else 'w'

self.log.info('Write to file %s ...' % self.path)
with open(self.path, openMode) as f:
f.write(self.content)


class TmpDir(BuildStep):
parameters = {
'parentdir' : Parameter(type=str,
Expand Down
2 changes: 1 addition & 1 deletion conduct/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _createSteps(self):
def _createReferencers(self, paramValues):
for paramName, paramValue in paramValues.items():
if isinstance(paramValue, str) \
and re.match('.*?(\{(.*?)\})+.*?', paramValue):
and re.findall('\{(.*?)\}', paramValue):
paramValues[paramName] = Referencer(paramValue)

return paramValues
Expand Down
58 changes: 42 additions & 16 deletions etc/chains/frm2/boximg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
This chain builds the image of FRM II's TACO/TANGO boxes.
'''

# Some specific global stuff

SOURCES_LIST = '''
deb http://ftp.de.debian.org/debian/ {chain.distribution} main
deb http://ftp.de.debian.org/debian/ {chain.distribution}-backports main
'''

GRUB_DEV_MAP = '''
(hd0) {steps.devmap.loopdev}
(hd0,1) {steps.devmap.mapped[0]}
'''


# Short description which will be displayed on command line help.
description = 'This chain builds the image of FRM II\'s TACO/TANGO boxes.'

Expand All @@ -46,7 +59,7 @@
# -8: some space for mbr and stuff
steps.partsize = Step('generic.Calculation',
description='Calculate partition size',
formula='({steps.imgdef.config[size]} - 8) / 2')
formula='({steps.imgdef.config[SIZE]} - 8) / 2')

steps.tmpdir = Step('fs.TmpDir',
description='Generate build dir',)
Expand All @@ -55,7 +68,7 @@
description='Create empty image file',
command='dcfldd if=/dev/zero '
'of={steps.tmpdir.tmpdir}/{chain.imgname}.img '
'bs=1048576 count={steps.imgdef.config[size]}')
'bs=1048576 count={steps.imgdef.config[SIZE]}')

steps.partition = Step('dev.Partitioning',
description='Partition image file',
Expand Down Expand Up @@ -85,26 +98,39 @@
steps.debootstrap = Step('deb.Debootstrap',
description='Boostrap basic system',
distribution='{chain.distribution}',
arch='i386',
arch='{steps.imgdef.config[ARCH]}',
destdir='{steps.tmpdir.tmpdir}/mount')

# replace by cp + sed steps
steps.aptmain = Step('syscall.SystemCall',
description='Add main apt repo',
command='echo "deb http://ftp.de.debian.org/debian/ '
'{chain.distribution} main" >> '
'{steps.mount.mountpoint}/etc/apt/sources.list')

# replace by cp + sed steps
steps.aptbackp = Step('syscall.SystemCall',
description='Add backport apt repo',
command='echo "deb http://ftp.de.debian.org/debian/ '
'{chain.distribution}-backports main" >> '
'{steps.mount.mountpoint}/etc/apt/sources.list')
steps.srclst = Step('fs.WriteFile',
description='Create source list',
path='{steps.mount.mountpoint}/etc/apt/sources.list',
append=True,
content=SOURCES_LIST)

steps.aptupdate = Step('syscall.ChrootedSystemCall',
description='Update package lists',
command='apt-get update',
chrootdir='{steps.mount.mountpoint}')

#steps.kernel = Step('syscall.ChrootedSystemCall',
# description='Install kernel image',
# command='apt-get install linux-image-{steps.imgdef.config[KERNEL]}',
# chrootdir='{steps.mount.mountpoint}')

#steps.grub = Step('syscall.ChrootedSystemCall',
# description='Install bootloader (grub2)',
# command='apt-get install grub2',
# chrootdir='{steps.mount.mountpoint}')

steps.grubdevmap = Step('fs.WriteFile',
description='Create source list',
path='{steps.mount.mountpoint}/boot/device.map',
content=GRUB_DEV_MAP)

steps.mbr = Step('syscall.SystemCall',
description='Install grub2 to mbr',
command='grub-install --no-floppy --grub-mkdevicemap='
'{steps.mount.mountpoint}/boot/device.map} '
'--root-directory={steps.mount.mountpoint} '
'{steps.devmap.loopdev}')

0 comments on commit e588db6

Please sign in to comment.