Skip to content

fix: migrate machine hostname#22207

Merged
jujubot merged 4 commits into
juju:3.6from
adisazhar123:juju-7682-hostname
Apr 14, 2026
Merged

fix: migrate machine hostname#22207
jujubot merged 4 commits into
juju:3.6from
adisazhar123:juju-7682-hostname

Conversation

@adisazhar123
Copy link
Copy Markdown
Member

@adisazhar123 adisazhar123 commented Apr 10, 2026

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

  • 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, with comments saying what you're testing
  • doc.go added or updated in changed packages

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

juju bootstrap localhost 3622-dst --build-agent
juju_36 bootstrap localhost 3621-src

Add model to migrate

juju_36 add-model moveme

Deploy a charm and add a machine

juju_36 deploy ubuntu u1
juju_36 add-machine

Wait until they are stable

# take note of the machine hostname
juju status --format json | jq '.machines | .[] | .hostname'

juju-072e50-0
juju-072e50-1

Migrate to destination

juju migrate moveme 3622-dst
juju switch 3622-dst:admin/moveme

Hostnames not carried over (this is the bug)

juju status --format json | jq '.machines | .[] | .hostname'

3.6.22 to 3.6.22

Outcome: hostname is carried over in migration

Build binary

make go-install

Bootstrap source and destination controllers

juju bootstrap localhost dst --build-agent
juju bootstrap localhost src --build-agent

Add model to migrate

juju add-model moveme

Deploy a charm and add a machine

juju deploy ubuntu u1
juju add-machine

Wait until they are stable

# take note of the machine hostname
juju status --format json | jq '.machines | .[] | .hostname'

"juju-f56121-0"
"juju-f56121-1"

Migrate to destination

juju migrate moveme dst

# should have message "uploading model binaries ..."

Model   Controller    Cloud/Region         Version   SLA          Timestamp       Notes
moveme  hostname-src  localhost/localhost  3.6.21.1  unsupported  14:08:45+07:00  migrating: uploading model binaries into target controller


juju switch dst:admin/moveme

Check hostname are carried over

juju status --format json | jq '.machines | .[] | .hostname'

"juju-f56121-0"
"juju-f56121-1"

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.

juju bootstrap localhost 406-dst --build-agent

Checkout this branch. 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. Migrate to destination

juju migrate moveme 406-dst
juju switch 406-dst:admin/moveme
juju status

Documentation changes

N/A

Links

Issue: Fixes #18641.

Jira card: JUJU-7682

@jujubot jujubot added the 3.6 label Apr 10, 2026
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
Copy link
Copy Markdown
Member

@wallyworld wallyworld left a comment

Choose a reason for hiding this comment

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

Thank you

Copy link
Copy Markdown
Contributor

@CodingCookieRookie CodingCookieRookie left a comment

Choose a reason for hiding this comment

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

LGTM and QA works as expected

@adisazhar123
Copy link
Copy Markdown
Member Author

/merge

@jujubot jujubot merged commit cbbd324 into juju:3.6 Apr 14, 2026
38 of 41 checks passed
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
Comment thread go.mod
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kian99 FYI, tip of 3.6 now uses description v11. Letting you know so that jimm can reflect this when it needs to. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants