예제 #1
0
    def stop(self, silent=True):
        if self._start_against_running:
            return
        if self.status != 'started':
            if not silent:
                raise Exception('Server is not started')
            return
        if not silent:
            color_stdout('Stopping the server ...\n', schema='serv_text')
        # kill only if process is alive
        if self.process is not None and self.process.returncode is None:
            color_log('TarantoolServer.stop(): stopping the %s\n' %
                      format_process(self.process.pid),
                      schema='test_var')
            try:
                self.process.terminate()
            except OSError:
                pass
            if self.crash_detector is not None:
                save_join(self.crash_detector)
            self.wait_stop()

        self.status = None
        if re.search(r'^/', str(self._admin.port)):
            if os.path.exists(self._admin.port):
                os.unlink(self._admin.port)
예제 #2
0
 def stop(self, silent):
     if not self.process:
         return
     color_log('AppServer.stop(): stopping the %s\n' %
               format_process(self.process.pid), schema='test_var')
     try:
         self.process.terminate()
     except OSError:
         pass
예제 #3
0
 def stop(self, silent):
     if not self.process:
         return
     color_log('AppServer.stop(): stopping the %s\n' %
               format_process(self.process.pid), schema='test_var')
     try:
         self.process.terminate()
     except OSError:
         pass
예제 #4
0
 def kill():
     qa_notice('The server \'{}\' does not stop during {} '
               'seconds after the {} ({}) signal.\n'
               'Info: {}\n'
               'Sending SIGKILL...'.format(
                   self.name, timeout, signal, signame(signal),
                   format_process(self.process.pid)))
     try:
         self.process.kill()
     except OSError:
         pass
예제 #5
0
 def _log(self, event, pid):
     # Those logs are not written due to gh-247.
     process_def = self._processes[pid]
     task_id = process_def['task_id']
     test_name = task_id[0] + ((':' + task_id[1]) if task_id[1] else '')
     worker_name = process_def['worker_name']
     server_name = process_def['server_name']
     color_log('DEBUG: sampler: {} {}\n'.format(event, format_process(pid)),
               schema='info')
     color_log(' | worker: {}\n'.format(worker_name))
     color_log(' | test: {}\n'.format(test_name))
     color_log(' | server: {}\n'.format(str(server_name)))
예제 #6
0
    def stop(self, silent=True, signal=signal.SIGTERM):
        # FIXME: Extract common parts of AppServer.stop() and
        # TarantoolServer.stop() to an utility function.

        color_log('DEBUG: [app server] Stopping the server...\n',
                  schema='info')

        if not self.process:
            color_log(' | Nothing to do: the process does not exist\n',
                      schema='info')
            return

        if self.process.returncode:
            if self.process.returncode < 0:
                signaled_by = -self.process.returncode
                color_log(' | Nothing to do: the process was terminated by '
                          'signal {} ({})\n'.format(signaled_by,
                                                    signame(signaled_by)),
                          schema='info')
            else:
                color_log(' | Nothing to do: the process was exited with code '
                          '{}\n'.format(self.process.returncode),
                          schema='info')
            return

        color_log(' | Sending signal {0} ({1}) to {2}\n'.format(
            signal, signame(signal), format_process(self.process.pid)))
        try:
            self.process.send_signal(signal)
        except OSError:
            pass

        # Waiting for stopping the server. If the timeout
        # reached, send SIGKILL.
        timeout = 5

        def kill():
            qa_notice('The app server does not stop during {} '
                      'seconds after the {} ({}) signal.\n'
                      'Info: {}\n'
                      'Sending SIGKILL...'.format(
                          timeout, signal, signame(signal),
                          format_process(self.process.pid)))
            try:
                self.process.kill()
            except OSError:
                pass

        timer = Timer(timeout, kill)
        timer.start()
        self.process.wait()
        timer.cancel()
예제 #7
0
    def wait_until_started(self, wait_load=True):
        """ Wait until server is started.

        Server consists of two parts:
        1) wait until server is listening on sockets
        2) wait until server tells us his status

        """
        color_log('DEBUG: [Instance {}] Waiting until started '
                  '(wait_load={})\n'.format(self.name, str(wait_load)),
                  schema='info')

        if wait_load:
            msg = 'entering the event loop|will retry binding|hot standby mode'
            p = self.process if not self.gdb and not self.lldb else None
            self.logfile_pos.seek_wait(msg, p, self.name)
        while True:
            try:
                temp = AdminConnection('localhost', self.admin.port)
                if not wait_load:
                    ans = yaml.safe_load(temp.execute("2 + 2"))
                    color_log(" | Successful connection check; don't wait for "
                              "loading")
                    return True
                ans = yaml.safe_load(temp.execute('box.info.status'))[0]
                if ans in ('running', 'hot_standby', 'orphan'):
                    color_log(" | Started {} (box.info.status: '{}')\n".format(
                        format_process(self.process.pid), ans))
                    return True
                elif ans in ('loading',):
                    continue
                else:
                    raise Exception(
                        "Strange output for `box.info.status`: %s" % (ans)
                    )
            except socket.error as e:
                if e.errno == errno.ECONNREFUSED:
                    color_log(' | Connection refused; will retry every 0.1 '
                              'seconds...')
                    time.sleep(0.1)
                    continue
                raise
