diff --git a/setup.py b/setup.py index 5df37bcf..fc0aaee9 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/src/rpdk/core/__init__.py b/src/rpdk/core/__init__.py index 1e5bbc36..e6219d37 100644 --- a/src/rpdk/core/__init__.py +++ b/src/rpdk/core/__init__.py @@ -1,5 +1,5 @@ import logging -__version__ = "0.1" +__version__ = "0.1.1" logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/src/rpdk/core/project.py b/src/rpdk/core/project.py index d85fb544..336bf157 100644 --- a/src/rpdk/core/project.py +++ b/src/rpdk/core/project.py @@ -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 @@ -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. " diff --git a/tests/test_project.py b/tests/test_project.py index e4407f4a..86706862 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -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 @@ -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 @@ -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( @@ -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 @@ -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 @@ -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( @@ -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" @@ -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(