예제 #1
0
 def test_ignore_signal_sigint(self):
     with ignore_user_entered_signals():
         try:
             os.kill(os.getpid(), signal.SIGINT)
         except KeyboardInterrupt:
             self.fail('The ignore_user_entered_signals context '
                       'manager should have ignored')
예제 #2
0
파일: test_compat.py 프로젝트: aws/aws-cli
 def test_ignore_signal_sigint(self):
     with ignore_user_entered_signals():
         try:
             os.kill(os.getpid(), signal.SIGINT)
         except KeyboardInterrupt:
             self.fail('The ignore_user_entered_signals context '
                       'manager should have ignored')
예제 #3
0
    def invoke(self, service_name, operation_name, parameters,
               parsed_globals):
        client = self._session.create_client(
            service_name, region_name=parsed_globals.region,
            endpoint_url=parsed_globals.endpoint_url,
            verify=parsed_globals.verify_ssl)
        response = client.start_session(**parameters)
        session_id = response['SessionId']
        region_name = client.meta.region_name
        # profile_name is used to passed on to session manager plugin
        # to fetch same profile credentials to make an api call in the plugin.
        # If no profile is passed then pass on empty string
        profile_name = self._session.profile \
            if self._session.profile is not None else ''
        endpoint_url = client.meta.endpoint_url

        try:
            # ignore_user_entered_signals ignores these signals
            # because if signals which kills the process are not
            # captured would kill the foreground process but not the
            # background one. Capturing these would prevents process
            # from getting killed and these signals are input to plugin
            # and handling in there
            with ignore_user_entered_signals():
                # call executable with necessary input
                check_call(["session-manager-plugin",
                            json.dumps(response),
                            region_name,
                            "StartSession",
                            profile_name,
                            json.dumps(parameters),
                            endpoint_url])
            return 0
        except OSError as ex:
            if ex.errno == errno.ENOENT:
                logger.debug('SessionManagerPlugin is not present',
                             exc_info=True)
                # start-session api call returns response and starts the
                # session on ssm-agent and response is forwarded to
                # session-manager-plugin. If plugin is not present, terminate
                # is called so that service and ssm-agent terminates the
                # session to avoid zombie session active on ssm-agent for
                # default self terminate time
                client.terminate_session(SessionId=session_id)
                raise ValueError(''.join(ERROR_MESSAGE))
예제 #4
0
    def invoke(self, service_name, operation_name, parameters, parsed_globals):
        client = self._session.create_client(
            service_name,
            region_name=parsed_globals.region,
            endpoint_url=parsed_globals.endpoint_url,
            verify=parsed_globals.verify_ssl)
        response = client.start_session(**parameters)
        session_id = response['SessionId']
        region_name = client.meta.region_name
        # profile_name is used to passed on to session manager plugin
        # to fetch same profile credentials to make an api call in the plugin.
        # If no profile is passed then pass on empty string
        profile_name = self._session.profile \
            if self._session.profile is not None else ''
        endpoint_url = client.meta.endpoint_url

        try:
            # ignore_user_entered_signals ignores these signals
            # because if signals which kills the process are not
            # captured would kill the foreground process but not the
            # background one. Capturing these would prevents process
            # from getting killed and these signals are input to plugin
            # and handling in there
            with ignore_user_entered_signals():
                # call executable with necessary input
                check_call([
                    "session-manager-plugin",
                    json.dumps(response), region_name, "StartSession",
                    profile_name,
                    json.dumps(parameters), endpoint_url
                ])
            return 0
        except OSError as ex:
            if ex.errno == errno.ENOENT:
                logger.debug('SessionManagerPlugin is not present',
                             exc_info=True)
                # start-session api call returns response and starts the
                # session on ssm-agent and response is forwarded to
                # session-manager-plugin. If plugin is not present, terminate
                # is called so that service and ssm-agent terminates the
                # session to avoid zombie session active on ssm-agent for
                # default self terminate time
                client.terminate_session(SessionId=session_id)
                raise ValueError(''.join(ERROR_MESSAGE))
예제 #5
0
 def invoke(self, service_name, operation_name, parameters, parsed_globals):
     try:
         # making an execute-command call to connect to an
         # active session on a container would require
         # session-manager-plugin to be installed on the client machine.
         # Hence, making this empty session-manager-plugin call
         # before calling execute-command to ensure that
         # session-manager-plugin is installed
         # before execute-command-command is made
         check_call(["session-manager-plugin"])
         client = self._session.create_client(
             service_name,
             region_name=parsed_globals.region,
             endpoint_url=parsed_globals.endpoint_url,
             verify=parsed_globals.verify_ssl)
         response = client.execute_command(**parameters)
         region_name = client.meta.region_name
         profile_name = self._session.profile \
             if self._session.profile is not None else ''
         endpoint_url = client.meta.endpoint_url
         ssm_request_params = build_ssm_request_paramaters(response, client)
         # ignore_user_entered_signals ignores these signals
         # because if signals which kills the process are not
         # captured would kill the foreground process but not the
         # background one. Capturing these would prevents process
         # from getting killed and these signals are input to plugin
         # and handling in there
         with ignore_user_entered_signals():
             # call executable with necessary input
             check_call([
                 "session-manager-plugin",
                 json.dumps(response['session']), region_name,
                 "StartSession", profile_name,
                 json.dumps(ssm_request_params), endpoint_url
             ])
         return 0
     except OSError as ex:
         if ex.errno == errno.ENOENT:
             logger.debug('SessionManagerPlugin is not present',
                          exc_info=True)
             raise ValueError(''.join(ERROR_MESSAGE))
예제 #6
0
 def test_ignore_signal_sigtstp(self):
     with ignore_user_entered_signals():
         self.assertEqual(signal.getsignal(signal.SIGTSTP), signal.SIG_IGN)
         os.kill(os.getpid(), signal.SIGTSTP)
예제 #7
0
파일: test_compat.py 프로젝트: aws/aws-cli
 def test_ignore_signal_sigtstp(self):
     with ignore_user_entered_signals():
         self.assertEqual(signal.getsignal(signal.SIGTSTP), signal.SIG_IGN)
         os.kill(os.getpid(), signal.SIGTSTP)