Beispiel #1
0
    def test_deploy_stack_wait_failed(self, cfngin_context):
        """Test for deploy_stack with wait and skip."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = 'test-stack'

        with pytest.raises(StackFailed):
            assert hook.deploy_stack(stack=stack, wait=True) == FAILED
Beispiel #2
0
    def test_get_template_description(self, cfngin_context):
        """Test for get_template_description."""
        hook = Hook(cfngin_context, MagicMock())

        result = hook.get_template_description()

        assert result == 'Automatically generated by {}'.format(
            hook.__class__.__module__)
        assert hook.get_template_description('suffix').endswith(' - suffix')
Beispiel #3
0
    def test_get_template_description(
            self, cfngin_context: MockCFNginContext) -> None:
        """Test for get_template_description."""
        hook = Hook(cfngin_context, MagicMock())

        result = hook.get_template_description()

        assert result == "Automatically generated by {}".format(
            hook.__class__.__module__)
        assert hook.get_template_description("suffix").endswith(" - suffix")
Beispiel #4
0
    def test_deploy_stack(self, cfngin_context, caplog):
        """Test for deploy_stack."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = 'test-stack'

        with caplog.at_level(logging.INFO, logger='runway.cfngin.hooks.base'):
            assert hook.deploy_stack(stack=stack, wait=False) == COMPLETE

        assert caplog.records[0].message == '%s: %s' % (stack.name,
                                                        COMPLETE.name)
Beispiel #5
0
    def test_deploy_stack_wait_skipped(self, cfngin_context, caplog):
        """Test for deploy_stack with wait and skip."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = 'test-stack'

        with caplog.at_level(logging.INFO, logger='runway.cfngin.hooks.base'):
            assert hook.deploy_stack(stack=stack, wait=True) == SKIPPED

        assert caplog.records[0].message == '%s: %s' % (stack.name,
                                                        SKIPPED.name)
Beispiel #6
0
    def test_deploy_stack(self, cfngin_context: MockCFNginContext,
                          caplog: LogCaptureFixture) -> None:
        """Test for deploy_stack."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = "test-stack"

        with caplog.at_level(logging.INFO, logger="runway.cfngin.hooks.base"):
            assert hook.deploy_stack(stack=stack, wait=False) == COMPLETE

        assert caplog.records[0].message == "%s:%s" % (stack.name,
                                                       COMPLETE.name)
Beispiel #7
0
    def test_deploy_stack_wait_skipped(self, cfngin_context: MockCFNginContext,
                                       caplog: LogCaptureFixture) -> None:
        """Test for deploy_stack with wait and skip."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = "test-stack"

        with caplog.at_level(logging.INFO, logger="runway.cfngin.hooks.base"):
            assert hook.deploy_stack(stack=stack, wait=True) == SKIPPED

        assert caplog.records[0].message == "%s:%s" % (stack.name,
                                                       SKIPPED.name)
Beispiel #8
0
    def test_deploy_stack_wait(self, cfngin_context, caplog):
        """Test for deploy_stack with wait."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = 'test-stack'

        with caplog.at_level(logging.DEBUG, logger='runway.cfngin.hooks.base'):
            assert hook.deploy_stack(stack=stack, wait=True) == COMPLETE

        assert caplog.records[0].message == '%s: %s' % (stack.name,
                                                        SUBMITTED.name)
        assert caplog.records[1].message == 'Waiting for stack to complete...'
        assert caplog.records[2].message == '%s: %s' % (stack.name,
                                                        COMPLETE.name)
Beispiel #9
0
    def test_deploy_stack_wait(self, cfngin_context: MockCFNginContext,
                               caplog: LogCaptureFixture) -> None:
        """Test for deploy_stack with wait."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = "test-stack"

        with caplog.at_level(logging.DEBUG, logger="runway.cfngin.hooks.base"):
            assert hook.deploy_stack(stack=stack, wait=True) == COMPLETE

        assert caplog.records[0].message == "%s:%s" % (stack.name,
                                                       SUBMITTED.name)
        assert caplog.records[1].message == "waiting for stack to complete..."
        assert caplog.records[2].message == "%s:%s" % (stack.name,
                                                       COMPLETE.name)
Beispiel #10
0
    def test_destroy_stack(self, cfngin_context, caplog):
        """Test for destroy_stack with wait."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock()
        stack.name = "test-stack"

        with caplog.at_level(logging.DEBUG, logger="runway.cfngin.hooks.base"):
            assert hook.destroy_stack(stack=stack, wait=True) == COMPLETE

        assert caplog.records[0].message == "%s:%s" % (stack.name,
                                                       SUBMITTED.name)
        assert caplog.records[1].message == "waiting for stack to complete..."
        assert caplog.records[2].message == "%s:%s (%s)" % (
            stack.name,
            COMPLETE_W_REASON.name,
            COMPLETE_W_REASON.reason,
        )
