Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freebsd_instance:
image_family: freebsd-14-1
image_family: freebsd-15-0-amd64-zfs

iocage_tests_task:
create_pool_script:
Expand All @@ -12,7 +12,7 @@ iocage_tests_task:
populate_script:
- pkg fetch -udy git python3 py311-sqlite3 devel/py-libzfs
- pkg fetch -Udy rust
- sed -E 's/([^<>=]+).*/py311-\1/' requirements.txt requirements-test.txt | xargs pkg fetch -Udy
- sed -E 's/([^<>=]+).*/py311-\1/' requirements.txt requirements-test.txt | xargs pkg fetch -Udiy
install_pkgs_script:
- pkg update
- pkg install -Uy git python3 py311-sqlite3
Expand All @@ -35,7 +35,7 @@ iocage_tests_task:
- pip
- name: Use prebuilt packages
install_python_packages_script:
- sed -E 's/([^<>=]+).*/py311-\1/' requirements.txt requirements-test.txt | xargs pkg install -Uy
- sed -E 's/([^<>=]+).*/py311-\1/' requirements.txt requirements-test.txt | xargs pkg install -Uyi
# Necessary as long as py311-pytest and py311-pytest-pep8 conflict
- python3 -m pip install -r requirements-test.txt
env_setup_script:
Expand Down
6 changes: 2 additions & 4 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[pytest]
addopts = -vvv -rs --ignore=setup.py --pep8 --cov-report term-missing --cov=./iocage_lib --cov=./iocage_cli
pep8maxlinelength = 80
pep8ignore = * ALL
addopts = -vvv -rs --ignore=setup.py --pycodestyle --cov-report term-missing --cov=./iocage_lib --cov=./iocage_cli
markers =
require_zpool
require_root
Expand All @@ -10,4 +8,4 @@ markers =
require_networking
require_nat
require_upgrade
require_image
require_image
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest
pytest-cov
pytest-pep8
pytest-mock
pytest-pycodestyle
mock
flake8
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pycodestyle]
max-line-length = 80
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def pytest_addoption(parser):
help='Specify a zpool to use.'
)
parser.addoption(
'--release', action='store', default='14.1-RELEASE',
'--release', action='store', default='latest',
help='Specify a RELEASE to use.'
)
parser.addoption(
Expand Down
13 changes: 9 additions & 4 deletions tests/functional_tests/0004_start_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_02_start_rc_jail(invoke_cli, resource_selector):
for jail in resource_selector.rcjails:
assert jail.running is True, f'{jail.name} not running'


# Network-related tests belong here because the code is only executed at jail
# start time.

Expand Down Expand Up @@ -97,11 +98,15 @@ def test_03_create_and_start_nobridge_vnet_jail(release, jail, invoke_cli):
stdout, stderr = jail.run_command(['ifconfig'], jailed=False)

assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}'
assert re.search(r'bridge[0-9]', stdout) is None, 'Unexpected bridge was created.'
assert re.search(r'bridge[0-9]', stdout) is None, \
'Unexpected bridge was created.'
assert f'fe80::1%vnet0.{jail.jid}' in stdout
assert f'description: associated with jail: {jail.name} as nic: epair0b'
assert (f'description: associated with jail: {jail.name} '
'as nic: epair0b') in stdout

stdout, stderr = jail.run_command(['ping', '-c', '1', f'fe80::2%vnet0.{jail.jid}'], jailed=False)
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}'

invoke_cli([
Expand Down Expand Up @@ -136,4 +141,4 @@ def test_04_vnet_jail_with_loopback_alias(release, jail, invoke_cli):

invoke_cli([
'destroy', jail.name, '-f'
])
])
2 changes: 1 addition & 1 deletion tests/functional_tests/0005_stop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_03_test_force_flag_stopping_jail(
)

assert jail.running is False
assert not os.path.exists(test_file),\
assert not os.path.exists(test_file), \
f'Pre-stop services being executed'

