コード例 #1
0
    def testShutdownRecordKeeping(self):
        """Test that one server's shutdown keeps the other records."""

        # NOTE: Do NOT rename this method. It MUST come lexicographically
        # AFTER testServerStartSecondary, because we shut down a server started
        # by the aforementioned method.

        # Kill the second started server.
        EVENT_2.set()

        # Give the server some grace period to react to the kill command.
        time.sleep(5)

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']

        instance_1 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port']
            and i['workspace'] == self._test_workspace
        ]
        instance_2 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_2['viewer_port']
            and i['workspace'] == self._test_workspace
        ]

        self.assertNotEqual(
            instance_1, [], "The stopped server deleted another server's "
            "record from the instance list!")

        self.assertEqual(
            instance_2, [], "The stopped server did not disappear from the"
            " instance list.")
コード例 #2
0
    def testServerStartSecondary(self):
        """Another started server appends itself to instance list."""

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_2.clear()
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        # Workspaces must match, servers were started in the same workspace.
        instance_workspaces = [
            i['workspace'] for i in instance_manager.get_instances(self.home)
            if i['workspace'] == self._test_workspace]

        self.assertEqual(len(instance_workspaces), 2,
                         "Two servers in the same workspace but the workspace"
                         " was not found twice in the instance list.")

        # Exactly one server should own each port generated
        instance_ports = [
            i['port'] for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port'] or
            i['port'] == codechecker_2['viewer_port']]

        self.assertEqual(len(instance_ports), 2,
                         "The ports for the two started servers were not found"
                         " in the instance list.")
コード例 #3
0
    def testServerStartSecondary(self):
        """Another started server appends itself to instance list."""

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_2.clear()
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        # Workspaces must match, servers were started in the same workspace.
        instance_workspaces = [
            i['workspace'] for i in instance_manager.get_instances(self.home)
            if i['workspace'] == self._test_workspace
        ]

        self.assertEqual(
            len(instance_workspaces), 2,
            "Two servers in the same workspace but the workspace"
            " was not found twice in the instance list.")

        # Exactly one server should own each port generated
        instance_ports = [
            i['port'] for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port']
            or i['port'] == codechecker_2['viewer_port']
        ]

        self.assertEqual(
            len(instance_ports), 2,
            "The ports for the two started servers were not found"
            " in the instance list.")
コード例 #4
0
    def testShutdownTerminateStopAll(self):
        """Tests that --stop-all kills all servers on the host."""

        # NOTE: Yet again keep the lexicographical flow, no renames!

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_1.clear()
        EVENT_2.clear()
        start_server(codechecker_1, EVENT_1, ['--skip-db-cleanup'])
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        self.assertEqual(
            len(instance_manager.get_instances(self.home)), 2,
            "Two servers were started but they don't appear "
            "in the instance list.")

        # Kill the servers via cmdline.
        self.assertEqual(
            0, self.run_cmd([env.codechecker_cmd(), 'server', '--stop-all']),
            "The stop-all command didn't return exit code 0.")

        self.assertEqual(
            len(instance_manager.get_instances(self.home)), 0,
            "Both servers were allegedly stopped but they "
            "did not disappear.")
コード例 #5
0
    def testShutdownRecordKeeping(self):
        """Test that one server's shutdown keeps the other records."""

        # NOTE: Do NOT rename this method. It MUST come lexicographically
        # AFTER testServerStartSecondary, because we shut down a server started
        # by the aforementioned method.

        # Kill the second started server.
        EVENT_2.set()

        # Give the server some grace period to react to the kill command.
        time.sleep(5)

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']

        instance_1 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_1['viewer_port'] and
                      i['workspace'] == self._test_workspace]
        instance_2 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_2['viewer_port'] and
                      i['workspace'] == self._test_workspace]

        self.assertNotEqual(instance_1, [],
                            "The stopped server deleted another server's "
                            "record from the instance list!")

        self.assertEqual(instance_2, [],
                         "The stopped server did not disappear from the"
                         " instance list.")
コード例 #6
0
    def testShutdownTerminateStopAll(self):
        """Tests that --stop-all kills all servers on the host."""

        # NOTE: Yet again keep the lexicographical flow, no renames!

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_1.clear()
        EVENT_2.clear()
        start_server(codechecker_1, EVENT_1, ['--skip-db-cleanup'])
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        self.assertEqual(len(instance_manager.get_instances(self.home)), 2,
                         "Two servers were started but they don't appear "
                         "in the instance list.")

        # Kill the servers via cmdline.
        self.assertEqual(0, self.run_cmd([env.codechecker_cmd(),
                                          'server', '--stop-all']),
                         "The stop-all command didn't return exit code 0.")

        self.assertEqual(len(instance_manager.get_instances(self.home)), 0,
                         "Both servers were allegedly stopped but they "
                         "did not disappear.")
