Skip to content

Commit

Permalink
F-558: Add missing paramters in OS section of VM template
Browse files Browse the repository at this point in the history
This commit adds support for missing OS section in VM template.
It aligns the OS section with the Documentation:
https://docs.opennebula.io/6.10/management_and_operations/references/template.html?highlight=firmware#os-and-boot-options-section

A correct fix consist in updating GOCA OSVec structure to reflec the
Documentation
A dedicated issue has bee openned in the Goca Repo:
OpenNebula/one#6782

Closes: F-558
  • Loading branch information
jaypif committed Nov 8, 2024
1 parent 60707b6 commit 7f05741
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 2 deletions.
93 changes: 92 additions & 1 deletion opennebula/resource_opennebula_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,51 @@ func TestAccVirtualMachine(t *testing.T) {
}),
),
},
{
Config: testAccVirtualMachineTemplateConfigOs,
Check: resource.ComposeTestCheckFunc(
testAccSetDSdummy(),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "name", "test-virtual_machine-os"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "permissions", "642"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "memory", "128"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "cpu", "0.1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "context.%", "3"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "context.NETWORK", "YES"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "context.TESTVAR", "TEST"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "graphics.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "graphics.0.keymap", "en-us"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "graphics.0.listen", "0.0.0.0"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "graphics.0.type", "VNC"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.#", "1"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.0.arch", "x86_64"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.0.boot", ""),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.0.machine", "q35"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.0.firmware", ""),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "os.0.firmware_secure", "false"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "disk.#", "0"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "tags.%", "2"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "tags.env", "prod"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "tags.customer", "test"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "description", "VM created for provider acceptance tests"),
resource.TestCheckResourceAttr("opennebula_virtual_machine.test", "timeout", "5"),
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.test", "uid"),
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.test", "gid"),
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.test", "uname"),
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.test", "gname"),
testAccCheckVirtualMachinePermissions(&shared.Permissions{
OwnerU: 1,
OwnerM: 1,
GroupU: 1,
OtherM: 1,
}),
resource.TestCheckTypeSetElemNestedAttrs("opennebula_virtual_machine.test", "template_section.*", map[string]string{
"name": "test_vec_key",
"elements.%": "2",
"elements.testkey1": "testvalue1",
"elements.testkey2": "testvalue2",
}),
),
},
{
Config: testAccVirtualMachineConfigUpdate,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -635,7 +680,7 @@ resource "opennebula_virtual_machine" "test" {
os {
arch = "x86_64"
boot = ""
}
}
tags = {
env = "prod"
Expand All @@ -656,6 +701,52 @@ resource "opennebula_virtual_machine" "test" {
}
`

var testAccVirtualMachineTemplateConfigOs = `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine-os"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
description = "VM created for provider acceptance tests"
context = {
TESTVAR = "TEST"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
machine = "q35"
firmware = ""
firmware_secure = false
}
tags = {
env = "prod"
customer = "test"
}
template_section {
name = "test_vec_key"
elements = {
testkey1 = "testvalue1"
testkey2 = "testvalue2"
}
}
timeout = 5
}
`

var testAccVirtualMachineTemplateConfigCPUModel = `
resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine-renamed"
Expand Down
54 changes: 53 additions & 1 deletion opennebula/shared_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func osSchema() *schema.Schema {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Definition of OS boot and type for the Virtual Machine",
Description: "Definition of OS parameters for the Virtual Machine",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"arch": {
Expand All @@ -425,6 +425,58 @@ func osSchema() *schema.Schema {
Type: schema.TypeString,
Required: true,
},
"machine": {
Type: schema.TypeString,
Optional: true,
},
"kernel": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"os.0.kernel_ds"},
},
"kernel_ds": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"os.0.kernel"},
},
"initrd": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"os.0.initrd_ds"},
},
"initrd_ds": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"os.0.initrd"},
},
"root": {
Type: schema.TypeString,
Optional: true,
},
"kernel_cmd": {
Type: schema.TypeString,
Optional: true,
},
"bootloader": {
Type: schema.TypeString,
Optional: true,
},
"sd_disk_bus": {
Type: schema.TypeString,
Optional: true,
},
"uuid": {
Type: schema.TypeString,
Optional: true,
},
"firmware": {
Type: schema.TypeString,
Optional: true,
},
"firmware_secure": {
Type: schema.TypeBool,
Optional: true,
},
},
},
}
Expand Down

0 comments on commit 7f05741

Please sign in to comment.