Skip to content

Commit

Permalink
Add waiter (#350)
Browse files Browse the repository at this point in the history
* Updating botocore

* Adding back in waiter and bumping version
  • Loading branch information
John Tompkins authored and RJ Lohan committed Nov 18, 2019
1 parent 33a7fa4 commit 72c489a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def find_version(*file_paths):
python_requires=">=3.6",
install_requires=[
"boto3>=1.10.20",
"botocore>=1.13.20",
"Jinja2>=2.10",
"jsonschema>=3.0.1",
"pytest==4.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/rpdk/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

__version__ = "0.1"
__version__ = "0.1.1"

logging.getLogger(__name__).addHandler(logging.NullHandler())
33 changes: 32 additions & 1 deletion src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from uuid import uuid4

from botocore.exceptions import ClientError, WaiterError
from botocore.waiter import WaiterModel, create_waiter_with_client
from jinja2 import Environment, PackageLoader, select_autoescape
from jsonschema import Draft6Validator
from jsonschema.exceptions import ValidationError
Expand Down Expand Up @@ -335,7 +336,37 @@ def _upload(

@staticmethod
def _wait_for_registration(cfn_client, registration_token, set_default):
registration_waiter = cfn_client.get_waiter("TypeRegistrationComplete")
# temporarily creating waiter inline
# until the SDK releases and we can use get_waiter
waiter_config = {
"version": 2,
"waiters": {
"TypeRegistrationComplete": {
"delay": 5,
"operation": "DescribeTypeRegistration",
"maxAttempts": 200,
"description": "Wait until type registration is COMPLETE.",
"acceptors": [
{
"argument": "ProgressStatus",
"expected": "COMPLETE",
"matcher": "path",
"state": "success",
},
{
"argument": "ProgressStatus",
"expected": "FAILED",
"matcher": "path",
"state": "failure",
},
],
}
},
}
registration_waiter = create_waiter_with_client(
"TypeRegistrationComplete", WaiterModel(waiter_config), cfn_client
)
# registration_waiter = cfn_client.get_waiter("TypeRegistrationComplete")
try:
LOG.warning(
"Successfully submitted type. "
Expand Down
52 changes: 33 additions & 19 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,19 @@ def test__upload_clienterror(project):

def test__wait_for_registration_set_default(project):
mock_cfn_client = MagicMock(
spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
spec=["describe_type_registration", "set_type_default_version"]
)
mock_cfn_client.describe_type_registration.return_value = (
DESCRIBE_TYPE_COMPLETE_RETURN
)
mock_waiter = MagicMock(spec=["wait"])
mock_cfn_client.get_waiter.return_value = mock_waiter

project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, True)
patch_create_waiter = patch(
"rpdk.core.project.create_waiter_with_client",
autospec=True,
return_value=mock_waiter,
)
with patch_create_waiter:
project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, True)

mock_cfn_client.describe_type_registration.assert_called_once_with(
RegistrationToken=REGISTRATION_TOKEN
Expand All @@ -586,7 +590,7 @@ def test__wait_for_registration_set_default(project):

def test__wait_for_registration_set_default_fails(project):
mock_cfn_client = MagicMock(
spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
spec=["describe_type_registration", "set_type_default_version"]
)
mock_cfn_client.describe_type_registration.return_value = (
DESCRIBE_TYPE_COMPLETE_RETURN
Expand All @@ -595,9 +599,12 @@ def test__wait_for_registration_set_default_fails(project):
BLANK_CLIENT_ERROR, "SetTypeDefaultVersion"
)
mock_waiter = MagicMock(spec=["wait"])
mock_cfn_client.get_waiter.return_value = mock_waiter

with pytest.raises(DownstreamError):
patch_create_waiter = patch(
"rpdk.core.project.create_waiter_with_client",
autospec=True,
return_value=mock_waiter,
)
with patch_create_waiter, pytest.raises(DownstreamError):
project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, True)

mock_cfn_client.describe_type_registration.assert_called_once_with(
Expand All @@ -611,15 +618,19 @@ def test__wait_for_registration_set_default_fails(project):

def test__wait_for_registration_no_set_default(project):
mock_cfn_client = MagicMock(
spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
spec=["describe_type_registration", "set_type_default_version"]
)
mock_cfn_client.describe_type_registration.return_value = (
DESCRIBE_TYPE_COMPLETE_RETURN
)
mock_waiter = MagicMock(spec=["wait"])
mock_cfn_client.get_waiter.return_value = mock_waiter

project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, False)
patch_create_waiter = patch(
"rpdk.core.project.create_waiter_with_client",
autospec=True,
return_value=mock_waiter,
)
with patch_create_waiter:
project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, False)

mock_cfn_client.describe_type_registration.assert_called_once_with(
RegistrationToken=REGISTRATION_TOKEN
Expand All @@ -630,7 +641,7 @@ def test__wait_for_registration_no_set_default(project):

def test__wait_for_registration_waiter_fails(project):
mock_cfn_client = MagicMock(
spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
spec=["describe_type_registration", "set_type_default_version"]
)
mock_cfn_client.describe_type_registration.return_value = (
DESCRIBE_TYPE_FAILED_RETURN
Expand All @@ -641,9 +652,11 @@ def test__wait_for_registration_waiter_fails(project):
"Waiter encountered a terminal failure state",
DESCRIBE_TYPE_FAILED_RETURN,
)
mock_cfn_client.get_waiter.return_value = mock_waiter

with pytest.raises(DownstreamError):
patch_create_waiter = patch(
"rpdk.core.project.create_waiter_with_client", return_value=mock_waiter
)
with patch_create_waiter, pytest.raises(DownstreamError):
project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, True)

mock_cfn_client.describe_type_registration.assert_called_once_with(
Expand All @@ -655,7 +668,7 @@ def test__wait_for_registration_waiter_fails(project):

def test__wait_for_registration_waiter_fails_describe_fails(project):
mock_cfn_client = MagicMock(
spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
spec=["describe_type_registration", "set_type_default_version"]
)
mock_cfn_client.describe_type_registration.side_effect = ClientError(
BLANK_CLIENT_ERROR, "DescribeTypeRegistration"
Expand All @@ -667,9 +680,10 @@ def test__wait_for_registration_waiter_fails_describe_fails(project):
DESCRIBE_TYPE_FAILED_RETURN,
)

mock_cfn_client.get_waiter.return_value = mock_waiter

with pytest.raises(DownstreamError):
patch_create_waiter = patch(
"rpdk.core.project.create_waiter_with_client", return_value=mock_waiter
)
with patch_create_waiter, pytest.raises(DownstreamError):
project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, False)

mock_cfn_client.describe_type_registration.assert_called_once_with(
Expand Down

0 comments on commit 72c489a

Please sign in to comment.