コード例 #7
0
def __instance_management(args):
    """Handles the instance-manager commands --list/--stop/--stop-all."""

    # TODO: The server stopping and listing must be revised on its invocation
    # once "workspace", as a concept, is removed.
    # QUESTION: What is the bestest way here to identify a server for the user?
    if 'list' in args:
        instances = instance_manager.get_instances()

        instances_on_multiple_hosts = any(
            True for inst in instances
            if inst['hostname'] != socket.gethostname())
        if not instances_on_multiple_hosts:
            head = ['Workspace', 'View port']
        else:
            head = ['Workspace', 'Computer host', 'View port']

        rows = []
        for instance in instances:
            if not instances_on_multiple_hosts:
                rows.append((instance['workspace'], str(instance['port'])))
            else:
                rows.append(
                    (instance['workspace'], instance['hostname']
                     if instance['hostname'] != socket.gethostname() else '',
                     str(instance['port'])))

        print("Your running CodeChecker servers:")
        print(output_formatters.twodim_to_str('table', head, rows))
    elif 'stop' in args or 'stop_all' in args:
        for i in instance_manager.get_instances():
            if i['hostname'] != socket.gethostname():
                continue

            # A STOP only stops the server associated with the given workspace
            # and view-port.
            if 'stop' in args and \
                not (i['port'] == args.view_port and
                     os.path.abspath(i['workspace']) ==
                     os.path.abspath(args.config_directory)):
                continue

            try:
                util.kill_process_tree(i['pid'])
                LOG.info(
                    "Stopped CodeChecker server running on port %s "
                    "in workspace %s (PID: %s)", i['port'], i['workspace'],
                    i['pid'])
            except Exception:
                # Let the exception come out if the commands fail
                LOG.error("Couldn't stop process PID #%s", str(i['pid']))
                raise
コード例 #8
0
ファイル: server.py プロジェクト: Ericsson/codechecker
def __instance_management(args):
    """Handles the instance-manager commands --list/--stop/--stop-all."""

    # TODO: The server stopping and listing must be revised on its invocation
    # once "workspace", as a concept, is removed.
    # QUESTION: What is the bestest way here to identify a server for the user?
    if 'list' in args:
        instances = instance_manager.get_instances()

        instances_on_multiple_hosts = any(True for inst in instances
                                          if inst['hostname'] !=
                                          socket.gethostname())
        if not instances_on_multiple_hosts:
            head = ['Workspace', 'View port']
        else:
            head = ['Workspace', 'Computer host', 'View port']

        rows = []
        for instance in instances:
            if not instances_on_multiple_hosts:
                rows.append((instance['workspace'], str(instance['port'])))
            else:
                rows.append((instance['workspace'],
                             instance['hostname']
                             if instance['hostname'] != socket.gethostname()
                             else '',
                             str(instance['port'])))

        print("Your running CodeChecker servers:")
        print(output_formatters.twodim_to_str('table', head, rows))
    elif 'stop' in args or 'stop_all' in args:
        for i in instance_manager.get_instances():
            if i['hostname'] != socket.gethostname():
                continue

            # A STOP only stops the server associated with the given workspace
            # and view-port.
            if 'stop' in args and \
                not (i['port'] == args.view_port and
                     os.path.abspath(i['workspace']) ==
                     os.path.abspath(args.config_directory)):
                continue

            try:
                util.kill_process_tree(i['pid'])
                LOG.info("Stopped CodeChecker server running on port %s "
                         "in workspace %s (PID: %s)",
                         i['port'], i['workspace'], i['pid'])
            except Exception:
                # Let the exception come out if the commands fail
                LOG.error("Couldn't stop process PID #%s", str(i['pid']))
                raise
コード例 #9
0
    def testServerStart(self):
        """Started server writes itself to instance list."""

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        EVENT_1.clear()
        start_server(codechecker_1, EVENT_1, ['--skip-db-cleanup'])

        instance = [i for i in instance_manager.get_instances(self.home)
                    if i['port'] == codechecker_1['viewer_port'] and
                    i['workspace'] == self._test_workspace]

        self.assertNotEqual(instance, [],
                            "The started server did not register itself to the"
                            " instance list.")
コード例 #10
0
    def testServerStart(self):
        """Started server writes itself to instance list."""

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        EVENT_1.clear()
        start_server(codechecker_1, EVENT_1, ['--skip-db-cleanup'])

        instance = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port']
            and i['workspace'] == self._test_workspace
        ]

        self.assertNotEqual(
            instance, [], "The started server did not register itself to the"
            " instance list.")
コード例 #11
0
def __reload_config(args):
    """
    Sends the CodeChecker server process a SIGHUP signal, causing it to
    reread it's configuration files.
    """
    for i in instance_manager.get_instances():
        if i['hostname'] != socket.gethostname():
            continue

        # A RELOAD only reloads the server associated with the given workspace
        # and view-port.
        if 'reload' in args and \
                not (i['port'] == args.view_port and
                     os.path.abspath(i['workspace']) ==
                     os.path.abspath(args.config_directory)):
            continue

        try:
            os.kill(i['pid'], signal.SIGHUP)
        except Exception:
            LOG.error("Couldn't reload configuration file for process PID #%s",
                      str(i['pid']))
            raise
