diff options
| author | John Estabrook <jestabro@vyos.io> | 2024-08-22 13:35:02 -0500 | 
|---|---|---|
| committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2024-08-26 05:25:22 +0000 | 
| commit | 27c41a40d5010df7811ddc1b3419adaa086becb9 (patch) | |
| tree | 118bb68add869c19f2d3da372ba1ce0bf72482c0 | |
| parent | 0d4df125ec584410036524fb83575ab2ec1c1435 (diff) | |
| download | vyos-1x-27c41a40d5010df7811ddc1b3419adaa086becb9.tar.gz vyos-1x-27c41a40d5010df7811ddc1b3419adaa086becb9.zip | |
configdep: T6671: run dependency only if not scheduled by priority
(cherry picked from commit 4f0e0265d87b01aafde39f2682d2d5099ac4e942)
| -rw-r--r-- | python/vyos/configdep.py | 26 | 
1 files changed, 23 insertions, 3 deletions
| diff --git a/python/vyos/configdep.py b/python/vyos/configdep.py index e0fe1ddac..cf7c9d543 100644 --- a/python/vyos/configdep.py +++ b/python/vyos/configdep.py @@ -95,7 +95,8 @@ def get_dependency_dict(config: 'Config') -> dict:          setattr(config, 'cached_dependency_dict', d)      return d -def run_config_mode_script(script: str, config: 'Config'): +def run_config_mode_script(target: str, config: 'Config'): +    script = target + '.py'      path = os.path.join(directories['conf_mode'], script)      name = canon_name(script)      mod = load_as_module(name, path) @@ -109,15 +110,34 @@ def run_config_mode_script(script: str, config: 'Config'):      except (VyOSError, ConfigError) as e:          raise ConfigError(str(e)) from e +def run_conditionally(target: str, tagnode: str, config: 'Config'): +    tag_ext = f'_{tagnode}' if tagnode else '' +    script_name = f'{target}{tag_ext}' + +    scripts_called = getattr(config, 'scripts_called', []) +    commit_scripts = getattr(config, 'commit_scripts', []) + +    debug_print(f'scripts_called: {scripts_called}') +    debug_print(f'commit_scripts: {commit_scripts}') + +    if script_name in commit_scripts and script_name not in scripts_called: +        debug_print(f'dependency {script_name} deferred to priority') +        return + +    run_config_mode_script(target, config) +  def def_closure(target: str, config: 'Config',                  tagnode: typing.Optional[str] = None) -> typing.Callable: -    script = target + '.py'      def func_impl(): +        tag_value = ''          if tagnode is not None:              os.environ['VYOS_TAGNODE_VALUE'] = tagnode -        run_config_mode_script(script, config) +            tag_value = tagnode +        run_conditionally(target, tag_value, config) +      tag_ext = f'_{tagnode}' if tagnode is not None else ''      func_impl.__name__ = f'{target}{tag_ext}' +      return func_impl  def set_dependents(case: str, config: 'Config', | 