finally:
Expand Down
3 changes: 2 additions & 1 deletion tests/functional_tests/0015_rename_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_01_rename_jail(invoke_cli, resource_selector, skip_test, jail):

@require_root
@require_zpool
def test_02_rename_template_jail(invoke_cli, resource_selector, skip_test, jail):
def test_02_rename_template_jail(invoke_cli, resource_selector, skip_test,
jail):
jails = resource_selector.template_jails
skip_test(not jails)

Expand Down
10 changes: 5 additions & 5 deletions tests/functional_tests/0016_restart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def test_01_restart_jail(invoke_cli, resource_selector, skip_test, write_file):

@require_root
@require_zpool
def test_02_soft_restart_jail(invoke_cli, resource_selector, skip_test, write_file):
def test_02_soft_restart_jail(invoke_cli, resource_selector, skip_test,
write_file):
common_restart_jail(
invoke_cli, resource_selector, skip_test,
['restart', '-s'], write_file
Expand All @@ -136,14 +137,13 @@ def test_02_soft_restart_jail(invoke_cli, resource_selector, skip_test, write_fi
@require_root
@require_zpool
def test_03_restart_all_jails(invoke_cli, resource_selector, skip_test):
common_restart_all_jails(invoke_cli, resource_selector, skip_test, ['restart'])


common_restart_all_jails(invoke_cli, resource_selector, skip_test,
['restart'])


@require_root
@require_zpool
def test_04_soft_restart_all_jails(invoke_cli, resource_selector, skip_test):
common_restart_all_jails(
invoke_cli, resource_selector, skip_test, ['restart', '-s']
)
)
11 changes: 6 additions & 5 deletions tests/functional_tests/0020_remove_snapshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_01_remove_snapshot(invoke_cli, resource_selector, skip_test):
@require_root
@require_zpool
def test_02_remove_snapshot_of_all_jails(
invoke_cli, resource_selector, skip_test):
invoke_cli, resource_selector, skip_test):
jails = resource_selector.all_jails
skip_test(not jails)

Expand All @@ -93,6 +93,7 @@ def test_02_remove_snapshot_of_all_jails(

assert all(snap.exists is False for snap in remove_snaps)


@require_root
@require_zpool
def test_03_remove_all_snapshots_fail(invoke_cli, resource_selector, skip_test):
Expand All @@ -102,7 +103,7 @@ def test_03_remove_all_snapshots_fail(invoke_cli, resource_selector, skip_test):
snap_jail = None
for jail in jails:
if (not jail.is_template and not jail.is_cloned and
len(jail.recursive_snapshots)>0):
len(jail.recursive_snapshots) > 0):
snap_jail = jail
break

Expand All @@ -124,14 +125,14 @@ def test_03_remove_all_snapshots_fail(invoke_cli, resource_selector, skip_test):
@require_root
@require_zpool
def test_04_remove_all_snapshots_success(invoke_cli, resource_selector,
snapshot, skip_test):
snapshot, skip_test):
jails = resource_selector.all_jails_having_snapshots
skip_test(not jails)

snap_jail = None
for jail in jails:
if (not jail.is_template and not jail.is_cloned and
len(jail.recursive_snapshots)>1):
len(jail.recursive_snapshots) > 1):
snap_jail = jail
break

Expand Down Expand Up @@ -160,7 +161,7 @@ def test_04_remove_all_snapshots_success(invoke_cli, resource_selector,
@require_root
@require_zpool
def test_05_remove_all_snapshots_all_jails(invoke_cli, resource_selector,
snapshot, skip_test):
snapshot, skip_test):
jails = resource_selector.all_jails_having_snapshots
skip_test(not jails)

Expand Down
2 changes: 1 addition & 1 deletion tests/functional_tests/0097_upgrade_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def test_02_upgrade_jail(

invoke_cli(
['upgrade', jail.name, '-r', release]
)
)
69 changes: 38 additions & 31 deletions tests/unit_tests/1000_lib_start_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@ def test_should_return_mtu_of_first_member_with_description(mock_checkoutput):
mock.call(["ifconfig", "bge0"])])


