Skip to content

Commit

Permalink
Implement test that verifies migrating from wait_for_ip to expected_c…
Browse files Browse the repository at this point in the history
…idr_range works as expected

Signed-off-by: Dom Del Nano <[email protected]>
  • Loading branch information
ddelnano committed Mar 19, 2024
1 parent 13f1b84 commit 4bfebc7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 3 additions & 3 deletions xoa/resource_xenorchestra_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/vatesfr/terraform-provider-xenorchestra/client"
"github.com/vatesfr/terraform-provider-xenorchestra/xoa/internal"
"github.com/vatesfr/terraform-provider-xenorchestra/xoa/internal/state"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

var validVga = []string{
Expand Down Expand Up @@ -530,7 +530,7 @@ func resourceVmCreate(d *schema.ResourceData, m interface{}) error {

if installMethod := d.Get("installation_method").(string); installMethod != "" {
installation = client.Installation{
Method: "network",
Method: "network",
Repository: "pxe",
}
}
Expand Down
43 changes: 42 additions & 1 deletion xoa/resource_xenorchestra_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/vatesfr/terraform-provider-xenorchestra/client"
"github.com/vatesfr/terraform-provider-xenorchestra/xoa/internal"
Expand Down Expand Up @@ -1847,6 +1848,46 @@ func TestAccXenorchestraVm_createWithV0StateMigration(t *testing.T) {
})
}

func TestAccXenorchestraVm_createWithV1StateMigration(t *testing.T) {
resourceName := "xenorchestra_vm.bar"
vmName := fmt.Sprintf("%s - %s", accTestPrefix, t.Name())
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: testAccCheckXenorchestraVmDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"xenorchestra": {
Source: "vatesfr/xenorchestra",
VersionConstraint: "0.28.1",
},
},
Config: state.V1TestAccVmConfigWithWaitForIp(accTestPrefix, vmName, testTemplate.NameLabel, accDefaultNetwork.NameLabel, accTestPool.Id, accDefaultSr.Id),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVmExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckNoResourceAttr(resourceName, "network.0.expected_ip_cidr"),
resource.TestCheckResourceAttr(resourceName, "wait_for_ip", "true"),
),
},
{
ProviderFactories: map[string]func() (*schema.Provider, error){
"xenorchestra": func() (*schema.Provider, error) {
return Provider(), nil
},
},
Config: testAccVmConfigWithWaitForIp(vmName, "0.0.0.0/0"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVmExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "network.0.expected_ip_cidr", "0.0.0.0/0"),
resource.TestCheckNoResourceAttr(resourceName, "wait_for_ip"),
),
},
},
})
}

func testAccVmExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -2067,7 +2108,7 @@ resource "xenorchestra_vm" "bar" {
}

func testAccVmConfig(vmName string) string {
return testAccVmConfigWithWaitForIp(vmName, "false")
return testAccVmConfigWithWaitForIp(vmName, "0.0.0.0/0")
}

func testAccVmConfigWithWaitForIp(vmName, expectedIpCidr string) string {
Expand Down

0 comments on commit 4bfebc7

Please sign in to comment.