Beispiel #11
0
    def test_wait_for_stack_till_reason(self, cfngin_context):
        """Test _wait_for_stack till_reason option."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock(fqn='test-stack', name='stack')
        action = MagicMock()
        action.run.side_effect = [
            SUBMITTED,
            SubmittedStatus('not yet'),
            SubmittedStatus('catch'), COMPLETE
        ]

        result = hook._wait_for_stack(
            action,  # pylint: disable=protected-access
            stack=stack,
            till_reason='catch')
        assert result == SUBMITTED
        assert result.reason == 'catch'
Beispiel #12
0
    def test_wait_for_stack_till_reason(self, cfngin_context):
        """Test _wait_for_stack till_reason option."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock(fqn="test-stack", name="stack")
        action = MagicMock()
        action.run.side_effect = [
            SUBMITTED,
            SubmittedStatus("not yet"),
            SubmittedStatus("catch"),
            COMPLETE,
        ]

        result = hook._wait_for_stack(  # pylint: disable=protected-access
            action,
            stack=stack,
            till_reason="catch")
        assert result == SUBMITTED
        assert result.reason == "catch"
Beispiel #13
0
    def test_wait_for_stack_log_change(self, cfngin_context, monkeypatch):
        """Test _wait_for_stack log status change."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock(fqn='test-stack', name='stack')
        new_status = SubmittedStatus('new')
        action = MagicMock()
        action.run.side_effect = [new_status, COMPLETE]
        mock_log = MagicMock()

        monkeypatch.setattr(hook, '_log_stack', mock_log)

        hook._wait_for_stack(
            action,  # pylint: disable=protected-access
            last_status=SubmittedStatus('original'),
            stack=stack,
            till_reason='catch')

        mock_log.assert_has_calls(
            [call(stack, new_status),
             call(stack, COMPLETE)])
        assert mock_log.call_count == 2
Beispiel #14
0
    def test_attributes(self, cfngin_context):
        """Test attributes set during __init__."""
        provider = MagicMock()
        args = {'key': 'val'}
        result = Hook(cfngin_context, provider, **args)

        assert result.args.key == 'val'
        assert result.args.tags == {}
        assert not result.blueprint
        assert result.context == cfngin_context
        assert result.provider == provider
        assert not result.stack
        assert result.stack_name == 'stack'
Beispiel #15
0
    def test_wait_for_stack_log_change(self, cfngin_context: MockCFNginContext,
                                       monkeypatch: MonkeyPatch) -> None:
        """Test _wait_for_stack log status change."""
        hook = Hook(cfngin_context, MagicMock())
        stack = MagicMock(fqn="test-stack", name="stack")
        new_status = SubmittedStatus("new")
        action = MagicMock()
        action.run.side_effect = [new_status, COMPLETE]
        mock_log = MagicMock()

        monkeypatch.setattr(hook, "_log_stack", mock_log)

        hook._wait_for_stack(  # pylint: disable=protected-access
            action,
            last_status=SubmittedStatus("original"),
            stack=stack,
            till_reason="catch",
        )

        mock_log.assert_has_calls(
            [call(stack, new_status),
             call(stack, COMPLETE)])
        assert mock_log.call_count == 2
Beispiel #16
0
    def test_attributes(self, cfngin_context: MockCFNginContext) -> None:
        """Test attributes set during __init__."""
        provider = MagicMock()
        args = {"tags": {"key": "val"}}
        result = Hook(cfngin_context, provider, **args)

        assert result.args.tags["key"] == "val"  # type: ignore
        assert result.args.tags == {
            "cfngin_namespace": "example",
            "key": "val"
        }
        assert not result.blueprint
        assert result.context == cfngin_context
        assert result.provider == provider
        assert not result.stack
        assert result.stack_name == "stack"
Beispiel #17
0
    def test_tags(self, cfngin_context):
        """Test tags property."""
        cfngin_context.config['tags'] = {'context_tag': 'val'}

        hook = Hook(cfngin_context, MagicMock(),
                    **{'tags': {
                        'arg_tag': 'val'
                    }})

        assert hook.tags.to_dict() == [{
            'Key': 'arg_tag',
            'Value': 'val'
        }, {
            'Key': 'context_tag',
            'Value': 'val'
        }]
Beispiel #18
0
    def test_tags(self, cfngin_context: MockCFNginContext) -> None:
        """Test tags property."""
        cfngin_context.config.tags = {"context_tag": "val"}

        hook = Hook(cfngin_context, MagicMock(),
                    **{"tags": {
                        "arg_tag": "val"
                    }})

        assert hook.tags.to_dict() == [
            {
                "Key": "arg_tag",
                "Value": "val"
            },
            {
                "Key": "context_tag",
                "Value": "val"
            },
        ]
Beispiel #19
0
    def test_pre_destroy(self, cfngin_context: MockCFNginContext):
        """Test pre_destroy."""
        hook = Hook(cfngin_context, MagicMock())

        with pytest.raises(NotImplementedError):
            hook.pre_destroy()
Beispiel #20
0
    def test_post_deploy(self, cfngin_context: MockCFNginContext) -> None:
        """Test post_deploy."""
        hook = Hook(cfngin_context, MagicMock())

        with pytest.raises(NotImplementedError):
            hook.post_deploy()