Skip to content

[YANG] Add new attributes in CONSOLE_PORT to support Console Logging feature - #28411

Open
nats-nokia wants to merge 3 commits into
sonic-net:masterfrom
nats-nokia:console_logging
Open

nats-nokia wants to merge 3 commits into
sonic-net:masterfrom
nats-nokia:console_logging

Conversation

@nats-nokia

@nats-nokia nats-nokia commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Why I did it

[YANG] Support logging_enabled, log_file, logrotate_count and logrotate_size attributes in CONSOLE_PORT table to enable/diable console logging feature on SONiC BMC/console switch.

YANG schema added:

  • logging_enabled (default "no")
  • log_file
  • logrotate_size (pattern [0-9]+[kKmMgG]?)
  • logrotate_count (range 1..100)

Sample config:

   "CONSOLE_PORT": {
        "0": {
            "baud_rate": "115200",
            "flow_control": "0",
            "log_file": "/var/log/console-0.log",
            "logging_enabled": "yes",
            "logrotate_count": "10",
            "logrotate_size": "10K",
            "remote_device": "SwitchCpu"
        }
    },

platform/aspeed/aspeed-platform-services/scripts/sonic-switchcpu-console-init.sh is modified to skip deleting CONSOLE_PORT|0 and keeps the previously saved CONSOLE_PORT|0 configuration.

Related PR from other submodules:
sonic-net/sonic-host-services#409
sonic-net/sonic-utilities#4685

Work item tracking
  • Microsoft ADO (number only):

How I did it

Update Yang model for sonic-console and add corresponding unit tests:
- Added logging_enabled attribute in CONSOLE_PORT
- Added test cases for default value verification
- Added test cases for valid configuration
- Added test cases for valid configuration with optional parameters as default
- Added test cases for invalid pattern detection

How to verify it

Verified by manual testing on testbed and unit test.

Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@yxieca

yxieca commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@nats-nokia please check if there is room to improve the unit test coverage?

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@nats-nokia

Copy link
Copy Markdown
Contributor Author

@nats-nokia please check if there is room to improve the unit test coverage?

Hi @yxieca
Thank you for your comments. Addressed your comment by adding more test cases.

Total Test cases summary.

Category Count
Valid 8
Invalid 7
Total logging test cases 15

Valid Test Cases:

Test case Description
CONSOLE_PORT_DEFAULT_LOGGING_ENABLED Verify default logging_enabled value
CONSOLE_PORT_VALID_LOGGING Full valid logging configuration
CONSOLE_PORT_VALID_LOGGING_DEFAULT_LOGROTATE Valid logging without explicit logrotate fields
CONSOLE_PORT_VALID_LOGGING_DEFAULT_ALL Valid logging with minimal config
CONSOLE_PORT_VALID_LOGGING_DISABLED Valid config with logging explicitly disabled
CONSOLE_PORT_VALID_LOGROTATE_SIZE_VARIANTS Valid logrotate_size pattern variants
CONSOLE_PORT_VALID_LOGROTATE_COUNT_BOUNDARY Valid logrotate_count boundary values
CONSOLE_PORT_VALID_LOGGING_WITH_ESCAPE_CHAR Logging combined with escape char

Invalid Test Cases:

Test Case Description Invalid
CONSOLE_PORT_INVALID_LOGGING_ENABLED Invalid logging_enabled value "true"
CONSOLE_PORT_INVALID_LOGGING_ENABLED_FALSE Invalid logging_enabled value "false"
CONSOLE_PORT_INVALID_LOGROTATE_SIZE Invalid logrotate_size value "big"
CONSOLE_PORT_INVALID_LOGROTATE_SIZE_EMPTY Empty logrotate_size ""
CONSOLE_PORT_INVALID_LOGROTATE_SIZE_SUFFIX Unsupported size suffix "10MB"
CONSOLE_PORT_INVALID_LOGROTATE_COUNT Below minimum count "0"
CONSOLE_PORT_INVALID_LOGROTATE_COUNT_HIGH Above maximum count "101"

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@bingwang-ms

Copy link
Copy Markdown
Contributor

@ediwibowo-msft, @judyjoseph Can you please help review?

@bingwang-ms

Copy link
Copy Markdown
Contributor

@yxieca , @judyjoseph Please review the latest code change.

@bingwang-ms

Copy link
Copy Markdown
Contributor

Retriggered PR test

@ediwibowo-msft

Copy link
Copy Markdown

lgtm.

I would suggest another PR should be created to update src/sonic-yang-models/doc/Configuration.md which has a ### Console section with a CONSOLE_PORT JSON sample, but it was not updated with the four new attributes. Please add the new fields (and their defaults/patterns) to that section.

@ediwibowo-msft
ediwibowo-msft self-requested a review September 9, 2026 05:12
ediwibowo-msft
ediwibowo-msft previously approved these changes Sep 9, 2026

@ediwibowo-msft ediwibowo-msft left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Natarajan Subbiramani <natarajan.subbiramani@nokia.com>
Signed-off-by: Natarajan Subbiramani <natarajan.subbiramani@nokia.com>
Signed-off-by: Natarajan Subbiramani <natarajan.subbiramani@nokia.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@judyjoseph

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants