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

enable dhcp as optional parameter (typelist) #385

Merged
merged 7 commits into from
Sep 3, 2018

Conversation

MalloZup
Copy link
Collaborator

@MalloZup MalloZup commented Aug 30, 2018

This pr contain:

Additionaly to the #288 we have:

  • real testing for real the dhcp parameter via xml property of network
    • we are testing that the xml networkDefinition have dhcp set or not (depending on dhcp nabl/disable)

@MalloZup MalloZup changed the title WIP: dhcp backport enable dhcp as optional parameter (typelist) Aug 30, 2018
@MalloZup MalloZup requested review from dmacvicar and inercia August 30, 2018 18:57
@MalloZup MalloZup changed the title enable dhcp as optional parameter (typelist) WIP: enable dhcp as optional parameter (typelist) Aug 30, 2018
@MalloZup MalloZup force-pushed the dhcp-backport branch 2 times, most recently from 4c7ccfa to 68e90bb Compare August 31, 2018 13:47
@MalloZup MalloZup changed the title WIP: enable dhcp as optional parameter (typelist) enable dhcp as optional parameter (typelist) Aug 31, 2018
@Bischoff
Copy link
Contributor

Bischoff commented Sep 1, 2018

@MalloZup

  1. The doc is not okay: addresses can be used for other things than DHCP, for example for setting an interface to the private network's bridge:
resource "libvirt_network" "private_network" {
  name = "ebi3-private"
  mode = "none"
  addresses = [ "192.168.5.0/24" ]
  dhcp { enabled = "false" }
}

produces:

<network connections='1'>
  <name>ebi3-private</name>
  <uuid>43fec82e-4129-45ac-b262-808cd71b4c44</uuid>
  <bridge name='virbr1' stp='on' delay='0'/>
  <mac address='52:54:00:65:a1:2e'/>
  <ip family='ipv4' address='192.168.5.1' prefix='24'>
  </ip>
</network>

so you get 192.168.5.1 on virbr1, which is nice.

  1. The example above produces a terraform crash.
panic: runtime error: invalid memory address or nil pointer dereference
[DEBUG] plugin.terraform-provider-libvirt: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xc5419c]
[DEBUG] plugin.terraform-provider-libvirt: 
[DEBUG] plugin.terraform-provider-libvirt: goroutine 227 [running]:
[DEBUG] plugin.terraform-provider-libvirt: libvirt.getDomainInterfacesFromNetworks(0x0, 0x0, 0x0, 0x0, 0x101dc98, 0x3, 0x0, 0xc420478af0, 0xe, 0x0, ...)
[DEBUG] plugin.terraform-provider-libvirt: libvirt/domain.go:232 +0x6cc
[DEBUG] plugin.terraform-provider-libvirt: libvirt.domainGetIfacesInfo(0x34c16d0, 0x0, 0x0, 0x0, 0x0, 0x101dc98, 0x3, 0x0, 0xc420478af0, 0xe, ...)
[DEBUG] plugin.terraform-provider-libvirt: libvirt/domain.go:170 +0x1e0
[DEBUG] plugin.terraform-provider-libvirt: libvirt.domainIfaceHasAddress(0x34c16d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc42046c990, ...)

@Bischoff
Copy link
Contributor

Bischoff commented Sep 1, 2018

@MalloZup just pick the fixes to the crash mentioned above from my own PR, it boils down to adding two tests:

I think it will not require much adaptation.

You may also see in my PR for better documentation.

@@ -130,3 +133,96 @@ func TestAccLibvirtNetwork_Import(t *testing.T) {
},
})
}

func TestAccLibvirtNetwork_EnableDhcpAndDisableItAfter(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rename this

Copy link
Contributor

Choose a reason for hiding this comment

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

To whom are you speaking to? 😸

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i just reviewed my code myself 🚀 🤖 was a sidenote 🤣

Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't get angry with your reviewer 😋 . Enjoy your week-end too 🎆 .

@@ -131,28 +147,28 @@ func resourceLibvirtNetworkUpdate(d *schema.ResourceData, meta interface{}) erro
}
network, err := virConn.LookupNetworkByUUIDString(d.Id())
if err != nil {
return err
return fmt.Errorf("Error by retrieving network ID during update: %s", err)
Copy link
Owner

Choose a reason for hiding this comment

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

Here you are not retrieving a network ID, but looking a network by its ID. I would suggest:

fmt.Errorf("Can't retrieve network with UUID '%s' during update: %s", uuid, err)

@@ -81,6 +42,48 @@ func networkExists(n string, network *libvirt.Network) resource.TestCheckFunc {
}
}

func testAccCheckLibvirtNetworkDhcpStatus(name string, network *libvirt.Network, DhcpStatus string) resource.TestCheckFunc {
Copy link
Owner

Choose a reason for hiding this comment

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

Why is DhcpStatus camel-cased? (and wondering... why go format or vet do not complain?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Speaking of this... In the comments, "dhcp" should be "DHCP" 😃

@MalloZup
Copy link
Collaborator Author

MalloZup commented Sep 3, 2018

@Bischoff in reply to your 2nd comment:

This is already here:

https://github.com/dmacvicar/terraform-provider-libvirt/pull/385/files#diff-042e2374df248e4277a3506b065eb28aR458

if the dhcp is not enabled we set it to nil which is equivalent to your suggestion.

For the domain.go yop i added the check 👍 Documentation is also improved/

@dmacvicar it is interesting the golint/go vet didn"t catch the "not formatted" function variable, i think it can be maybe an issue upstream.

Feel free to review and test it. TIA

@Bischoff
Copy link
Contributor

Bischoff commented Sep 3, 2018

@MalloZup ok for the second comment already applied.

For the first comment, I applied it locally, and terraform does not crash anymore.

Doc looks perfect now, thank you.

@inercia inercia merged commit c46f0f8 into dmacvicar:master Sep 3, 2018
@MalloZup MalloZup deleted the dhcp-backport branch September 10, 2018 09:00
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.

4 participants