diff --git a/.cirrus.yml b/.cirrus.yml index 174e2498..1a1470be 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,8 +1,7 @@ task: freebsd_instance: matrix: - #image: freebsd-11-2-release-amd64 - image: freebsd-12-0-release-amd64 + image: freebsd-12-1-release-amd64 pip_cache: folder: ~/.cache/pip fingerprint_script: cat requirements* @@ -15,6 +14,11 @@ task: zpool create -m "/.ioc-test-`uname -r`" "ioc-test-`uname -r`" "/pools/ioc-test-`uname -r`.img" zfs set compression=lz4 "ioc-test-`uname -r`" install_script: + - uname -a + - uname -KU + - kldstat + - sysrc -a + - sysctl -a - mount -t fdescfs null /dev/fd - pkg install -y git - make install-dev diff --git a/.travis.yml b/.travis.yml index df24de67..3606e167 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - "3.6" + - "3.7" sudo: false env: - MYPYPATH="$TRAVIS_BUILD_DIR/.travis/mypy-stubs" diff --git a/.travis/mypy-stubs/libzfs.pyi b/.travis/mypy-stubs/libzfs.pyi index 30c69bfc..fbde1514 100644 --- a/.travis/mypy-stubs/libzfs.pyi +++ b/.travis/mypy-stubs/libzfs.pyi @@ -77,7 +77,12 @@ class ZFS: pools: Generator[ZFSPool, None, None] = ... snapshots: Generator[ZFSSnapshot, None, None] = ... __pyx_vtable__ = ... # type: Any - def __init__(self, history: bool=True, history_prefix: str='') -> None: ... + def __init__( + self, + history: bool=True, + history_prefix: str='', + mnttab_cache: bool=True + ) -> None: ... def create( self, name: str, diff --git a/Makefile b/Makefile index d4e97c94..4e64abd2 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,11 @@ JAIL_NIC?=vtnet0 JAIL_IP?=172.16.0 JAIL_NET?=16 MYPYPATH = $(shell pwd)/.travis/mypy-stubs -PYTHON ?= python3.6 +PYTHON_VERSION ?= $(TRAVIS_PYTHON_VERSION) +SELECTED_PYTHON_VERSION != if [ "$(PYTHON_VERSION)" != "" ]; then echo $(PYTHON_VERSION); else pkg info -g 'python3*' | cut -d'-' -f1 | sed 's/^python//' | sort -n | tail -n1 | sed -r 's/^([0-9])([0-9]+)/\1.\2/'; fi +PYTHON ?= python${SELECTED_PYTHON_VERSION} +# turn python3.7 -> 3.7 -> 37 pyver= ${PYTHON:S/^python//:S/.//:C/\([0-9]+\)/\1/} .if $(pyver) < 35 @@ -19,13 +22,13 @@ install-python-requirements: install-python-requirements-dev: install-python-requirements $(PYTHON) -m pip install -Ur requirements-dev.txt install-deps: - pkg install -q -y libucl py$(pyver)-ucl py$(pyver)-cython rsync python$(pyver) py$(pyver)-libzfs + pkg install -q -y libucl py$(pyver)-ucl py$(pyver)-setuptools rsync python$(pyver) py$(pyver)-libzfs install-deps-dev: install-deps - if [ "`uname`" = "FreeBSD" ]; then pkg install -y gmake py36-sqlite3; fi + if [ "`uname`" = "FreeBSD" ]; then pkg install -y gmake py$(pyver)-sqlite3; fi install-dev: install-deps-dev install-python-requirements-dev $(PYTHON) -m pip install -e . install-travis: - python3.6 -m pip install -IU flake8-mutable flake8-docstrings flake8-builtins flake8-mypy bandit==1.5.1 bandit-high-entropy-string + python$(TRAVIS_PYTHON_VERSION) -m pip install -IU flake8-mutable flake8-docstrings flake8-builtins flake8-mypy bandit==1.5.1 bandit-high-entropy-string uninstall: $(PYTHON) -m pip uninstall -y ioc @if [ -f /usr/local/etc/rc.d/ioc ]; then \ @@ -33,6 +36,7 @@ uninstall: fi check: flake8 --version + mypy --version flake8 --exclude=".travis,.eggs,__init__.py,docs,tests" --ignore=E203,E252,W391,D107,A001,A002,A003,A004,D412,D413,T499 bandit --skip B404,B110 --exclude tests/ -r . test: diff --git a/README.md b/README.md index 53be4137..6f227ed2 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,17 @@ cd libioc make install ``` -At the current time libiocage is not packaged or available in FreeBSD ports. +The default Python version is 3.7. If you intend to run libioc from another version, please specify it during the installation: + +```sh +make PYTHON=python3.8 install +``` + +At the current time libioc is not packaged or available in FreeBSD ports. ## Documentation -- Iocage Handbook: https://bsdci.github.io/handbook +- Ioc Handbook: https://bsdci.github.io/handbook - Reference Documentation: https://bsdci.github.io/libioc - Gitter Chat: https://gitter.im/libioc/community diff --git a/libioc/Pkg.py b/libioc/Pkg.py index 9d795a0a..2135e6ec 100644 --- a/libioc/Pkg.py +++ b/libioc/Pkg.py @@ -144,7 +144,8 @@ def _update_host_repo(self, release_major_version: int) -> None: logger=self.logger, env=dict( ABI=self.__get_abi_string(release_major_version), - SIGNATURE_TYPE="fingerprints" + SIGNATURE_TYPE="fingerprints", + IGNORE_OSVERSION="yes" ) ) diff --git a/libioc/ZFS.py b/libioc/ZFS.py index 59ebd8cf..449a5c6c 100644 --- a/libioc/ZFS.py +++ b/libioc/ZFS.py @@ -280,7 +280,11 @@ def get_zfs( history_prefix: str="" ) -> ZFS: """Get an instance of iocages enhanced ZFS class.""" - zfs = ZFS(history=history, history_prefix=history_prefix) + zfs = ZFS( + history=history, + history_prefix=history_prefix, + mnttab_cache=False + ) zfs.logger = libioc.helpers_object.init_logger(zfs, logger) return zfs diff --git a/libioc/helpers_ioctl.py b/libioc/helpers_ioctl.py index 528042f1..b739a079 100644 --- a/libioc/helpers_ioctl.py +++ b/libioc/helpers_ioctl.py @@ -41,7 +41,12 @@ def get_sockio_ioctl(nic_name: str, ioctl: SOCKIO_IOCTLS) -> bytes: """Query a sockio ioctl for a given NIC.""" with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) as sock: ifconf = struct.pack('256s', nic_name.encode("UTF-8")[:15]) - return bytes(fcntl.ioctl(sock.fileno(), ioctl.value, ifconf)) + return bytes(fcntl.ioctl( + sock.fileno(), + int(ioctl.value), + bytes(ifconf), + True + )) def get_interface_ip4_address(nic_name: str) -> ipaddress.IPv4Address: diff --git a/requirements.txt b/requirements.txt index f853105f..73992402 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ gitpython -freebsd_sysctl==0.0.6 -jail==0.0.8 +freebsd_sysctl==0.0.7 +jail==0.0.11 diff --git a/setup.cfg b/setup.cfg index 57b59a67..f7fa6d93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ description-file = README.md [mypy] -python_version = 3.6 +python_version = 3.7 # override flake8-mypy defaults, since we provide (missing) types platform='freebsd' diff --git a/tests/test_Jail.py b/tests/test_Jail.py index 11ff4796..487297e9 100644 --- a/tests/test_Jail.py +++ b/tests/test_Jail.py @@ -87,7 +87,7 @@ def test_can_be_started( assert existing_jail.running is True stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") @@ -104,7 +104,7 @@ def test_can_mount_devfs( existing_jail.start() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev" in stdout @@ -112,7 +112,7 @@ def test_can_mount_devfs( existing_jail.stop() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev" not in stdout @@ -128,7 +128,7 @@ def test_can_mount_fdescfs( existing_jail.start() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev/fd" in stdout @@ -136,7 +136,7 @@ def test_can_mount_fdescfs( existing_jail.stop() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev/fd" not in stdout @@ -152,7 +152,7 @@ def test_can_mount_devfs_and_fdescfs( existing_jail.start() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev (" in stdout @@ -160,7 +160,7 @@ def test_can_mount_devfs_and_fdescfs( existing_jail.stop() stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "/dev (" not in stdout @@ -242,9 +242,9 @@ def test_can_be_started( existing_jail.start() assert existing_jail.running is True - root_path = existing_jail.root_dataset.name + root_path = existing_jail.root_dataset.mountpoint stdout = subprocess.check_output( - [f"/sbin/mount | grep {existing_jail.root_dataset.name}"], + [f"/sbin/mount | grep {existing_jail.root_dataset.mountpoint}"], shell=True ).decode("utf-8") assert "launch-scripts in stdout" @@ -268,7 +268,7 @@ def test_can_be_stopped( [f"/usr/sbin/jls", "-j", existing_jail.identifier] ).decode("utf-8") - root_path = existing_jail.root_dataset.name + root_path = existing_jail.root_dataset.mountpoint stdout = subprocess.check_output( [f"/sbin/mount | grep {root_path}"], shell=True diff --git a/tests/test_VNET.py b/tests/test_VNET.py index ca13b7b9..bf2f7f4b 100644 --- a/tests/test_VNET.py +++ b/tests/test_VNET.py @@ -22,6 +22,7 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. """Unit tests for VNET.""" +import pytest import json import os import subprocess @@ -31,6 +32,21 @@ import libioc.Jail + +def is_epair_enabled() -> bool: + proc = subprocess.Popen( + ["/sbin/kldstat", "-n", "if_epair"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) + proc.communicate() + return (proc.returncode == 0) + + +@pytest.mark.skipif( + (is_epair_enabled() is False), + reason="if_epair is not loaded" +) class TestVNET(object): """Run tests for VNET networking."""