From 6b9d3953d57a08ca5e1760a1a53a63cef8c89a10 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Wed, 3 Jun 2020 17:16:59 +0200 Subject: [PATCH] Add jail.conf key in focker compose jail spec in order to pass parameters directly to jail.conf. --- focker/compose.py | 15 +++++++++------ focker/jail.py | 4 +++- tests/test_compose.py | 8 +++++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/focker/compose.py b/focker/compose.py index f3566fd..d39821a 100644 --- a/focker/compose.py +++ b/focker/compose.py @@ -135,18 +135,21 @@ def build_jails(spec): zfs_untag([ jailname ], focker_type='jail') zfs_tag(name, [ jailname ]) path = zfs_mountpoint(name) + overrides={ + 'exec.stop': jailspec.get('exec.stop', '/bin/sh /etc/rc.shutdown'), + 'ip4.addr': jailspec.get('ip4.addr', '127.0.1.0'), + 'interface': jailspec.get('interface', 'lo1'), + 'host.hostname': jailspec.get('host.hostname', jailname) + } + if 'jail.conf' in jailspec: + overrides.update(jailspec['jail.conf']) generated_names[jailname] = jail_create(path, jailspec.get('exec.start', '/bin/sh /etc/rc'), jailspec.get('env', {}), [ [from_, on] \ for (from_, on) in jailspec.get('mounts', {}).items() ], hostname=jailname, - overrides={ - 'exec.stop': jailspec.get('exec.stop', '/bin/sh /etc/rc.shutdown'), - 'ip4.addr': jailspec.get('ip4.addr', '127.0.1.0'), - 'interface': jailspec.get('interface', 'lo1'), - 'host.hostname': jailspec.get('host.hostname', jailname) - }) + overrides=overrides) setup_dependencies(spec, generated_names) diff --git a/focker/jail.py b/focker/jail.py index 0232341..081909d 100644 --- a/focker/jail.py +++ b/focker/jail.py @@ -117,7 +117,9 @@ def jail_create(path, command, env, mounts, hostname=None, overrides={}): blk['exec.clean'] = True blk['host.hostname'] = hostname or name for (k, v) in overrides.items(): - blk[k] = quote(v) + blk[k] = quote(v) \ + if isinstance(v, str) \ + else v jail_conf_write(conf) return name diff --git a/tests/test_compose.py b/tests/test_compose.py index 596fdb8..ea5b3d1 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -226,7 +226,11 @@ def test_build_jails(): 'exec.stop': 'test-exec-stop', 'ip4.addr': 'test-ip4-addr', 'interface': 'test-interface', - 'host.hostname': 'test-build-jails-A' + 'host.hostname': 'test-build-jails-A', + 'jail.conf': { + 'allow.mount': True, + 'ip6.addr': 'abcd:abcd::0' + } } } spec['test-build-jails-B'] = spec['test-build-jails-A'].copy() @@ -247,6 +251,8 @@ def test_build_jails(): assert b['exec.stop'].strip('\'"') == 'test-exec-stop' assert b['ip4.addr'].strip('\'"') == 'test-ip4-addr' assert b['interface'].strip('\'"') == 'test-interface' + assert b['allow.mount'] + assert b['ip6.addr'] == '\'abcd:abcd::0\'' subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-A']) subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-build-jails-B']) subprocess.check_output(['focker', 'image', 'remove', '--force', 'test-focker-bootstrap'])