-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bgpcfg]: Batch bgp updates #6006
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import os | ||
import datetime | ||
import time | ||
import tempfile | ||
|
||
from bgpcfgd.log import log_err, log_info, log_warn, log_crit | ||
from .vars import g_debug | ||
from .utils import run_command | ||
|
||
|
||
class FRR(object): | ||
"""Proxy object with FRR""" | ||
def __init__(self, daemons): | ||
self.daemons = daemons | ||
|
||
def wait_for_daemons(self, seconds): | ||
""" | ||
Wait until FRR daemons are ready for requests | ||
:param seconds: number of seconds to wait, until raise an error | ||
""" | ||
stop_time = datetime.datetime.now() + datetime.timedelta(seconds=seconds) | ||
log_info("Start waiting for FRR daemons: %s" % str(datetime.datetime.now())) | ||
while datetime.datetime.now() < stop_time: | ||
ret_code, out, err = run_command(["vtysh", "-c", "show daemons"], hide_errors=True) | ||
if ret_code == 0 and all(daemon in out for daemon in self.daemons): | ||
log_info("All required daemons have connected to vtysh: %s" % str(datetime.datetime.now())) | ||
return | ||
else: | ||
log_warn("Can't read daemon status from FRR: %s" % str(err)) | ||
time.sleep(0.1) # sleep 100 ms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What happens if no sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Higher cpu usage. I think it is better to wait for 0.1 than to burn cpu by requests. |
||
raise RuntimeError("FRR daemons hasn't been started in %d seconds" % seconds) | ||
|
||
@staticmethod | ||
def get_config(): | ||
ret_code, out, err = run_command(["vtysh", "-c", "show running-config"]) | ||
if ret_code != 0: | ||
log_crit("can't update running config: rc=%d out='%s' err='%s'" % (ret_code, out, err)) | ||
return "" | ||
return out | ||
|
||
@staticmethod | ||
def write(config_text): | ||
fd, tmp_filename = tempfile.mkstemp(dir='/tmp') | ||
os.close(fd) | ||
with open(tmp_filename, 'w') as fp: | ||
fp.write("%s\n" % config_text) | ||
command = ["vtysh", "-f", tmp_filename] | ||
ret_code, out, err = run_command(command) | ||
if ret_code != 0: | ||
err_tuple = tmp_filename, ret_code, out, err | ||
log_err("ConfigMgr::commit(): can't push configuration from file='%s', rc='%d', stdout='%s', stderr='%s'" % err_tuple) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to keep this tmp file, or just put the tmpfile content into syslog? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tmp file content it is full config on the start. Kind of a lot. Do we want to see it in the syslog? |
||
else: | ||
if not g_debug: | ||
os.remove(tmp_filename) | ||
return ret_code == 0 | ||
|
||
@staticmethod | ||
def restart_peer_groups(peer_groups): | ||
""" Restart peer-groups which support BBR | ||
:param peer_groups: List of peer_groups to restart | ||
:return: True if restart of all peer-groups was successful, False otherwise | ||
""" | ||
res = True | ||
for peer_group in sorted(peer_groups): | ||
rc, out, err = run_command(["vtysh", "-c", "clear bgp peer-group %s soft in" % peer_group]) | ||
if rc != 0: | ||
log_value = peer_group, rc, out, err | ||
log_crit("Can't restart bgp peer-group '%s'. rc='%d', out='%s', err='%s'" % log_value) | ||
res = res and (rc == 0) | ||
return res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure if it is always correct to restart peer group after we make any change. for example, if we shutdown a bgp session, which peer group to restart?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.peer_groups_to_restart would be empty in 'shutdown a bgp session" situation and restart_peer_groups will do nothing in this case. I update self.peer_groups_to_restart in two cases now: BBR and allow_prefix.