Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sweeper): add sweeper base function #1959

Closed
wants to merge 2 commits into from

Conversation

hmbig2
Copy link
Collaborator

@hmbig2 hmbig2 commented Feb 15, 2022

What this PR does / why we need it:

  1. add sweeper base function
  2. add vpc sweeper

Which issue this PR fixes:
(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged)
fixes #1951

Special notes for your reviewer:

Release note:


PR Checklist

  • Tests added/passed.
  • Documentation updated.
  • Schema updated.

Acceptance Steps Performed

go test ./huaweicloud/services/acceptance/sweep -v  -sweep=cn-north-4 -sweep-run=huaweicloud_vpc  -sweep-allow-failures=true
2022/02/15 11:23:55 [DEBUG] Completed Sweeper (huaweicloud_vpc_subnet) in region (cn-north-4) in 454.1145ms
2022/02/15 11:23:55 [DEBUG] Running Sweeper (huaweicloud_vpc) in region (cn-north-4)
2022/02/15 11:23:55 [DEBUG] Completed Sweeper (huaweicloud_vpc) in region (cn-north-4) in 5.9µs
2022/02/15 11:23:55 [DEBUG] Sweeper (huaweicloud_vpc_subnet) already ran in region (cn-north-4)
2022/02/15 11:23:55 Completed Sweepers for region (cn-north-4) in 454.2272ms
2022/02/15 11:23:55 Sweeper Tests for region (cn-north-4) ran successfully:
        - huaweicloud_vpc_subnet
        - huaweicloud_vpc
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/sweep     2.939s

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with fmt and log


err := initProviderConfig()
if err != nil {
logp.Printf("[ERROR]Error init huaweicloud provider config: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with log

config := acceptance.TestAccProvider.Meta().(*config.Config)
rmsClient, err := config.RmsV1Client(region)
if err != nil {
logp.Printf("Error creating RMS client: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

pages, err := resources.List(rmsClient, resources.ListOpts{Region: region}).AllPages()

if err != nil {
logp.Printf("Unable to retrieve all resources in the region %s:%s ", region, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


allResources, err := resources.ExtractResources(pages)
if err != nil {
logp.Printf("Unable to retrieve all resources in the region %s:%s ", region, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

SweepResourcesList["unKnow_resources"] = append(b, v)
}
}
logp.Printf("[WARN]%d resource is not in sweeper, please check: %s ", len(SweepResourcesList),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

raw := make(map[string]interface{})
diags := testProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(raw))
if diags.HasError() {
return fmtp.Errorf("Unexpected error when configure HuaweiCloud provider: %s", diags[0].Summary)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with fmt

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/sweep"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/vpc"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

config := acceptance.TestAccProvider.Meta().(*config.Config)
client, err := config.NetworkingV1Client(region)
if err != nil {
return fmtp.Errorf("Error creating huaweicloud vpc client: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@hmbig2 hmbig2 closed this May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sweep] init the common sweeper
2 participants