Log when unable to ascertain ZFS version

Use established logging strategy to emit an error log when ZFS
version information cannot be obtained.
This commit is contained in:
Alex Boag-Munroe 2019-09-26 23:30:06 +01:00
parent fd990eb4fd
commit e44eea3318

View file

@ -25,10 +25,12 @@ Be aware of security implications of doing this!
""" """
import time import time
import logging
from pkg_resources import parse_version from pkg_resources import parse_version
import bumblebee.engine import bumblebee.engine
from bumblebee.util import execute, bytefmt, asbool from bumblebee.util import execute, bytefmt, asbool
log = logging.getLogger(__name__)
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
@ -64,13 +66,15 @@ class Module(bumblebee.engine.Module):
return state return state
def _update_widgets(self, widgets): def _update_widgets(self, widgets):
zfs_version_path = "/sys/module/zfs/version"
# zpool list -H: List all zpools, use script mode (no headers and tabs as separators). # zpool list -H: List all zpools, use script mode (no headers and tabs as separators).
try: try:
with open('/sys/module/zfs/version', 'r') as zfs_mod_version: with open(zfs_version_path, 'r') as zfs_mod_version:
zfs_version = zfs_mod_version.readline().rstrip().split('-')[0] zfs_version = zfs_mod_version.readline().rstrip().split('-')[0]
except FileNotFoundError: except FileNotFoundError:
# ZFS isn't installed or the module isn't loaded, stub the version # ZFS isn't installed or the module isn't loaded, stub the version
zfs_version = "0.0.0" zfs_version = "0.0.0"
logging.error("ZFS version information not found at {}, check the module is loaded.".format(zfs_version_path))
raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n') raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n')