Skip to content

Commit 549e4f8

Browse files
authored
Merge branch 'master' into intf_cmds
2 parents 0113996 + ca8ffe7 commit 549e4f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3631
-631
lines changed

config/main.py

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import time
1414

1515
from minigraph import parse_device_desc_xml
16-
from portconfig import get_child_ports, get_port_config_file_name
16+
17+
from portconfig import get_child_ports
1718
from sonic_py_common import device_info, multi_asic
1819
from sonic_py_common.interface import front_panel_prefix, portchannel_prefix, vlan_prefix, loopback_prefix
1920
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
@@ -69,31 +70,12 @@ def readJsonFile(fileName):
6970
raise Exception(str(e))
7071
return result
7172

72-
def _get_breakout_cfg_file_name():
73-
"""
74-
Get name of config file for Dynamic Port Breakout
75-
"""
76-
try:
77-
(platform, hwsku) = device_info.get_platform_and_hwsku()
78-
except Exception as e:
79-
click.secho("Failed to get platform and hwsku with error:{}".format(str(e)), fg='red')
80-
raise click.Abort()
81-
82-
try:
83-
breakout_cfg_file_name = get_port_config_file_name(hwsku, platform)
84-
except Exception as e:
85-
click.secho("Breakout config file not found with error:{}".format(str(e)), fg='red')
86-
raise click.Abort()
87-
88-
return breakout_cfg_file_name
89-
90-
9173
def _get_breakout_options(ctx, args, incomplete):
9274
""" Provides dynamic mode option as per user argument i.e. interface name """
9375
all_mode_options = []
9476
interface_name = args[-1]
9577

96-
breakout_cfg_file = _get_breakout_cfg_file_name()
78+
breakout_cfg_file = device_info.get_path_to_port_config_file()
9779

9880
if not os.path.isfile(breakout_cfg_file) or not breakout_cfg_file.endswith('.json'):
9981
return []
@@ -1659,63 +1641,35 @@ def reload():
16591641
click.secho(
16601642
"Command 'qos reload' failed with invalid namespace '{}'".
16611643
format(ns),
1662-
fg='yellow'
1644+
fg="yellow"
16631645
)
16641646
raise click.Abort()
16651647
asic_id_suffix = str(asic_id)
16661648

1667-
buffer_template_file = os.path.join(
1668-
hwsku_path,
1669-
asic_id_suffix,
1670-
'buffers.json.j2'
1671-
)
1672-
buffer_output_file = "/tmp/buffers{}.json".format(asic_id_suffix)
1673-
qos_output_file = "/tmp/qos{}.json".format(asic_id_suffix)
1674-
1675-
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
1649+
buffer_template_file = os.path.join(hwsku_path, asic_id_suffix, "buffers.json.j2")
16761650
if os.path.isfile(buffer_template_file):
1677-
command = "{} {} -d -t {} > {}".format(
1678-
SONIC_CFGGEN_PATH,
1679-
cmd_ns,
1680-
buffer_template_file,
1681-
buffer_output_file
1682-
)
1683-
clicommon.run_command(command, display_cmd=True)
1684-
qos_template_file = os.path.join(
1685-
hwsku_path,
1686-
asic_id_suffix,
1687-
'qos.json.j2'
1688-
)
1689-
sonic_version_file = os.path.join(
1690-
'/etc/sonic/', 'sonic_version.yml'
1691-
)
1651+
qos_template_file = os.path.join(hwsku_path, asic_id_suffix, "qos.json.j2")
16921652
if os.path.isfile(qos_template_file):
1693-
command = "{} {} -d -t {} -y {} > {}".format(
1653+
cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
1654+
sonic_version_file = os.path.join('/', "etc", "sonic", "sonic_version.yml")
1655+
command = "{} {} -d -t {},config-db -t {},config-db -y {} --write-to-db".format(
16941656
SONIC_CFGGEN_PATH,
16951657
cmd_ns,
1658+
buffer_template_file,
16961659
qos_template_file,
1697-
sonic_version_file,
1698-
qos_output_file
1660+
sonic_version_file
16991661
)
1700-
clicommon.run_command(command, display_cmd=True)
17011662
# Apply the configurations only when both buffer and qos
1702-
# configuration files are presented
1703-
command = "{} {} -j {} --write-to-db".format(
1704-
SONIC_CFGGEN_PATH, cmd_ns, buffer_output_file
1705-
)
1706-
clicommon.run_command(command, display_cmd=True)
1707-
command = "{} {} -j {} --write-to-db".format(
1708-
SONIC_CFGGEN_PATH, cmd_ns, qos_output_file
1709-
)
1663+
# configuration files are present
17101664
clicommon.run_command(command, display_cmd=True)
17111665
else:
1712-
click.secho('QoS definition template not found at {}'.format(
1666+
click.secho("QoS definition template not found at {}".format(
17131667
qos_template_file
1714-
), fg='yellow')
1668+
), fg="yellow")
17151669
else:
1716-
click.secho('Buffer definition template not found at {}'.format(
1670+
click.secho("Buffer definition template not found at {}".format(
17171671
buffer_template_file
1718-
), fg='yellow')
1672+
), fg="yellow")
17191673

17201674
#
17211675
# 'warm_restart' group ('config warm_restart ...')
@@ -2270,7 +2224,7 @@ def speed(ctx, interface_name, interface_speed, verbose):
22702224
@click.pass_context
22712225
def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load_predefined_config):
22722226
""" Set interface breakout mode """
2273-
breakout_cfg_file = _get_breakout_cfg_file_name()
2227+
breakout_cfg_file = device_info.get_path_to_port_config_file()
22742228

22752229
if not os.path.isfile(breakout_cfg_file) or not breakout_cfg_file.endswith('.json'):
22762230
click.secho("[ERROR] Breakout feature is not available without platform.json file", fg='red')

fdbutil/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#!/usr/bin/env python
2-
1+
import argparse
32
import json
4-
import sys
53
import os
6-
import argparse
4+
import sys
75
import syslog
8-
import traceback
96
import time
7+
import traceback
108

11-
from ipaddress import ip_address, ip_network, ip_interface
129
from collections import defaultdict
10+
from ipaddress import ip_address, ip_network, ip_interface
1311

1412
def get_vlan_cidr_map(filename):
1513
"""
@@ -35,7 +33,9 @@ def get_vlan_cidr_map(filename):
3533
continue
3634
vlan, cidr = tuple(vlan_key.split('|'))
3735
if vlan in config_db_entries["VLAN"]:
38-
vlan_cidr[vlan] = ip_interface(cidr).network
36+
if vlan not in vlan_cidr:
37+
vlan_cidr[vlan] = {4: ip_address("0.0.0.0".decode()), 6: ip_address("::".decode())}
38+
vlan_cidr[vlan][ip_interface(cidr).version] = ip_interface(cidr).network
3939

4040
return vlan_cidr
4141

@@ -65,8 +65,9 @@ def get_arp_entries_map(arp_filename, config_db_filename):
6565
continue
6666
table, vlan, ip = tuple(key.split(':'))
6767
if "NEIGH_TABLE" in table and vlan in vlan_cidr.keys() \
68-
and ip_address(ip) in ip_network(vlan_cidr[vlan]) and "neigh" in config.keys():
69-
arp_map[config["neigh"].replace(':', '-')] = ""
68+
and ip_address(ip) in ip_network(vlan_cidr[vlan][ip_interface(ip).version]) \
69+
and "neigh" in config.keys():
70+
arp_map[config["neigh"].replace(':', '-').upper()] = ""
7071

7172
return arp_map
7273

@@ -94,7 +95,7 @@ def filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_fi
9495
def filter_fdb_entry(fdb_entry):
9596
for key, _ in fdb_entry.items():
9697
if 'FDB_TABLE' in key:
97-
return key.split(':')[-1] in arp_map
98+
return key.split(':')[-1].upper() in arp_map
9899

99100
# malformed entry, default to False so it will be deleted
100101
return False
@@ -124,44 +125,33 @@ def file_exists_or_raise(filename):
124125
if not os.path.exists(filename):
125126
raise Exception("file '{0}' does not exist".format(filename))
126127

127-
def main():
128+
def main(argv=sys.argv):
128129
parser = argparse.ArgumentParser()
129130
parser.add_argument('-f', '--fdb', type=str, default='/tmp/fdb.json', help='fdb file name')
130131
parser.add_argument('-a', '--arp', type=str, default='/tmp/arp.json', help='arp file name')
131132
parser.add_argument('-c', '--config_db', type=str, default='/tmp/config_db.json', help='config db file name')
132133
parser.add_argument('-b', '--backup_file', type=bool, default=True, help='Back up old fdb entries file')
133-
args = parser.parse_args()
134+
args = parser.parse_args(argv[1:])
134135

135136
fdb_filename = args.fdb
136137
arp_filename = args.arp
137138
config_db_filename = args.config_db
138139
backup_file = args.backup_file
139140

141+
res = 0
140142
try:
143+
syslog.openlog('filter_fdb_entries')
141144
file_exists_or_raise(fdb_filename)
142145
file_exists_or_raise(arp_filename)
143146
file_exists_or_raise(config_db_filename)
144147
except Exception as e:
145148
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
146-
else:
147-
filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_file)
148-
149-
return 0
150-
151-
if __name__ == '__main__':
152-
res = 0
153-
try:
154-
syslog.openlog('filter_fdb_entries')
155-
res = main()
156149
except KeyboardInterrupt:
157150
syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting")
158151
res = 1
159-
except Exception as e:
160-
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
161-
res = 2
152+
else:
153+
filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_file)
162154
finally:
163155
syslog.closelog()
164-
try:
165-
sys.exit(res)
166-
except SystemExit:
167-
os._exit(res)
156+
157+
return res

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
22
filterwarnings =
33
ignore::DeprecationWarning
4-
addopts = --cov=acl_loader --cov=clear --cov=config --cov=connect --cov=consutil --cov=counterpoll --cov=crm --cov=debug --cov=fwutil --cov=pcieutil --cov=pfcwd --cov=psuutil --cov=pddf_fanutil --cov=pddf_ledutil --cov=pddf_psuutil --cov=pddf_thermalutil --cov=scripts --cov=sfputil --cov=show --cov=sonic_installer --cov=ssdutil --cov=utilities_common --cov=watchdogutil --cov-report html --cov-report term --cov-report xml
4+
addopts = --cov=acl_loader --cov=clear --cov=config --cov=connect --cov=consutil --cov=counterpoll --cov=crm --cov=debug --cov=fdbutil --cov=fwutil --cov=pcieutil --cov=pfcwd --cov=psuutil --cov=pddf_fanutil --cov=pddf_ledutil --cov=pddf_psuutil --cov=pddf_thermalutil --cov=scripts --cov=sfputil --cov=show --cov=sonic_installer --cov=ssdutil --cov=utilities_common --cov=watchdogutil --cov-report html --cov-report term --cov-report xml

scripts/fanshow

100644100755
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
"""
55
from __future__ import print_function
66

7+
import os
8+
import sys
79
from tabulate import tabulate
810
from swsssdk import SonicV2Connector
911
from natsort import natsorted
1012

13+
# mock the redis for unit test purposes #
14+
try:
15+
if os.environ["UTILITIES_UNIT_TESTING"] == "1":
16+
modules_path = os.path.join(os.path.dirname(__file__), "..")
17+
test_path = os.path.join(modules_path, "tests")
18+
sys.path.insert(0, modules_path)
19+
sys.path.insert(0, test_path)
20+
import mock_tables.dbconnector
21+
except KeyError:
22+
pass
23+
1124

1225
header = ['Drawer', 'LED', 'FAN', 'Speed', 'Direction', 'Presence', 'Status', 'Timestamp']
1326

@@ -52,13 +65,13 @@ class FanShow(object):
5265

5366
presence = data_dict[PRESENCE_FIELD_NAME].lower()
5467
presence = 'Present' if presence == 'true' else 'Not Present'
55-
status = data_dict[STATUS_FIELD_NAME].lower()
56-
if status == 'true':
68+
69+
status = data_dict[STATUS_FIELD_NAME]
70+
status_lower = status.lower()
71+
if status_lower == 'true':
5772
status = 'OK'
58-
elif status == 'false':
73+
elif status_lower == 'false':
5974
status = 'Not OK'
60-
else:
61-
status = 'N/A'
6275

