diff --git a/.cirrus.yml b/.cirrus.yml index 0301ecc0..40ce256b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,5 +1,5 @@ freebsd_instance: - image_family: freebsd-14-1 + image_family: freebsd-15-0-amd64-zfs iocage_tests_task: create_pool_script: @@ -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 @@ -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: diff --git a/pytest.ini b/pytest.ini index 9919cb60..a80e93aa 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 @@ -10,4 +8,4 @@ markers = require_networking require_nat require_upgrade - require_image \ No newline at end of file + require_image diff --git a/requirements-test.txt b/requirements-test.txt index 01d4b18b..d93bb512 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,6 @@ pytest pytest-cov -pytest-pep8 pytest-mock +pytest-pycodestyle mock flake8 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..4e64d554 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[pycodestyle] +max-line-length = 80 diff --git a/tests/conftest.py b/tests/conftest.py index be54a33f..2e0111d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( diff --git a/tests/functional_tests/0004_start_test.py b/tests/functional_tests/0004_start_test.py index 4777f26c..bed2b163 100644 --- a/tests/functional_tests/0004_start_test.py +++ b/tests/functional_tests/0004_start_test.py @@ -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. @@ -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([ @@ -136,4 +141,4 @@ def test_04_vnet_jail_with_loopback_alias(release, jail, invoke_cli): invoke_cli([ 'destroy', jail.name, '-f' - ]) \ No newline at end of file + ]) diff --git a/tests/functional_tests/0005_stop_test.py b/tests/functional_tests/0005_stop_test.py index db6c6a25..3b6684df 100644 --- a/tests/functional_tests/0005_stop_test.py +++ b/tests/functional_tests/0005_stop_test.py @@ -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: diff --git a/tests/functional_tests/0015_rename_test.py b/tests/functional_tests/0015_rename_test.py index 1577f1e2..75155ccd 100644 --- a/tests/functional_tests/0015_rename_test.py +++ b/tests/functional_tests/0015_rename_test.py @@ -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) diff --git a/tests/functional_tests/0016_restart_test.py b/tests/functional_tests/0016_restart_test.py index dadfb665..6318944e 100644 --- a/tests/functional_tests/0016_restart_test.py +++ b/tests/functional_tests/0016_restart_test.py @@ -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 @@ -136,9 +137,8 @@ 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 @@ -146,4 +146,4 @@ def test_03_restart_all_jails(invoke_cli, resource_selector, skip_test): 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'] - ) \ No newline at end of file + ) diff --git a/tests/functional_tests/0020_remove_snapshot_test.py b/tests/functional_tests/0020_remove_snapshot_test.py index bf9bbbb3..c343899d 100644 --- a/tests/functional_tests/0020_remove_snapshot_test.py +++ b/tests/functional_tests/0020_remove_snapshot_test.py @@ -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) @@ -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): @@ -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 @@ -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 @@ -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) diff --git a/tests/functional_tests/0097_upgrade_test.py b/tests/functional_tests/0097_upgrade_test.py index 706c9dc0..6423444c 100644 --- a/tests/functional_tests/0097_upgrade_test.py +++ b/tests/functional_tests/0097_upgrade_test.py @@ -64,4 +64,4 @@ def test_02_upgrade_jail( invoke_cli( ['upgrade', jail.name, '-r', release] - ) \ No newline at end of file + ) diff --git a/tests/unit_tests/1000_lib_start_test.py b/tests/unit_tests/1000_lib_start_test.py index 0b439b1e..9226a355 100644 --- a/tests/unit_tests/1000_lib_start_test.py +++ b/tests/unit_tests/1000_lib_start_test.py @@ -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') @@ -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', [ @@ -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 metric 0 mtu 1500 +bridge_if_config = """\ +bridge0: flags=8843 metric 0 mtu 1500 ether 00:00:00:00:00:00 nd6 options=1 groups: bridge @@ -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 metric 0 mtu 1500 +bridge_with_description_if_config = """\ +bridge0: flags=8843 metric 0 mtu 1500 description: first-bridge ether 00:00:00:00:00:00 nd6 options=1 @@ -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 metric 0 mtu 1500 +bridge_with_no_members_if_config = """\ +bridge0: flags=8843 metric 0 mtu 1500 description: first-bridge ether 00:00:00:00:00:00 nd6 options=1 @@ -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 metric 0 mtu 1500 - options=c019b - 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 - media: Ethernet autoselect (1000baseT ) - status: active -""" +member_if_config = ( + "bge0: flags=8943" + " metric 0 mtu 1500\n" + " options=c019b\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\n" + " media: Ethernet autoselect (1000baseT )\n" + " status: active\n" + ) diff --git a/tests/unit_tests/1003_lib_host_gateways_test.py b/tests/unit_tests/1003_lib_host_gateways_test.py index 7778f136..0a9b5148 100644 --- a/tests/unit_tests/1003_lib_host_gateways_test.py +++ b/tests/unit_tests/1003_lib_host_gateways_test.py @@ -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"}]}]}}}}') diff --git a/tests/unit_tests/1004_lib_plugin_manifest_test.py b/tests/unit_tests/1004_lib_plugin_manifest_test.py index dbaa90b9..c0b14ab7 100644 --- a/tests/unit_tests/1004_lib_plugin_manifest_test.py +++ b/tests/unit_tests/1004_lib_plugin_manifest_test.py @@ -11,7 +11,10 @@ "iocage-plugins": [ { "function": "sha256", - "fingerprint": "b0170035af3acc5f3f3ae1859dc717101b4e6c1d0a794ad554928ca0cbb2f438" + "fingerprint": ( + "b0170035af3acc5f3f3ae1859dc71710" + "1b4e6c1d0a794ad554928ca0cbb2f438" + ) } ] },