예제 #8
0
    def stop(self, silent=True, signal=signal.SIGTERM):
        """ Kill tarantool server using specified signal (SIGTERM by default)

            signal - a number of a signal
        """
        if self._start_against_running:
            color_log('Server [%s] start against running ...\n',
                      schema='test_var')
            return
        if self.status != 'started':
            if not silent:
                raise Exception('Server is not started')
            else:
                color_log(
                    'Server [{0.name}] is not started '
                    '(status:{0.status}) ...\n'.format(self),
                    schema='test_var'
                )
            return
        if not silent:
            color_stdout('Stopping the server ...\n', schema='serv_text')
        else:
            color_log('Stopping the server ...\n', schema='serv_text')
        # kill only if process is alive
        if self.process is not None and self.process.returncode is None:
            color_log('TarantoolServer.stop(): stopping the {0}\n'.format(
                      format_process(self.process.pid)), schema='test_var')
            try:
                color_log('Sending signal {0} ({1}) to process {2}\n'.format(
                          signal, signame(signal), self.process.pid))
                self.process.send_signal(signal)
            except OSError:
                pass
            if self.crash_detector is not None:
                save_join(self.crash_detector)
            self.wait_stop()

        self.status = None
        if re.search(r'^/', str(self._admin.port)):
            if os.path.exists(self._admin.port):
                os.unlink(self._admin.port)
예제 #9
0
    def stop(self, silent=True, signal=signal.SIGTERM):
        """ Kill tarantool server using specified signal (SIGTERM by default)

            signal - a number of a signal
        """
        if self._start_against_running:
            color_log('Server [%s] start against running ...\n',
                      schema='test_var')
            return
        if self.status != 'started':
            if not silent:
                raise Exception('Server is not started')
            else:
                color_log('Server [{0.name}] is not started '
                          '(status:{0.status}) ...\n'.format(self),
                          schema='test_var')
            return
        if not silent:
            color_stdout('Stopping the server ...\n', schema='serv_text')
        else:
            color_log('Stopping the server ...\n', schema='serv_text')
        # kill only if process is alive
        if self.process is not None and self.process.returncode is None:
            color_log('TarantoolServer.stop(): stopping the {0}\n'.format(
                format_process(self.process.pid)),
                      schema='test_var')
            try:
                color_log('Sending signal {0} ({1}) to process {2}\n'.format(
                    signal, signame(signal), self.process.pid))
                self.process.send_signal(signal)
            except OSError:
                pass
            if self.crash_detector is not None:
                save_join(self.crash_detector)
            self.wait_stop()

        self.status = None
        if re.search(r'^/', str(self._admin.port)):
            if os.path.exists(self._admin.port):
                os.unlink(self._admin.port)
예제 #10
0
    def stop(self, silent=True, signal=signal.SIGTERM):
        """ Kill tarantool server using specified signal (SIGTERM by default)

            signal - a number of a signal
        """
        if self._start_against_running:
            color_log('Server [%s] start against running ...\n',
                      schema='test_var')
            return
        if self.status != 'started':
            if not silent:
                raise Exception('Server is not started')
            else:
                color_log(
                    'Server [{0.name}] is not started '
                    '(status:{0.status}) ...\n'.format(self),
                    schema='test_var'
                )
            return
        if not silent:
            color_stdout('[Instance {}] Stopping the server...\n'.format(
                self.name), schema='info')
        else:
            color_log('DEBUG: [Instance {}] Stopping the server...\n'.format(
                self.name), schema='info')
        # kill only if process is alive
        if self.process is not None and self.process.returncode is None:
            color_log(' | Sending signal {0} ({1}) to {2}\n'.format(
                      signal, signame(signal),
                      format_process(self.process.pid)))
            try:
                self.process.send_signal(signal)
            except OSError:
                pass

            # Waiting for stopping the server. If the timeout
            # reached, send SIGKILL.
            timeout = 5

            def kill():
                qa_notice('The server \'{}\' does not stop during {} '
                          'seconds after the {} ({}) signal.\n'
                          'Info: {}\n'
                          'Sending SIGKILL...'.format(
                              self.name, timeout, signal, signame(signal),
                              format_process(self.process.pid)))
                try:
                    self.process.kill()
                except OSError:
                    pass

            timer = Timer(timeout, kill)
            timer.start()
            if self.crash_detector is not None:
                save_join(self.crash_detector)
            self.wait_stop()
            timer.cancel()

        self.status = None
        if re.search(r'^/', str(self._admin.port)):
            if os.path.exists(self._admin.port):
                os.unlink(self._admin.port)