Skip to content
Snippets Groups Projects
Commit 717ea87a authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Made the `flamenco-worker.cfg` file mandatory

This makes debugging configuration issues easier. When the file does not
exist, the absolute path of its expected location is logged.

Also moved from os.path to using pathlib.
parent 37f687e3
Branches
Tags
No related merge requests found
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
This file logs the changes that are actually interesting to users (new features, This file logs the changes that are actually interesting to users (new features,
changed functionality, fixed bugs). changed functionality, fixed bugs).
## Version 2.0.3 (released 2017-04-07)
- Made the `flamenco-worker.cfg` file mandatory, as this makes debugging configuration
issues easier. When the file does not exist, the absolute path of its expected
location is logged.
## Version 2.0.2 (released 2017-04-07) ## Version 2.0.2 (released 2017-04-07)
......
...@@ -20,24 +20,24 @@ Configuration is read from three locations: ...@@ -20,24 +20,24 @@ Configuration is read from three locations:
- A hard-coded default in the Python source code. - A hard-coded default in the Python source code.
- `flamenco-worker.cfg` in the current working directory. - `flamenco-worker.cfg` in the current working directory.
- `$HOME/.flamenco-worker.cfg`. - `$HOME/.flamenco-worker.cfg`; this file is optional.
When those files do not exist, they are skipped (i.e. this is not an error). They The configuration files should be in INI format, as specified by the
should be in INI format, as specified by the
[configparser documentation](https://docs.python.org/3/library/configparser.html) [configparser documentation](https://docs.python.org/3/library/configparser.html)
### Configuration contents: ### Configuration contents:
All configuration keys should be placed in the `[flamenco-worker]` section of the All configuration keys should be placed in the `[flamenco-worker]` section of the
config files. config files. At least take a look at:
- `manager_url`: Flamenco Manager URL. - `manager_url`: Flamenco Manager URL.
- `job_types`: Space-separated list of job types this worker may execute. - `task_types`: Space-separated list of task types this worker may execute.
- `task_update_queue_db`: filename of the SQLite3 database holding the queue of task - `task_update_queue_db`: filename of the SQLite3 database holding the queue of task
updates to be sent to the Master. updates to be sent to the Master.
These configuration keys are also required, but are created automatically upon startup
when they don't exist yet: These configuration keys are also required, but are created automatically in
`$HOME/.flamenco-worker.cfg` when they don't exist yet:
- `worker_id`: ID of the worker, handed out by the Manager upon registration (see - `worker_id`: ID of the worker, handed out by the Manager upon registration (see
Registration below) and used for authentication with the Manager. Registration below) and used for authentication with the Manager.
......
...@@ -34,6 +34,7 @@ args = (sys.stderr,) ...@@ -34,6 +34,7 @@ args = (sys.stderr,)
class = logging.handlers.TimedRotatingFileHandler class = logging.handlers.TimedRotatingFileHandler
formatter = flamenco formatter = flamenco
# (filename, when, interval, backupCount, encoding, delay, utc, atTime=None) # (filename, when, interval, backupCount, encoding, delay, utc, atTime=None)
# Be aware that tilde expansion is *not* performed on the path.
args = ('/tmp/flamenco-worker.log', 'midnight', 1, 7, 'utf8', True, True) args = ('/tmp/flamenco-worker.log', 'midnight', 1, 7, 'utf8', True, True)
[formatters] [formatters]
......
...@@ -4,13 +4,14 @@ import argparse ...@@ -4,13 +4,14 @@ import argparse
import asyncio import asyncio
import logging import logging
import logging.config import logging.config
import pathlib
import requests import requests
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', parser.add_argument('-c', '--config', type=pathlib.Path,
help='Load this configuration file instead of the default files.') help='Load this configuration file instead of the default files.')
parser.add_argument('-v', '--verbose', action='store_true', parser.add_argument('-v', '--verbose', action='store_true',
help='Show configuration before starting, ' help='Show configuration before starting, '
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
import collections import collections
import configparser import configparser
import datetime import datetime
import os.path import pathlib
import logging import logging
from . import worker from . import worker
HOME_CONFIG_FILE = os.path.expanduser('~/.flamenco-worker.cfg') HOME_CONFIG_FILE = pathlib.Path('~/.flamenco-worker.cfg').expanduser()
GLOBAL_CONFIG_FILE = 'flamenco-worker.cfg' GLOBAL_CONFIG_FILE = pathlib.Path('./flamenco-worker.cfg').absolute()
CONFIG_SECTION = 'flamenco-worker' CONFIG_SECTION = 'flamenco-worker'
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
...@@ -56,18 +56,18 @@ def merge_with_home_config(new_conf: dict): ...@@ -56,18 +56,18 @@ def merge_with_home_config(new_conf: dict):
for key, value in new_conf.items(): for key, value in new_conf.items():
confparser.set(CONFIG_SECTION, key, value) confparser.set(CONFIG_SECTION, key, value)
tmpname = HOME_CONFIG_FILE + '~' tmpname = HOME_CONFIG_FILE.with_name(HOME_CONFIG_FILE.name + '~')
log.debug('Writing configuration file to %s', tmpname) log.debug('Writing configuration file to %s', tmpname)
with open(tmpname, mode='wt', encoding='utf8') as outfile: with open(tmpname, mode='wt', encoding='utf8') as outfile:
confparser.write(outfile) confparser.write(outfile)
log.debug('Moving configuration file to %s', HOME_CONFIG_FILE) log.debug('Moving configuration file to %s', HOME_CONFIG_FILE)
os.replace(tmpname, HOME_CONFIG_FILE) tmpname.replace(HOME_CONFIG_FILE)
log.info('Updated configuration file %s', HOME_CONFIG_FILE) log.info('Updated configuration file %s', HOME_CONFIG_FILE)
def load_config(config_file: str = None, def load_config(config_file: pathlib.Path = None,
show_effective_config: bool = False) -> ConfigParser: show_effective_config: bool = False) -> ConfigParser:
"""Loads one or more configuration files.""" """Loads one or more configuration files."""
...@@ -80,11 +80,19 @@ def load_config(config_file: str = None, ...@@ -80,11 +80,19 @@ def load_config(config_file: str = None,
if config_file: if config_file:
log.info('Loading configuration from %s', config_file) log.info('Loading configuration from %s', config_file)
if not config_file.exists():
log.fatal('Config file %s does not exist', config_file)
raise SystemExit()
loaded = confparser.read(config_file, encoding='utf8') loaded = confparser.read(config_file, encoding='utf8')
else: else:
if not GLOBAL_CONFIG_FILE.exists():
log.fatal('Config file %s does not exist', GLOBAL_CONFIG_FILE)
raise SystemExit()
config_files = [GLOBAL_CONFIG_FILE, HOME_CONFIG_FILE] config_files = [GLOBAL_CONFIG_FILE, HOME_CONFIG_FILE]
log.info('Loading configuration from %s', ', '.join(config_files)) filenames = [str(f.absolute()) for f in config_files]
loaded = confparser.read(config_files, encoding='utf8') log.info('Loading configuration from %s', ', '.join(filenames))
loaded = confparser.read(filenames, encoding='utf8')
log.info('Succesfully loaded: %s', loaded) log.info('Succesfully loaded: %s', loaded)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment