def test_missing_template_body(placeboify):
    m = FakeModule()
    with pytest.raises(
            Exception,
            message='Expected module to fail with no template') as exc_info:
        cfn_module.create_stack(module=m, stack_params={}, cfn=None)
    assert exc_info.match('FAIL')
    assert not m.exit_args
    assert "Either 'template', 'template_body' or 'template_url' is required when the stack does not exist." == m.exit_kwargs[
        'msg']
示例#2
0
def test_invalid_template_json(placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-wrong-json',
        'TemplateBody': bad_json_tpl,
    }
    m = FakeModule(disable_rollback=False)
    with pytest.raises(Exception, message='Malformed JSON should cause the test to fail') as exc_info:
        cfn_module.create_stack(m, params, connection)
    assert exc_info.match('FAIL')
    assert "ValidationError" in m.exit_kwargs['msg']
示例#3
0
def test_missing_template_body(placeboify):
    m = FakeModule()
    with pytest.raises(Exception, message='Expected module to fail with no template') as exc_info:
        cfn_module.create_stack(
            module=m,
            stack_params={},
            cfn=None
        )
    assert exc_info.match('FAIL')
    assert not m.exit_args
    assert "Either 'template' or 'template_url' is required when the stack does not exist." == m.exit_kwargs['msg']
def test_invalid_template_json(placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-wrong-json',
        'TemplateBody': bad_json_tpl,
    }
    m = FakeModule(disable_rollback=False)
    with pytest.raises(Exception) as exc_info:
        cfn_module.create_stack(m, params, connection, default_events_limit)
        pytest.fail('Expected malformed JSON to have caused the call to fail')

    assert exc_info.match('FAIL')
    assert "ValidationError" in m.exit_kwargs['msg']
def test_missing_template_body():
    m = FakeModule()
    with pytest.raises(Exception) as exc_info:
        cfn_module.create_stack(module=m,
                                stack_params={},
                                cfn=None,
                                events_limit=default_events_limit)
        pytest.fail('Expected module to have failed with no template')

    assert exc_info.match('FAIL')
    assert not m.exit_args
    assert "Either 'template', 'template_body' or 'template_url' is required when the stack does not exist." == m.exit_kwargs[
        'msg']
示例#6
0
def test_disable_rollback_and_on_failure_defined():
    m = FakeModule(
        on_create_failure='DELETE',
        disable_rollback=True,
    )
    with pytest.raises(
            Exception,
            message=
            'Expected module to fail with both on_create_failure and disable_rollback defined'
    ) as exc_info:
        cfn_module.create_stack(module=m,
                                stack_params={'TemplateBody': ''},
                                cfn=None,
                                events_limit=default_events_limit)
    assert exc_info.match('FAIL')
    assert not m.exit_args
    assert "You can specify either 'on_create_failure' or 'disable_rollback', but not both." == m.exit_kwargs[
        'msg']
def test_basic_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-basic-yaml',
        'TemplateBody': basic_yaml_tpl
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-basic-yaml')
示例#8
0
def test_basic_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-basic-yaml',
        'TemplateBody': basic_yaml_tpl,
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-basic-yaml')
示例#9
0
def test_client_request_token_s3_stack(maybe_sleep, placeboify):
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-client-request-token-yaml',
        'TemplateBody': basic_yaml_tpl,
        'ClientRequestToken': '3faf3fb5-b289-41fc-b940-44151828f6cf',
    }
    m = FakeModule(disable_rollback=False)
    result = cfn_module.create_stack(m, params, connection, default_events_limit)
    assert result['changed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was CREATE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'CREATE_COMPLETE' in result['events'][0]
    connection.delete_stack(StackName='ansible-test-client-request-token-yaml')
示例#10
0
def test_on_create_failure_delete(maybe_sleep, placeboify):
    m = FakeModule(
        on_create_failure='DELETE',
        disable_rollback=False,
    )
    connection = placeboify.client('cloudformation')
    params = {
        'StackName': 'ansible-test-on-create-failure-delete',
        'TemplateBody': failing_yaml_tpl
    }
    result = cfn_module.create_stack(m, params, connection, default_events_limit)
    assert result['changed']
    assert result['failed']
    assert len(result['events']) > 1
    # require that the final recorded stack state was DELETE_COMPLETE
    # events are retrieved newest-first, so 0 is the latest
    assert 'DELETE_COMPLETE' in result['events'][0]