From dcac8b83983a2d408889fd2a067a129601eab66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 28 Aug 2017 16:20:48 +0200 Subject: [PATCH 01/15] implement type-hints for all our functions as a first step, we'll ad mypy static analyzer to check those. This should give us extra (offline) guarantees about those types. --- .gitignore | 1 + setup.cfg | 3 +++ setup.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ee0fab70..5251a9a1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ venv-*/ .python-version python3.6.core man/*.gz +.mypy_cache/ diff --git a/setup.cfg b/setup.cfg index 0fa743fd..defb2320 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,9 @@ [metadata] description-file = README.md +[mypy] +python_version = 3.6 + [tool:pytest] addopts = -v -x -rs --ignore=setup.py --pep8 --cov-report term-missing --cov=libiocage/lib libiocage/lib libiocage/tests pep8maxlinelength = 80 diff --git a/setup.py b/setup.py index fb4f00e1..fafe7ada 100644 --- a/setup.py +++ b/setup.py @@ -64,5 +64,5 @@ ] }, data_files=_data, - tests_require=['pytest', 'pytest-cov', 'pytest-pep8'] + tests_require=['pytest', 'pytest-cov', 'pytest-pep8', 'mypy'] ) From 73983e03323b1cf4c28712b27e6dcef6e6354533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 28 Aug 2017 21:12:19 +0200 Subject: [PATCH 02/15] Jail: start adding type hints --- libiocage/lib/Jail.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index a719fdf1..0c2c9b6a 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -17,6 +17,8 @@ import libiocage.lib.events import libiocage.lib.helpers +from typing import Union, Optional, List + class JailGenerator: """ @@ -64,19 +66,24 @@ class JailGenerator: _class_host = libiocage.lib.Host.HostGenerator _class_storage = libiocage.lib.Storage.Storage - def __init__(self, data={}, zfs=None, host=None, logger=None, new=False): + def __init__(self, + data: Union[str, dict]={}, + zfs: Optional[libzfs.ZFS]=None, + host: Optional[libiocage.lib.Host]=None, + logger: Optional[libiocage.lib.Logger]=None, + new=False) -> None: """ Initializes a Jail Args: - data (string|dict): + data: Jail configuration dict or jail name as string identifier. - zfs (libzfs.ZFS): (optional) + zfs: Inherit an existing libzfs.ZFS() instance from ancestor classes - host (libiocage.lib.Host): (optional) + host: Inherit an existing Host instance from ancestor classes logger (libiocage.lib.Logger): (optional) @@ -99,7 +106,7 @@ def __init__(self, data={}, zfs=None, host=None, logger=None, new=False): logger=self.logger ) - self.networks = [] + self.networks: List[str] = [] self.storage = self._class_storage( auto_create=True, @@ -209,13 +216,13 @@ def _start_services(self): self.logger.debug(f"Running exec_start on {self.humanreadable_name}") self.exec(command) - def stop(self, force=False): + def stop(self, force: bool=False) -> None: """ Stop a jail. Args: - force (bool): (default=False) + force: Ignores failures and enforces teardown if True """ @@ -245,13 +252,13 @@ def stop(self, force=False): self.update_jail_state() - def destroy(self, force=False): + def destroy(self, force: bool=False) -> None: """ Destroy a Jail and it's datasets Args: - force (bool): (default=False) + force: This flag enables whether an existing jail should be shut down before destroying the dataset. By default destroying a jail requires it to be stopped. From e718786cc0879be59992367a33d22c46d7f3e765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 28 Aug 2017 21:13:04 +0200 Subject: [PATCH 03/15] Jail: apparently no one cares if stop() is successful --- libiocage/lib/Jail.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index 0c2c9b6a..250f0f9b 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -273,15 +273,12 @@ def destroy(self, force: bool=False) -> None: self.storage.delete_dataset_recursive(self.dataset) - def _force_stop(self): - - successful = True + def _force_stop(self) -> None: try: self._destroy_jail() self.logger.debug(f"{self.humanreadable_name}: jail destroyed") except Exception as e: - successful = False self.logger.warn(str(e)) if self.config["vnet"]: @@ -289,31 +286,26 @@ def _force_stop(self): self._stop_vimage_network() self.logger.debug(f"{self.humanreadable_name}: VNET stopped") except Exception as e: - successful = False self.logger.warn(str(e)) try: self._teardown_mounts() self.logger.debug(f"{self.humanreadable_name}: mounts destroyed") except Exception as e: - successful = False self.logger.warn(str(e)) try: self.update_jail_state() except Exception as e: - successful = False self.logger.warn(str(e)) - return successful - - def create(self, release_name): + def create(self, release_name: str) -> None: """ Create a Jail from a Release Args: - release_name (string): + release_name: The jail is created from the release matching the name provided """ From e33c1dd0909b2297767bbdd6eab807fd55c861c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 28 Aug 2017 21:13:29 +0200 Subject: [PATCH 04/15] Jail: type-hint execs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in the process i also found a few instances where we were mutating input parameters — unnecessarily so. n.b.: libiocage.lib.Foo is the module, libiocage.lib.Foo.Foo is the actual class that we want --- libiocage/lib/Jail.py | 29 ++++++++++++++--------------- libiocage/lib/helpers.py | 24 ++++++++++-------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index 250f0f9b..f879e097 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -2,6 +2,8 @@ import subprocess import uuid +import libzfs + import libiocage.lib.DevfsRules import libiocage.lib.JailConfig import libiocage.lib.Network @@ -67,11 +69,11 @@ class JailGenerator: _class_storage = libiocage.lib.Storage.Storage def __init__(self, - data: Union[str, dict]={}, - zfs: Optional[libzfs.ZFS]=None, - host: Optional[libiocage.lib.Host]=None, - logger: Optional[libiocage.lib.Logger]=None, - new=False) -> None: + data: Union[str, dict]={}, + zfs: Optional[libzfs.ZFS]=None, + host: Optional[libiocage.lib.Host.Host]=None, + logger: Optional[libiocage.lib.Logger.Logger]=None, + new: bool=False) -> None: """ Initializes a Jail @@ -86,7 +88,7 @@ def __init__(self, host: Inherit an existing Host instance from ancestor classes - logger (libiocage.lib.Logger): (optional) + logger: Inherit an existing Logger instance from ancestor classes """ @@ -363,35 +365,32 @@ def create(self, release_name: str) -> None: self.config.data["release"] = release.name self.config.save() - def exec(self, command, **kwargs): + def exec(self, command: List[str], **kwargs): """ Execute a command in a started jail - command (list): + command: A list of command and it's arguments Example: ["/usr/bin/whoami"] """ - command = ["/usr/sbin/jexec", self.identifier] + command + jexec_command = ["/usr/sbin/jexec", self.identifier] + command return libiocage.lib.helpers.exec( - command, logger=self.logger, **kwargs + jexec_command, logger=self.logger, **kwargs ) - def passthru(self, command): + def passthru(self, command: List[str]): """ Execute a command in a started jail ans passthrough STDIN and STDOUT - command (list): + command: A list of command and it's arguments Example: ["/bin/sh"] """ - if isinstance(command, str): - command = [command] - return libiocage.lib.helpers.exec_passthru( [ "/usr/sbin/jexec", diff --git a/libiocage/lib/helpers.py b/libiocage/lib/helpers.py index 6e4b026e..95bee053 100644 --- a/libiocage/lib/helpers.py +++ b/libiocage/lib/helpers.py @@ -8,6 +8,8 @@ import libiocage.lib.Host import libiocage.lib.Logger +from typing import List + def init_zfs(self, zfs): if isinstance(zfs, libzfs.ZFS): @@ -50,11 +52,10 @@ def init_logger(self, logger=None): object.__setattr__(self, 'logger', new_logger) -def exec(command, logger=None, ignore_error=False): - if isinstance(command, str): - command = [command] +def exec(command, logger=None, ignore_error=False) -> ( + subprocess.Popen, str, str,): - command_str = " ".join(command) + command_str = " ".join(list([command])) if logger: logger.log(f"Executing: {command_str}", level="spam") @@ -230,21 +231,16 @@ def to_string(data, true="yes", false="no", none="-"): return str(data) -def exec_passthru(command, logger=None): - if isinstance(command, str): - command = [command] - +def exec_passthru(command: List[str], logger=None): command_str = " ".join(command) + if logger: logger.spam(f"Executing (interactive): {command_str}") - return subprocess.Popen(command).communicate() - + return subprocess.Popen(command_str).communicate() -def exec_raw(command, logger=None, **kwargs): - if isinstance(command, str): - command = [command] +def exec_raw(command: List[str], logger=None, **kwargs): command_str = " ".join(command) if logger: logger.spam(f"Executing (raw): {command_str}") @@ -255,7 +251,7 @@ def exec_raw(command, logger=None, **kwargs): ) -def exec_iter(command, logger=None): +def exec_iter(command: List[str], logger=None): process = exec_raw( command, logger=logger, From a72c2c75bad40abb378c3165bc9300c831557ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 10:49:21 +0200 Subject: [PATCH 05/15] Jail: add return values where unambigous --- libiocage/lib/Jail.py | 71 ++++++++++++++++++++--------------------- libiocage/lib/RCConf.py | 6 +++- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index f879e097..345c8c63 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -126,21 +126,21 @@ def __init__(self, self.config.read() @property - def zfs_pool_name(self): + def zfs_pool_name(self) -> str: """ Name of the ZFS pool the jail is stored on """ return self.host.datasets.root.name.split("/", maxsplit=1)[0] @property - def _rc_conf_path(self): + def _rc_conf_path(self) -> str: """ Absolute path to the jail's rc.conf file """ return f"{self.path}/root/etc/rc.conf" @property - def rc_conf(self): + def rc_conf(self) -> libiocage.lib.RCConf.RCConf: """ The jail's libiocage.RCConf instance (lazy-loaded on first access) """ @@ -152,7 +152,7 @@ def rc_conf(self): ) return self._rc_conf - def start(self): + def start(self) -> None: """ Start the jail. """ @@ -365,7 +365,7 @@ def create(self, release_name: str) -> None: self.config.data["release"] = release.name self.config.save() - def exec(self, command: List[str], **kwargs): + def exec(self, command: List[str], **kwargs) -> None: """ Execute a command in a started jail @@ -407,7 +407,7 @@ def exec_console(self): ["/usr/bin/login"] + self.config["login_flags"] ) - def _destroy_jail(self): + def _destroy_jail(self) -> None: command = ["jail", "-r"] command.append(self.identifier) @@ -419,7 +419,7 @@ def _destroy_jail(self): ) @property - def _dhcp_enabled(self): + def _dhcp_enabled(self) -> bool: """ True if any ip4_addr uses DHCP """ @@ -467,7 +467,7 @@ def devfs_ruleset(self): ruleset_line_position = self.host.devfs.index(devfs_ruleset) return self.host.devfs[ruleset_line_position].number - def _launch_jail(self): + def _launch_jail(self) -> None: command = ["jail", "-c"] @@ -561,7 +561,7 @@ def _launch_jail(self): ) raise - def _start_vimage_network(self): + def _start_vimage_network(self) -> None: self.logger.debug("Starting VNET/VIMAGE", jail=self) @@ -591,15 +591,15 @@ def _start_vimage_network(self): net.setup() self.networks.append(net) - def _stop_vimage_network(self): + def _stop_vimage_network(self) -> None: for network in self.networks: network.teardown() self.networks.remove(network) - def _configure_nameserver(self): + def _configure_nameserver(self) -> None: self.config["resolver"].apply(self) - def _configure_routes(self): + def _configure_routes(self) -> None: defaultrouter = self.config["defaultrouter"] defaultrouter6 = self.config["defaultrouter6"] @@ -614,7 +614,7 @@ def _configure_routes(self): if defaultrouter6: self._configure_route(defaultrouter6, ipv6=True) - def _configure_route(self, gateway, ipv6=False): + def _configure_route(self, gateway: str, ipv6: bool=False) -> None: ip_version = 4 + 2 * (ipv6 is True) @@ -628,7 +628,7 @@ def _configure_route(self, gateway, ipv6=False): self.exec(command) - def require_jail_not_existing(self): + def require_jail_not_existing(self) -> None: """ Raise JailAlreadyExists exception if the jail already exists """ @@ -637,7 +637,7 @@ def require_jail_not_existing(self): jail=self, logger=self.logger ) - def require_jail_existing(self): + def require_jail_existing(self) -> None: """ Raise JailDoesNotExist exception if the jail does not exist """ @@ -647,7 +647,7 @@ def require_jail_existing(self): logger=self.logger ) - def require_jail_stopped(self): + def require_jail_stopped(self) -> None: """ Raise JailAlreadyRunning exception if the jail is runninhg """ @@ -657,7 +657,7 @@ def require_jail_stopped(self): logger=self.logger ) - def require_jail_running(self): + def require_jail_running(self) -> None: """ Raise JailNotRunning exception if the jail is stopped """ @@ -667,7 +667,7 @@ def require_jail_running(self): logger=self.logger ) - def update_jail_state(self): + def update_jail_state(self) -> None: """ Invoke update of the jail state from jls output """ @@ -688,7 +688,7 @@ def update_jail_state(self): except: self.jail_state = None - def _teardown_mounts(self): + def _teardown_mounts(self) -> None: mountpoints = list(map( lambda mountpoint: f"{self.path}/root{mountpoint}", @@ -712,11 +712,10 @@ def _teardown_mounts(self): ignore_error=True # maybe it was not mounted ) - def _resolve_name(self, text): + def _resolve_name(self, text: str) -> str: if (text is None) or (len(text) == 0): raise libiocage.lib.errors.JailNotSupplied(logger=self.logger) - jails_dataset = self.host.datasets.jails for dataset in list(jails_dataset.children): @@ -732,14 +731,14 @@ def _resolve_name(self, text): raise libiocage.lib.errors.JailNotFound(text, logger=self.logger) @property - def name(self): + def name(self) -> str: """ The name (formerly UUID) of the Jail """ return self.config["id"] @property - def humanreadable_name(self): + def humanreadable_name(self) -> str: """ A human-readable identifier to print in logs and CLI output @@ -754,21 +753,21 @@ def humanreadable_name(self): ) @property - def stopped(self): + def stopped(self) -> bool: """ Boolean value that is True if a jail is stopped """ return self.running is not True @property - def running(self): + def running(self) -> bool: """ Boolean value that is True if a jail is running """ return self.jid is not None @property - def jid(self): + def jid(self) -> Optional[int]: """ The JID of a running jail or None if the jail is not running """ @@ -784,14 +783,14 @@ def jid(self): return None @property - def identifier(self): + def identifier(self) -> str: """ Used internally to identify jails (in snapshots, jls, etc) """ return f"ioc-{self.config['id']}" @property - def exists(self): + def exists(self) -> bool: """ Boolean value that is True if the Jail datset exists locally """ @@ -802,7 +801,7 @@ def exists(self): return False @property - def release(self): + def release(self) -> libiocage.lib.Release.Release: """ The libiocage.Release instance linked with the jail """ @@ -814,7 +813,7 @@ def release(self): ) @property - def dataset_name(self): + def dataset_name(self) -> str: """ Name of the jail's base ZFS dataset """ @@ -824,25 +823,25 @@ def dataset_name(self): return f"{self.host.datasets.root.name}/jails/{self.config['id']}" @dataset_name.setter - def dataset_name(self, value=None): + def dataset_name(self, value: str) -> None: self._dataset_name = value @property - def dataset(self): + def dataset(self) -> str: """ The jail's base ZFS dataset """ return self.zfs.get_dataset(self.dataset_name) @property - def path(self): + def path(self) -> str: """ Mountpoint of the jail's base ZFS dataset """ return self.dataset.mountpoint @property - def logfile_path(self): + def logfile_path(self) -> str: """ Absolute path of the jail log file """ @@ -869,7 +868,7 @@ def __getattr__(self, key): raise AttributeError(f"Jail property {key} not found") - def getstring(self, key): + def getstring(self, key: str) -> str: """ Returns a jail properties string or '-' @@ -889,7 +888,7 @@ def getstring(self, key): except AttributeError: return "-" - def __dir__(self): + def __dir__(self) -> List[str]: properties = set() diff --git a/libiocage/lib/RCConf.py b/libiocage/lib/RCConf.py index e5942910..b9d8f364 100644 --- a/libiocage/lib/RCConf.py +++ b/libiocage/lib/RCConf.py @@ -4,9 +4,13 @@ import libiocage.lib.helpers +from typing import Optional + class RCConf(dict): - def __init__(self, path, data={}, logger=None, jail=None): + def __init__(self, path: str, data: dict={}, + logger: Optional[libiocage.lib.Logger.Logger]=None, + jail: Optional[libiocage.lib.Jail.Jail]=None) -> None: dict.__init__(self, {}) libiocage.lib.helpers.init_logger(self, logger=logger) From e2f785517eba43811cfe75a56c3d47ad6518d83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 15:53:08 +0200 Subject: [PATCH 06/15] typles need to be specified as such explicitly, with Tuple[foo, bar], not implicitly with (foo, bar,) --- libiocage/lib/helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libiocage/lib/helpers.py b/libiocage/lib/helpers.py index 95bee053..e931141a 100644 --- a/libiocage/lib/helpers.py +++ b/libiocage/lib/helpers.py @@ -8,7 +8,7 @@ import libiocage.lib.Host import libiocage.lib.Logger -from typing import List +from typing import List, Tuple def init_zfs(self, zfs): @@ -52,8 +52,8 @@ def init_logger(self, logger=None): object.__setattr__(self, 'logger', new_logger) -def exec(command, logger=None, ignore_error=False) -> ( - subprocess.Popen, str, str,): +def exec(command, logger=None, ignore_error=False) -> Tuple[ + subprocess.Popen, str, str]: command_str = " ".join(list([command])) From e7f75500722d0e2d24ed6e311a32254aa1eeb097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 16:18:50 +0200 Subject: [PATCH 07/15] type-check Jail#start() --- libiocage/lib/Jail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index 345c8c63..2a26e613 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -120,7 +120,7 @@ def __init__(self, self.jail_state = None self._dataset_name = None - self._rc_conf = None + self._rc_conf: Optional[libiocage.lib.RCConf.RCConf] = None if new is False: self.config.read() From f7d78ffe074bbde5df0eac606a820e23da5b493b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 18:00:00 +0200 Subject: [PATCH 08/15] correcting a few mistakes: str is always a good guess but not always right ;) --- libiocage/lib/Jail.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index 2a26e613..8d531290 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -19,7 +19,7 @@ import libiocage.lib.events import libiocage.lib.helpers -from typing import Union, Optional, List +from typing import Union, Optional, List, Tuple class JailGenerator: @@ -70,9 +70,9 @@ class JailGenerator: def __init__(self, data: Union[str, dict]={}, - zfs: Optional[libzfs.ZFS]=None, - host: Optional[libiocage.lib.Host.Host]=None, - logger: Optional[libiocage.lib.Logger.Logger]=None, + zfs: libzfs.ZFS=None, + host: libiocage.lib.Host.Host=None, + logger: libiocage.lib.Logger.Logger=None, new: bool=False) -> None: """ Initializes a Jail @@ -108,7 +108,7 @@ def __init__(self, logger=self.logger ) - self.networks: List[str] = [] + self.networks: List[libiocage.lib.Network.Network] = [] self.storage = self._class_storage( auto_create=True, @@ -118,7 +118,7 @@ def __init__(self, zfs=self.zfs ) - self.jail_state = None + self.jail_state: dict[str, Union[str, int]] = None self._dataset_name = None self._rc_conf: Optional[libiocage.lib.RCConf.RCConf] = None @@ -365,7 +365,8 @@ def create(self, release_name: str) -> None: self.config.data["release"] = release.name self.config.save() - def exec(self, command: List[str], **kwargs) -> None: + def exec(self, command: List[str], **kwargs) -> Tuple[ + subprocess.Popen, str, str]: """ Execute a command in a started jail From a8dbb5f5f9b5e82369e6b394c759733cbbd0f7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 19:04:23 +0200 Subject: [PATCH 09/15] x: Foo=None == x: Optional[Foo]=None --- libiocage/lib/RCConf.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libiocage/lib/RCConf.py b/libiocage/lib/RCConf.py index b9d8f364..bf363aad 100644 --- a/libiocage/lib/RCConf.py +++ b/libiocage/lib/RCConf.py @@ -2,15 +2,14 @@ import ucl +import libiocage.lib.Jail import libiocage.lib.helpers -from typing import Optional - class RCConf(dict): def __init__(self, path: str, data: dict={}, - logger: Optional[libiocage.lib.Logger.Logger]=None, - jail: Optional[libiocage.lib.Jail.Jail]=None) -> None: + logger: libiocage.lib.Logger.Logger=None, + jail: libiocage.lib.Jail.Jail=None) -> None: dict.__init__(self, {}) libiocage.lib.helpers.init_logger(self, logger=logger) From ed716fcb22146878795bf8e0feb7ec096d21c19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 22:01:08 +0200 Subject: [PATCH 10/15] fix eol_check types --- libiocage/lib/Distribution.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libiocage/lib/Distribution.py b/libiocage/lib/Distribution.py index a387b49a..f4c8e04d 100644 --- a/libiocage/lib/Distribution.py +++ b/libiocage/lib/Distribution.py @@ -29,6 +29,7 @@ def __init__(self, host, zfs=None, logger=None): libiocage.lib.helpers.init_zfs(self, zfs) libiocage.lib.helpers.init_host(self, host) self.available_releases = None + self.host = host self.zfs = zfs self.logger = logger @@ -110,18 +111,18 @@ def _get_eol_list(self) -> List[str]: _eol = "https://www.freebsd.org/security/unsupported.html" req = requests.get(_eol) status = req.status_code == requests.codes.ok - eol_releases = [] + eol_releases: List[str] = [] if not status: req.raise_for_status() for eol in req.content.decode("iso-8859-1").split(): - eol = eol.strip("href=").strip("/").split(">") + eol_line = eol.strip("href=").strip("/").split(">") # We want a dynamic EOL try: - if "-RELEASE" in eol[1]: - eol = eol[1].strip(' Date: Thu, 31 Aug 2017 22:04:17 +0200 Subject: [PATCH 11/15] simplify Jail types around dict --- libiocage/lib/Jail.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index 8d531290..fa87c619 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -19,7 +19,7 @@ import libiocage.lib.events import libiocage.lib.helpers -from typing import Union, Optional, List, Tuple +from typing import Union, Optional, List, Tuple, Dict, Any class JailGenerator: @@ -118,8 +118,8 @@ def __init__(self, zfs=self.zfs ) - self.jail_state: dict[str, Union[str, int]] = None - self._dataset_name = None + self.jail_state: Optional[Dict[str, Any]] = None + self._dataset_name: Optional[str] = None self._rc_conf: Optional[libiocage.lib.RCConf.RCConf] = None if new is False: @@ -889,7 +889,7 @@ def getstring(self, key: str) -> str: except AttributeError: return "-" - def __dir__(self) -> List[str]: + def __dir__(self) -> List[Any]: properties = set() From f99b9a5820a5060c257948f74a8e78745761f5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 22:04:45 +0200 Subject: [PATCH 12/15] dataset is a libzfs.ZFSDataset! and not a string.. --- libiocage/lib/Jail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index fa87c619..afa89f85 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -828,7 +828,7 @@ def dataset_name(self, value: str) -> None: self._dataset_name = value @property - def dataset(self) -> str: + def dataset(self) -> libzfs.ZFSDataset: """ The jail's base ZFS dataset """ From f59c676147e2e3cb825f507e0ac28115afc79cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 22:25:31 +0200 Subject: [PATCH 13/15] ignore E241: multiple space after ":" --- .travis/flake8.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis/flake8.sh b/.travis/flake8.sh index d67c89db..3a635dbf 100755 --- a/.travis/flake8.sh +++ b/.travis/flake8.sh @@ -2,7 +2,7 @@ # Run pep8 on all .py files in all subfolders tmpafter=$(mktemp) -find ./libiocage/ -name \*.py -exec flake8 --ignore=E203,W391 {} + | grep -v "./libiocage/__init__.py" > ${tmpafter} +find ./libiocage/ -name \*.py -exec flake8 --ignore=E203,E241,W391 {} + | grep -v "./libiocage/__init__.py" > ${tmpafter} num_errors_after=`cat ${tmpafter} | wc -l` echo "Current Error Count: ${num_errors_after}" echo "Current Errors:" @@ -17,7 +17,7 @@ echo "Comparing with last stable release: ${last_release}" git checkout ${last_release} tmpbefore=$(mktemp) -find ./libiocage/ -name \*.py -exec flake8 --ignore=E203,W391 {} + | grep -v "./libiocage/__init__.py" > ${tmpbefore} +find ./libiocage/ -name \*.py -exec flake8 --ignore=E203,E241,W391 {} + | grep -v "./libiocage/__init__.py" > ${tmpbefore} num_errors_before=`cat ${tmpbefore} | wc -l` echo "${last_release}'s Error Count: ${num_errors_before}" From 541fca456e64c25b519d34ccf2508b9d6625fe80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 22:28:58 +0200 Subject: [PATCH 14/15] do not type-check RCCconf for now this leads to some circular, or otherwise impossible imports. --- libiocage/lib/RCConf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libiocage/lib/RCConf.py b/libiocage/lib/RCConf.py index bf363aad..fb257072 100644 --- a/libiocage/lib/RCConf.py +++ b/libiocage/lib/RCConf.py @@ -7,9 +7,7 @@ class RCConf(dict): - def __init__(self, path: str, data: dict={}, - logger: libiocage.lib.Logger.Logger=None, - jail: libiocage.lib.Jail.Jail=None) -> None: + def __init__(self, path: str, data={}, logger=None, jail=None) -> None: dict.__init__(self, {}) libiocage.lib.helpers.init_logger(self, logger=logger) From 8377a72b057df125d92ab701cfb519fbeb822bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 31 Aug 2017 23:08:00 +0200 Subject: [PATCH 15/15] fix flake8: remove Dict again --- libiocage/lib/Jail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiocage/lib/Jail.py b/libiocage/lib/Jail.py index afa89f85..7c12ab8a 100644 --- a/libiocage/lib/Jail.py +++ b/libiocage/lib/Jail.py @@ -19,7 +19,7 @@ import libiocage.lib.events import libiocage.lib.helpers -from typing import Union, Optional, List, Tuple, Dict, Any +from typing import Union, Optional, List, Tuple, Any class JailGenerator: