Skip to content

Commit

Permalink
F #115: VM: add acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh committed Dec 2, 2021
1 parent fb7eda6 commit 3e2da26
Showing 1 changed file with 117 additions and 24 deletions.
141 changes: 117 additions & 24 deletions opennebula/resource_opennebula_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,68 +155,91 @@ func TestAccVirtualMachineDiskUpdate(t *testing.T) {
),
},
{
Config: testAccVirtualMachinePersistentDisk,
Config: testAccVirtualMachineVolatileDisk,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "8"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
),
},
{
Config: testAccVirtualMachinePersistentDisk,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdb"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "8"),
),
},
{
Config: testAccVirtualMachinePersistentDiskSizeUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdb"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "16"),
),
},
{
Config: testAccVirtualMachineSwitchNonPersistentDisk,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vdb"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdc"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "16"),
),
},
{
Config: testAccVirtualMachineNonPersistentDiskTargetUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vdc"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdd"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "16"),
),
},
{
Config: testAccVirtualMachineNonPersistentDiskSizeUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vdc"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "32"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdd"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "32"),
),
},
{
Config: testAccVirtualMachineNonPersistentDiskAttachedTwice,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vdc"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "32"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "3"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdd"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "64"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "32"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.2.computed_target", "vde"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.2.computed_size", "64"),
),
},
{
Config: testAccVirtualMachineNonPersistentDiskSizeUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vdc"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "32"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_target", "vda"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.0.computed_size", "16"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_target", "vdd"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.1.computed_size", "32"),
),
},
{
Expand Down Expand Up @@ -726,6 +749,46 @@ resource "opennebula_image" "image1" {
}
`

var testAccVirtualMachineVolatileDisk = testDiskImageResources + `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
}
tags = {
env = "prod"
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
timeout = 5
}
`

var testAccVirtualMachinePersistentDisk = testDiskImageResources + `
resource "opennebula_virtual_machine" "test" {
Expand Down Expand Up @@ -756,9 +819,14 @@ resource "opennebula_virtual_machine" "test" {
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image2.id
target = "vda"
target = "vdb"
}
timeout = 5
Expand Down Expand Up @@ -795,9 +863,14 @@ resource "opennebula_virtual_machine" "test" {
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image2.id
target = "vda"
target = "vdb"
size = "16"
}
Expand Down Expand Up @@ -835,9 +908,14 @@ var testAccVirtualMachineSwitchNonPersistentDisk = testDiskImageResources + `
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image1.id
target = "vdb"
target = "vdc"
}
timeout = 5
Expand Down Expand Up @@ -874,9 +952,14 @@ var testAccVirtualMachineNonPersistentDiskTargetUpdate = testDiskImageResources
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image1.id
target = "vdc"
target = "vdd"
}
timeout = 5
Expand Down Expand Up @@ -913,9 +996,14 @@ var testAccVirtualMachineNonPersistentDiskSizeUpdate = testDiskImageResources +
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image1.id
target = "vdc"
target = "vdd"
size = 32
}
Expand Down Expand Up @@ -953,14 +1041,19 @@ var testAccVirtualMachineNonPersistentDiskAttachedTwice = testDiskImageResources
customer = "test"
}
disk {
volatile_type = "swap"
size = 16
target = "vda"
}
disk {
image_id = opennebula_image.image1.id
target = "vdc"
target = "vdd"
size = 32
}
disk {
image_id = opennebula_image.image1.id
target = "vdd"
target = "vde"
size = 64
}
Expand Down

0 comments on commit 3e2da26

Please sign in to comment.