Commit 11df5d84 authored by Joanne Hugé's avatar Joanne Hugé

Update Release Candidate

parents b27cfcb9 465fc24d
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
[template] [template]
filename = instance.cfg filename = instance.cfg
md5sum = 3919d261bdf366b7f7cc5149ab4c609d md5sum = f23909a703ac9001afec38cbac19591a
[amarisoft-stats.jinja2.py] [amarisoft-stats.jinja2.py]
_update_hash_filename_ = amarisoft-stats.jinja2.py _update_hash_filename_ = amarisoft-stats.jinja2.py
...@@ -56,23 +56,23 @@ md5sum = 63472d5dc9bd46923d3941b5189e2ccd ...@@ -56,23 +56,23 @@ md5sum = 63472d5dc9bd46923d3941b5189e2ccd
[template-enb] [template-enb]
_update_hash_filename_ = instance-enb.jinja2.cfg _update_hash_filename_ = instance-enb.jinja2.cfg
md5sum = f61ba5e691bf263c8666e92f9eeef643 md5sum = 40f735514d8f4ead0d4328c58b78be93
[template-gnb] [template-gnb]
_update_hash_filename_ = instance-gnb.jinja2.cfg _update_hash_filename_ = instance-gnb.jinja2.cfg
md5sum = 9575d69d3ea61842750b44ad67e92258 md5sum = 2d7558e4799818a5546850f735fbb399
[template-core-network] [template-core-network]
_update_hash_filename_ = instance-core-network.jinja2.cfg _update_hash_filename_ = instance-core-network.jinja2.cfg
md5sum = 919340a049d628a86838453354c9efa2 md5sum = aa7fcf7f68ced7e880158d0aa3307be4
[template-ue-lte] [template-ue-lte]
_update_hash_filename_ = instance-ue-lte.jinja2.cfg _update_hash_filename_ = instance-ue-lte.jinja2.cfg
md5sum = f6d8e97add6d11b0a5436744cb455195 md5sum = b444f859248778e18c5eba60f5670f6c
[template-ue-nr] [template-ue-nr]
_update_hash_filename_ = instance-ue-nr.jinja2.cfg _update_hash_filename_ = instance-ue-nr.jinja2.cfg
md5sum = e57780260a1588d1dab29431c5e5ed97 md5sum = bc65fdce1c453d92310d53928dcaaa7a
[template-obsolete] [template-obsolete]
_update_hash_filename_ = instance-obsolete.jinja2.cfg _update_hash_filename_ = instance-obsolete.jinja2.cfg
...@@ -84,7 +84,7 @@ md5sum = dcaac06553a3222b14c0013a13f4a149 ...@@ -84,7 +84,7 @@ md5sum = dcaac06553a3222b14c0013a13f4a149
[enb.jinja2.cfg] [enb.jinja2.cfg]
filename = config/enb.jinja2.cfg filename = config/enb.jinja2.cfg
md5sum = c1fef7cec616ba3594549090591a56d2 md5sum = 9e10632057d64068313267ecee999e97
[sib23.jinja2.asn] [sib23.jinja2.asn]
filename = config/sib23.jinja2.asn filename = config/sib23.jinja2.asn
...@@ -92,11 +92,7 @@ md5sum = a1973ba6e43d40e510d61d461c2d13ac ...@@ -92,11 +92,7 @@ md5sum = a1973ba6e43d40e510d61d461c2d13ac
[gnb.jinja2.cfg] [gnb.jinja2.cfg]
filename = config/gnb.jinja2.cfg filename = config/gnb.jinja2.cfg
md5sum = 075df4848e08ef8a595b33164238a0e7 md5sum = 003bf8098175415c975a10c102df6b8c
[ltelogs.jinja2.sh]
filename = ltelogs.jinja2.sh
md5sum = 1ba2e065bdf14a6411e95e80db17dcfd
[mme.jinja2.cfg] [mme.jinja2.cfg]
filename = config/mme.jinja2.cfg filename = config/mme.jinja2.cfg
......
...@@ -358,7 +358,7 @@ ...@@ -358,7 +358,7 @@
dpc: true, dpc: true,
dpc_pusch_snr_target: 25, dpc_pusch_snr_target: 25,
dpc_pucch_snr_target: 20, dpc_pucch_snr_target: 25,
cipher_algo_pref: [], cipher_algo_pref: [],
integ_algo_pref: [2, 1], integ_algo_pref: [2, 1],
......
...@@ -544,6 +544,7 @@ ...@@ -544,6 +544,7 @@
}, },
}, },
pusch: { pusch: {
dpc_snr_target: 25,
mapping_type: "typeA", mapping_type: "typeA",
n_symb: 14, n_symb: 14,
dmrs_add_pos: 1, dmrs_add_pos: 1,
......
...@@ -37,7 +37,6 @@ info = DNS entry with has been attached to service ${slap-configuration:instance ...@@ -37,7 +37,6 @@ info = DNS entry with has been attached to service ${slap-configuration:instance
[buildout] [buildout]
parts = parts =
directory directory
ltelogs
mme-config mme-config
mme-service mme-service
monitor-base monitor-base
...@@ -100,14 +99,6 @@ service = ${:etc}/service ...@@ -100,14 +99,6 @@ service = ${:etc}/service
promise = ${:etc}/promise promise = ${:etc}/promise
log = ${:var}/log log = ${:var}/log
[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
section directory directory
{% if slapparameter_dict.get("mme_config_link", None) %} {% if slapparameter_dict.get("mme_config_link", None) %}
[mme-config-dl] [mme-config-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -119,7 +110,6 @@ offline = false ...@@ -119,7 +110,6 @@ offline = false
### IMS ### IMS
[ims-service] [ims-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/ims.log; sleep 1
command-line = {{ mme }}/lteims ${directory:etc}/ims.cfg command-line = {{ mme }}/lteims ${directory:etc}/ims.cfg
wrapper-path = ${directory:service}/ims wrapper-path = ${directory:service}/ims
mode = 0775 mode = 0775
...@@ -148,7 +138,6 @@ inline = ...@@ -148,7 +138,6 @@ inline =
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
# When the machine shutdowns abruptly, lte_ue is not cleaned up which causes # When the machine shutdowns abruptly, lte_ue is not cleaned up which causes
# amarisoft ltemme to fail. TODO: find a cleaner way to handle this # amarisoft ltemme to fail. TODO: find a cleaner way to handle this
init = ${ltelogs:output} ${directory:log}/mme.log
command-line = ${mme-sh-wrapper:output} command-line = ${mme-sh-wrapper:output}
wrapper-path = ${directory:service}/mme wrapper-path = ${directory:service}/mme
mode = 0775 mode = 0775
......
[buildout] [buildout]
parts = parts =
directory directory
ltelogs
enb-config enb-config
enb-service enb-service
xamari-xlog-service xamari-xlog-service
...@@ -35,7 +34,6 @@ parts = ...@@ -35,7 +34,6 @@ parts =
check-lopcomm-sync.py check-lopcomm-sync.py
check-lopcomm-config-log.py check-lopcomm-config-log.py
check-lopcomm-stats-log.py check-lopcomm-stats-log.py
check-cpri-lock.py
{% endif %} {% endif %}
{% if slapparameter_dict.get("dnsmasq", None) %} {% if slapparameter_dict.get("dnsmasq", None) %}
dnsmasq-service dnsmasq-service
...@@ -48,6 +46,7 @@ parts = ...@@ -48,6 +46,7 @@ parts =
{% endif %} {% endif %}
monitor-base monitor-base
publish-connection-information publish-connection-information
{% set extra_part_list = [] %}
extends = {{ monitor_template }} extends = {{ monitor_template }}
...@@ -100,14 +99,6 @@ service = ${:etc}/service ...@@ -100,14 +99,6 @@ service = ${:etc}/service
promise = ${:etc}/promise promise = ${:etc}/promise
log = ${:var}/log log = ${:var}/log
[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
section directory directory
{% if slapparameter_dict.get("enb_config_link", None) %} {% if slapparameter_dict.get("enb_config_link", None) %}
[enb-config-dl] [enb-config-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -143,7 +134,6 @@ inline = ...@@ -143,7 +134,6 @@ inline =
[enb-service] [enb-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/enb.log; sleep 2
command-line = ${enb-sh-wrapper:output} command-line = ${enb-sh-wrapper:output}
wrapper-path = ${directory:service}/enb wrapper-path = ${directory:service}/enb
mode = 0775 mode = 0775
...@@ -690,12 +680,21 @@ config-testing = {{ slapparameter_dict.get("testing", False) }} ...@@ -690,12 +680,21 @@ config-testing = {{ slapparameter_dict.get("testing", False) }}
config-config-log = ${lopcomm-rrh-config-template:log-output} config-config-log = ${lopcomm-rrh-config-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }} config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
[check-cpri-lock.py] {% if ru == "lopcomm" %}
{%- set cell_list = slapparameter_dict.get('cell_list', {'default': {}}) %}
{%- for i, k in enumerate(cell_list) %}
{%- set sfp_port = cell_list[k].get('cpri_port_number', i) %}
{%- do extra_part_list.append('SFP%s-cpri-lock.py' % sfp_port) %}
[SFP{{sfp_port}}-cpri-lock.py]
<= macro.promise <= macro.promise
promise = check_cpri_lock promise = check_cpri_lock
config-testing = {{ slapparameter_dict.get("testing", False) }} config-testing = {{ slapparameter_dict.get("testing", False) }}
config-sdr_dev = {{ slapparameter_dict.get('sdr_number', 0) }}
config-sfp_port = {{ sfp_port }}
config-amarisoft-rf-info-log = ${amarisoft-rf-info-template:log-output} config-amarisoft-rf-info-log = ${amarisoft-rf-info-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }} config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
{%- endfor %}
{% endif %}
[check-rx-saturated.py] [check-rx-saturated.py]
<= macro.promise <= macro.promise
...@@ -705,3 +704,9 @@ config-rf-rx-chan-list = {{ list(range(0, int(slapparameter_dict.get('n_antenna_ ...@@ -705,3 +704,9 @@ config-rf-rx-chan-list = {{ list(range(0, int(slapparameter_dict.get('n_antenna_
config-amarisoft-stats-log = ${amarisoft-stats-template:log-output} config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }} config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
config-max-rx-sample-db = {{ slapparameter_dict.get("max_rx_sample_db", 0) }} config-max-rx-sample-db = {{ slapparameter_dict.get("max_rx_sample_db", 0) }}
[buildout]
parts +=
{%- for part in extra_part_list %}
{{ part }}
{%- endfor %}
[buildout] [buildout]
parts = parts =
directory directory
ltelogs
gnb-config gnb-config
enb-service enb-service
xamari-xlog-service xamari-xlog-service
...@@ -70,14 +69,6 @@ service = ${:etc}/service ...@@ -70,14 +69,6 @@ service = ${:etc}/service
promise = ${:etc}/promise promise = ${:etc}/promise
log = ${:var}/log log = ${:var}/log
[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
section directory directory
{% if slapparameter_dict.get("gnb_config_link", None) %} {% if slapparameter_dict.get("gnb_config_link", None) %}
[gnb-config-dl] [gnb-config-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -106,7 +97,6 @@ inline = ...@@ -106,7 +97,6 @@ inline =
### eNodeB (enb) ### eNodeB (enb)
[enb-service] [enb-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/enb.log; sleep 2
command-line = ${enb-sh-wrapper:output} command-line = ${enb-sh-wrapper:output}
wrapper-path = ${directory:service}/enb wrapper-path = ${directory:service}/enb
mode = 0775 mode = 0775
......
[buildout] [buildout]
parts = parts =
directory directory
ltelogs
lte-ue-lte-config lte-ue-lte-config
lte-ue-service lte-ue-service
check-sdr-busy.py check-sdr-busy.py
...@@ -57,14 +56,6 @@ service = ${:etc}/service ...@@ -57,14 +56,6 @@ service = ${:etc}/service
promise = ${:etc}/promise promise = ${:etc}/promise
log = ${:var}/log log = ${:var}/log
[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
section directory directory
{% if slapparameter_dict.get("ue_lte_config_link", None) %} {% if slapparameter_dict.get("ue_lte_config_link", None) %}
[ue-lte-config-dl] [ue-lte-config-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -90,7 +81,6 @@ inline = ...@@ -90,7 +81,6 @@ inline =
### User Equipment (UE) ### User Equipment (UE)
[lte-ue-service] [lte-ue-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/ue.log; sleep 2
command-line = ${lte-ue-sh-wrapper:output} command-line = ${lte-ue-sh-wrapper:output}
wrapper-path = ${directory:service}/lte-ue wrapper-path = ${directory:service}/lte-ue
mode = 0775 mode = 0775
......
[buildout] [buildout]
parts = parts =
directory directory
ltelogs
lte-ue-nr-config lte-ue-nr-config
lte-ue-service lte-ue-service
check-sdr-busy.py check-sdr-busy.py
...@@ -57,14 +56,6 @@ service = ${:etc}/service ...@@ -57,14 +56,6 @@ service = ${:etc}/service
promise = ${:etc}/promise promise = ${:etc}/promise
log = ${:var}/log log = ${:var}/log
[ltelogs]
recipe = slapos.recipe.template:jinja2
url = {{ ltelogs_template }}
output = ${directory:home}/ltelogs.sh
extensions = jinja2.ext.do
context =
section directory directory
{% if slapparameter_dict.get("ue_nr_config_link", None) %} {% if slapparameter_dict.get("ue_nr_config_link", None) %}
[ue-nr-config-dl] [ue-nr-config-dl]
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
...@@ -90,7 +81,6 @@ inline = ...@@ -90,7 +81,6 @@ inline =
### User Equipment (UE) ### User Equipment (UE)
[lte-ue-service] [lte-ue-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
init = ${ltelogs:output} ${directory:log}/ue.log; sleep 2
command-line = ${lte-ue-sh-wrapper:output} command-line = ${lte-ue-sh-wrapper:output}
wrapper-path = ${directory:service}/lte-ue wrapper-path = ${directory:service}/lte-ue
mode = 0775 mode = 0775
......
...@@ -268,7 +268,6 @@ extra-context = ...@@ -268,7 +268,6 @@ extra-context =
key sdr amarisoft:sdr key sdr amarisoft:sdr
raw enb_template ${enb.jinja2.cfg:target} raw enb_template ${enb.jinja2.cfg:target}
raw sib23_template ${sib23.jinja2.asn:target} raw sib23_template ${sib23.jinja2.asn:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target} raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target}
raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target} raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target}
raw lopcomm_rrh_stats_template ${lopcomm-rrh-stats.jinja2.py:target} raw lopcomm_rrh_stats_template ${lopcomm-rrh-stats.jinja2.py:target}
...@@ -305,7 +304,6 @@ extra-context = ...@@ -305,7 +304,6 @@ extra-context =
key enb amarisoft:enb key enb amarisoft:enb
key sdr amarisoft:sdr key sdr amarisoft:sdr
raw gnb_template ${gnb.jinja2.cfg:target} raw gnb_template ${gnb.jinja2.cfg:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target} raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target}
raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target} raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target}
raw openssl_location ${openssl:location} raw openssl_location ${openssl:location}
...@@ -330,7 +328,6 @@ extra-context = ...@@ -330,7 +328,6 @@ extra-context =
raw mme_template ${mme.jinja2.cfg:target} raw mme_template ${mme.jinja2.cfg:target}
raw dnsmasq_template ${dnsmasq.jinja2.cfg:target} raw dnsmasq_template ${dnsmasq.jinja2.cfg:target}
raw ims_template ${ims.jinja2.cfg:target} raw ims_template ${ims.jinja2.cfg:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw openssl_location ${openssl:location} raw openssl_location ${openssl:location}
raw nghttp2_location ${nghttp2:location} raw nghttp2_location ${nghttp2:location}
raw iperf3_location ${iperf3:location} raw iperf3_location ${iperf3:location}
...@@ -349,7 +346,6 @@ extra-context = ...@@ -349,7 +346,6 @@ extra-context =
key ue amarisoft:ue key ue amarisoft:ue
key sdr amarisoft:sdr key sdr amarisoft:sdr
raw ue_lte_template ${ue-lte.jinja2.cfg:target} raw ue_lte_template ${ue-lte.jinja2.cfg:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw openssl_location ${openssl:location} raw openssl_location ${openssl:location}
raw default_lte_bandwidth ${default-params:default-lte-bandwidth} raw default_lte_bandwidth ${default-params:default-lte-bandwidth}
raw default_n_antenna_dl ${default-params:default-n-antenna-dl} raw default_n_antenna_dl ${default-params:default-n-antenna-dl}
...@@ -367,7 +363,6 @@ extra-context = ...@@ -367,7 +363,6 @@ extra-context =
key ue amarisoft:ue key ue amarisoft:ue
key sdr amarisoft:sdr key sdr amarisoft:sdr
raw ue_nr_template ${ue-nr.jinja2.cfg:target} raw ue_nr_template ${ue-nr.jinja2.cfg:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw openssl_location ${openssl:location} raw openssl_location ${openssl:location}
raw default_nr_bandwidth ${default-params:default-nr-bandwidth} raw default_nr_bandwidth ${default-params:default-nr-bandwidth}
raw default_n_antenna_dl ${default-params:default-n-antenna-dl} raw default_n_antenna_dl ${default-params:default-n-antenna-dl}
......
#!/bin/bash
# Copyright (C) 2012-2015 Amarisoft
# LTE system logger version 2016-10-13
# Path for multi environment support
export PATH="$PATH:/bin/:/usr/bin/:/usr/local/bin"
while [ "$1" != "" ] ; do
if [ -e "$1" ] ; then
# Avoid storing logs with comments only
HAS_LOG=$(grep -v -l "#" $1)
if [ "$HAS_LOG" != "" ] ; then
DATE=$(date -u +%Y%m%d.%H:%M:%S | sed -e "s/ /-/g")
FILE=$(basename $1)
mv $1 "{{ directory['log'] }}/${FILE}.${DATE}"
else
rm -f $1
fi
fi
shift
done
...@@ -12,10 +12,10 @@ if args.delete: ...@@ -12,10 +12,10 @@ if args.delete:
directory = os.path.dirname(os.path.realpath(__file__)) directory = os.path.dirname(os.path.realpath(__file__))
test_directory = os.path.join(directory, 'test') test_directory = os.path.join(directory, 'test')
for f in os.listdir(directory): for f in os.listdir(directory):
if 'tdd' in f: if 'tdd' in f or 'fdd' in f:
os.remove(os.path.join(directory, f)) os.remove(os.path.join(directory, f))
for f in os.listdir(test_directory): for f in os.listdir(test_directory):
if 'testTDD' in f: if 'testTDD' in f or 'testFDD' in f:
os.remove(os.path.join(test_directory, f)) os.remove(os.path.join(test_directory, f))
exit() exit()
......
# Program slapos-render-config is handy during config/ templates development.
#
# It mimics the way config files are generated during the build but runs much
# faster compared to full `slapos node software` + `slapos node instance` runs.
import zc.buildout.buildout # XXX workaround for https://lab.nexedi.com/nexedi/slapos.recipe.template/merge_requests/9
from slapos.recipe.template import jinja2_template
import json
# j2render renders config/<cfg>.jinja2.cfg into config/<cfg>.cfg with provided json parameters.
def j2render(cfg, jcfg):
ctx = json.loads(jcfg)
textctx = ''
for k, v in ctx.items():
textctx += 'json %s %s\n' % (k, json.dumps(v))
buildout = None # stub
r = jinja2_template.Recipe(buildout, "recipe", {
'extensions': 'jinja2.ext.do',
'url': 'config/{}.jinja2.cfg'.format(cfg),
'output': 'config/{}.cfg'.format(cfg),
'context': textctx,
})
#print(r.context)
# avoid dependency on zc.buildout.download and the need to use non-stub buildout section
def _read(url, *args):
with open(url, *args) as f:
return f.read()
r._read = _read
with open('config/{}.cfg'.format(cfg), 'w+') as f:
f.write(r._render().decode())
config = "gnb" config = "gnb"
json_params_empty = """{ json_params_empty = """{
"rf_mode": 'fdd', "rf_mode": 'fdd',
...@@ -32,7 +68,11 @@ json_params = """{ ...@@ -32,7 +68,11 @@ json_params = """{
"configuration.default_nr_ssb_pos_bitmap": "10000000", "configuration.default_nr_ssb_pos_bitmap": "10000000",
"configuration.default_n_antenna_dl": 2, "configuration.default_n_antenna_dl": 2,
"configuration.default_n_antenna_ul": 2, "configuration.default_n_antenna_ul": 2,
"configuration.default_nr_inactivity_timer": 10000 "configuration.default_nr_inactivity_timer": 10000,
"configuration.com_ws_port": 9001,
"configuration.com_addr": "127.0.1.2",
"configuration.amf_addr": "127.0.1.100",
"configuration.gtp_addr": "127.0.1.1"
}, },
"directory": { "directory": {
"log": "log", "log": "log",
...@@ -43,190 +83,5 @@ json_params = """{ ...@@ -43,190 +83,5 @@ json_params = """{
"tdd_ul_dl_config": "5ms 8UL 1DL 2/10 (maximum uplink)" "tdd_ul_dl_config": "5ms 8UL 1DL 2/10 (maximum uplink)"
} }
}""" }"""
import os
import json
from jinja2 import Environment, StrictUndefined, \
BaseLoader, TemplateNotFound, PrefixLoader
import six
DEFAULT_CONTEXT = {x.__name__: x for x in (
abs, all, any, bin, bool, bytes, callable, chr, complex, dict, divmod,
enumerate, filter, float, format, frozenset, hex, int,
isinstance, iter, len, list, map, max, min, next, oct, ord, pow,
range, repr, reversed, round, set, six, sorted, str, sum, tuple, zip)}
if six.PY2:
import itertools
DEFAULT_CONTEXT.update(
filter=itertools.ifilter,
map=itertools.imap,
range=xrange,
zip=itertools.izip,
)
def _assert(x, *args):
if x:
return ""
raise AssertionError(*args)
DEFAULT_CONTEXT['assert'] = _assert
DUMPS_KEY = 'dumps'
DEFAULT_IMPORT_DELIMITER = '/'
def getKey(expression, buildout, _, options):
section, entry = expression.split(':')
if section:
return buildout[section][entry]
else:
return options[entry]
def getJsonKey(expression, buildout, _, __): j2render(config, json_params)
return json.loads(getKey(expression, buildout, _, __))
EXPRESSION_HANDLER = {
'raw': (lambda expression, _, __, ___: expression),
'key': getKey,
'json': (lambda expression, _, __, ___: json.loads(expression)),
'jsonkey': getJsonKey,
'import': (lambda expression, _, __, ___:
__import__(expression, fromlist=['*'], level=0)),
'section': (lambda expression, buildout, _, __: dict(
buildout[expression])),
}
class RelaxedPrefixLoader(PrefixLoader):
"""
Same as PrefixLoader, but accepts imports lacking separator.
"""
def get_loader(self, template):
if self.delimiter not in template:
template += self.delimiter
return super(RelaxedPrefixLoader, self).get_loader(template)
class RecipeBaseLoader(BaseLoader):
"""
Base class for import classes altering import path.
"""
def __init__(self, path, delimiter, encoding):
self.base = os.path.normpath(path)
self.delimiter = delimiter
self.encoding = encoding
def get_source(self, environment, template):
path = self._getPath(template)
# Code adapted from jinja2's doc on BaseLoader.
if path is None or not os.path.exists(path):
raise TemplateNotFound(template)
mtime = os.path.getmtime(path)
with open(path, 'rb') as f:
source = f.read().decode(self.encoding)
return source, path, lambda: mtime == os.path.getmtime(path)
def _getPath(self, template):
raise NotImplementedError
class FileLoader(RecipeBaseLoader):
"""
Single-path loader.
"""
def _getPath(self, template):
if template:
return None
return self.base
class FolderLoader(RecipeBaseLoader):
"""
Multi-path loader (to allow importing a folder's content).
"""
def _getPath(self, template):
path = os.path.normpath(os.path.join(
self.base,
*template.split(self.delimiter)
))
if path.startswith(self.base):
return path
return None
LOADER_TYPE_DICT = {
'rawfile': (FileLoader, EXPRESSION_HANDLER['raw']),
'file': (FileLoader, getKey),
'rawfolder': (FolderLoader, EXPRESSION_HANDLER['raw']),
'folder': (FolderLoader, getKey),
}
compiled_source_cache = {}
class Recipe():
def _init(self, name, options):
self.once = options.get('once')
self.encoding = options.get('encoding', 'utf-8')
self._update = True
import_delimiter = options.get('import-delimiter',
DEFAULT_IMPORT_DELIMITER)
import_dict = {}
for line in options.get('import-list', '').splitlines(False):
if not line:
continue
expression_type, alias, expression = line.split(None, 2)
if alias in import_dict:
raise ValueError('Duplicate import-list entry %r' % alias)
loader_type, expression_handler = LOADER_TYPE_DICT[
expression_type]
import_dict[alias] = loader_type(
expression_handler(expression, *args),
import_delimiter, self.encoding,
)
if import_dict:
loader = RelaxedPrefixLoader(import_dict,
delimiter=import_delimiter)
else:
loader = None
self.template = options['url']
extension_list = [x for x in (y.strip()
for y in options.get('extensions', '').split()) if x]
self.context = options['context']
self.context.update(DEFAULT_CONTEXT.copy())
self.env = Environment(
extensions=extension_list,
undefined=StrictUndefined,
loader=loader)
def _render(self):
env = self.env
template = self.template
with open(template, 'rb') as f:
source = f.read().decode(self.encoding)
compiled_source_cache[template] = compiled_source = \
env.compile(source, filename=template)
template_object = env.template_class.from_code(env,
compiled_source,
env.make_globals(None), None)
print(self.context)
return template_object.render(**self.context).encode(self.encoding)
def install(self):
once = self.once
if once and os.path.exists(once):
return
installed = super(Recipe, self).install()
if once:
open(once, 'ab').close()
return
return installed
def update(self):
if self._update:
self.install()
else:
super(Recipe, self).update()
r = Recipe()
r._init("recipe", {
'extensions': 'jinja2.ext.do',
'url': 'config/{}.jinja2.cfg'.format(config),
'output': 'config/{}.cfg'.format(config),
'context': json.loads(json_params),
})
with open('config/{}.cfg'.format(config), 'w+') as f:
f.write(r._render().decode())
...@@ -19,7 +19,6 @@ extends = ...@@ -19,7 +19,6 @@ extends =
parts += parts +=
template template
slapos-cookbook slapos-cookbook
ltelogs.jinja2.sh
ncclient_common ncclient_common
# copy all configs by default # copy all configs by default
mme.jinja2.cfg mme.jinja2.cfg
...@@ -149,9 +148,6 @@ filename = sib23.jinja2.asn ...@@ -149,9 +148,6 @@ filename = sib23.jinja2.asn
[gnb.jinja2.cfg] [gnb.jinja2.cfg]
<= copy-config-to-instance <= copy-config-to-instance
filename = gnb.jinja2.cfg filename = gnb.jinja2.cfg
[ltelogs.jinja2.sh]
<= copy-to-instance
filename = ltelogs.jinja2.sh
[ue_db.jinja2.cfg] [ue_db.jinja2.cfg]
<= copy-config-to-instance <= copy-config-to-instance
filename = ue_db.jinja2.cfg filename = ue_db.jinja2.cfg
......
Markdown is supported
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