Commit 03136450 authored by juga  's avatar juga
Browse files

config: continue when the file is not found

Continue running with defaults when the config argument is provided
but not found. This could be the case of system packages.
parent 9e76b82f
......@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Make sbws round to 3 significant figures in torflow rounding mode, rather
than rounding to the nearest 1000 kilobytes (#28442).
- Continue running with defaults when the config argument is provided
but not found (#28500).
## [1.0.2] - 2018-11-10
......
......@@ -10,7 +10,7 @@ from string import Template
from tempfile import NamedTemporaryFile
from sbws.globals import (DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH,
USER_CONFIG_PATH, SUPERVISED_RUN_DPATH,
SUPERVISED_USER_CONFIG_PATH, fail_hard)
SUPERVISED_USER_CONFIG_PATH)
_ALPHANUM = 'abcdefghijklmnopqrstuvwxyz'
_ALPHANUM += _ALPHANUM.upper()
......@@ -66,8 +66,11 @@ def _get_user_config(args, conf=None):
assert isinstance(conf, ConfigParser)
if args.config:
if not os.path.isfile(args.config):
fail_hard('Configuration file %s not found.', args.config)
return _extend_config(conf, args.config)
# XXX: The logger is not configured at this stage,
# sbws should start with a logger before reading configurations.
print('Configuration file %s not found, using defaults.' %
args.config)
return conf
user_config_path = _obtain_user_conf_path()
if os.path.isfile(user_config_path):
return _extend_config(conf, user_config_path)
......
......@@ -230,3 +230,8 @@ def test_nickname():
d = {'n': nick}
valid, reason = con._validate_nickname(d, 'n')
assert not valid, reason
def test_config_arg_provided_but_no_found(args, conf):
args.config = 'non_existing_file'
con._get_user_config(args, conf=None)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment