Commit 28ab315b authored by Kirill Smelkov's avatar Kirill Smelkov

software/ors-amarisoft: slapos-render-config: Retarget currently generated...

software/ors-amarisoft: slapos-render-config: Retarget currently generated enb.cfg and gnb.cfg to out/ors/

Besides ORS we will soon add other cases to enb.cfg generation. It will be
handy to clearly see what is what and to keep ORS case to be also alive and distinguished.

Prepare to that by emitting generated enb.cfg and gnb.cfg to out/ors/enb/ and
out/ors/gnb instead of just out. Name the file itself enb.cfg always to match
what happens for real in the SR.

There is no change to generated files - it is only renaming:

```
$ ./pythonwitheggs slapos-render-config.py && xdiff config/{old,out}
```

```diff
diff --git a/config/old/enb.cfg b/config/out/ors/enb/enb.cfg
similarity index 100%
rename from config/old/enb.cfg
rename to config/out/ors/enb/enb.cfg
diff --git a/config/old/gnb.cfg b/config/out/ors/gnb/enb.cfg
similarity index 100%
rename from config/old/gnb.cfg
rename to config/out/ors/gnb/enb.cfg
```
parent 08731df7
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
import zc.buildout.buildout # XXX workaround for https://lab.nexedi.com/nexedi/slapos.recipe.template/merge_requests/9 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 from slapos.recipe.template import jinja2_template
import json, os, glob import json, os, shutil
# j2render renders config/<src> into config/out/<out> with provided json parameters. # j2render renders config/<src> into config/out/<out> with provided json parameters.
def j2render(src, out, jcfg): def j2render(src, out, jcfg):
src = 'config/{}'.format(src)
out = 'config/out/{}'.format(out)
ctx = json.loads(jcfg) ctx = json.loads(jcfg)
assert '_standalone' not in ctx assert '_standalone' not in ctx
ctx['_standalone'] = True ctx['_standalone'] = True
...@@ -21,8 +24,8 @@ def j2render(src, out, jcfg): ...@@ -21,8 +24,8 @@ def j2render(src, out, jcfg):
buildout = None # stub buildout = None # stub
r = jinja2_template.Recipe(buildout, "recipe", { r = jinja2_template.Recipe(buildout, "recipe", {
'extensions': 'jinja2.ext.do', 'extensions': 'jinja2.ext.do',
'url': 'config/{}'.format(src), 'url': src,
'output': 'config/out/{}'.format(out), 'output': out,
'context': textctx, 'context': textctx,
'import-list': ''' 'import-list': '''
rawfile slaplte.jinja2 slaplte.jinja2''', rawfile slaplte.jinja2 slaplte.jinja2''',
...@@ -35,7 +38,8 @@ def j2render(src, out, jcfg): ...@@ -35,7 +38,8 @@ def j2render(src, out, jcfg):
return f.read() return f.read()
r._read = _read r._read = _read
with open('config/out/{}'.format(out), 'w+') as f: os.makedirs(os.path.dirname(out), exist_ok=True)
with open(out, 'w+') as f:
f.write(r._render().decode()) f.write(r._render().decode())
...@@ -109,7 +113,7 @@ def do_enb(): ...@@ -109,7 +113,7 @@ def do_enb():
'rx_gain': 43, 'rx_gain': 43,
} }
do('enb.jinja2.cfg', 'enb.cfg', { do('enb.jinja2.cfg', 'ors/enb/enb.cfg', {
'enb_id': "0x1A2D0", 'enb_id': "0x1A2D0",
'cell_list': {'CELL': { 'cell_list': {'CELL': {
'cell_type': 'lte', 'cell_type': 'lte',
...@@ -128,7 +132,7 @@ def do_enb(): ...@@ -128,7 +132,7 @@ def do_enb():
'plmn_list': {"1": {'plmn': '00101'}}, 'plmn_list': {"1": {'plmn': '00101'}},
"ncell_list": {'1': peer_lte}, "ncell_list": {'1': peer_lte},
}) })
do('enb.jinja2.cfg', 'gnb.cfg', { do('enb.jinja2.cfg', 'ors/gnb/enb.cfg', {
'gnb_id': "0x12345", 'gnb_id': "0x12345",
'gnb_id_bits': 28, 'gnb_id_bits': 28,
'cell_list': {'CELL': { 'cell_list': {'CELL': {
...@@ -159,9 +163,8 @@ def do_ue(): ...@@ -159,9 +163,8 @@ def do_ue():
def main(): def main():
os.makedirs('config/out', exist_ok=True) if os.path.exists('config/out'):
for f in glob.glob('config/out/*'): shutil.rmtree('config/out')
os.remove(f)
do_enb() do_enb()
do_ue() do_ue()
......
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