#@mock.patch('iocage_lib.ioc_common.checkoutput')
#def test_should_return_default_mtu_if_no_members(mock_checkoutput):
# mock_checkoutput.side_effect = [bridge_with_no_members_if_config,
# member_if_config]
# @mock.patch('iocage_lib.ioc_common.checkoutput')
# def test_should_return_default_mtu_if_no_members(mock_checkoutput):
# mock_checkoutput.side_effect = [bridge_with_no_members_if_config,
# member_if_config]
#
# # IOCStart.get() is not implemented in test mode. We need it for this test.
# # So provide a dummy implementation which gives us the default MTU.
# def _mock_iocstart_get(prop):
# if prop=='vnet_default_mtu':
# return "1500"
# raise AttributeError(prop)
# # IOCStart.get() is not implemented in test mode.
# # We need it for this test.
# # So provide a dummy implementation which gives us the default MTU.
# def _mock_iocstart_get(prop):
# if prop=='vnet_default_mtu':
# return "1500"
# raise AttributeError(prop)
#
# iocs = ioc_start.IOCStart("", "", unit_test=True)
# iocs.get = _mock_iocstart_get
# mtu = iocs.find_bridge_mtu('bridge0')
# assert mtu == '1500'
# mock_checkoutput.called_with(["ifconfig", "bridge0"])
# iocs = ioc_start.IOCStart("", "", unit_test=True)
# iocs.get = _mock_iocstart_get
# mtu = iocs.find_bridge_mtu('bridge0')
# assert mtu == '1500'
# mock_checkoutput.called_with(["ifconfig", "bridge0"])


@mock.patch('iocage_lib.ioc_common.logit')
Expand Down Expand Up @@ -96,10 +97,10 @@ def test_should_return_default_interface(mock_logit, test_input, expected):
assert actual == expected
mock_logit.assert_not_called()
else:
mock_logit.assert_called_once_with({'level': 'EXCEPTION',
'message': 'No default interface found'},
_callback=None,
silent=False)
mock_logit.assert_called_once_with(
{'level': 'EXCEPTION', 'message': 'No default interface found'},
_callback=None,
silent=False)


