remove JINJA2_CACHE (#12155)
This commit is contained in:
parent
d5bd2dd6bf
commit
9191779b13
@ -1,29 +0,0 @@
|
|||||||
import jinja2
|
|
||||||
|
|
||||||
from base64 import b64encode, b64decode
|
|
||||||
|
|
||||||
class RedisBytecodeCache(jinja2.BytecodeCache):
|
|
||||||
""" A bytecode cache for jinja2 template that stores bytecode in Redis """
|
|
||||||
|
|
||||||
REDIS_HASH = 'JINJA2_CACHE'
|
|
||||||
|
|
||||||
def __init__(self, client):
|
|
||||||
self._client = client
|
|
||||||
try:
|
|
||||||
self._client.connect(self._client.LOGLEVEL_DB, retry_on=False)
|
|
||||||
except Exception:
|
|
||||||
self._client = None
|
|
||||||
|
|
||||||
def load_bytecode(self, bucket):
|
|
||||||
if self._client is None:
|
|
||||||
return
|
|
||||||
code = self._client.get(self._client.LOGLEVEL_DB, self.REDIS_HASH, bucket.key)
|
|
||||||
if code is not None:
|
|
||||||
bucket.bytecode_from_string(b64decode(code.encode()))
|
|
||||||
|
|
||||||
def dump_bytecode(self, bucket):
|
|
||||||
if self._client is None:
|
|
||||||
return
|
|
||||||
self._client.set(self._client.LOGLEVEL_DB, self.REDIS_HASH,
|
|
||||||
bucket.key, b64encode(bucket.bytecode_to_string()).decode())
|
|
||||||
|
|
@ -43,7 +43,6 @@ py_modules = [
|
|||||||
'minigraph',
|
'minigraph',
|
||||||
'openconfig_acl',
|
'openconfig_acl',
|
||||||
'portconfig',
|
'portconfig',
|
||||||
'redis_bcc',
|
|
||||||
]
|
]
|
||||||
if sys.version_info.major == 3:
|
if sys.version_info.major == 3:
|
||||||
# Python 3-only modules
|
# Python 3-only modules
|
||||||
|
@ -31,10 +31,9 @@ from config_samples import generate_sample_config, get_available_config
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type
|
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type
|
||||||
from portconfig import get_port_config, get_breakout_mode
|
from portconfig import get_port_config, get_breakout_mode
|
||||||
from redis_bcc import RedisBytecodeCache
|
|
||||||
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
|
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
|
||||||
from sonic_py_common import device_info
|
from sonic_py_common import device_info
|
||||||
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
|
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
|
||||||
|
|
||||||
|
|
||||||
PY3x = sys.version_info >= (3, 0)
|
PY3x = sys.version_info >= (3, 0)
|
||||||
@ -234,8 +233,7 @@ def _get_jinja2_env(paths):
|
|||||||
Retreive Jinj2 env used to render configuration templates
|
Retreive Jinj2 env used to render configuration templates
|
||||||
"""
|
"""
|
||||||
loader = jinja2.FileSystemLoader(paths)
|
loader = jinja2.FileSystemLoader(paths)
|
||||||
redis_bcc = RedisBytecodeCache(SonicV2Connector(host='127.0.0.1'))
|
env = jinja2.Environment(loader=loader, trim_blocks=True)
|
||||||
env = jinja2.Environment(loader=loader, trim_blocks=True, bytecode_cache=redis_bcc)
|
|
||||||
env.filters['sort_by_port_index'] = sort_by_port_index
|
env.filters['sort_by_port_index'] = sort_by_port_index
|
||||||
env.filters['ipv4'] = is_ipv4
|
env.filters['ipv4'] = is_ipv4
|
||||||
env.filters['ipv6'] = is_ipv6
|
env.filters['ipv6'] = is_ipv6
|
||||||
|
Reference in New Issue
Block a user