Skip to content

[action] [PR:66] Use shutil.move instead of os.rename to move config_db.json on place#76

Merged
mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/66
Apr 15, 2026
Merged

[action] [PR:66] Use shutil.move instead of os.rename to move config_db.json on place#76
mssonicbld merged 1 commit intosonic-net:202511from
mssonicbld:cherry/202511/66

Conversation

@mssonicbld
Copy link
Copy Markdown

What I did
I replaced os.rename call with shutil.move.
Also, I reordered imports to be in alphabetical order (cosmetic change).

Why I did it
After sonic-net/sonic-buildimage#20640, SONiC systems mount /tmp as separate tmpfs mount.

SONiC ZTP scripts currently prepares config_dl.json file in /tmp folder and then tries to rename file to /etc/sonic/config_db.json. Earlier there was no issue with that, as /tmp and /etc/sonic was residing on the same mount, on the same device. Now (sonic-buildimage master, and 202505 branch - sonic-net/sonic-buildimage@fbd9252), os.rename raises a OSError: [Errno 18] Invalid cross-device link: '/tmp/config_dl.json' -> '/etc/sonic/config_db.json' exception.

Such behaviour of os.rename is documented:

The operation may fail on some Unix flavors if src and dst are on different filesystems.

I replaced os.rename call with shutil.move (docs) one, which should either use os.rename if such operation is possible, or fall back into "manual" course of actions: first copy the file onto new place, then remove the source file.

I suspect this change will also solve #54, but I'm not entirely sure that the cause was the similar one there.

Signed-off-by: Sonic Build Admin [email protected]

…place

**What I did**
I replaced `os.rename` call with `shutil.move`.
Also, I reordered imports to be in alphabetical order (cosmetic change).

**Why I did it**
After sonic-net/sonic-buildimage#20640, SONiC systems mount `/tmp` as separate _tmpfs_ mount.

SONiC ZTP scripts currently prepares `config_dl.json` file in `/tmp` folder and then tries to **rename** file to `/etc/sonic/config_db.json`. Earlier there was no issue with that, as `/tmp` and `/etc/sonic` was residing on the same mount, on the same device. Now (`sonic-buildimage` master, and `202505` branch - sonic-net/sonic-buildimage@fbd9252), `os.rename` raises a `OSError: [Errno 18] Invalid cross-device link: '/tmp/config_dl.json' -> '/etc/sonic/config_db.json'` exception.

Such behaviour of `os.rename` is [documented](https://docs.python.org/3/library/os.html#os.rename):
> The operation may fail on some Unix flavors if _src_ and _dst_ are on different filesystems.

I replaced `os.rename` call with `shutil.move` ([docs](https://docs.python.org/3/library/shutil.html#shutil.move)) one, which should either use `os.rename` if such operation is possible, or fall back into "manual" course of actions: first copy the file onto new place, then remove the source file.

I suspect this change will also solve sonic-net#54, but I'm not entirely sure that the cause was the similar one there.

Signed-off-by: Sonic Build Admin <[email protected]>
@mssonicbld
Copy link
Copy Markdown
Author

Original PR: #66

@mssonicbld
Copy link
Copy Markdown
Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld merged commit 33002f7 into sonic-net:202511 Apr 15, 2026
5 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