Skip to content

Commit

Permalink
Merge branch 'master' into dhcp_dos_mitigation_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ridahanif96 authored Oct 18, 2024
2 parents 1a69d16 + 244a188 commit 6db15aa
Show file tree
Hide file tree
Showing 135 changed files with 11,167 additions and 2,610 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A convenient alternative is to let the SONiC build system configure a build envi
2. Build the sonic-utilities Python wheel package inside the Bullseye slave container, and tell the build system to keep the container alive when finished
```
make NOSTRETCH=1 NOBUSTER=1 KEEP_SLAVE_ON=yes target/python-wheels/bullseye/sonic_utilities-1.2-py3-none-any.whl
make -f Makefile.work BLDENV=bookworm KEEP_SLAVE_ON=yes target/python-wheels/bookworm/sonic_utilities-1.2-py3-none-any.whl
```
3. When the build finishes, your prompt will change to indicate you are inside the slave container. Change into the `src/sonic-utilities/` directory
Expand All @@ -66,13 +66,20 @@ A convenient alternative is to let the SONiC build system configure a build envi
```
python3 setup.py bdist_wheel
```
Note: This command by default will not update the wheel package in target/. To specify the destination location of wheel package, use "-d" option.
#### To run unit tests
```
python3 setup.py test
```
#### To install the package on a SONiC machine
```
sudo pip uninstall sonic-utilities
sudo pip install YOUR_WHEEL_PACKAGE
```
Note: Don't use "--force-reinstall".
### sonic-utilities-data
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ stages:
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-add-repository https://packages.microsoft.com/debian/11/prod
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
sudo apt-get install -y dotnet-sdk-8.0
displayName: "Install .NET CORE"
- script: |
Expand Down
158 changes: 146 additions & 12 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,38 @@ def watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
@watermark.command('headroom')
def clear_wm_pg_headroom():
def clear_wm_pg_headroom(namespace):
"""Clear user headroom WM for pg"""
command = ['watermarkstat', '-c', '-t', 'pg_headroom']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('shared')
def clear_wm_pg_shared():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_pg_shared(namespace):
"""Clear user shared WM for pg"""
command = ['watermarkstat', '-c', '-t', 'pg_shared']
if namespace:
command += ['-n', str(namespace)]
run_command(command)

@priority_group.group()
Expand All @@ -261,16 +283,38 @@ def persistent_watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@persistent_watermark.command('headroom')
def clear_pwm_pg_headroom():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_pg_headroom(namespace):
"""Clear persistent headroom WM for pg"""
command = ['watermarkstat', '-c', '-p', '-t', 'pg_headroom']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('shared')
def clear_pwm_pg_shared():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_pg_shared(namespace):
"""Clear persistent shared WM for pg"""
command = ['watermarkstat', '-c', '-p', '-t', 'pg_shared']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


Expand All @@ -285,69 +329,159 @@ def watermark():
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@watermark.command('unicast')
def clear_wm_q_uni():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_uni(namespace):
"""Clear user WM for unicast queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_uni']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('multicast')
def clear_wm_q_multi():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_multi(namespace):
"""Clear user WM for multicast queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_multi']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@watermark.command('all')
def clear_wm_q_all():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_wm_q_all(namespace):
"""Clear user WM for all queues"""
command = ['watermarkstat', '-c', '-t', 'q_shared_all']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@queue.group(name='persistent-watermark')
def persistent_watermark():
"""Clear queue persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")


@persistent_watermark.command('unicast')
def clear_pwm_q_uni():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_uni(namespace):
"""Clear persistent WM for persistent queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_uni']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('multicast')
def clear_pwm_q_multi():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_multi(namespace):
"""Clear persistent WM for multicast queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_multi']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@persistent_watermark.command('all')
def clear_pwm_q_all():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def clear_pwm_q_all(namespace):
"""Clear persistent WM for all queues"""
command = ['watermarkstat', '-c', '-p', '-t', 'q_shared_all']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@cli.group(name='headroom-pool')
def headroom_pool():
"""Clear headroom pool WM"""
pass


@headroom_pool.command('watermark')
def watermark():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def watermark(namespace):
"""Clear headroom pool user WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")

command = ['watermarkstat', '-c', '-t', 'headroom_pool']
if namespace:
command += ['-n', str(namespace)]
run_command(command)


@headroom_pool.command('persistent-watermark')
def persistent_watermark():
@click.option('--namespace',
'-n',
'namespace',
default=None,
type=str,
show_default=True,
help='Namespace name or all',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def persistent_watermark(namespace):
"""Clear headroom pool persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
sys.exit("Root privileges are required for this operation")

command = ['watermarkstat', '-c', '-p', '-t', 'headroom_pool']
if namespace:
command += ['-n', str(namespace)]
run_command(command)

#
Expand Down
8 changes: 4 additions & 4 deletions config/chassis_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def fabric_module_set_admin_status(db, chassis_module_name, state):
if state == "down":
for asic in asic_list:
click.echo("Stop swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl stop swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'stop', 'swss@{}.service'.format(asic)])

is_active = subprocess.call(["systemctl", "is-active", "--quiet", "swss@{}.service".format(asic)])

Expand All @@ -89,13 +89,13 @@ def fabric_module_set_admin_status(db, chassis_module_name, state):
# without bring down the hardware
for asic in asic_list:
# To address systemd service restart limit by resetting the count
clicommon.run_command('sudo systemctl reset-failed swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'reset-failed', 'swss@{}.service'.format(asic)])
click.echo("Start swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl start swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'start', 'swss@{}.service'.format(asic)])
elif state == "up":
for asic in asic_list:
click.echo("Start swss@{} and peer services".format(asic))
clicommon.run_command('sudo systemctl start swss@{}.service'.format(asic))
clicommon.run_command(['sudo', 'systemctl', 'start', 'swss@{}.service'.format(asic)])

#
# 'shutdown' subcommand ('config chassis_modules shutdown ...')
Expand Down
Loading

0 comments on commit 6db15aa

Please sign in to comment.