Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IP address changes #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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
Owner

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 89
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
Owner

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
Owner

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.

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 2376943 to b8d6908 Compare November 23, 2024 18:38
@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!

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
4 participants