-
Notifications
You must be signed in to change notification settings - Fork 456
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
Set hostname for dhcp networks #714
Conversation
ee36ca0
to
96bc263
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work. The whole code is needs a lot of refactoring to clean it up, but this is something that should be done later, with a dedicated set or PRs.
Some overall comments/requests:
- Please do not conflate all the changes into a single commit. You're solving different problems with the same PR (which is acceptable), but you should have multiple commits (eg: the fixes about the
network
resource being released twice should be part of a different commit) - I preferred to leave the deallocation of the
network
instances to the caller of thesetNetworkInterfaces
function. Yes, we can build on top of the GC offered by the libvirt library (using theRef()
method), but I would prefer not to do that because 1) I don't know how much we can trust that to work 2) IMHO it makes the code less idiomatic
Thanks a lot for your fixes, I know it has been a hard one 👏
I tend to do this except that in this case, without this change, the refactoring for setting the hostname doesn't work. The test fails. I generally don't like to make commits that don't work. On the other hand, the way the reference to the network is freed depends on the re-organization of the code introduced. I could make a fix for that under the actual code structure, but that change will be completely lost in the second commit. |
thx @flavio and @pablochacin for this. i will have a look to this PR also next week |
To elaborate more on why I'm not so convinced about using the When dealing with resource cleanup a Go developer doesn't have a double garbage collector running like in this case, where we have Go's GC and the one implemented inside of libvirt. When dealing with resources like a database object a Go developer has still to take care of invoking some finalization code before Go's GC takes the object instance out of reach. The developer does that by leveraging the I would prefer to ignore the |
@flavio I gave a try to your proposal and the resulting code is extremely convoluted and hard to maintain because it must ensure it will work on every possible code execution path. It is a lot of changes for something that we expect to solve by refactoring the code. One alternative could be to change the If you disagree with this alternative, then do you want to include this refactoring in the present PR? I would prefer not, but this is the only alternative to introducing multiple Free in the code, I prefer to refactor the code. |
Let's go ahead with the |
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckLibvirtDomainDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Config: config, | ||
ExpectNonEmptyPlan: false, // TODO: find why if set to true, the test fails |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might need to check this before mergin because it could be a code smell of regression.
same also the Destroy
I think we never used in Testacc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I was unable to identify the reason, except that before the plan had the hostname but after the apply, it was empty. Terraform complained about this. I pointed this out in the issue #708 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, not expecting nonempty plans is good:
Expecting errors or non-empty plans:
It is possible for scenarios to exist where a valid configuration (no errors during plan) would result in a non-empty plan after successfully running terraform apply. This is typically due to a valid but otherwise misconfiguration of the resource, and is generally undesirable.
@pablochacin @flavio regarding the Ref or not Ref approach. I'm fine with both approaches, BUT please add some comment on the design. I remember to have looked in the past how we process networks and until you don't dive in actively in the code, you can't understand ( the code is also pretty complicated for good and bad reasons). So if we can have comments explaining how we use the REF and why, this will be appreciate, because I have already forgotten that part of code. 😁 A part of this, I think we might check 2 times the testacc because imho we are modifying them to Thx sofar.. 🌞 |
For dhcp networks, ensure the hostname is set when the ip address is allocated. Unify behavior when network is referenced either by name or by id. Fix bug using network after it was freed Improve test for covering new behavior Signed-off-by: Pablo Chacin <pchacin@suse.com>
96bc263
to
aeec698
Compare
I have updated the PR. I think I've addressed all the concerns except the change in the test, as @MalloZup pointed out. I finally changed the code not to pass a reference to the network in the structure of the pending interface, but the network name. I think this way we delegate to the routine that handles the pending interfaces when to acquire an release the network reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks so much better!
@MalloZup I would be fine approving this PR. What do you think? Also, once merged, how can we tag a new release including this fix? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx!
@flavio ok I will prepare a new tag including this fix. Then we can build the RPM . @dmacvicar is ok for you at this point to do a new release? I think we have a release draft but is more a sketch. I will need to go trough the PR merged and summarize them. Sofar thx lot for helping and contributing. Looking forward 🌻 🎸 |
see https://github.com/dmacvicar/terraform-provider-libvirt/releases/tag/untagged-30bccf4e7c1526ff1438 but is not complete. If you want to help feel free @flavio , otherwise I will do it during the day. @pablochacin @flavio if you want a RPM package from If you wanna right there feel free to ask via obs I will accept. otherwise for the "official" normally the process is to :
|
PR dmacvicar#714 introduced spurious changes in the test configuration for `resource_libvirt_domain_test.go`. The added `Destroy` parameter has no effect and the comment regarding the `ExpectNonEmptyPlan` are outdated. dmacvicar#714 Signed-off-by: Pablo Chacin <pchacin@suse.com>
Thanks a lot, @MalloZup. Not sure what can/should/must do here. |
we need to release a new version. I will make it happen |
For dhcp networks, ensure the hostname is set when the ip address is allocated.
Unify behavior when network is referenced either by name or by id.
Fix bug using network after it was freed
Improve test for covering new behavior
Fixes #708
Please make sure you read the contributor documentation before opening a Pull Request.