コード例 #12
0
ファイル: server.py プロジェクト: Ericsson/codechecker
def __reload_config(args):
    """
    Sends the CodeChecker server process a SIGHUP signal, causing it to
    reread it's configuration files.
    """
    for i in instance_manager.get_instances():
        if i['hostname'] != socket.gethostname():
            continue

        # A RELOAD only reloads the server associated with the given workspace
        # and view-port.
        if 'reload' in args and \
                not (i['port'] == args.view_port and
                     os.path.abspath(i['workspace']) ==
                     os.path.abspath(args.config_directory)):
            continue

        try:
            os.kill(i['pid'], signal.SIGHUP)
        except Exception:
            LOG.error("Couldn't reload configuration file for process PID #%s",
                      str(i['pid']))
            raise
コード例 #13
0
    def testShutdownTerminateByCmdline(self):
        """Tests that the command-line command actually kills the server,
        and that it does not kill anything else."""

        # NOTE: Yet again keep the lexicographical flow, no renames!

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_2.clear()
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        # Kill the server, but yet again give a grace period.
        self.assertEqual(
            0,
            self.run_cmd([
                env.codechecker_cmd(), 'server', '--stop', '--view-port',
                str(codechecker_2['viewer_port']), '--workspace',
                self._test_workspace
            ]), "The stop command didn't return exit code 0.")

        # Check if the remaining server is still there,
        # we need to make sure that --stop only kills the specified server!
        instance_1 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port']
            and i['workspace'] == self._test_workspace
        ]
        instance_2 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_2['viewer_port']
            and i['workspace'] == self._test_workspace
        ]

        self.assertNotEqual(
            instance_1, [], "The stopped server deleted another server's "
            "record from the instance list!")

        self.assertEqual(
            instance_2, [], "The stopped server did not disappear from the"
            " instance list.")

        # Kill the first server via cmdline too.
        self.assertEqual(
            0,
            self.run_cmd([
                env.codechecker_cmd(), 'server', '--stop', '--view-port',
                str(codechecker_1['viewer_port']), '--workspace',
                self._test_workspace
            ]), "The stop command didn't return exit code 0.")

        instance_1 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_1['viewer_port']
            and i['workspace'] == self._test_workspace
        ]
        instance_2 = [
            i for i in instance_manager.get_instances(self.home)
            if i['port'] == codechecker_2['viewer_port']
            and i['workspace'] == self._test_workspace
        ]

        self.assertEqual(
            instance_1, [], "The stopped server did not disappear from the"
            " instance list.")

        self.assertEqual(
            instance_2, [], "The stopped server made another server's record "
            "appear in the instance list.")
コード例 #14
0
    def testShutdownTerminateByCmdline(self):
        """Tests that the command-line command actually kills the server,
        and that it does not kill anything else."""

        # NOTE: Yet again keep the lexicographical flow, no renames!

        test_cfg = env.import_test_cfg(self._test_workspace)
        codechecker_1 = test_cfg['codechecker_1']
        codechecker_2 = test_cfg['codechecker_2']
        EVENT_2.clear()
        start_server(codechecker_2, EVENT_2, ['--skip-db-cleanup'])

        # Kill the server, but yet again give a grace period.
        self.assertEqual(0, self.run_cmd([env.codechecker_cmd(),
                                          'server', '--stop',
                                          '--view-port',
                                          str(codechecker_2['viewer_port']),
                                          '--workspace',
                                          self._test_workspace]),
                         "The stop command didn't return exit code 0.")

        # Check if the remaining server is still there,
        # we need to make sure that --stop only kills the specified server!
        instance_1 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_1['viewer_port'] and
                      i['workspace'] == self._test_workspace]
        instance_2 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_2['viewer_port'] and
                      i['workspace'] == self._test_workspace]

        self.assertNotEqual(instance_1, [],
                            "The stopped server deleted another server's "
                            "record from the instance list!")

        self.assertEqual(instance_2, [],
                         "The stopped server did not disappear from the"
                         " instance list.")

        # Kill the first server via cmdline too.
        self.assertEqual(0, self.run_cmd([env.codechecker_cmd(),
                                          'server', '--stop',
                                          '--view-port',
                                          str(codechecker_1['viewer_port']),
                                          '--workspace',
                                          self._test_workspace]),
                         "The stop command didn't return exit code 0.")

        instance_1 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_1['viewer_port'] and
                      i['workspace'] == self._test_workspace]
        instance_2 = [i for i in instance_manager.get_instances(self.home)
                      if i['port'] == codechecker_2['viewer_port'] and
                      i['workspace'] == self._test_workspace]

        self.assertEqual(instance_1, [],
                         "The stopped server did not disappear from the"
                         " instance list.")

        self.assertEqual(instance_2, [],
                         "The stopped server made another server's record "
                         "appear in the instance list.")