pierky / arouteserver

A tool to automatically build (and test) feature-rich configurations for BGP route servers.
https://arouteserver.readthedocs.org/
GNU General Public License v3.0
288 stars 46 forks source link

if the environment contains any variable with "\u", arouteserver fails #50

Closed sthen closed 5 years ago

sthen commented 5 years ago

Noticed because my usual shell prompt in $PS1 has "\u" in it to show my username, the presence of "\u" in any environment variable causes arouteserver to fail like this:

$ export FOO='\u'
$ arouteserver show_config 
ARouteServer 2019-10-06 17:39:04,919 ERROR An unexpected error occurred: bad escape \u at position 0

Please consider reporting this issue to the author using the URL below, including the following traceback and some hints on how to reproduce it: https://github.com/pierky/arouteserver/issues

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\u'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/arouteserver", line 64, in <module>
    if main():
  File "/usr/local/bin/arouteserver", line 53, in main
    return cmd.run()
  File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/commands/show_config.py", line 46, in run
    self.show_config(current_config_path, sys.stdout)
  File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/commands/show_config.py", line 70, in show_config
    distrib._load_from_yaml("cfg:\n"
  File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 87, in _load_from_yaml
    expanded_doc = expand_env_vars(expanded_doc)
  File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 81, in expand_env_vars
    res = re.sub("\$\{" + v + "\}", os.environ[v], res)
  File "/usr/local/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/local/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/local/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/usr/local/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \u at position 0
pierky commented 5 years ago

Hello @sthen, thanks for reporting this.

I've just pushed a fix, it's in the "dev" branch now, but also a CI/CD pipeline is running https://travis-ci.org/pierky/arouteserver/builds/594270338 and if everything will work as expected, a pre-release (v0.22.2-alpha1 ) will be pushed to the PyPi testing environment.

If you want to test it, you'll be able to install it using the following instructions: https://arouteserver.readthedocs.io/en/latest/INSTALLATION.html#development-and-pre-release-versions

sthen commented 5 years ago

Thanks, confirmed that fixes it for me.

pierky commented 5 years ago

The PyPi file has not been pushed yet because of some integration tests are failing on CentOS, but it's not related to this hot fix, it's just a matter of tuning the tests for the latest version 8, which has been released only recently. Hopefully the pipeline should work now, and the pre-release should go out. After that, I'll push it upstream to master, hopefully tomorrow.

pierky commented 5 years ago

Fixed in v0.22.2.