6376
table.append((data_dict[DRAWER_FIELD_NAME], data_dict[LED_STATUS_FIELD_NAME], name, speed, data_dict[DIRECTION_FIELD_NAME], presence, status,
6477
data_dict[TIMESTAMP_FIELD_NAME]))

scripts/fast-reboot

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DEVPATH="/usr/share/sonic/device"
1818
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
1919
PLATFORM_PLUGIN="${REBOOT_TYPE}_plugin"
2020
LOG_SSD_HEALTH="/usr/bin/log_ssd_health"
21-
21+
SSD_FW_UPDATE="ssd-fw-upgrade"
2222
# Require 100M available on the hard drive for warm reboot temp files,
2323
# Size is in 1K blocks:
2424
MIN_HD_SPACE_NEEDED=100000
@@ -456,7 +456,7 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
456456
457457
FILTER_FDB_ENTRIES_RC=0
458458
# Filter FDB entries using MAC addresses from ARP table
459-
/usr/bin/filter_fdb_entries.py -f $DUMP_DIR/fdb.json -a $DUMP_DIR/arp.json -c $CONFIG_DB_FILE || FILTER_FDB_ENTRIES_RC=$?
459+
/usr/bin/filter_fdb_entries -f $DUMP_DIR/fdb.json -a $DUMP_DIR/arp.json -c $CONFIG_DB_FILE || FILTER_FDB_ENTRIES_RC=$?
460460
if [[ FILTER_FDB_ENTRIES_RC -ne 0 ]]; then
461461
error "Failed to filter FDb entries. Exit code: $FILTER_FDB_ENTRIES_RC"
462462
unload_kernel
@@ -503,9 +503,9 @@ systemctl stop nat
503503
debug "Stopped nat ..."
504504
505505
# Kill radv before stopping BGP service to prevent annoucing our departure.
506-
debug "Stopping radv ..."
507-
docker kill radv &>/dev/null || [ $? == 1 ]
506+
debug "Stopping radv service..."
508507
systemctl stop radv
508+
debug "Stopped radv service..."
509509
510510
# Kill bgpd to start the bgp graceful restart procedure
511511
debug "Stopping bgp ..."
@@ -536,12 +536,9 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
536536
debug "Stopped teamd ..."
537537
fi
538538
539-
# Kill swss Docker container
540-
# We call `docker kill swss` to ensure the container stops as quickly as possible,
541-
# then immediately call `systemctl stop swss` to prevent the service from
542-
# restarting the container automatically.
543-
docker kill swss &> /dev/null || debug "Docker swss is not running ($?) ..."
539+
debug "Stopping swss service ..."
544540
systemctl stop swss
541+
debug "Stopped swss service ..."
545542
546543
# Pre-shutdown syncd
547544
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; then
@@ -633,6 +630,11 @@ if [ -x /sbin/hwclock ]; then
633630
/sbin/hwclock -w || /bin/true
634631
fi
635632
633+
if [ -x ${DEVPATH}/${PLATFORM}/${SSD_FW_UPDATE} ]; then
634+
debug "updating ssd fw for${REBOOT_TYPE}"
635+
${DEVPATH}/${PLATFORM}/${SSD_FW_UPDATE} ${REBOOT_TYPE}
636+
fi
637+
636638
# Enable Watchdog Timer
637639
if [ -x ${WATCHDOG_UTIL} ]; then
638640
debug "Enabling Watchdog before ${REBOOT_TYPE}"

0 commit comments

Comments
 (0)