Commit 8d4af687 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed config. Added config test.

parent 6fd43331
Pipeline #45742 passed with stages
in 25 minutes and 21 seconds
......@@ -170,17 +170,16 @@ transformations = {
logger = logging.getLogger(__name__)
def apply(config, key, value) -> None:
def apply(key, value) -> None:
"""
Changes the config according to given key and value. The keys are interpreted as paths
to config values with ``_`` as a separator. E.g. ``fs_staging`` leading to
``config.fs.staging``
"""
path = list(reversed(key.split('_')))
child_segment = None
current_value = None
child_config = config
child_config = globals()
child_key = None
try:
......@@ -200,6 +199,7 @@ def apply(config, key, value) -> None:
continue
if isinstance(current_value, NomadConfig):
child_config = current_value
current_value = None
child_segment = None
else:
if len(path) > 0:
......@@ -263,9 +263,9 @@ def load_config(config_file: str = os.environ.get('NOMAD_CONFIG', 'nomad.yaml'))
for key, value in os.environ.items()
if key.startswith('NOMAD_')
}
config = globals()
for key, value in kwargs.items():
apply(config, key, value)
apply(key, value)
load_config()
......@@ -76,7 +76,8 @@ class TestAdmin:
rv = client.post('/admin/reset', headers=test_user_auth)
assert rv.status_code == 401
def test_disabled(self, client, admin_user_auth, postgres):
def test_disabled(self, client, admin_user_auth, expandable_postgres, monkeypatch):
monkeypatch.setattr('nomad.config.services.disable_reset', True)
rv = client.post('/admin/reset', headers=admin_user_auth)
assert rv.status_code == 400
......
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from nomad import config
def test_apply():
config.apply('fs_migration_packages', 'test_value')
assert config.fs.migration_packages == 'test_value'
Supports Markdown
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