diff --git a/tests/functional_tests/0004_start_test.py b/tests/functional_tests/0004_start_test.py index 5193627d..602d31de 100644 --- a/tests/functional_tests/0004_start_test.py +++ b/tests/functional_tests/0004_start_test.py @@ -23,6 +23,7 @@ # POSSIBILITY OF SUCH DAMAGE. import pytest +import inspect require_root = pytest.mark.require_root @@ -62,28 +63,43 @@ def test_02_start_rc_jail(invoke_cli, resource_selector): def test_03_create_and_start_nobridge_vnet_jail(release, jail, invoke_cli, nobridge_jail_ip): jail = jail('nobridge_jail') - invoke_cli([ - 'create', '-r', release, '-n', jail.name, - f'ip4_addr=lo0|{nobridge_jail_ip}', 'boot=on', 'vnet=on', - 'interfaces=vnet0:none', 'vnet_default_interface=none', - 'ip6_addr=vnet0|fe80::2/64', 'defaultrouter6=none', - 'defaultrouter=none', - f'exec_poststart="ifconfig vnet0.$(jls -j ioc-{jail.name} jid) inet6 fe80::1/64"' - ]) - - assert jail.exists is True - assert jail.running is True - - stdout, stderr = jail.run_command(['ifconfig']) - assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}' - assert 'fe80::2%epair0b' in stdout - - stdout, stderr = jail.run_command(['ifconfig'], jailed=False) - - assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}' - assert 'bridge' not in stdout, 'Unexpected bridge was created.' - assert f'fe80::1%vnet0.{jail.jid}:' in stdout - assert f'description: associated with jail: {jail.name} as nic: epair0b' - - stdout, stderr = jail.run_command(['ping', '-c', '1', f'fe80::2%vnet0.{jail.jid}'], jailed=False) - assert bool(stderr) is False, f'Ping returned an error: {stderr}' + fd, path = tempfile.mkstemp() + + try: + with os.fdopen(fd, 'w') as tmp: + tmp.write(inspect.cleandoc(""" + #!/bin/sh + jailname=ioc-$1 + jid=jls -j $jailname jid + iface=vnet0.$jid + ifconfig $iface inet6 fe80::1/64 + """)) + + invoke_cli([ + 'create', '-r', release, '-n', jail.name, + f'ip4_addr=lo0|{nobridge_jail_ip}', 'boot=on', 'vnet=on', + 'interfaces=vnet0:none', 'vnet_default_interface=none', + 'ip6_addr=vnet0|fe80::2/64', 'defaultrouter6=none', + 'defaultrouter=none', + f'exec_poststart="{path} {jail.name}"' + ]) + + assert jail.exists is True + assert jail.running is True + + stdout, stderr = jail.run_command(['ifconfig']) + assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}' + assert 'fe80::2%epair0b' in stdout + + stdout, stderr = jail.run_command(['ifconfig'], jailed=False) + + assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}' + assert 'bridge' not in stdout, 'Unexpected bridge was created.' + assert f'fe80::1%vnet0.{jail.jid}:' in stdout + assert f'description: associated with jail: {jail.name} as nic: epair0b' + + stdout, stderr = jail.run_command(['ping', '-c', '1', f'fe80::2%vnet0.{jail.jid}'], jailed=False) + assert bool(stderr) is False, f'Ping returned an error: {stderr}' + + finally: + os.remove(path)