Skip to content

Commit

Permalink
1. [Update] existing protection rules test to run on basis of env fla…
Browse files Browse the repository at this point in the history
…g. 2.[Update] Use test_config for uuids in protection rules tests
  • Loading branch information
bhati-pradeep committed May 12, 2022
1 parent 5937089 commit c1f58b4
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 47 deletions.
3 changes: 3 additions & 0 deletions nutanix/data_source_protection_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func dataSourceNutanixProtectionRuleRead(ctx context.Context, d *schema.Resource
if err := d.Set("name", resp.Spec.Name); err != nil {
return diag.FromErr(err)
}
if err := d.Set("description", resp.Spec.Description); err != nil {
return diag.FromErr(err)
}
if err := d.Set("start_time", resp.Spec.Resources.StartTime); err != nil {
return diag.FromErr(err)
}
Expand Down
35 changes: 19 additions & 16 deletions nutanix/data_source_protection_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,53 @@ package nutanix

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNutanixProtectionRuleDataSource_basic(t *testing.T) {
t.Skip()
resourceName := "nutanix_protection_rule.test"
if os.Getenv("PROTECTION_RULES_TEST_FLAG") != "true" {
t.Skip()
}
dataSourceName := "data.nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")
aZUrlSource := "c99ab7cd-9191-4fcb-8fc0-232eff76e595"
uuidSource := "0005b21a-2b28-7bac-699a-ac1f6b6e5556"
aZUrlTarget := "c7926832-4976-4fe4-bead-7e508e03e3ec"
uuidTarget := "0005b5f7-2c60-d181-1c29-ac1f6b6e5435"
aZUUIDSource := testVars.ProtectionPolicy.LocalAz.UUID
clusterUUIDSource := testVars.ProtectionPolicy.LocalAz.ClusterUUID
aZUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID
clusterUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID

nameUpdated := acctest.RandomWithPrefix("test-protection-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-protection-desc-dou")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProtectionRUleDestroy,
CheckDestroy: testAccCheckNutanixProtectionRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccProtectionRuleDataSourceConfig(name, description, aZUrlSource, uuidSource, aZUrlTarget, uuidTarget, 1),
Config: testAccProtectionRuleDataSourceConfig(name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "description", description),
),
},
{
Config: testAccProtectionRuleDataSourceConfig(nameUpdated, descriptionUpdated, aZUrlSource, uuidSource, aZUrlTarget, uuidTarget, 1),
Config: testAccProtectionRuleDataSourceConfig(nameUpdated, descriptionUpdated, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", nameUpdated),
resource.TestCheckResourceAttr(resourceName, "description", descriptionUpdated),
resource.TestCheckResourceAttr(dataSourceName, "name", nameUpdated),
resource.TestCheckResourceAttr(dataSourceName, "description", descriptionUpdated),
),
},
},
})
}

