fix: migrate machine hostname#22207
Merged
Merged
Conversation
5 tasks
jujubot
added a commit
that referenced
this pull request
Apr 10, 2026
#22208 description v12 has a new hostname field in machine struct. It also bumps the machine version from v3 to v4. To allow 3.6 to 4.0.6 migration, we have to add this change so that 4.0.6 knows how to deserialize machine v4. The PR to set hostname in DB will come afterwards. It's important this PR lands first to make migration work. The 3.6 PR is here #22207 ## Checklist <!-- If an item is not applicable, use `~strikethrough~`. --> - [ ] Code style: imports ordered, good names, simple structure, etc - [ ] Comments saying why design decisions were made - [ ] Go unit tests, with comments saying what you're testing - [ ] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing - [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages ## QA steps Unit test ## Documentation changes N/A ## Links <!-- Link to all relevant specification, documentation, bug, issue or JIRA card. --> <!-- Replace #19267 with an issue reference or link, otherwise remove this line. --> **Issue:** Fixes #18641. <!-- Place JIRA number in both places below. --> **Jira card:** [JUJU-7682](https://warthogs.atlassian.net/browse/JUJU-7682) [JUJU-7682]: https://warthogs.atlassian.net/browse/JUJU-7682?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
b3677d3 to
58145a6
Compare
This was referenced Apr 13, 2026
CodingCookieRookie
approved these changes
Apr 14, 2026
Contributor
CodingCookieRookie
left a comment
There was a problem hiding this comment.
LGTM and QA works as expected
Member
Author
|
/merge |
jujubot
added a commit
that referenced
this pull request
Apr 15, 2026
#22217 This PR persists the machine hostname when we import a 3.6 model. Requires #22207 to test as it contains setting the hostname in the description machine struct. ## Checklist - [x] Code style: imports ordered, good names, simple structure, etc - [ ] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing - [ ] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing - [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages ## QA steps #### Test Case 1 - Migrate machine Outcome: migrate from 3.6 to 4.0.6 works. 4.0.6 sets the machine hostname. Checkout this branch. Bootstrap 4.0 controller. ``` juju bootstrap localhost 406-dst --build-agent ``` Checkout #22207. Bootstrap source controller. Add model, deploy charm, add machine. ``` juju bootstrap localhost 3622-src --build-agent juju add-model moveme juju deploy ubuntu u1 juju add-machine ``` Wait to stabilize. ``` # take note of the machine hostname juju status --format json | jq '.machines | .[] | .hostname' "juju-6fe27a-0" "juju-6fe27a-0" ``` Migrate to destination ``` juju migrate moveme 406-dst juju switch 406-dst:admin/moveme ``` ``` Check hostname are carried over juju status --format json | jq '.machines | .[] | .hostname' "juju-6fe27a-0" "juju-6fe27a-0" ``` #### Test Case 2 - Migrate machine hosting a container Outcome: hostnames of host machine and its container are migrated. Unfortunately, an existing bug fails to import the layer link device #22224. Apply this patch as a workaround to verify hostnames are set. It gives us enough time to query the records in DB. ``` diff --git a/domain/network/modelmigration/import_linklayerdevices.go b/domain/network/modelmigration/import_linklayerdevices.go index 01330b6..c789eb04c9 100644 --- a/domain/network/modelmigration/import_linklayerdevices.go +++ b/domain/network/modelmigration/import_linklayerdevices.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "strings" + "time" "github.com/juju/description/v12" @@ -65,6 +66,10 @@ func (i *importOperation) Setup(scope modelmigration.Scope) error { // Execute the import of the link layer devices contained in the model. func (i *importOperation) Execute(ctx context.Context, model description.Model) error { + i.logger.Infof(ctx, "[linklayerimport] sleeping for 3 mins...") + <-time.After(3 prdesc time.Minute) + i.logger.Infof(ctx, "[linklayerimport] woke up from sleep...") + if err := i.importLinkLayerDevices(ctx, model.LinkLayerDevices(), model.IPAddresses()); err != nil { return errors.Capture(err) } ``` Checkout this branch. Bootstrap 4.0 destination controller ``` juju bootstrap localhost 40-dst-new --build-agent ``` Checkout #22207. Bootstrap source controller. Add model and machines. ``` juju bootstrap localhost 36-src-new --debug juju add-model moveme juju add-machine # create container on machine 0 juju add-machine lxd:0 ``` Wait until machines are started... Check machine and container hostname. Note them down ``` juju status --format json \n| jq '.machines[] | (.hostname, .containers[]?.hostname)' "juju-6fe27a-0" "juju-6fe27a-0-lxd-0" ``` Then migrate ``` juju migrate moveme 40-dst-new ``` We have 3 minutes to check the records in DB before the next import operation is run. ``` juju switch 40-dst-new juju ssh -m controller controller/0 repl (controller)> .switch model-move repl (model-move)> select name, hostname from machine name hostname 0 juju-6fe27a-0 0/lxd/0 juju-6fe27a-0-lxd-0 ``` Eventually migration fails with ``` migration model data transfer failed, failed to import model into target controller: execute operation import link layer devices: importing link layer devices: converting device "lxdbr0" on machine "0": converting address "10.136.55.1/24": no subnet found, nor created ``` However, this occurs in link layer devices import ([ref](https://github.com/juju/juju/blob/f3d234040cc8ad825373628d03e0b6d875a8bb28/domain/modelmigration/import.go#L83)) which is executed after machines import. So we know that the machine import was successful. Ideally, if the link layer device import succeeded, you should be able to juju status to see the hostnames set. ## Documentation changes <!-- How it affects user workflow (CLI or API). --> ## Links **Issue:** Fixes #18641. **Jira card:** [JUJU-7682](https://warthogs.atlassian.net/browse/JUJU-7682) [JUJU-7682]: https://warthogs.atlassian.net/browse/JUJU-7682?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
adisazhar123
commented
Apr 15, 2026
| github.com/juju/collections v1.0.4 | ||
| github.com/juju/description/v10 v10.0.0 | ||
| github.com/juju/description/v11 v11.0.1 | ||
| github.com/juju/errors v1.0.0 |
Member
Author
There was a problem hiding this comment.
@kian99 FYI, tip of 3.6 now uses description v11. Letting you know so that jimm can reflect this when it needs to. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Majority of files are churn due to replacing description v10 to v11.
The commits of interest are:
feat: add hostname to import and export
test: assert hostname in import and export
Checklist
QA steps
old 3.6 to 3.6.22
Outcome: migration still works. But you won't see the hostname carried over.
Bootstrap source and destination controllers
juju_36 is v3.6.21
Add model to migrate
Deploy a charm and add a machine
Wait until they are stable
Migrate to destination
Hostnames not carried over (this is the bug)
3.6.22 to 3.6.22
Outcome: hostname is carried over in migration
Build binary
Bootstrap source and destination controllers
Add model to migrate
Deploy a charm and add a machine
Wait until they are stable
Migrate to destination
Check hostname are carried over
3.6.22 to 4.0.6
Outcome: migrate to 4.0.6 works. 4.0.6 knows how to deserialize machine v4 struct. The set hostname on import in 4.0 is not yet implemented. For now we verify the migration isn't rejected.
Checkout tip of 4.0. Bootstrap 4.0 controller.
Checkout this branch. Bootstrap source controller. Add model, deploy charm, add machine.
Wait to stabilize. Migrate to destination
Documentation changes
N/A
Links
Issue: Fixes #18641.
Jira card: JUJU-7682