Skip to content

sonic/config_generator: align syslog and mgmt_port values with schema#2260

Open
berendt wants to merge 1 commit intomainfrom
fix-sonic-1
Open

sonic/config_generator: align syslog and mgmt_port values with schema#2260
berendt wants to merge 1 commit intomainfrom
fix-sonic-1

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented May 5, 2026

Three values produced by config generation did not match the SONiC schema enforced by the new Pydantic validator:

  • MGMT_PORT.eth0.autoneg in the base config_db.json was "true"; the schema requires "on"|"off".
  • _add_log_server_configuration uppercased the syslog protocol ("UDP"), but the schema requires lowercase "tcp"|"udp".
  • _add_log_server_configuration passed the severity through unchanged, so common syslog aliases like "warning" or "critical" failed against the SONiC-accepted set (none, debug, info, notice, warn, error, crit).

Lowercase the protocol, lowercase and alias-map the severity (warning -> warn, informational -> info, err -> error, critical -> crit), fix the autoneg value in the base config, and update the existing tests to match.

AI-assisted: Claude Code

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="osism/tasks/conductor/sonic/config_generator.py" line_range="2096-2100" />
<code_context>
         proto = device.config_context.get("_segment_log_server_proto", "udp")
         severity = device.config_context.get("_segment_log_server_severity", "info")
         vrf = device.config_context.get("_segment_log_server_vrf", "mgmt")
+        proto = proto.lower()
+        severity = severity.lower()
+        severity = _SYSLOG_SEVERITY_ALIASES.get(severity, severity)
         config["SYSLOG_SERVER"] = {}
         for host in hosts:
</code_context>
<issue_to_address>
**suggestion:** Consider trimming whitespace when normalizing severity to avoid subtle misconfigurations.

Currently, leading/trailing whitespace in values from `config_context` (e.g. `' INFO '`) will prevent matching in `_SYSLOG_SEVERITY_ALIASES` and result in `' info '` being written. Using `severity = severity.strip().lower()` before the alias lookup would make this more tolerant of minor formatting issues in the context data.

```suggestion
        severity = device.config_context.get("_segment_log_server_severity", "info")
        vrf = device.config_context.get("_segment_log_server_vrf", "mgmt")
        proto = proto.lower()
        severity = severity.strip().lower()
        severity = _SYSLOG_SEVERITY_ALIASES.get(severity, severity)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread osism/tasks/conductor/sonic/config_generator.py
Three values produced by config generation did not match the SONiC schema
enforced by the new Pydantic validator:

- MGMT_PORT.eth0.autoneg in the base config_db.json was "true"; the
  schema requires "on"|"off".
- _add_log_server_configuration uppercased the syslog protocol ("UDP"),
  but the schema requires lowercase "tcp"|"udp".
- _add_log_server_configuration passed the severity through unchanged,
  so common syslog aliases like "warning" or "critical" failed against
  the SONiC-accepted set (none, debug, info, notice, warn, error, crit).

Lowercase the protocol, lowercase and alias-map the severity
(warning -> warn, informational -> info, err -> error, critical -> crit),
fix the autoneg value in the base config, and update the existing tests
to match.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt berendt requested a review from osfrickler May 5, 2026 05:23
berendt added a commit that referenced this pull request May 5, 2026
_add_bgp_configurations wrote "admin_status": "true" for every
BGP_NEIGHBOR_AF row it generated: ipv4_unicast, ipv6_unicast and
l2vpn_evpn keys for both interfaces and port channels, plus the
VLAN peer ipv4_unicast row. The schema enforced by the new Pydantic
validator (BgpNeighborAfListRow.admin_status) is Literal["up", "down"],
so validation rejected every generated row with "Input should be 'up'
or 'down'". Same fix pattern as #2260.

Replace the literal "true" with "up" at all seven BGP call sites,
and centralise the schema-allowed values as ADMIN_STATUS_UP /
ADMIN_STATUS_DOWN constants in sonic/constants.py so future drift
fails at import time rather than at validation. Switch the remaining
admin_status producers (MGMT_INTERFACE, INTERFACE incl. breakout
ports, VLAN, VLAN_INTERFACE, LOOPBACK, and the PORTCHANNEL row built
in sonic/interface.py) to the same constants for consistency.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt
Copy link
Copy Markdown
Member Author

berendt commented May 5, 2026

Depends on #2258

"informational": "info",
"warning": "warn",
"err": "error",
"critical": "crit",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why did you omit the other three? at least debug sounds like it could be useful in certain cases

proto = device.config_context.get("_segment_log_server_proto", "udp")
severity = device.config_context.get("_segment_log_server_severity", "info")
vrf = device.config_context.get("_segment_log_server_vrf", "mgmt")
proto = proto.strip().lower()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is uppercase in the generated config, I would prefer to stick to that

"eth0": {
"admin_status": "up",
"autoneg": "true",
"autoneg": "on",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

again, I'd prefer to stick to how the config is generated and amend the scheme if needed

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.

2 participants