Skip to content

Commit 3e0b7f8

Browse files
committed
Modified prefix_list and manager err check logic
added correct check for UpstreamLC and stderr statements Signed-off-by: Mukul Chodhary <70460358+Muckthebuck@users.noreply.github.com>
1 parent 6b16eba commit 3e0b7f8

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

dockers/docker-fpm-frr/base_image_files/prefix_list

+14-16
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ display_help() {
2727
# Function to check if the user has root privileges
2828
check_root_privileges() {
2929
if [ "$EUID" -ne 0 ] ; then
30-
echo "Root privileges are needed for this operation"
30+
echo "Root privileges are needed for this operation." >&2
3131
exit 1
3232
fi
3333
}
3434

35-
# Function to check if the command is supported on spine routers
35+
# Function to check if the device is supported device with type spine routers and subtype UpstreamLC
3636
check_spine_router() {
37-
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.type)" != *"SpineRouter"* ]] ; then
38-
echo "Operation is not supported on this platform"
37+
type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.type)
38+
sub_type=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.sub_type)
39+
40+
# only supported on spine routers and UpstreamLC
41+
if [[ "$type" != "SpineRouter" || "$sub_type" != "UpstreamLC" ]]; then
42+
echo "Operation is only supported on UpstreamLC of SpineRouter." >&2
3943
exit 1
4044
fi
4145
}
@@ -61,10 +65,10 @@ validate_operation() {
6165
done
6266

6367
if [ $valid_operation == false ]; then
64-
echo "Invalid parameter $1, Operation not supported"
68+
echo "Invalid parameter $1, Operation not supported" >&2
6569
echo ""
6670
display_help
67-
exit 0
71+
exit 1
6872
fi
6973

7074
# Check if the prefix type is supported or not if the operation is not status
@@ -77,10 +81,10 @@ validate_operation() {
7781
done
7882

7983
if [ $valid_prefix_type == false ]; then
80-
echo "Invalid parameter $2, Prefix type not supported"
84+
echo "Invalid parameter $2, Prefix type not supported" >&2
8185
echo ""
8286
display_help
83-
exit 0
87+
exit 1
8488
fi
8589
fi
8690
}
@@ -160,19 +164,13 @@ if [[ ($NUM_ASIC -gt 1) ]]; then
160164
while [ $asic -lt $NUM_ASIC ]
161165
do
162166
sub_role=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['sub_role']" -n asic$asic`
163-
subtype=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['subtype']" -n asic$asic`
164-
if [ $sub_role == 'FrontEnd' ] ; then
165-
if [ $subtype == 'UpstreamLC' ] ; then
166-
handle_prefix_list_asic $asic $1 $2 $3
167-
fi
167+
if [ $sub_role == 'FrontEnd' ]; then
168+
handle_prefix_list_asic $asic $1 $2 $3
168169
fi
169170
asic=$((asic+1))
170171
done
171172
else
172-
subtype=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['subtype']"`
173-
if [ $subtype == 'UpstreamLC' ] ; then
174173
handle_prefix_list_single $1 $2 $3
175-
fi
176174
fi
177175

178176
if [ $1 != 'status' ]; then

src/sonic-bgpcfgd/bgpcfgd/managers_prefix_list.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,27 @@ def generate_prefix_list_config(self, data, add):
3434
:return: rendered configuration
3535
"""
3636
cmd = "\n"
37-
bgp_asn = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["bgp_asn"]
38-
localhost_type = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["type"]
39-
subtype = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["subtype"]
40-
if data["prefix_list_name"] == "ANCHOR_PREFIX" and localhost_type == "SpineRouter" and subtype == "UpstreamLC":
41-
# Add the anchor prefix to the radian configuration`
42-
data["bgp_asn"] = bgp_asn
43-
if add:
44-
# add some way of getting this asn list from the database in the future
45-
cmd += self.templates["add_radian"].render(data=data)
46-
log_debug("PrefixListMgr:: Anchor prefix %s added to radian configuration" % data["prefix"])
47-
else:
48-
cmd += self.templates["del_radian"].render(data=data)
49-
log_debug("PrefixListMgr:: Anchor prefix %s removed from radian configuration" % data["prefix"])
37+
metadata = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]
38+
bgp_asn = metadata["bgp_asn"]
39+
localhost_type = metadata["type"]
40+
subtype = metadata["subtype"]
41+
42+
if data["prefix_list_name"] != "ANCHOR_PREFIX":
43+
log_warn("PrefixListMgr:: Prefix list %s is not supported" % data["prefix_list_name"])
44+
return
45+
if localhost_type != "SpineRouter" or subtype != "UpstreamLC":
46+
log_warn("PrefixListMgr:: Prefix list %s is only supported on UpstreamLC of SpineRouter" % data["prefix_list_name"])
47+
return
48+
49+
# Add the anchor prefix to the radian configuration
50+
data["bgp_asn"] = bgp_asn
51+
if add:
52+
# add some way of getting this asn list from the database in the future
53+
cmd += self.templates["add_radian"].render(data=data)
54+
log_debug("PrefixListMgr:: Anchor prefix %s added to radian configuration" % data["prefix"])
55+
else:
56+
cmd += self.templates["del_radian"].render(data=data)
57+
log_debug("PrefixListMgr:: Anchor prefix %s removed from radian configuration" % data["prefix"])
5058
self.cfg_mgr.push(cmd)
5159

5260

0 commit comments

Comments
 (0)