func testAccProtectionRuleDataSourceConfig(name, description, aZUrlSource, clusterUUIDSource, aZUrlTarget, clusterUUIDTarget string, snapshots int64) string {
func testAccProtectionRuleDataSourceConfig(name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget string, snapshots int64) string {
return fmt.Sprintf(`
resource "nutanix_protection_rule" "test" {
name = "%s"
Expand Down Expand Up @@ -84,12 +87,12 @@ func testAccProtectionRuleDataSourceConfig(name, description, aZUrlSource, clust
category_filter {
params {
name = "Environment"
values = ["Dev"]
values = ["Staging"]
}
}
}
data "nutanix_protection_rule" "test" {
protection_rule_id = nutanix_protection_rule.test.id
}
`, name, description, aZUrlSource, clusterUUIDSource, aZUrlTarget, clusterUUIDTarget, snapshots)
`, name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, snapshots)
}
74 changes: 68 additions & 6 deletions nutanix/data_source_protection_rules_test.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,87 @@
package nutanix

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNutanixProtectionRulesDataSource_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
if os.Getenv("PROTECTION_RULES_TEST_FLAG") != "true" {
t.Skip()
}
dataSourceName := "data.nutanix_protection_rules.test"
aZUUIDSource := testVars.ProtectionPolicy.LocalAz.UUID
clusterUUIDSource := testVars.ProtectionPolicy.LocalAz.ClusterUUID
aZUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID
clusterUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccProtectionRulesDataSourceConfig(),
Config: testAccProtectionRulesDataSourceConfig(aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "entities.1.metadata.uuid"),
),
},
},
})
}

func testAccProtectionRulesDataSourceConfig() string {
return `
data "nutanix_protection_rules" "test" {}
`
func testAccProtectionRulesDataSourceConfig(aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget string, snapshots int64) string {
return fmt.Sprintf(`
locals{
category = "AnalyticsExclusions"
keys = ["EfficiencyMeasurement", "AnomalyDetection"]
}
resource "nutanix_protection_rule" "test" {
count = 2
name = "test-rule-${count.index}"
description = "test-rule-desc-${count.index}"
ordered_availability_zone_list{
availability_zone_url = "%s"
cluster_uuid = "%s"
}
ordered_availability_zone_list{
availability_zone_url = "%s"
cluster_uuid = "%s"
}
availability_zone_connectivity_list{
source_availability_zone_index = 0
destination_availability_zone_index = 1
snapshot_schedule_list{
recovery_point_objective_secs = 3600
snapshot_type= "CRASH_CONSISTENT"
local_snapshot_retention_policy {
num_snapshots = %[5]d
}
}
}
availability_zone_connectivity_list{
source_availability_zone_index = 1
destination_availability_zone_index = 0
snapshot_schedule_list{
recovery_point_objective_secs = 3600
snapshot_type= "CRASH_CONSISTENT"
local_snapshot_retention_policy {
num_snapshots = %[5]d
}
}
}
category_filter {
params {
name = local.category
values = [local.keys[(count.index)]]
}
}
}
data "nutanix_protection_rules" "test" {
depends_on = [nutanix_protection_rule.test]
}
`, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, snapshots)
}
11 changes: 11 additions & 0 deletions nutanix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ type TestConfig struct {
Name string `json:"name"`
Values string `json:"values"`
} `json:"ad_rule_target"`
// here UUID = availability_zone_url
ProtectionPolicy struct {
LocalAz struct {
UUID string `json:"uuid"`
ClusterUUID string `json:"cluster_uuid"`
} `json:"local_az"`
DestinationAz struct {
UUID string `json:"uuid"`
ClusterUUID string `json:"cluster_uuid"`
} `json:"destination_az"`
} `json:"protection_policy"`
}

type IPMIConfig struct {
Expand Down
43 changes: 24 additions & 19 deletions nutanix/resource_nutanix_protection_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nutanix

import (
"fmt"
"os"
"strings"
"testing"
"time"
Expand All @@ -13,34 +14,36 @@ import (
)

func TestAccNutanixProtectionRule_basic(t *testing.T) {
t.Skip()
if os.Getenv("PROTECTION_RULES_TEST_FLAG") != "true" {
t.Skip()
}
resourceName := "nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")
aZUrlSource := "c99ab7cd-9191-4fcb-8fc0-232eff76e595"
uuidSource := "4db9adc1-8d13-4585-a901-a3ce1276ecb0"
aZUrlTarget := "45a97947-4b09-4179-8e9b-0c2859020539"
uuidTarget := "40cc9ba1-4c3c-4deb-a04e-a5e33c09d767"
aZUUIDSource := testVars.ProtectionPolicy.LocalAz.UUID
clusterUUIDSource := testVars.ProtectionPolicy.LocalAz.ClusterUUID
aZUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID
clusterUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID

nameUpdated := acctest.RandomWithPrefix("test-protection-name-dou")
descriptionUpdated := acctest.RandomWithPrefix("test-protection-desc-dou")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProtectionRUleDestroy,
CheckDestroy: testAccCheckNutanixProtectionRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixProtectionRuleConfig(name, description, aZUrlSource, uuidSource, aZUrlTarget, uuidTarget, 1),
Config: testAccNutanixProtectionRuleConfig(name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 1),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProtectionRuleExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
),
},
{
Config: testAccNutanixProtectionRuleConfig(nameUpdated, descriptionUpdated, aZUrlSource, uuidSource, aZUrlTarget, uuidTarget, 2),
Config: testAccNutanixProtectionRuleConfig(nameUpdated, descriptionUpdated, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 2),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProtectionRuleExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", nameUpdated),
Expand All @@ -51,24 +54,26 @@ func TestAccNutanixProtectionRule_basic(t *testing.T) {
})
}

func TestAccNutanixProtectionRule_importBasic(t *testing.T) {
t.Skip()
func TestAccResourceNutanixProtectionRule_importBasic(t *testing.T) {
if os.Getenv("PROTECTION_RULES_TEST_FLAG") != "true" {
t.Skip()
}
resourceName := "nutanix_protection_rule.test"

name := acctest.RandomWithPrefix("test-protection-name-dou")
description := acctest.RandomWithPrefix("test-protection-desc-dou")
aZUrlSource := "c99ab7cd-9191-4fcb-8fc0-232eff76e595"
uuidSource := "4db9adc1-8d13-4585-a901-a3ce1276ecb0"
aZUrlTarget := "45a97947-4b09-4179-8e9b-0c2859020539"
uuidTarget := "40cc9ba1-4c3c-4deb-a04e-a5e33c09d767"
aZUUIDSource := testVars.ProtectionPolicy.LocalAz.UUID
clusterUUIDSource := testVars.ProtectionPolicy.LocalAz.ClusterUUID
aZUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID
clusterUUIDTarget := testVars.ProtectionPolicy.DestinationAz.UUID

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProtectionRUleDestroy,
CheckDestroy: testAccCheckNutanixProtectionRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccNutanixProtectionRuleConfig(name, description, aZUrlSource, uuidSource, aZUrlTarget, uuidTarget, 1),
Config: testAccNutanixProtectionRuleConfig(name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, 1),
},
{
ResourceName: resourceName,
Expand Down Expand Up @@ -104,7 +109,7 @@ func testAccCheckNutanixProtectionRuleExists(resourceName *string) resource.Test
}
}

func testAccCheckNutanixProtectionRUleDestroy(s *terraform.State) error {
func testAccCheckNutanixProtectionRuleDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Client)

for _, rs := range s.RootModule().Resources {
Expand All @@ -125,7 +130,7 @@ func testAccCheckNutanixProtectionRUleDestroy(s *terraform.State) error {
return nil
}

func testAccNutanixProtectionRuleConfig(name, description, aZUrlSource, clusterUUIDSource, aZUrlTarget, clusterUUIDTarget string, snapshots int64) string {
func testAccNutanixProtectionRuleConfig(name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget string, snapshots int64) string {
return fmt.Sprintf(`
resource "nutanix_protection_rule" "test" {
name = "%s"
Expand Down Expand Up @@ -168,5 +173,5 @@ func testAccNutanixProtectionRuleConfig(name, description, aZUrlSource, clusterU
}
}
}
`, name, description, aZUrlSource, clusterUUIDSource, aZUrlTarget, clusterUUIDTarget, snapshots)
`, name, description, aZUUIDSource, clusterUUIDSource, aZUUIDTarget, clusterUUIDTarget, snapshots)
}
22 changes: 16 additions & 6 deletions test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,48 @@
"user_group_with_distinguished_name": {
"distinguished_name": "cn=sspadmins,cn=users,dc=qa,dc=nucalm,dc=io",
"display_name": "sspadmins",
"uuid": "a4f29c09-2552-4c01-992f-b96061796c98"
"uuid": "6d2f6c7f-9054-46aa-afab-c715fae06f1b"
},
"permissions": [
{
"name": "",
"uuid": "57f9b783-2a85-4684-b543-1976855027d4"
"uuid": "62e795a1-5c40-4ba7-b51d-fced5cbad6d2"
},
{
"name": "Delete_ACP",
"uuid": "0696cac3-516b-460e-9bc1-d6a5d1b761d3"
"uuid": "c98d099d-43ee-42ce-b76e-136ee8c65b72"
}
],
"users": [
{
"principal_name": "[email protected]",
"expected_display_name": "user4",
"directory_service_uuid": "0791faca-1a48-499e-8171-60801dd41637"
"directory_service_uuid": "0bcc5599-927b-48cb-9e5d-2bd33cfbf709"
},
{
"principal_name": "[email protected]",
"expected_display_name": "user6",
"directory_service_uuid": "0791faca-1a48-499e-8171-60801dd41637"
"directory_service_uuid": "0bcc5599-927b-48cb-9e5d-2bd33cfbf709"
},
{
"principal_name": "[email protected]",
"expected_display_name": "ssptest3",
"directory_service_uuid": "0791faca-1a48-499e-8171-60801dd41637"
"directory_service_uuid": "0bcc5599-927b-48cb-9e5d-2bd33cfbf709"
}
],
"node_os_version": "ntnx-1.0",
"ad_rule_target": {
"name": "ADGroup",
"values": "sspadmins"
},
"protection_policy":{
"local_az":{
"uuid":"a973cd7b-7696-4ca5-b959-04b5bcb9e683",
"cluster_uuid":"0005ded3-2367-7205-3507-ac1f6b60292f"
},
"destination_az":{
"uuid":"97b0cc07-d838-4925-acd7-540c11bd653d",
"cluster_uuid":"0005dc0f-13a7-62e0-185b-ac1f6b6f97e2"
}
}
}

0 comments on commit c1f58b4

Please sign in to comment.