Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions mig/shared/configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -31,12 +31,12 @@
from __future__ import print_function
from future import standard_library
from builtins import range
from builtins import object

Check failure on line 34 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused import 'object' (90% confidence)

import base64
import copy
import datetime
import functools

Check failure on line 39 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused import 'functools' (90% confidence)
import os
import pwd
import re
Expand Down Expand Up @@ -68,7 +68,7 @@
valid_filter_methods, default_twofactor_auth_apps, \
mig_conf_section_dirname
from mig.shared.logger import Logger, SYSLOG_GDP
from mig.shared.htmlgen import menu_items, vgrid_items

Check failure on line 71 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused import 'vgrid_items' (90% confidence)
from mig.shared.fileio import read_file, load_json, write_file
except ImportError as ioe:
print("could not import migrid modules")
Expand Down Expand Up @@ -130,7 +130,7 @@
return val
# logger.debug("expand any ENV and FILE content in %r" % val)
env_pattern = "[a-zA-Z][a-zA-Z0-9_]+"
cache_pattern = file_pattern = "[^ ]+"

Check failure on line 133 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'cache_pattern' (60% confidence)
expanded = val
expand_pairs = [(keyword_env, env_pattern), (keyword_file, file_pattern)]
for (key, pattern) in expand_pairs:
Expand Down Expand Up @@ -158,7 +158,7 @@
# "reading conf content from file in %r" % cache)
content = read_file(path, logger)
if cache and content:
# logger.debug("caching conf content salt in %r" % cache)

Check warning on line 161 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
write_file(content, cache, logger)
if not content:
logger.warning("salt file not found or empty: %s" % path)
Expand All @@ -179,7 +179,7 @@
return expanded


def fix_missing(config_file, verbose=True):

Check failure on line 182 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'fix_missing' (60% confidence)
"""Add missing configuration options - used by checkconf script"""

config = ConfigParser()
Expand Down Expand Up @@ -232,7 +232,7 @@
'server_home': '~/state/server_home/',
'webserver_home': '~/state/webserver_home/',
'sessid_to_mrsl_link_home': '~/state/sessid_to_mrsl_link_home/',
'sessid_to_jupyter_mount_link_home': '~/state/sessid_to_jupyter_mount_link_home/',

Check warning on line 235 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (90 > 80 characters)
'mig_system_files': '~/state/mig_system_files/',
'mig_system_storage': '~/state/mig_system_storage',
'mig_system_run': '~/state/mig_system_run/',
Expand Down Expand Up @@ -371,7 +371,7 @@
'architectures': 'X86 AMD64 IA64 SPARC SPARC64 ITANIUM SUN4U SPARC-T1',
'scriptlanguages': 'sh python java',
'jobtypes': 'batch interactive bulk all',
'lrmstypes': 'Native Native-execution-leader Batch Batch-execution-leader',

Check warning on line 374 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)
}
scheduler_section = {'algorithm': 'FairFit',
'expire_after': '99999999999',
Expand Down Expand Up @@ -409,7 +409,7 @@
'QUOTA': quota_section,
}
for section in defaults:
if not section in config.sections():

Check warning on line 412 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

test for membership should be 'not in'
config.add_section(section)

modified = False
Expand All @@ -423,7 +423,7 @@
modified = True
if modified:
backup_path = '%s.%d' % (config_file, time.time())
print('Backing up existing configuration to %s as update removes all comments'

Check warning on line 426 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (86 > 80 characters)
% backup_path)
fd = open(config_file, 'r')
backup_fd = open(backup_path, 'w')
Expand Down Expand Up @@ -711,7 +711,7 @@
'VERIFYFILES', 'VGRID', 'SANDBOX'],
'job_cond_yellow': ['DISK', 'MEMORY', 'CPUTIME'],
'job_cond_orange': ['CPUCOUNT', 'NODECOUNT'],
'job_cond_red': ['EXECUTABLES', 'INPUTFILES', 'REGISTERED', 'SEEN_WITHIN_X'],

Check warning on line 714 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
'enable_suggest': False,
'suggest_threshold': 'GREEN',

Expand Down Expand Up @@ -755,12 +755,13 @@
def __init__(self, config_file, verbose=False, skip_log=False,
disable_auth_log=False):
self.config_file = config_file
self.mig_server_id = None

Check failure on line 758 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused attribute 'mig_server_id' (60% confidence)
# Explicitly init a few helpers hot-plugged and used in ways where it's
# less obvious if they are always guaranteed to already be initialized.
self.default_page = None
self.auth_logger_obj = None
self.gdp_logger_obj = None
self._context = None

configuration_options = copy.deepcopy(_CONFIGURATION_DEFAULTS)

Expand All @@ -772,6 +773,26 @@
disable_auth_log=disable_auth_log,
_config_file=config_file)

def context(self, namespace=None):
"""Retrieve the context or a previously registered namespace.
"""

if self._context is None:
self._context = {}
if namespace is None:
return self._context
# allow the KeyError to escape if the registered namespace is missing
return self._context[namespace]

def context_set(self, value, namespace=None):

Check failure on line 787 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused method 'context_set' (60% confidence)
"""Attach a value as named namespace within the active congifuration.
"""
assert namespace is not None

context = self.context()
context[namespace] = value
return value

def reload_config(self, verbose, skip_log=False, disable_auth_log=False,
_config_file=None):
"""Re-read and parse configuration file. Optional skip_log arg
Expand All @@ -791,7 +812,7 @@
try:
if self.logger:
self.logger.info('reloading configuration and reopening log')
except:

Check warning on line 815 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

do not use bare 'except'
pass

try:
Expand Down Expand Up @@ -826,7 +847,7 @@
self.log_dir = config.get('GLOBAL', 'log_dir')
self.logfile = config.get('GLOBAL', 'logfile')
self.loglevel = config.get('GLOBAL', 'loglevel')
except:

Check warning on line 850 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

do not use bare 'except'

# Fall back to file in current dir

Expand Down Expand Up @@ -936,7 +957,7 @@
# Mandatory options first

try:
self.mig_server_id = config.get('GLOBAL', 'mig_server_id')

Check failure on line 960 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused attribute 'mig_server_id' (60% confidence)
self.mrsl_files_dir = config.get('GLOBAL', 'mrsl_files_dir')
self.re_files_dir = config.get('GLOBAL', 're_files_dir')
self.re_pending_dir = config.get('GLOBAL', 're_pending_dir')
Expand Down Expand Up @@ -976,7 +997,7 @@
self.jobtypes = config.get('GLOBAL', 'jobtypes').split()
self.lrmstypes = config.get('GLOBAL', 'lrmstypes').split()
self.sessid_to_mrsl_link_home = config.get('GLOBAL',
'sessid_to_mrsl_link_home')

Check warning on line 1000 in mig/shared/configuration.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (82 > 80 characters)
self.mig_system_files = config.get('GLOBAL',
'mig_system_files')
self.mig_system_storage = config.get('GLOBAL',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mig_shared_configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
#
# --- BEGIN_HEADER ---
Expand Down Expand Up @@ -42,7 +42,7 @@

def _to_dict(obj):
return {k: v for k, v in inspect.getmembers(obj)
if not (k.startswith('__') or _is_method(v))}
if not (k.startswith('_') or _is_method(v))}


class MigSharedConfiguration(MigTestCase):
Expand Down