Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lxd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,12 @@ func instancesPost(d *Daemon, r *http.Request) response.Response {

req.Type = api.InstanceType(sourceInst.Type.String())

// Use source instance's architecture.
req.Architecture, err = osarch.ArchitectureName(sourceInst.Architecture)
if err != nil {
return err
}

// Use source instance's profiles if no profile override.
if req.Profiles == nil {
sourceInstArgs, err := tx.InstancesToInstanceArgs(ctx, true, *sourceInst)
Expand Down
5 changes: 5 additions & 0 deletions test/suites/container_copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ test_container_copy_start() {
lxc copy c1 c2
[ "$(lxc list -f csv -c s c2)" = "STOPPED" ]

sub_test "Copied container inherits the source architecture"
source_arch="$(lxc query /1.0/instances/c1 | jq --raw-output '.architecture')"
target_arch="$(lxc query /1.0/instances/c2 | jq --raw-output '.architecture')"
Comment on lines +135 to +136
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

The jq extraction uses --raw-output on .architecture, which will yield the literal string "null" if the field is missing; comparing two "null" strings would incorrectly pass. Consider using jq -er '.architecture' (and/or explicitly asserting it is non-empty) and declare source_arch/target_arch as local to match the rest of the function’s scoping style.

Suggested change
source_arch="$(lxc query /1.0/instances/c1 | jq --raw-output '.architecture')"
target_arch="$(lxc query /1.0/instances/c2 | jq --raw-output '.architecture')"
local source_arch
local target_arch
source_arch="$(lxc query /1.0/instances/c1 | jq -er '.architecture')"
target_arch="$(lxc query /1.0/instances/c2 | jq -er '.architecture')"

Copilot uses AI. Check for mistakes.
[ "${source_arch}" = "${target_arch}" ]
Comment on lines +134 to +137
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This new sub-test does not actually exercise the reported API behavior (copy request without an Architecture field). lxc copy (CLI) fetches the source instance and calls CopyInstance, which sends InstancePut including the source architecture, so this test would still pass even before the server-side fix. To validate the fix, perform the copy using a raw API request (e.g. lxc query --request POST /1.0/instances -d ...) that omits architecture (and ideally omits type too), and assert the operation succeeds and the target instance is created with the source architecture.

Copilot uses AI. Check for mistakes.

lxc delete -f c2

echo "==> Check that a container can be copied and started with the same command"
Expand Down
Loading