Hi Gerdriaan,
Thank you for your interest and asking those questions. Finally I found the
issue and luckily was not a Bird2's fault but some weird python3 behavior. For
the record:
- The following does not work:
my_file.write(template.render(nawas_routes).encode('ascii',
'ignore').decode('ascii'))
- The following works:
new_data = template.render(nawas_routes).encode('ascii',
'ignore').decode('ascii')
my_file.write(new_data)
Although the first expression is (syntactically and logically) correct, by the
time the "birdc configure" was called/executed the config file was empty. Even
if I put a 1-2-3 second time sleep the file was still empty and thus, Bird2 had
nothing to read. Once, the Python3 script completes successfully and exits to
the CLI, you could see however the new data in the "my_file. Thus, it was quite
confusing to understand and find the issue.
I need to reach some more experienced python developers to understand why, but
I suspect that Python3 puts the first method in a separate thread and leaves it
execute separately while the rest of the python3 interpreter moves to the rest
of the script. When I switched the code to the second method it worked
immediately.
I hope this finding can help future Bird users with their automation scripts.
Kind Regards
Stavros Konstantaras | Sr. Network Engineer | AMS-IX
Frederiksplein 42, 1017 XN Amsterdam, The Netherlands
M +31 (0) 620 89 51 04
ams-ix.net <http://ams-ix.net>
On 26/11/2022, 15:02, "Gerdriaan Mulder" <[email protected]> wrote:
Hi Stavros,
Could you share any of the Python3 scripts you used? This may help in
debugging / reproducing your issue.
A few thoughts in the meantime:
- are there any other BIRD processes running on the system involved?
- if so, are you connecting to the correct control socket?
- are you sure all buffers (i.e. for the configuration file) have been
flushed before calling birdc configure?
- did you capture any output from birdc reconfigure? (Bird 2.0.10 on
Ubuntu 20.04, though compiled from source, says "Reading configuration
from /etc/bird.conf")
- if so, did the correct configuration filename come up?
Best regards,
Gerdriaan Mulder
On 24/11/2022 14:09, Stavros Konstantaras via Bird-users wrote:
> Hi all,
>
> I am trying to automate Bird2 configuration with Python3 and I faced
> this strange issue:
>
> * If I generate a part of the config which is included in the main
> config file and then I call “birdc configure” via os.system()
> function, the new configuration is ignored.
>
> * If I generate a full config and I call “birdc configure” via
> os.system() function, I get the strange error
> “bird2_control.conf:1:1 No protocol is specified in the config file”
> Which is strange because the first line of my config is a big
> comment that can be ignored.
>
> * If myself execute ““birdc configure” without touching/changing
> anything in the config, it is accepted and executed immediately
> without issues !!!
>
> Things I tried so far to overcome the issue:
>
> * I used subprocess.run() but didn’t have any luck
> * Tried to use a 2s sleep between writing the new config and reloading
> bird2, didn’t work
> * I used python2 instead of python3 but still didn’t have any luck
> * I executed “birdc configure” via a BASH script, still didn’t work
> * User and file permissions checked, now problem.
>
> Anyone has experienced this weird problem before and has a suggestion to
> overcome it? It seems to be a birdc issue and doesn’t like to be called
> from scripts.
>
> FYI, I use Bird 2.0.10 on CentOS 7 and Python 3.6.8
>
> Kind Regards
>
> Stavros
>