Skip to content

Commit

Permalink
B #423: add test case reproducing the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh committed Mar 30, 2023
1 parent 3989231 commit fbaccb4
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions opennebula/resource_opennebula_virtual_machine_nic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,38 @@ func TestAccVirtualMachineTemplateNIC(t *testing.T) {
})
}

// reproduce #423 problem: index out of range when reordering the list of NICs to attach
func TestAccVirtualMachineAddNIC(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccVirtualMachineOneNIC,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "nic.#", "1"),
),
},
{
Config: testAccVirtualMachineTwoNICs,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "nic.#", "2"),
),
},
{
Config: testAccVirtualMachineNoNics,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "nic.#", "0"),
),
},
},
})
}

var testNICVNetResources = `
resource "opennebula_security_group" "mysecgroup" {
Expand Down Expand Up @@ -582,3 +614,59 @@ resource "opennebula_virtual_machine" "test" {
timeout = 5
}
`

var testAccVirtualMachineOneNIC = testNICVNetResources + `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine"
cpu = 1
vcpu = 2
memory = 128
context = {
SET_HOSTNAME = "$NAME"
NETWORK = "YES"
}
nic {
model = "virtio"
network_id = opennebula_virtual_network.network1.id
}
}
`

var testAccVirtualMachineTwoNICs = testNICVNetResources + `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine"
cpu = 1
vcpu = 2
memory = 128
context = {
SET_HOSTNAME = "$NAME"
NETWORK = "YES"
}
nic {
model = "virtio"
network_id = opennebula_virtual_network.network1.id
}
nic {
model = "virtio"
network_id = opennebula_virtual_network.network2.id
}
}
`

var testAccVirtualMachineNoNics = testNICVNetResources + `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine"
cpu = 1
vcpu = 2
memory = 128
context = {
SET_HOSTNAME = "$NAME"
NETWORK = "YES"
}
}
`

0 comments on commit fbaccb4

Please sign in to comment.