Skip to content

Commit 471df28

Browse files
committed
frr: T7896: Adding profile selection templating in frr.conf
frr: T7896: Simplifying code and adhere to already existing design / coding rules
1 parent 6e79d77 commit 471df28

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

interface-definitions/system_frr.xml.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
</leafNode>
3838
<leafNode name="profile">
3939
<properties>
40-
<help>Configuration profiles to adapt different defaults</help>
40+
<help>Select configuration profile to adapt different defaults</help>
4141
<completionHelp>
4242
<list>traditional datacenter</list>
4343
</completionHelp>
4444
<valueHelp>
4545
<format>traditional</format>
46-
<description>Reflects defaults adhering mostly to IETF standards or common practices in wide-area internet routing</description>
46+
<description>Adhere mostly to IETF standards or common practices in wide-area internet routing</description>
4747
</valueHelp>
4848
<valueHelp>
4949
<format>datacenter</format>
50-
<description>Reflects a single administrative domain with intradomain links using aggressive timers</description>
50+
<description>Single administrative domain using aggressive timers</description>
5151
</valueHelp>
5252
<constraint>
5353
<regex>(datacenter|traditional)</regex>

python/vyos/frrender.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ def dict_helper_nhrp_defaults(nhrp):
233233
ip_dict['afi'] = ip_version
234234
dict.update({ip_version : ip_dict})
235235

236+
# Get FRR profile
237+
frr_system_cli_path = ['system', 'frr']
238+
dict['system_frr'] = conf.get_config_dict(frr_system_cli_path , key_mangling=('-', '_'),
239+
get_first_key=True, with_recursive_defaults=True)
240+
236241
# Enable SNMP agentx support
237242
# SNMP AgentX support cannot be disabled once enabled
238243
if conf.exists(['service', 'snmp']):
@@ -733,6 +738,10 @@ def inline_helper(config_dict) -> str:
733738
# we can not reload an empty file, thus we always embed the marker
734739
output = '!\n'
735740

741+
# FRR profile configuration
742+
tmp = dict_search('system_frr.profile', config_dict)
743+
if tmp: output += f'frr defaults {tmp}\n'
744+
736745
# Enable FRR logging
737746
output += 'log facility daemon\n'
738747
output += 'log timestamp precision 3\n'

smoketest/scripts/cli/test_system_frr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ def test_frr_profile_add_remove(self):
159159
self.cli_commit()
160160
# read the config file and check content
161161
self.assertIn(f'frr_profile="{profile}"', read_file(config_file))
162+
# read the frr.conf file and check content
163+
frrconfig = self.getFRRconfig()
164+
self.assertIn(f'frr defaults {profile}', frrconfig)
162165

163166
# test remove profile
164167
self.cli_delete(base_path + ['profile'])
165168
self.cli_commit()
166169
# read the config file and check content
167170
self.assertIn(f'frr_profile="{frr_profiles[0]}"', read_file(config_file))
171+
# read the frr.conf file and check content
172+
frrconfig = self.getFRRconfig()
173+
self.assertIn(f'frr defaults {profile}', frrconfig)
168174

169175
def test_frr_file_descriptors(self):
170176
file_descriptors = '4096'

src/conf_mode/system_frr.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919
from vyos import ConfigError
2020
from vyos.base import Warning
2121
from vyos.config import Config
22+
from vyos.frrender import FRRender
23+
from vyos.frrender import get_frrender_dict
2224
from vyos.logger import syslog
2325
from vyos.template import render_to_string
2426
from vyos.utils.boot import boot_configuration_complete
2527
from vyos.utils.file import read_file
2628
from vyos.utils.file import write_file
2729
from vyos.utils.process import call
30+
from vyos.utils.process import is_systemd_service_running
2831

2932
from vyos import airbag
3033
airbag.enable()
3134

3235
# path to daemons config and config status files
33-
config_file = '/etc/frr/daemons'
36+
daemon_config_file = '/etc/frr/daemons'
3437

3538
def get_config(config=None):
3639
if config:
@@ -42,6 +45,8 @@ def get_config(config=None):
4245
frr_config = conf.get_config_dict(base, key_mangling=('-', '_'),
4346
get_first_key=True,
4447
with_recursive_defaults=True)
48+
# get FRR configuration
49+
frr_config['frrender'] = get_frrender_dict(conf)
4550

4651
return frr_config
4752

@@ -51,15 +56,25 @@ def verify(frr_config):
5156

5257
def generate(frr_config):
5358
# read daemons config file
54-
daemons_config_current = read_file(config_file)
59+
daemons_config_current = read_file(daemon_config_file)
5560
# generate new config file
5661
daemons_config_new = render_to_string('frr/daemons.frr.tmpl', frr_config)
5762
# update configuration file if this is necessary
5863
if daemons_config_new != daemons_config_current:
5964
syslog.warning('FRR daemons configuration file need to be changed')
60-
write_file(config_file, daemons_config_new)
65+
write_file(daemon_config_file, daemons_config_new)
6166
frr_config['config_file_changed'] = True
6267

68+
# profile could be automatically generated by frr in frr.conf
69+
# and needs to be updated as it is taking precedence
70+
if 'frrender' in frr_config and 'profile' in frr_config['frrender']:
71+
frr_config['frrender']['profile'] = frr_config['profile']
72+
if frr_config['frrender'] and not is_systemd_service_running('vyos-configd.service'):
73+
FRRender().generate(frr_config['frrender'])
74+
# apply here to keep consistency with the generated daemons
75+
# config file
76+
FRRender().apply()
77+
6378
def apply(frr_config):
6479
# display warning to user
6580
if boot_configuration_complete() and frr_config.get('config_file_changed'):

0 commit comments

Comments
 (0)