-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1095 from uc-cdis/feat/more-backoffs
feat(backoff): Add backoff to give_service_account_billing_access
- Loading branch information
Showing
5 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,4 @@ tests/resources/keys/*.pem | |
|
||
.DS_Store | ||
.vscode | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from unittest.mock import patch, MagicMock | ||
|
||
import pytest | ||
|
||
from fence.resources.google.utils import ( | ||
give_service_account_billing_access_if_necessary, | ||
GoogleCloudManager, | ||
) | ||
from fence.utils import DEFAULT_BACKOFF_SETTINGS | ||
|
||
|
||
def test_give_service_account_billing_access_if_necessary_fails(cloud_manager): | ||
""" | ||
Tests that the GCM give_service_account_billing_access backs off the right number of times when | ||
give_service_account_billing_access_if_necessary calls it. | ||
""" | ||
|
||
sa_private_key = {"client_email": "paying_requestor@somewhere.com"} | ||
r_pays_project = "some_project_id" | ||
|
||
# Grab the GCM instance from the with block in _give_service_account_billing_access | ||
cloud_manager_instance = cloud_manager.return_value.__enter__.return_value | ||
# Set the GCM method to raise an exception. | ||
cloud_manager_instance.give_service_account_billing_access.side_effect = Exception( | ||
"Something's wrong" | ||
) | ||
|
||
with pytest.raises(Exception): | ||
give_service_account_billing_access_if_necessary(sa_private_key, r_pays_project) | ||
|
||
assert ( | ||
cloud_manager_instance.give_service_account_billing_access.call_count | ||
== DEFAULT_BACKOFF_SETTINGS["max_tries"] | ||
) |