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