Skip to content

Commit

Permalink
Do not return most sweeper errors (#3315)
Browse files Browse the repository at this point in the history
* Do not return sql database instance sweeper errors

* Fix some other sweepers

* Fix typo
  • Loading branch information
c2thorn authored Mar 27, 2020
1 parent 7b67854 commit a1cd767
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func testSweepAccessContextManagerPolicies(region string) error {

resp, err := sendRequest(config, "GET", "", listUrl, nil)
if err != nil && !isGoogleApiErrorWithCode(err, 404) {
return fmt.Errorf("unable to list AccessPolicies for organization %q: %v", testOrg, err)
log.Printf("unable to list AccessPolicies for organization %q: %v", testOrg, err)
return nil
}
var policies []interface{}
if resp != nil {
Expand All @@ -57,15 +58,17 @@ func testSweepAccessContextManagerPolicies(region string) error {
return nil
}
if len(policies) > 1 {
return fmt.Errorf("unexpected - more than one access policies found, change the tests")
log.Printf("unexpected - more than one access policies found, change the tests")
return nil
}

policy := policies[0].(map[string]interface{})
log.Printf("[DEBUG] Deleting test Access Policies %q", policy["name"])

policyUrl := config.AccessContextManagerBasePath + policy["name"].(string)
if _, err := sendRequest(config, "DELETE", "", policyUrl, nil); err != nil && !isGoogleApiErrorWithCode(err, 404) {
return fmt.Errorf("unable to delete access policy %q", policy["name"].(string))
log.Printf("unable to delete access policy %q", policy["name"].(string))
return nil
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ func createZIPArchiveForCloudFunctionSource(t *testing.T, sourcePath string) str
func sweepCloudFunctionSourceZipArchives(_ string) error {
files, err := ioutil.ReadDir(os.TempDir())
if err != nil {
return err
log.Printf("Error reading files: %s",err)
return nil
}
for _, f := range files {
if f.IsDir() {
Expand All @@ -521,7 +522,8 @@ func sweepCloudFunctionSourceZipArchives(_ string) error {
if strings.HasPrefix(f.Name(), testFunctionsSourceArchivePrefix) {
filepath := fmt.Sprintf("%s/%s", os.TempDir(), f.Name())
if err := os.Remove(filepath); err != nil {
return err
log.Printf("Error removing files: %s",err)
return nil
}
log.Printf("[INFO] cloud functions sweeper removed old file %s", filepath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func testSweepDatabases(region string) error {

found, err := config.clientSqlAdmin.Instances.List(config.Project).Do()
if err != nil {
log.Fatalf("error listing databases: %s", err)
log.Printf("error listing databases: %s", err)
return nil
}

if len(found.Items) == 0 {
Expand Down Expand Up @@ -100,15 +101,17 @@ func testSweepDatabases(region string) error {
op, err := config.clientSqlAdmin.Instances.StopReplica(config.Project, replicaName).Do()

if err != nil {
return fmt.Errorf("error, failed to stop replica instance (%s) for instance (%s): %s", replicaName, d.Name, err)
log.Printf("error, failed to stop replica instance (%s) for instance (%s): %s", replicaName, d.Name, err)
return nil
}

err = sqlAdminOperationWait(config, op, config.Project, "Stop Replica")
if err != nil {
if strings.Contains(err.Error(), "does not exist") {
log.Printf("Replication operation not found")
} else {
return err
log.Printf("Error waiting for sqlAdmin operation: %s", err)
return nil
}
}

Expand All @@ -130,7 +133,8 @@ func testSweepDatabases(region string) error {
continue
}

return fmt.Errorf("Error, failed to delete instance %s: %s", db, err)
log.Printf("Error, failed to delete instance %s: %s", db, err)
return nil
}

err = sqlAdminOperationWait(config, op, config.Project, "Delete Instance")
Expand All @@ -139,7 +143,8 @@ func testSweepDatabases(region string) error {
log.Printf("SQL instance not found")
continue
}
return err
log.Printf("Error, failed to delete instance %s: %s", db, err)
return nil
}
}
}
Expand Down

0 comments on commit a1cd767

Please sign in to comment.