@pytest.mark.parametrize('test_input,expected', [
Expand Down Expand Up @@ -141,7 +142,8 @@ def test_should_return_default_gateway(test_input, expected):
assert iocstart.get_default_gateway('ipv6') == expected['ipv6']


bridge_if_config = """bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
bridge_if_config = """\
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 00:00:00:00:00:00
nd6 options=1<PERFORMNUD>
groups: bridge
Expand All @@ -152,7 +154,8 @@ def test_should_return_default_gateway(test_input, expected):
ifmaxaddr 0 port 1 priority 128 path cost 20000
"""

bridge_with_description_if_config = """bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
bridge_with_description_if_config = """\
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: first-bridge
ether 00:00:00:00:00:00
nd6 options=1<PERFORMNUD>
Expand All @@ -164,7 +167,8 @@ def test_should_return_default_gateway(test_input, expected):
ifmaxaddr 0 port 1 priority 128 path cost 20000
"""

bridge_with_no_members_if_config = """bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
bridge_with_no_members_if_config = """\
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: first-bridge
ether 00:00:00:00:00:00
nd6 options=1<PERFORMNUD>
Expand All @@ -174,12 +178,15 @@ def test_should_return_default_gateway(test_input, expected):
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
"""

member_if_config = """bge0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=c019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>
ether 00:00:00:00:00:00
inet6 fe80::0000:0000:0000:0000%bge0 prefixlen 64 scopeid 0x1
inet 10.2.3.4 netmask 0xffffff00 broadcast 10.2.3.255
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
"""
member_if_config = (
"bge0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST>"
" metric 0 mtu 1500\n"
" options=c019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,"
"VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>\n"
" ether 00:00:00:00:00:00\n"
" inet6 fe80::0000:0000:0000:0000%bge0 prefixlen 64 scopeid 0x1\n"
" inet 10.2.3.4 netmask 0xffffff00 broadcast 10.2.3.255\n"
" nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>\n"
" media: Ethernet autoselect (1000baseT <full-duplex>)\n"
" status: active\n"
)
48 changes: 47 additions & 1 deletion tests/unit_tests/1003_lib_host_gateways_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,50 @@ def test_01_get_host_gateways(mock_checkoutput):
'ipv6': {'gateway': 'fe80::8%inet0', 'interface': 'inet0'}}


netstat_output = '{"statistics": {"route-information": {"route-table": {"rt-family": [{"address-family":"Internet", "rt-entry": [{"destination":"default","gateway":"217.29.43.254","flags":"UGS", "flags_pretty": ["up","gateway","static"],"interface-name":"inet0"}, {"destination":"10.5.0.0/16","gateway":"link#5","flags":"U", "flags_pretty": ["up"],"interface-name":"mgmt0"}, {"destination":"10.5.105.29","gateway":"link#5","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"127.0.0.1","gateway":"lo0","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"217.29.42.0/23","gateway":"link#4","flags":"U", "flags_pretty": ["up"],"interface-name":"inet0"}, {"destination":"217.29.42.186","gateway":"link#4","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}]}, {"address-family":"Internet6", "rt-entry": [{"destination":"::/96","gateway":"::1","flags":"UGRS", "flags_pretty": ["up","gateway","reject","static"],"interface-name":"lo0"}, {"destination":"default","gateway":"fe80::8%inet0","flags":"UGS", "flags_pretty": ["up","gateway","static"],"interface-name":"inet0"}, {"destination":"::1","gateway":"lo0","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"::ffff:0.0.0.0/96","gateway":"::1","flags":"UGRS", "flags_pretty": ["up","gateway","reject","static"],"interface-name":"lo0"}, {"destination":"2a00:b580:8000:8::/64","gateway":"link#4","flags":"U", "flags_pretty": ["up"],"interface-name":"inet0"}, {"destination":"2a00:b580:8000:8:9d6:2f93:3504:d4c9","gateway":"link#4","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"fe80::/10","gateway":"::1","flags":"UGRS", "flags_pretty": ["up","gateway","reject","static"],"interface-name":"lo0"}, {"destination":"fe80::%lo0/64","gateway":"link#3","flags":"U", "flags_pretty": ["up"],"interface-name":"lo0"}, {"destination":"fe80::1%lo0","gateway":"link#3","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"fe80::%inet0/64","gateway":"link#4","flags":"U", "flags_pretty": ["up"],"interface-name":"inet0"}, {"destination":"fe80::921b:eff:fe63:ef31%inet0","gateway":"link#4","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"fe80::%mgmt0/64","gateway":"link#5","flags":"U", "flags_pretty": ["up"],"interface-name":"mgmt0"}, {"destination":"fe80::921b:eff:fe63:f359%mgmt0","gateway":"link#5","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"fe80::%vnet0.97/64","gateway":"link#7","flags":"U", "flags_pretty": ["up"],"interface-name":"vnet0.97"}, {"destination":"fe80::1015:29ff:fecd:61a7%vnet0.97","gateway":"link#7","flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {"destination":"ff02::/16","gateway":"::1","flags":"UGRS", "flags_pretty": ["up","gateway","reject","static"],"interface-name":"lo0"}]}]}}}}'
netstat_output = (
'{"statistics": {"route-information": {"route-table": {"rt-family": '
'[{"address-family":"Internet", "rt-entry": [{"destination":"default",'
'"gateway":"217.29.43.254","flags":"UGS", "flags_pretty": ["up",'
'"gateway","static"],"interface-name":"inet0"}, {"destination":'
'"10.5.0.0/16","gateway":"link#5","flags":"U", "flags_pretty": ["up"],'
'"interface-name":"mgmt0"}, {"destination":"10.5.105.29","gateway":'
'"link#5","flags":"UHS", "flags_pretty": ["up","host","static"],'
'"interface-name":"lo0"}, {"destination":"127.0.0.1","gateway":"lo0",'
'"flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":'
'"lo0"}, {"destination":"217.29.42.0/23","gateway":"link#4","flags":"U", '
'"flags_pretty": ["up"],"interface-name":"inet0"}, {"destination":'
'"217.29.42.186","gateway":"link#4","flags":"UHS", "flags_pretty": ["up",'
'"host","static"],"interface-name":"lo0"}]}, {"address-family":'
'"Internet6", "rt-entry": [{"destination":"::/96","gateway":"::1",'
'"flags":"UGRS", "flags_pretty": ["up","gateway","reject","static"],'
'"interface-name":"lo0"}, {"destination":"default","gateway":'
'"fe80::8%inet0","flags":"UGS", "flags_pretty": ["up","gateway","static"]'
',"interface-name":"inet0"}, {"destination":"::1","gateway":"lo0","flags"'
':"UHS", "flags_pretty": ["up","host","static"],"interface-name":"lo0"}, '
'{"destination":"::ffff:0.0.0.0/96","gateway":"::1","flags":"UGRS", '
'"flags_pretty": ["up","gateway","reject","static"],"interface-name":'
'"lo0"}, {"destination":"2a00:b580:8000:8::/64","gateway":"link#4",'
'"flags":"U", "flags_pretty": ["up"],"interface-name":"inet0"}, '
'{"destination":"2a00:b580:8000:8:9d6:2f93:3504:d4c9","gateway":"link#4",'
'"flags":"UHS", "flags_pretty": ["up","host","static"],"interface-name":'
'"lo0"}, {"destination":"fe80::/10","gateway":"::1","flags":"UGRS", '
'"flags_pretty": ["up","gateway","reject","static"],"interface-name":'
'"lo0"}, {"destination":"fe80::%lo0/64","gateway":"link#3","flags":"U", '
'"flags_pretty": ["up"],"interface-name":"lo0"}, {"destination":'
'"fe80::1%lo0","gateway":"link#3","flags":"UHS", "flags_pretty": ["up",'
'"host","static"],"interface-name":"lo0"}, {"destination":'
'"fe80::%inet0/64","gateway":"link#4","flags":"U", "flags_pretty": '
'["up"],"interface-name":"inet0"}, {"destination":'
'"fe80::921b:eff:fe63:ef31%inet0","gateway":"link#4","flags":"UHS", '
'"flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {'
'"destination":"fe80::%mgmt0/64","gateway":"link#5","flags":"U", '
'"flags_pretty": ["up"],"interface-name":"mgmt0"}, {"destination":'
'"fe80::921b:eff:fe63:f359%mgmt0","gateway":"link#5","flags":"UHS", '
'"flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {'
'"destination":"fe80::%vnet0.97/64","gateway":"link#7","flags":"U", '
'"flags_pretty": ["up"],"interface-name":"vnet0.97"}, {"destination":'
'"fe80::1015:29ff:fecd:61a7%vnet0.97","gateway":"link#7","flags":"UHS", '
'"flags_pretty": ["up","host","static"],"interface-name":"lo0"}, {'
'"destination":"ff02::/16","gateway":"::1","flags":"UGRS", '
'"flags_pretty": ["up","gateway","reject","static"],"interface-name":'
'"lo0"}]}]}}}}')
5 changes: 4 additions & 1 deletion tests/unit_tests/1004_lib_plugin_manifest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"iocage-plugins": [
{
"function": "sha256",
"fingerprint": "b0170035af3acc5f3f3ae1859dc717101b4e6c1d0a794ad554928ca0cbb2f438"
"fingerprint": (
"b0170035af3acc5f3f3ae1859dc71710"
"1b4e6c1d0a794ad554928ca0cbb2f438"
)
}
]
},
Expand Down