Skip to content

Use shutil.move instead of os.rename to move config_db.json on place#66

Open
leenr wants to merge 1 commit intosonic-net:masterfrom
leenr:fix/shutil-move-config_db-instead-of-os-rename
Open

Use shutil.move instead of os.rename to move config_db.json on place#66
leenr wants to merge 1 commit intosonic-net:masterfrom
leenr:fix/shutil-move-config_db-instead-of-os-rename

Conversation

@leenr
Copy link
Copy Markdown

@leenr leenr commented May 22, 2025

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.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented May 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: leenr / name: Vladimir Solomatin (fd57a8c)

@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@leenr
Copy link
Copy Markdown
Author

leenr commented Jun 22, 2025

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 66 in repo sonic-net/sonic-ztp

@leenr
Copy link
Copy Markdown
Author

leenr commented Jun 22, 2025

/azpw run

@mssonicbld
Copy link
Copy Markdown

/AzurePipelines run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bebeisdog
Copy link
Copy Markdown

I also encountered the same issue. I think this solution is good, but I'm not sure why it hasn't been merged yet. You also explained the root cause

@anders-nexthop
Copy link
Copy Markdown

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.

4 participants