Skip to content

Conversation

@Erik142
Copy link

@Erik142 Erik142 commented Apr 10, 2023

This PR improves upon the existing "Wait for IP step", by continuously checking for changes to the IP address for the VM, even after the IP address has been retrieved.

The implementation is using a simple goroutine which encapsulates the existing method used to wait for the IP address. When an IP address has been found, the goroutine will put the IP address directly in the state, which will be queried when the IP address should be retrieved.

A minor customization has been made to the "SSH port forward step", to retrieve the IP address from the state instead of using a string variable.

Closes #61

@sergej-brazdeikis
Copy link

JFYI This Merge Request didn't work for me - same issue

TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: connect: connection refused
TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: i/o timeout
TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: connect: host is down
TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: connect: host is down
TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: connect: host is down
TCP connection to SSH ip/port failed: dial tcp 192.168.178.104:22: i/o timeout

@Erik142
Copy link
Author

Erik142 commented Jun 23, 2023

Thank you for this feedback @sjevs! The PR has worked flawlessly for me. Could you describe in more detail how to reproduce the fault you described? A minimal set of steps to reproduce the issue would be preferable, that way I can start to work on a fix directly. Or if possible, please post the complete Packer HCL file that you are using when this error occurs.

Thanks!

@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from b5fc2d3 to d25dc0f Compare June 23, 2023 07:56
@hoerup
Copy link

hoerup commented Jul 5, 2023

while your'e at it
ip_getter is not a documented option could you add it to docs/builders/iso/xenserver-iso.html.markdown ?

@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from d25dc0f to 01d5455 Compare July 16, 2023 06:47
@Erik142
Copy link
Author

Erik142 commented Jul 16, 2023

@hoerup I could definitely take a look at that. However, I believe that should be a separate issue/pull request, no? If you think it's OK to include it in this PR, I can take care of that!

@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from 01d5455 to b9d8cb6 Compare July 16, 2023 06:51
@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from b9d8cb6 to 2376943 Compare January 18, 2024 07:06
}
}(*c, ui, config)

time.Sleep(500 * time.Millisecond)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the purpose of this time.Sleep?

Copy link
Author

Choose a reason for hiding this comment

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

The purpose of this time.sleep is, as you mentioned in your other comment, a minimum wait time to prevent the Predicate from resolving early. I have replaced the hardcoded value with a configurable one instead.

Comment on lines 83 to 90
Predicate: func() (result bool, err error) {
var ok bool
if ip, ok = state.Get("instance_ssh_address").(string); ok && ip != "" {
return true, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the InterruptibleWait could still return a stale value. I'm wondering if it makes sense to introduce a minimum wait time to prevent the Predicate from resolving early. This would allow end users to further delay resolving the predicate if the default runtime isn't enough time for their DHCP to converge. I think we could account for the existing time.Sleep call above as the default for this value.

In addition to that, it looks like the Timeout is hard coded to 300 seconds for the xva builder (source). We should update to be consistent with the iso version so the maximum can be tuned as well.

Copy link
Author

Choose a reason for hiding this comment

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

Good suggestion! I have added a configurable wait time, named "dhcp_wait" that will be used as an initial wait time before executing the Predicate. I have also, in a separate commit, aligned the XVA builder so that it uses the same self.config.InstallTimeout value as the ISO builder. However, I could not successfully update "config.hcl2spec.go" by executing make generate. I got an error that I have not (yet) been able to understand. If you haven't seen it before, I'll spend some time to figure it out, as I assume that I have to include the changes made by make generate in this PR? The error I get is the following:

mapstructure-to-hcl2: common.[Config]: internal error: package "fmt" without types was imported from "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common"
builder/xenserver/common/config.go:1: running "packer-sdc": exit status 1
make: *** [generate] Error 1

@ddelnano
Copy link
Collaborator

ddelnano commented Feb 8, 2024

@Erik142 sorry for the delay. The overall idea sounds good to me. I have a few questions about hardening a bit to make sure if there is still a race with DHCP converging, that it can be tuned appropriately.

@Erik142
Copy link
Author

Erik142 commented Nov 23, 2024

Hi @ddelnano, apologies for the delay on my side as well. I've been having quite a lot to tend to personally for a while. I have answered and addressed your comments. I have one question regarding make generate which I hope you will be able to answer for me! Other than that, please have another look at this PR. If there is anything else you want me to change, just let me know!

@enkaskal
Copy link

ran into this issue as well, fetched @Erik142's branch, rebased to current master and it solved my issue as well.

N.B. I did have to install guest-utilities as part of the d-i preseed in order for it to work; although I believe that is intended based on the original code.

while my testing was done go build -o ... and packer plugins install --path ... I did notice that the make generate error happens on master identical to the branch so not sure this should be a blocker.

@ddelnano if that's the case, what if any hold ups are remaining on this PR?

@nathanael-h
Copy link
Member

Hey @enkaskal thanks for your message. I'll try to reboot and merge this old PR.

N.B. I did have to install guest-utilities as part of the d-i preseed in order for it to work; although I believe that is intended based on the original code.

Indeed, the VM IP information goes like this: VM --> Guest Agent (old or new rust ones) --> XCP-ng --> Packer. So without agent at some point the IP cannot be retrieved.

while my testing was done go build -o ... and packer plugins install --path ... I did notice that the make generate error happens on master identical to the branch so not sure this should be a blocker.

Let's fix this in another PR

@ddelnano if that's the case, what if any hold ups are remaining on this PR?

Time 😅

@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from b8d6908 to 2bca591 Compare September 18, 2025 17:41
@Erik142
Copy link
Author

Erik142 commented Sep 18, 2025

Hi @enkaskal, @nathanael-h!

Thanks for reviving this PR. I have rebased my branch onto the latest main. Let me know if anything else is required from my side!

@nathanael-h
Copy link
Member

Oh very nice from you @Erik142 !! Thanks, @gCyrille or I will review this next week I think.

This commit improves upon the existing "Wait for IP step", by
continuously checking for changes to the IP address for the VM, even
after the IP address has been retrieved.

The implementation is using a simple goroutine which encapsulates the
existing method used to wait for the IP address. When an IP address has
been found, the goroutine will put the IP address directly in the state,
which will be queried when the IP address should be retrieved. The
goroutine will check for IP address changes every 500ms.

Finally, a configurable initial delay has been added, with the intention
of waiting for the initial IP address to be retrieved via DHCP. This
configuration item is called "dhcp_wait", inspired by the already
existing "boot_wait".
This commit aligns the timeout value in StepWaitForIP so that the ISO
and XVA builder use the value coming from the configuration, instead of
hardcoding a value for the XVA builder.
@Erik142 Erik142 force-pushed the 61-support-ip-address-changes branch from 2bca591 to ba91910 Compare September 27, 2025 13:48
@Erik142 Erik142 requested a review from gCyrille September 27, 2025 13:49
@nathanael-h
Copy link
Member

Thanks, I'll try to fix the code generation first and then merge this PR. (As this PR adds a config field, it would be better to do things like this). Work is in progress on my laptop 😅

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.

Support changes of IP address on reboot of VM

7 participants