mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
log_call uses own logger now
This commit is contained in:
parent
a26c83fc93
commit
0fc535cb29
5 changed files with 29 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
def log_check_call(command, logger):
|
def log_check_call(command):
|
||||||
status = log_call(command, logger)
|
status = log_call(command)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
msg = ('Command \'{command}\' returned non-zero exit status '
|
msg = ('Command \'{command}\' returned non-zero exit status '
|
||||||
|
@ -9,10 +9,14 @@ def log_check_call(command, logger):
|
||||||
raise CalledProcessError(msg)
|
raise CalledProcessError(msg)
|
||||||
|
|
||||||
|
|
||||||
def log_call(command, logger):
|
def log_call(command):
|
||||||
import subprocess
|
import subprocess
|
||||||
import select
|
import select
|
||||||
|
|
||||||
|
import logging
|
||||||
|
command_log = command[0].replace('/', '.')
|
||||||
|
log = logging.getLogger(__name__ + command_log)
|
||||||
|
|
||||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
while True:
|
while True:
|
||||||
reads = [process.stdout.fileno(), process.stderr.fileno()]
|
reads = [process.stdout.fileno(), process.stderr.fileno()]
|
||||||
|
@ -21,11 +25,11 @@ def log_call(command, logger):
|
||||||
if fd == process.stdout.fileno():
|
if fd == process.stdout.fileno():
|
||||||
line = process.stdout.readline()
|
line = process.stdout.readline()
|
||||||
if line != '':
|
if line != '':
|
||||||
logger.debug(line.strip())
|
log.debug(line.strip())
|
||||||
if fd == process.stderr.fileno():
|
if fd == process.stderr.fileno():
|
||||||
line = process.stderr.readline()
|
line = process.stderr.readline()
|
||||||
if line != '':
|
if line != '':
|
||||||
logger.error(line.strip())
|
log.error(line.strip())
|
||||||
if process.poll() is not None:
|
if process.poll() is not None:
|
||||||
return process.returncode
|
return process.returncode
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
from base import Task
|
from base import Task
|
||||||
from common import phases
|
from common import phases
|
||||||
from common.tools import log_check_call
|
from common.tools import log_check_call
|
||||||
import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_bootstrap_args(info):
|
def get_bootstrap_args(info):
|
||||||
|
@ -30,7 +28,7 @@ class MakeTarball(Task):
|
||||||
info.tarball = os.path.join(info.manifest.bootstrapper['tarball_dir'], tarball_filename)
|
info.tarball = os.path.join(info.manifest.bootstrapper['tarball_dir'], tarball_filename)
|
||||||
|
|
||||||
command = executable + options + ['--make-tarball=' + info.tarball] + arguments
|
command = executable + options + ['--make-tarball=' + info.tarball] + arguments
|
||||||
log_check_call(command, log)
|
log_check_call(command)
|
||||||
|
|
||||||
|
|
||||||
class Bootstrap(Task):
|
class Bootstrap(Task):
|
||||||
|
@ -44,4 +42,4 @@ class Bootstrap(Task):
|
||||||
options.extend(['--unpack-tarball=' + info.tarball])
|
options.extend(['--unpack-tarball=' + info.tarball])
|
||||||
|
|
||||||
command = executable + options + arguments
|
command = executable + options + arguments
|
||||||
log_check_call(command, log)
|
log_check_call(command)
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
from base import Task
|
from base import Task
|
||||||
from common import phases
|
from common import phases
|
||||||
from common.tools import log_check_call
|
|
||||||
import os.path
|
import os.path
|
||||||
import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateLocale(Task):
|
class GenerateLocale(Task):
|
||||||
|
@ -12,6 +9,7 @@ class GenerateLocale(Task):
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
from common.tools import sed_i
|
from common.tools import sed_i
|
||||||
|
from common.tools import log_check_call
|
||||||
locale_gen = os.path.join(info.root, 'etc/locale.gen')
|
locale_gen = os.path.join(info.root, 'etc/locale.gen')
|
||||||
locale_str = '{locale}.{charmap} {charmap}'.format(locale=info.manifest.system['locale'],
|
locale_str = '{locale}.{charmap} {charmap}'.format(locale=info.manifest.system['locale'],
|
||||||
charmap=info.manifest.system['charmap'])
|
charmap=info.manifest.system['charmap'])
|
||||||
|
@ -19,7 +17,7 @@ class GenerateLocale(Task):
|
||||||
sed_i(locale_gen, search, locale_str)
|
sed_i(locale_gen, search, locale_str)
|
||||||
|
|
||||||
command = ['chroot', info.root, 'dpkg-reconfigure', '--priority=critical', 'locales']
|
command = ['chroot', info.root, 'dpkg-reconfigure', '--priority=critical', 'locales']
|
||||||
log_check_call(command, log)
|
log_check_call(command)
|
||||||
|
|
||||||
|
|
||||||
class SetTimezone(Task):
|
class SetTimezone(Task):
|
||||||
|
|
|
@ -3,8 +3,6 @@ from common import phases
|
||||||
from common.exceptions import TaskError
|
from common.exceptions import TaskError
|
||||||
from common.tools import log_check_call
|
from common.tools import log_check_call
|
||||||
from bootstrap import Bootstrap
|
from bootstrap import Bootstrap
|
||||||
import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class FormatVolume(Task):
|
class FormatVolume(Task):
|
||||||
|
@ -14,7 +12,7 @@ class FormatVolume(Task):
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
dev_path = info.bootstrap_device['path']
|
dev_path = info.bootstrap_device['path']
|
||||||
mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem'])
|
mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem'])
|
||||||
log_check_call([mkfs, dev_path], log)
|
log_check_call([mkfs, dev_path])
|
||||||
|
|
||||||
|
|
||||||
class TuneVolumeFS(Task):
|
class TuneVolumeFS(Task):
|
||||||
|
@ -26,7 +24,7 @@ class TuneVolumeFS(Task):
|
||||||
dev_path = info.bootstrap_device['path']
|
dev_path = info.bootstrap_device['path']
|
||||||
# Disable the time based filesystem check
|
# Disable the time based filesystem check
|
||||||
command = ['/sbin/tune2fs', '-i', '0', dev_path]
|
command = ['/sbin/tune2fs', '-i', '0', dev_path]
|
||||||
log_check_call(command, log)
|
log_check_call(command)
|
||||||
|
|
||||||
|
|
||||||
class AddXFSProgs(Task):
|
class AddXFSProgs(Task):
|
||||||
|
@ -63,7 +61,7 @@ class MountVolume(Task):
|
||||||
raise TaskError(msg)
|
raise TaskError(msg)
|
||||||
|
|
||||||
command = ['mount', info.bootstrap_device['path'], info.root]
|
command = ['mount', info.bootstrap_device['path'], info.root]
|
||||||
log_check_call(command, log)
|
log_check_call(command)
|
||||||
|
|
||||||
|
|
||||||
class MountSpecials(Task):
|
class MountSpecials(Task):
|
||||||
|
@ -72,10 +70,10 @@ class MountSpecials(Task):
|
||||||
after = [Bootstrap]
|
after = [Bootstrap]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
log_check_call(['mount', '--bind', '/dev', '{root}/dev'.format(root=info.root)], log)
|
log_check_call(['mount', '--bind', '/dev', '{root}/dev'.format(root=info.root)])
|
||||||
log_check_call(['chroot', info.root, 'mount', '-t', 'proc', 'none', '/proc'], log)
|
log_check_call(['chroot', info.root, 'mount', '-t', 'proc', 'none', '/proc'])
|
||||||
log_check_call(['chroot', info.root, 'mount', '-t', 'sysfs', 'none', '/sys'], log)
|
log_check_call(['chroot', info.root, 'mount', '-t', 'sysfs', 'none', '/sys'])
|
||||||
log_check_call(['chroot', info.root, 'mount', '-t', 'devpts', 'none', '/dev/pts'], log)
|
log_check_call(['chroot', info.root, 'mount', '-t', 'devpts', 'none', '/dev/pts'])
|
||||||
|
|
||||||
|
|
||||||
class UnmountSpecials(Task):
|
class UnmountSpecials(Task):
|
||||||
|
@ -83,10 +81,10 @@ class UnmountSpecials(Task):
|
||||||
phase = phases.volume_unmounting
|
phase = phases.volume_unmounting
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
log_check_call(['chroot', info.root, 'umount', '/dev/pts'], log)
|
log_check_call(['chroot', info.root, 'umount', '/dev/pts'])
|
||||||
log_check_call(['chroot', info.root, 'umount', '/sys'], log)
|
log_check_call(['chroot', info.root, 'umount', '/sys'])
|
||||||
log_check_call(['chroot', info.root, 'umount', '/proc'], log)
|
log_check_call(['chroot', info.root, 'umount', '/proc'])
|
||||||
log_check_call(['umount', '{root}/dev'.format(root=info.root)], log)
|
log_check_call(['umount', '{root}/dev'.format(root=info.root)])
|
||||||
|
|
||||||
|
|
||||||
class UnmountVolume(Task):
|
class UnmountVolume(Task):
|
||||||
|
@ -95,7 +93,7 @@ class UnmountVolume(Task):
|
||||||
after = [UnmountSpecials]
|
after = [UnmountSpecials]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
log_check_call(['umount', info.root], log)
|
log_check_call(['umount', info.root])
|
||||||
|
|
||||||
|
|
||||||
class DeleteMountDir(Task):
|
class DeleteMountDir(Task):
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
from base import Task
|
from base import Task
|
||||||
from common import phases
|
from common import phases
|
||||||
from common.exceptions import TaskError
|
from common.exceptions import TaskError
|
||||||
from common.tools import log_check_call
|
|
||||||
import packages
|
import packages
|
||||||
import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CheckPackages(Task):
|
class CheckPackages(Task):
|
||||||
|
@ -13,11 +10,12 @@ class CheckPackages(Task):
|
||||||
after = [packages.HostPackages, packages.ImagePackages]
|
after = [packages.HostPackages, packages.ImagePackages]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
import subprocess
|
from common.tools import log_check_call
|
||||||
|
from subprocess import CalledProcessError
|
||||||
for package in info.host_packages:
|
for package in info.host_packages:
|
||||||
try:
|
try:
|
||||||
log_check_call(['/usr/bin/dpkg', '-s', package], log)
|
log_check_call(['/usr/bin/dpkg', '-s', package])
|
||||||
except subprocess.CalledProcessError:
|
except CalledProcessError:
|
||||||
msg = "The package ``{0}\'\' is not installed".format(package)
|
msg = "The package ``{0}\'\' is not installed".format(package)
|
||||||
raise TaskError(msg)
|
raise TaskError(msg)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue