How to use the sceptre.exceptions.InvalidHookArgumentTypeError function in sceptre

To help you get started, we’ve selected a few sceptre examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sceptre / sceptre / tests / test_hooks / test_asg_scaling_processes.py View on Github external
def test_run_with_non_string_argument(self, mock_find_autoscaling_groups):
        self.asg_scaling_processes.argument = 10
        mock_find_autoscaling_groups.return_value = ["autoscaling_group_1"]
        with pytest.raises(InvalidHookArgumentTypeError):
            self.asg_scaling_processes.run()
github Sceptre / sceptre / tests / test_hooks / test_asg_scheduled_actions.py View on Github external
def test_run_with_non_string_argument(
        self, mock_find_autoscaling_groups, mock_warn
    ):
        self.mock_asg_scheduled_actions.argument = 10
        mock_find_autoscaling_groups.return_value = ["autoscaling_group_1"]
        self.mock_asg_scheduled_actions.connection_manager = Mock()
        with pytest.raises(InvalidHookArgumentTypeError):
            self.mock_asg_scheduled_actions.run()
        mock_warn.assert_called_once_with(
            self.deprecation_notice,
            DeprecationWarning
        )
github Sceptre / sceptre / tests / test_hooks / test_bash.py View on Github external
def test_run_with_non_str_argument(self, mock_warn):
        self.mock_bash.argument = None
        with pytest.raises(InvalidHookArgumentTypeError):
            self.mock_bash.run()
        mock_warn.assert_called_once_with(
            "{0}The bash hook has been deprecated, "
            "and will be removed in a later version of "
            "Sceptre. Use the cmd hook instead. "
            "Example: !cmd {1}"
            .format(Fore.YELLOW, Style.RESET_ALL),
            DeprecationWarning
        )
github Sceptre / sceptre / tests / test_hooks / test_cmd.py View on Github external
def test_run_with_non_str_argument(self):
        self.cmd.argument = None
        with pytest.raises(InvalidHookArgumentTypeError):
            self.cmd.run()
github Sceptre / sceptre / sceptre / hooks / asg_scaling_processes.py View on Github external
def run(self):
        """
        Either suspends or resumes any scaling processes on all autoscaling
        groups within the current stack.

        :raises: InvalidHookArgumentSyntaxError, when syntax is not using "::".
        :raises: InvalidHookArgumentTypeError, if argument is not a string.
        :raises: InvalidHookArgumentValueError, if not using resume or suspend.
        """

        if not isinstance(self.argument, string_types):
            raise InvalidHookArgumentTypeError(
                'The argument "{0}" is the wrong type - asg_scaling_processes '
                'hooks require arguments of type string.'.format(self.argument)
            )
        if "::" not in str(self.argument):
            raise InvalidHookArgumentSyntaxError(
                'Wrong syntax for the argument "{0}" - asg_scaling_processes '
                'hooks use:'
                '- !asg_scaling_processes ::'
                .format(self.argument)
            )

        action, scaling_processes = self.argument.split("::")

        if action not in ["resume", "suspend"]:
            raise InvalidHookArgumentValueError(
                'The argument "{0}" is invalid - valid arguments for '
github Sceptre / sceptre / sceptre / hooks / bash.py View on Github external
def run(self):
        """
        Runs argument string in child process with bash.

        :raise: sceptre.exceptions.InvalidTaskArgumentTypeException
        """
        warnings.warn(
            "{0}The bash hook has been deprecated, and will "
            "be removed in a later version of Sceptre. "
            "Use the cmd hook instead. Example: !cmd {1}"
            .format(Fore.YELLOW, Style.RESET_ALL),
            DeprecationWarning
        )
        if not isinstance(self.argument, string_types):
            raise InvalidHookArgumentTypeError(
                'The argument "{0}" is the wrong type - Bash hooks require '
                'arguments of type string.'.format(self.argument)
            )

        if Bash.ALLOW_COMMAND_ERROR:
            subprocess.call(["/bin/bash", "-c", self.argument])
        else:
            subprocess.check_call(["/bin/bash", "-c", self.argument])
github Sceptre / sceptre / sceptre / hooks / asg_scheduled_actions.py View on Github external
def run(self):
        """
        Either suspends or resumes any scheduled actions on all autoscaling
        groups with in the current stack.
        """
        warnings.warn(
            "{0}The asg_scheduled_actions hook has been deprecated and will "
            "be removed in a later version of Sceptre. Use the "
            "asg_scaling_processes hook instead. Example: "
            "!asg_scaling_processes ::ScheduledActions{1}"
            .format(Fore.YELLOW, Style.RESET_ALL),
            DeprecationWarning
        )
        if not isinstance(self.argument, string_types):
            raise InvalidHookArgumentTypeError(
                'The argument "{0}" is the wrong type - asg_scheduled_actions '
                'hooks require arguments of type string.'.format(self.argument)
            )
        if self.argument not in ["resume", "suspend"]:
            raise InvalidHookArgumentValueError(
                'The argument "{0}" is invalid - valid arguments for '
                'asg_scheduled_actions hooks are "resume" or "suspend".'
                .format(self.argument)
            )

        self.argument += "_processes"

        autoscaling_group_names = self._find_autoscaling_groups()
        for autoscaling_group in autoscaling_group_names:
            self.connection_manager.call(
                service="autoscaling",
github Sceptre / sceptre / sceptre / hooks / cmd.py View on Github external
def run(self):
        """
        Runs the argument string in a subprocess.

        :raises: sceptre.exceptions.InvalidTaskArgumentTypeException
        :raises: subprocess.CalledProcessError
        """
        try:
            subprocess.check_call(self.argument, shell=True)
        except TypeError:
            raise InvalidHookArgumentTypeError(
                'The argument "{0}" is the wrong type - cmd hooks require '
                'arguments of type string.'.format(self.argument)
            )