Skip to content

[code sync] Merge code from sonic-net/sonic-utilities:202511 to 202603#297

Merged
mssonicbld merged 3 commits into
Azure:202603from
mssonicbld:sonicbld/202603-merge
Mar 27, 2026
Merged

[code sync] Merge code from sonic-net/sonic-utilities:202511 to 202603#297
mssonicbld merged 3 commits into
Azure:202603from
mssonicbld:sonicbld/202603-merge

Conversation

@mssonicbld

Copy link
Copy Markdown
Collaborator
* b921a54a - (origin/202511) Fix migrate_sonic_packages() crash on symlink resolv.conf (#4380) (2026-03-21) [mssonicbld]
* beeaad66 - fix: skip PORT_INGRESS/EGRESS_MIRROR_CAPABLE check for ERSPAN mirror sessions (#4368) (2026-03-17) [mssonicbld]<br>```

mssonicbld and others added 3 commits March 17, 2026 20:24
…sessions (#4368)

## What I did

Fixed is_port_mirror_capability_supported() so that ERSPAN sessions (direction=None) are not blocked by the PORT_INGRESS_MIRROR_CAPABLE / PORT_EGRESS_MIRROR_CAPABLE capability check.

## Root cause

PR #4089 added a capability check that reads PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE from STATE_DB SWITCH_CAPABILITY|switch. For ERSPAN sessions, direction=None was treated as 'check both', but:
1. These capability flags only apply to SPAN (port mirror) sessions, not ERSPAN (which uses source/destination IPs, not ports)
2. Platforms that don't populate these STATE_DB keys return None, which != 'true', so the function incorrectly returns False (unsupported)

PR #4159 partially addressed the multi-ASIC namespace issue but did not fix the fundamental problem for ERSPAN sessions with no src/dst port specified.

## How I fixed it

- **For ERSPAN (direction=None)**: Return True immediately. PORT_INGRESS/EGRESS_MIRROR_CAPABLE does not apply to ERSPAN sessions.
- **For SPAN (direction != None)**: Treat absent STATE_DB key (None value) as 'supported' for backward compatibility with platforms that don't populate SWITCH_CAPABILITY table entries.

## How to verify it

Unit tests updated in 	ests/config_mirror_session_test.py:
- Added Test 4 to verify behavior when STATE_DB keys are absent (all return True)
- Updated Test 2 and Test 3 assertions for direction=None to expect True

Fixes: sonic-net/sonic-mgmt#21690

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "closes #xxxx",
 "fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
 issue when the PR is merged.

 If you are adding/modifying/removing any command or utility script, please also
 make sure to add/modify/remove any unit tests from the tests
 directory as appropriate.

 If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
 subcommand, or you are adding a new subcommand, please make sure you also
 update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
 your changes.

 Please provide the following information:
-->

#### What I did

Fixed `sonic-installer install` failing during `migrate_sonic_packages()` when `/etc/resolv.conf` in the new image is a symlink to `/run/resolvconf/resolv.conf`.

The failure occurs because the `cp` command at `main.py:386` follows the symlink through the overlay mount. Since the symlink target is an absolute path, it resolves to the **host's** `/run/resolvconf/resolv.conf` — the same file as the source. `cp` detects same source and destination inode and exits with:

```
cp: '/etc/resolv.conf' and '/tmp/image-<version>-fs/etc/resolv.conf' are the same file
```

This was introduced by the `build_debian.sh` change that replaced `touch` with `ln -sf /run/resolvconf/resolv.conf` for `/etc/resolv.conf` in the image filesystem.

#### How I did it

Check whether `/etc/resolv.conf` in the chroot is a symlink or a regular file, and handle each case appropriately:

- **Symlink** (images with `resolvconf` package installed): Read the symlink target via `readlink` (e.g. `/run/resolvconf/resolv.conf`), then create the target file inside the chroot with the host's DNS content. The symlink then resolves correctly inside the chroot. This avoids touching the symlink itself, so the overlay upper dir's `etc/resolv.conf` is never modified and the new image boots with the symlink intact. No cleanup is needed — the target lives under `/run`, which is a tmpfs recreated at every boot.

- **Regular file** (images without `resolvconf`, or where the build process explicitly creates a regular file via `touch`): Overwrite directly with the host's DNS content. No backup/restore is needed — the original file is empty (cleared during build), and after reboot the `resolv-config` service reconfigures DNS from CONFIG_DB.

The previous backup-overwrite-restore pattern has been removed since it is unnecessary in both cases.

#### How to verify it

1. Start with a switch running an image where `/etc/resolv.conf` is a symlink:
 ```bash
 # Confirm symlink exists
 ls -la /etc/resolv.conf
 # Expected: /etc/resolv.conf -> /run/resolvconf/resolv.conf

 # Ensure only one image is installed (clean state)
 sudo sonic-installer list
 # If the target image is already present, remove it:
 sudo sonic-installer remove <target-image> -y
 ```

2. Run `sonic-installer install` with an image that also has the symlink:
 ```bash
 sudo sonic-installer install <image-path> -y
 ```

3. Verify:
 - Installation completes without `cp: ... are the same file` error
 - `sonic-installer list` shows the new image as default
 - After reboot, `/etc/resolv.conf` is still a symlink to `/run/resolvconf/resolv.conf`
 - DNS resolution works

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>

#### Previous command output (if the output of a command-line utility has changed)

#### New command output (if the output of a command-line utility has changed)
@mssonicbld mssonicbld merged commit 8ea9b11 into Azure:202603 Mar 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant