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

libvirt/resource_libvirt_network: Support updates for dns.hosts #469

Merged
merged 1 commit into from
Nov 9, 2018

Conversation

wking
Copy link
Contributor

@wking wking commented Nov 6, 2018

Recreating the nework detaches associated interfaces:

Sometimes, one needs to edit the network definition and apply the changes on the fly. The most common scenario for this is adding new static MAC+IP mappings for the network's DHCP server. If you edit the network with "virsh net-edit", any changes you make won't take effect until the network is destroyed and re-started, which unfortunately will cause a all guests to lose network connectivity with the host until their network interfaces are explicitly re-attached.

With this pull-request, we update the network on dns.hosts changes instead of forcing a new network. This allows DNS host changes without clearing domain network interfaces.

Partially handles #389, #468.

@wking
Copy link
Contributor Author

wking commented Nov 6, 2018

Looks like this needs indexes or some such for deleting an entry where there were previously more than one. As of 5f190c9, that's giving me:

* libvirt_network.tectonic_net: Error updating libvirt network DNS hosts: virError(Code=55, Domain=19, Message='Requested operation is not valid: multiple matching DNS HOST records were found in network wking')

@MalloZup
Copy link
Collaborator

MalloZup commented Nov 6, 2018

@wking thx for pr.

so for testing the update operation in CI the PR you will need to add this:

https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/libvirt/resource_libvirt_cloud_init_test.go#L73

Basically when you add a 2nd step in the terraformACC framework it will tests for updating the resource

https://www.terraform.io/docs/extend/best-practices/testing.html#update-test-verify-configuration-changes

I will have a deeper loook when i have time thx!

@wking
Copy link
Contributor Author

wking commented Nov 6, 2018

I'm working through the review suggestions now. Also related is the libvirt patch I just filed, although I don't think we need to block this PR on that landing.

@MalloZup
Copy link
Collaborator

MalloZup commented Nov 6, 2018

@wking nice one yop

wking added a commit to wking/terraform-provider-libvirt that referenced this pull request Nov 6, 2018
Recreating the nework detaches associated interfaces [1]:

  Sometimes, one needs to edit the network definition and apply the
  changes on the fly.  The most common scenario for this is adding new
  static MAC+IP mappings for the network's DHCP server.  If you edit
  the network with "virsh net-edit", any changes you make won't take
  effect until the network is destroyed and re-started, which
  unfortunately will cause a all guests to lose network connectivity
  with the host until their network interfaces are explicitly
  re-attached.

With this commit, we update the network on dns.hosts changes instead
of forcing a new network.  This allows DNS host changes without
clearing domain network interfaces.

I'm removing stale entries by IP alone, because libvirt allows
multiple IP addresses to share a hostname [2,3].  I have a patch in
flight that may update that logic to make IP matching explicitly the
only consideration [4].

The lowercase error messages break with the existing pattern for at
least some of this package, but they comply with [5]:

  Error strings should not be capitalized (unless beginning with
  proper nouns or acronyms) or end with punctuation, since they are
  usually printed following other context.

Putting the new helpers in their own network.go is Dario's suggestion
[6].

[1]: https://wiki.libvirt.org/page/Networking#Applying_modifications_to_the_network
[2]: https://libvirt.org/formatnetwork.html#elementsAddress
[3]: https://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/network_conf.c;h=39a13b433dbbf91ccb080036df754fdeb3adc905;hb=7a10a6a598ab4e8599c867060a7232a06c663e51#l3336
[4]: https://www.redhat.com/archives/libvir-list/2018-November/msg00231.html
[5]: https://github.com/golang/go/wiki/CodeReviewComments#error-strings
[6]: dmacvicar#469 (comment)
Recreating the nework detaches associated interfaces [1]:

  Sometimes, one needs to edit the network definition and apply the
  changes on the fly.  The most common scenario for this is adding new
  static MAC+IP mappings for the network's DHCP server.  If you edit
  the network with "virsh net-edit", any changes you make won't take
  effect until the network is destroyed and re-started, which
  unfortunately will cause a all guests to lose network connectivity
  with the host until their network interfaces are explicitly
  re-attached.

With this commit, we update the network on dns.hosts changes instead
of forcing a new network.  This allows DNS host changes without
clearing domain network interfaces.

I'm removing stale entries by IP alone, because libvirt allows
multiple IP addresses to share a hostname [2,3].  I have a patch in
flight that may update that logic to make IP matching explicitly the
only consideration [4].

The lowercase error messages break with the existing pattern for at
least some of this package, but they comply with [5]:

  Error strings should not be capitalized (unless beginning with
  proper nouns or acronyms) or end with punctuation, since they are
  usually printed following other context.

Putting the new helpers in their own network.go is Dario's suggestion
[6].

Update unit tests are documented in [7].

[1]: https://wiki.libvirt.org/page/Networking#Applying_modifications_to_the_network
[2]: https://libvirt.org/formatnetwork.html#elementsAddress
[3]: https://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/network_conf.c;h=39a13b433dbbf91ccb080036df754fdeb3adc905;hb=7a10a6a598ab4e8599c867060a7232a06c663e51#l3336
[4]: https://www.redhat.com/archives/libvir-list/2018-November/msg00231.html
[5]: https://github.com/golang/go/wiki/CodeReviewComments#error-strings
[6]: dmacvicar#469 (comment)
[7]: https://www.terraform.io/docs/extend/best-practices/testing.html#update-test-verify-configuration-changes
@wking
Copy link
Contributor Author

wking commented Nov 6, 2018

Ok, I've pushed 5f190c9 -> ef44231, moving the helpers into libvirt/network.go, adding unit tests, and fixing some implementation issues that the unit tests turned up. Test with:

$ TF_ACC=1 LIBVIRT_DEFAULT_URI=qemu:///system go test -v -run TestAccLibvirtNetwork_DNSHosts ./libvirt/
=== RUN   TestAccLibvirtNetwork_DNSHosts
--- PASS: TestAccLibvirtNetwork_DNSHosts (10.44s)
PASS
ok  	github.com/dmacvicar/terraform-provider-libvirt/libvirt	10.457s

@wking
Copy link
Contributor Author

wking commented Nov 6, 2018

I've filed this libvirt bug to track the patch I mentioned earlier.

Copy link
Collaborator

@MalloZup MalloZup left a comment

Choose a reason for hiding this comment

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

looks good
thx

@MalloZup
Copy link
Collaborator

MalloZup commented Nov 7, 2018

@wking we can wait for @dmacvicar when he has time for review

Otherwise i will merge it during the week but looks good thx

@wking
Copy link
Contributor Author

wking commented Nov 9, 2018

Otherwise i will merge it during the week but looks good thx

Let me know if you don't expect to get this landed before the weekend. We're planning on cutting an openshift-installer release and I'll have to adjust the docs to point at my branch until this lands here.

@MalloZup MalloZup merged commit 8a0acba into dmacvicar:master Nov 9, 2018
@MalloZup
Copy link
Collaborator

MalloZup commented Nov 9, 2018

@wking merged, thanks you for your contribution. Enjoy your day 🌞

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.

2 participants