Skip to content

Commit

Permalink
Merge pull request #44 from mssonicbld/sonicbld/202205-merge
Browse files Browse the repository at this point in the history
[code sync] Merge code from sonic-net/sonic-utilities.msft:202205 to 202205
  • Loading branch information
mssonicbld authored Feb 19, 2024
2 parents 2242e5a + b80fbdf commit 6535704
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 18 deletions.
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ stages:
artifact: sonic-swss-common.bullseye.amd64
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/$(sourceBranch)'
allowPartiallySucceededBuilds: true
displayName: "Download sonic swss common deb packages"

- script: |
Expand Down
53 changes: 36 additions & 17 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import time
import itertools
import copy
import tempfile

from collections import OrderedDict
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
Expand Down Expand Up @@ -131,6 +132,14 @@ def read_json_file(fileName):
raise Exception(str(e))
return result

# write given JSON file
def write_json_file(json_input, fileName):
try:
with open(fileName, 'w') as f:
json.dump(json_input, f, indent=4)
except Exception as e:
raise Exception(str(e))

def _get_breakout_options(ctx, args, incomplete):
""" Provides dynamic mode option as per user argument i.e. interface name """
all_mode_options = []
Expand Down Expand Up @@ -1452,6 +1461,12 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
# Get the file from user input, else take the default file /etc/sonic/config_db{NS_id}.json
if cfg_files:
file = cfg_files[inst+1]
# Save to tmpfile in case of stdin input which can only be read once
if file == "/dev/stdin":
file_input = read_json_file(file)
(_, tmpfname) = tempfile.mkstemp(dir="/tmp", suffix="_configReloadStdin")
write_json_file(file_input, tmpfname)
file = tmpfname
else:
if file_format == 'config_db':
if namespace is None:
Expand All @@ -1467,6 +1482,19 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
click.echo("The config file {} doesn't exist".format(file))
continue

if file_format == 'config_db':
file_input = read_json_file(file)

platform = file_input.get("DEVICE_METADATA", {}).\
get("localhost", {}).get("platform")
mac = file_input.get("DEVICE_METADATA", {}).\
get("localhost", {}).get("mac")

if not platform or not mac:
log.log_warning("Input file does't have platform or mac. platform: {}, mac: {}"
.format(None if platform is None else platform, None if mac is None else mac))
load_sysinfo = True

if load_sysinfo:
try:
command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, file)
Expand Down Expand Up @@ -1528,6 +1556,13 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
clicommon.run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, 1)

if os.path.exists(file) and file.endswith("_configReloadStdin"):
# Remove tmpfile
try:
os.remove(file)
except OSError as e:
click.echo("An error occurred while removing the temporary file: {}".format(str(e)), err=True)

# Migrate DB contents to latest version
db_migrator='/usr/local/bin/db_migrator.py'
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
Expand Down Expand Up @@ -4058,28 +4093,12 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load
click.secho("[ERROR] port_dict is None!", fg='red')
raise click.Abort()

""" Special Case: Dont delete those ports where the current mode and speed of the parent port
remains unchanged to limit the traffic impact """

click.secho("\nAfter running Logic to limit the impact", fg="cyan", underline=True)
matched_items = [intf for intf in del_intf_dict if intf in add_intf_dict and del_intf_dict[intf] == add_intf_dict[intf]]

# Remove the interface which remains unchanged from both del_intf_dict and add_intf_dict
for item in matched_items:
del_intf_dict.pop(item)
add_intf_dict.pop(item)

# validate all del_ports before calling breakOutPort
for intf in del_intf_dict.keys():
if not interface_name_is_valid(config_db, intf):
click.secho("[ERROR] Interface name {} is invalid".format(intf))
raise click.Abort()

click.secho("\nFinal list of ports to be deleted : \n {} \nFinal list of ports to be added : \n {}".format(json.dumps(del_intf_dict, indent=4), json.dumps(add_intf_dict, indent=4), fg='green', blink=True))
if not add_intf_dict:
click.secho("[ERROR] add_intf_dict is None or empty! No interfaces are there to be added", fg='red')
raise click.Abort()

port_dict = {}
for intf in add_intf_dict:
if intf in add_ports:
Expand Down Expand Up @@ -6350,7 +6369,7 @@ def disable(ctx):
def polling_int(ctx, interval):
"""Set polling-interval for counter-sampling (0 to disable)"""
if interval not in range(5, 301) and interval != 0:
click.echo("Polling interval must be between 5-300 (0 to disable)")
ctx.fail("Polling interval must be between 5-300 (0 to disable)")

config_db = ctx.obj['db']
sflow_tbl = config_db.get_table('SFLOW')
Expand Down
30 changes: 30 additions & 0 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TAG_LATEST=yes
DETACH=no
LOG_PATH="/var/log/${REBOOT_TYPE}.txt"
UIMAGE_HDR_SIZE=64
REQUIRE_TEAMD_RETRY_COUNT=no

# Require 100M available on the hard drive for warm reboot temp files,
# Size is in 1K blocks:
Expand All @@ -47,6 +48,7 @@ EXIT_DB_INTEGRITY_FAILURE=15
EXIT_NO_CONTROL_PLANE_ASSISTANT=20
EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21
EXIT_PLATFORM_FW_AU_FAILURE=22
EXIT_TEAMD_RETRY_COUNT_FAILURE=23

function error()
{
Expand Down Expand Up @@ -77,6 +79,8 @@ function showHelpAndExit()
echo " - control plane assistant IP list."
echo " -t : Don't tag the current kube images as latest"
echo " -D : detached mode - closing terminal will not cause stopping reboot"
echo " -n : don't require peer devices to be running SONiC with retry count feature [default]"
echo " -N : require peer devices to be running SONiC with retry count feature"

exit "${EXIT_SUCCESS}"
}
Expand Down Expand Up @@ -121,6 +125,12 @@ function parseOptions()
D )
DETACH=yes
;;
n )
REQUIRE_TEAMD_RETRY_COUNT=no
;;
N )
REQUIRE_TEAMD_RETRY_COUNT=yes
;;
esac
done
}
Expand Down Expand Up @@ -605,6 +615,22 @@ init_warm_reboot_states
setup_control_plane_assistant
TEAMD_INCREASE_RETRY_COUNT=0
if [[ "${REBOOT_TYPE}" = "warm-reboot" || "${REBOOT_TYPE}" = "fastfast-reboot" ]]; then
TEAMD_RETRY_COUNT_PROBE_RC=0
/usr/local/bin/teamd_increase_retry_count.py --probe-only || TEAMD_RETRY_COUNT_PROBE_RC=$?
if [[ ${TEAMD_RETRY_COUNT_PROBE_RC} -ne 0 ]]; then
if [[ "${REQUIRE_TEAMD_RETRY_COUNT}" = "yes" ]]; then
error "Could not confirm that all neighbor devices are running SONiC with the retry count feature"
exit "${EXIT_TEAMD_RETRY_COUNT_FAILURE}"
else
debug "Warning: Retry count feature support unknown for one or more neighbor devices; assuming that it's not available"
fi
else
TEAMD_INCREASE_RETRY_COUNT=1
fi
fi
if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" || "$REBOOT_TYPE" = "fast-reboot" ]]; then
# Freeze orchagent for warm restart
# Ask orchagent_restart_check to try freeze 5 times with interval of 2 seconds,
Expand Down Expand Up @@ -633,6 +659,10 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
fi
fi
if [[ ( "${REBOOT_TYPE}" = "warm-reboot" || "${REBOOT_TYPE}" = "fastfast-reboot" ) && "${TEAMD_INCREASE_RETRY_COUNT}" -eq 1 ]]; then
/usr/local/bin/teamd_increase_retry_count.py
fi
# We are fully committed to reboot from this point on because critical
# service will go down and we cannot recover from it.
set +e
Expand Down
Loading

0 comments on commit 6535704

Please sign in to comment.