Skip to content

memoize sdb module's function for config application #55740

@kiemlicz

Description

@kiemlicz

Description of Issue

I've created custom sdb module that reads KDBX
I use this module in Salt Master installations which contain a lot of sdb://kdbx/... schemes.
During:

  File "/usr/lib/python3/dist-packages/salt/config/__init__.py", line 3938, in master_config
    apply_sdb(opts)

Every config's sdb scheme causes separate call to heavy method: _load
I thought that if I add @memoize for _load method that would help the KDBX load once

However during evaluating config the apply_sdb doesn't save the memoize closue, thus adding @memoize doesn't help

  1. Could someone explain me why the memoize doesn't work (I'm not a Python dev)? Is it because of https://github.com/saltstack/salt/blob/master/salt/loader.py#L954 sdb loader returning new Loader instance with every sdb entry in config?
  2. How can I achieve caching of loaded KDBX instance for all consecutive entries in config?

Setup

  1. Add any custom module with heavyweight method, like this custom kdbx
  2. Use it in config file:
somekey1: sdb://kdbx/a/b/c
somekey2: sdb://kdbx/a/b/d
somekey3: sdb://kdbx/a/b/e

Steps to Reproduce Issue

With aforementioned setup, run any runner module. It will take ages to run, e.g. salt-run saltutil.sync_all

Versions Report

Salt Version:
           Salt: 2019.2.2
 
Dependency Versions:
           cffi: 1.13.2
       cherrypy: unknown
       dateutil: 2.5.3
      docker-py: 1.10.6
          gitdb: 2.0.0
      gitpython: 2.1.1
          ioflo: Not Installed
         Jinja2: 2.10.3
        libgit2: 0.28.2
        libnacl: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 3.9.4
   pycryptodome: Not Installed
         pygit2: 0.28.2
         Python: 3.5.3 (default, Sep 27 2018, 17:25:39)
   python-gnupg: Not Installed
         PyYAML: 5.2
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.1
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1
 
System Versions:
           dist: debian 9.11 
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-8-amd64
         system: Linux
        version: debian 9.11 

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionThe issue is more of a question rather than a bug or a feature requestpending-discussionThe issue or pull request needs more discussion before it can be closed or merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions