def test_jailspec_to_jailconf_07(): spec = { 'path': '/no/path', 'mounts': { '/foo/bar': '/bar/baf', '/bar/baz': '/baz/bee' } } conf = jailspec_to_jailconf(spec, 'noname') assert conf['exec.prestart'] == quote('cp /etc/resolv.conf /no/path/etc/resolv.conf && mount -t nullfs /foo/bar /no/path/bar/baf && mount -t nullfs /bar/baz /no/path/baz/bee') assert conf['exec.poststop'] == quote('umount -f /no/path/baz/bee && umount -f /no/path/bar/baf')
def test_jailspec_to_jailconf_03(): spec = dict(_spec) del spec['command'] del spec['exec.system_jail_user'] #with pytest.raises(KeyError) as excinfo: blk = jailspec_to_jailconf(spec, 'noname') # assert excinfo.value.args == ('exec.jail_user and exec.system_jail_user are mutually exclusive',) for k, v in spec.items(): if k == 'exec.prestart' or k == 'exec.poststop' or k == 'depend': continue assert blk[k] == quote(v) assert blk['exec.prestart'] == "'cp /etc/resolv.conf /no/path/etc/resolv.conf && echo Prestart'" assert blk['exec.poststop'] == "'echo Poststop'"
def test_jail_create(): subprocess.check_output( ['focker', 'jail', 'remove', '--force', 'test-jail-create']) subprocess.check_output( ['focker', 'volume', 'remove', '--force', 'test-jail-create']) name = jail_fs_create() zfs_tag(name, ['test-jail-create']) subprocess.check_output( ['focker', 'volume', 'create', '-t', 'test-jail-create']) mountpoint = zfs_mountpoint(name) spec = { 'path': mountpoint, 'exec.start': '/bin/sh /etc/rc', 'env': { 'DUMMY_1': 'foo', 'DUMMY_2': 'bar' }, 'mounts': { 'test-jail-create': '/test-jail-create', '/tmp': '/test-tmp' }, 'ip4.addr': '127.1.2.3', 'host.hostname': 'test-jail-create' } jail_name = os.path.split(mountpoint)[-1] jail_create(spec, jail_name) assert jail_name == os.path.split(mountpoint)[-1] assert os.path.exists(mountpoint) vol_name, _ = zfs_find('test-jail-create', focker_type='volume') vol_mountpoint = zfs_mountpoint(vol_name) assert os.path.exists(vol_mountpoint) conf = jailconf.load('/etc/jail.conf') assert jail_name in conf conf = conf[jail_name] assert conf['path'] == quote(mountpoint) assert conf[ 'exec.start'] == '\'export DUMMY_1=foo && export DUMMY_2=bar && /bin/sh /etc/rc\'' assert conf[ 'exec.prestart'] == f'\'cp /etc/resolv.conf {mountpoint}/etc/resolv.conf && mount -t nullfs {vol_mountpoint} {mountpoint}/test-jail-create && mount -t nullfs /tmp {mountpoint}/test-tmp\'' assert conf['ip4.addr'] == '\'127.1.2.3\'' subprocess.check_output(['focker', 'jail', 'remove', 'test-jail-create']) subprocess.check_output(['focker', 'volume', 'remove', 'test-jail-create'])
def test_quote(): res = quote('foo \\ bar \'baz\'') assert res == '\'foo \\\\ bar \\\'baz\\\'\''
def test_jailspec_to_jailconf_04(): spec = dict(_spec2) blk = jailspec_to_jailconf(spec, 'noname') for k, v in spec.items(): assert blk[k] == quote(v)