Skip to content

Commit

Permalink
fix(rms): fix the failing test cases in RMS
Browse files Browse the repository at this point in the history
  • Loading branch information
profoundwu committed Jan 9, 2025
1 parent 41dba37 commit a76cd43
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 77 deletions.
16 changes: 12 additions & 4 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ var (
HW_RAM_SHARE_INVITATION_ID = os.Getenv("HW_RAM_SHARE_INVITATION_ID")
HW_RAM_SHARE_ID = os.Getenv("HW_RAM_SHARE_ID")

HW_RMS_TARGET_ID_FOR_FGS = os.Getenv("HW_RMS_TARGET_ID_FOR_FGS")
HW_RMS_TARGET_ID_FOR_RFS = os.Getenv("HW_RMS_TARGET_ID_FOR_RFS")
HW_RMS_EXCLUDED_ACCOUNT_1 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_1")
HW_RMS_EXCLUDED_ACCOUNT_2 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_2")
HW_RMS_TARGET_ID_FOR_FGS = os.Getenv("HW_RMS_TARGET_ID_FOR_FGS")
HW_RMS_TARGET_ID_FOR_RFS = os.Getenv("HW_RMS_TARGET_ID_FOR_RFS")
HW_RMS_EXCLUDED_ACCOUNT_1 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_1")
HW_RMS_EXCLUDED_ACCOUNT_2 = os.Getenv("HW_RMS_EXCLUDED_ACCOUNT_2")
HW_RMS_RESOURCE_RECORDER_CLOSED = os.Getenv("HW_RMS_RESOURCE_RECORDER_CLOSED")

HW_CDN_DOMAIN_NAME = os.Getenv("HW_CDN_DOMAIN_NAME")
// `HW_CDN_CERT_DOMAIN_NAME` Configure the domain name environment variable of the certificate type.
Expand Down Expand Up @@ -1155,6 +1156,13 @@ func TestAccPreCheckRMSExcludedAccounts(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckRMSResourceRecorder(t *testing.T) {
if HW_RMS_RESOURCE_RECORDER_CLOSED == "" {
t.Skip("HW_RMS_RESOURCE_RECORDER_CLOSED must be set for the acceptance tests.")
}
}

// lintignore:AT003
func TestAccPreCheckDms(t *testing.T) {
if HW_DMS_ENVIRONMENT == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAccDataSourceRmsOrganizationalAssignmentPackages_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckOrganizationsOpen(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ func TestAccDataSourceAggregatorAdvancedQuery_basic(t *testing.T) {
acceptance.TestAccPrecheckDomainId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"null": {
Source: "hashicorp/null",
VersionConstraint: "3.2.1",
},
},
Steps: []resource.TestStep{
{
Config: testDataSourceAggregatorAdvancedQuery_basic(rName),
Expand All @@ -46,15 +40,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" {
name = "%[1]s"
type = "ACCOUNT"
account_ids = ["%[2]s"]
}
# wait 30 seconds to let the policies evaluate
resource "null_resource" "test" {
# wait 30 seconds to let the policies evaluate
provisioner "local-exec" {
command = "sleep 30"
}
depends_on = [ huaweicloud_rms_resource_aggregator.test ]
}
`, name, acceptance.HW_DOMAIN_ID)
}
Expand All @@ -66,8 +56,6 @@ func testDataSourceAggregatorAdvancedQuery_basic(name string) string {
data "huaweicloud_rms_resource_aggregator_advanced_query" "test" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
expression = "select name, id from aggregator_resources where provider = 'ecs' and type = 'cloudservers'"
depends_on = [ null_resource.test ]
}
locals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func TestAccDataSourceAggregatorDiscoveredResources_basic(t *testing.T) {
acceptance.TestAccPrecheckDomainId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"null": {
Source: "hashicorp/null",
VersionConstraint: "3.2.1",
},
},
Steps: []resource.TestStep{
{
Config: testDataSourceAggregatorDiscoveredResources_basic(rName),
Expand Down Expand Up @@ -63,15 +57,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" {
account_ids = ["%[2]s"]
depends_on = [huaweicloud_vpc.test]
}
# wait 30 seconds to let the aggregator discover resources
resource "null_resource" "test" {
# wait 30 seconds to let the aggregator discover resources
provisioner "local-exec" {
command = "sleep 30"
}
depends_on = [ huaweicloud_rms_resource_aggregator.test ]
}
`, name, acceptance.HW_DOMAIN_ID)
}
Expand All @@ -82,22 +72,16 @@ func testDataSourceAggregatorDiscoveredResources_basic(name string) string {
data "huaweicloud_rms_resource_aggregator_discovered_resources" "basic" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_service_type" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
service_type = "vpc"
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resource_type" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
resource_type = "vpcs"
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resource_id" {
Expand All @@ -106,8 +90,6 @@ data "huaweicloud_rms_resource_aggregator_discovered_resources" "filter_by_resou
filter {
resource_id = huaweicloud_vpc.test.id
}
depends_on = [ null_resource.test ]
}
locals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ func TestAccDataSourceAggregatorPolicyAssignments_basic(t *testing.T) {
acceptance.TestAccPrecheckDomainId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"null": {
Source: "hashicorp/null",
VersionConstraint: "3.2.1",
},
},
Steps: []resource.TestStep{
{
Config: testDataSourceAggregatorPolicyAssignments_basic(rName),
Expand All @@ -52,15 +46,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" {
name = "%[1]s"
type = "ACCOUNT"
account_ids = ["%[2]s"]
}
# wait 30 seconds to let the policies evaluate
resource "null_resource" "test" {
# wait 30 seconds to let the policies evaluate
provisioner "local-exec" {
command = "sleep 30"
}
depends_on = [ huaweicloud_rms_resource_aggregator.test ]
}
`, name, acceptance.HW_DOMAIN_ID)
}
Expand All @@ -71,8 +61,6 @@ func testDataSourceAggregatorPolicyAssignments_basic(name string) string {
data "huaweicloud_rms_resource_aggregator_policy_assignments" "basic" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_compliance_state" {
Expand All @@ -81,8 +69,6 @@ data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_complia
filter {
compliance_state = "Compliant"
}
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_policy_assignment_name" {
Expand All @@ -91,8 +77,6 @@ data "huaweicloud_rms_resource_aggregator_policy_assignments" "filter_by_policy_
filter {
policy_assignment_name = "iam-password-policy"
}
depends_on = [ null_resource.test ]
}
locals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ func TestAccDataSourceAggregatorPolicyStates_basic(t *testing.T) {
acceptance.TestAccPrecheckDomainId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"null": {
Source: "hashicorp/null",
VersionConstraint: "3.2.1",
},
},
Steps: []resource.TestStep{
{
Config: testDataSourceAggregatorPolicyStates_basic(rName, password),
Expand Down Expand Up @@ -66,15 +60,11 @@ resource "huaweicloud_rms_resource_aggregator" "test" {
account_ids = ["%[3]s"]
depends_on = [huaweicloud_identity_user.test]
}
# wait 30 seconds to let the policies evaluate
resource "null_resource" "test" {
# wait 40 seconds to let the policies evaluate
provisioner "local-exec" {
command = "sleep 30"
command = "sleep 40"
}
depends_on = [ huaweicloud_rms_resource_aggregator.test ]
}
`, name, password, acceptance.HW_DOMAIN_ID)
}
Expand All @@ -85,29 +75,21 @@ func testDataSourceAggregatorPolicyStates_basic(name, password string) string {
data "huaweicloud_rms_resource_aggregator_policy_states" "basic" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_compliance_state" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
compliance_state = "Compliant"
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_policy_assignment_name" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
policy_assignment_name = "iam-password-policy"
depends_on = [ null_resource.test ]
}
data "huaweicloud_rms_resource_aggregator_policy_states" "filter_by_resource_id" {
aggregator_id = huaweicloud_rms_resource_aggregator.test.id
resource_id = huaweicloud_identity_user.test.id
depends_on = [ null_resource.test ]
}
locals {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func TestAccRecorder_basic(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
// Some test cases in RMS require the resource recorder to be enabled.
// Skip this test case during batch execution to ensure other test cases execute smoothly.
acceptance.TestAccPreCheckRMSResourceRecorder(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
Expand All @@ -65,7 +70,7 @@ func TestAccRecorder_basic(t *testing.T) {
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "agency_name", "rms_tracker_agency"),
resource.TestCheckResourceAttr(rName, "selector.0.all_supported", "false"),
resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "5"),
resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "8"),
resource.TestCheckResourceAttrSet(rName, "obs_channel.0.region"),
resource.TestCheckResourceAttrPair(rName, "obs_channel.0.bucket",
"huaweicloud_obs_bucket.test", "bucket"),
Expand Down Expand Up @@ -144,7 +149,11 @@ resource "huaweicloud_rms_resource_recorder" "test" {
selector {
all_supported = false
resource_types = ["vpc.vpcs", "rds.instances", "dms.kafkas", "dms.rabbitmqs", "dms.queues"]
resource_types = [
"vpc.vpcs", "rds.instances", "dms.kafkas", "dms.rabbitmqs", "dms.queues",
"config.trackers", "config.policyAssignments", "config.conformancePacks",
]
}
obs_channel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (w *AssignmentPackagesDSWrapper) listConformancePacksToSchema(body *gjson.R
func(varStr gjson.Result) any {
return map[string]any{
"var_key": varStr.Get("var_key").Value(),
"var_value": varStr.Get("var_value").Value(),
"var_value": utils.JsonToString(varStr.Get("var_value").Value()),
}
},
),
Expand Down

0 comments on commit a76cd43

Please sign in to comment.