Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] Support config file #2611

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions docs/web/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ to the database.
usage: CodeChecker store [-h] [-t {plist}] [-n NAME] [--tag TAG]
[--description DESCRIPTION]
[--trim-path-prefix [TRIM_PATH_PREFIX [TRIM_PATH_PREFIX ...]]]
[-f] [--url PRODUCT_URL]
[--config CONFIG_FILE] [-f] [--url PRODUCT_URL]
[--verbose {info,debug,debug_analyzer}]
[file/folder [file/folder ...]]

Expand Down Expand Up @@ -199,6 +199,18 @@ optional arguments:
removing "/a/b/" prefix will store files like c/x.cpp
and c/y.cpp. If multiple prefix is given, the longest
match will be removed.
--config CONFIG_FILE Allow the configuration from an explicit JSON based
configuration file. The values configured in the
config file will overwrite the values set in the
command line. The format of configuration file is:
{
"enabled": true,
"store": [
"--name=run_name",
"--tag=my_tag",
"--url=http://codechecker.my/MyProduct"
]
}. (default: None)
-f, --force Delete analysis results stored in the database for the
current analysis run's name and store only the results
reported in the 'input' files. (By default,
Expand Down Expand Up @@ -269,11 +281,13 @@ or via the `CodeChecker cmd` command-line client.
```
usage: CodeChecker server [-h] [-w WORKSPACE] [-f CONFIG_DIRECTORY]
[--host LISTEN_ADDRESS] [-v PORT] [--not-host-only]
[--skip-db-cleanup] [--config CONFIG_FILE]
[--sqlite SQLITE_FILE | --postgresql]
[--dbaddress DBADDRESS] [--dbport DBPORT]
[--dbusername DBUSERNAME] [--dbname DBNAME]
[--reset-root] [--force-authentication]
[-l | -s | --stop-all]
[-l | -r | -s | --stop-all]
[--db-status STATUS | --db-upgrade-schema PRODUCT_TO_UPGRADE | --db-force-upgrade]
[--verbose {info,debug,debug_analyzer}]

The CodeChecker Web server is used to handle the storage and navigation of
Expand Down Expand Up @@ -305,7 +319,18 @@ optional arguments:
over the Internet. (Equivalent to specifying '--host
""'.) (default: False)
--skip-db-cleanup Skip performing cleanup jobs on the database like
removing unused files.
removing unused files. (default: False)
--config CONFIG_FILE Allow the configuration from an explicit JSON based
configuration file. The values configured in the
config file will overwrite the values set in the
command line. The format of configuration file is:
{
"enabled": true,
"server": [
"--workspace=/home/<username>/workspace",
"--port=9090"
]
}. (default: None)
--verbose {info,debug,debug_analyzer}
Set verbosity level.

Expand Down
36 changes: 33 additions & 3 deletions web/client/codechecker_client/cmd/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def get_argparser_ctor_args():
'formatter_class': arg.RawDescriptionDefaultHelpFormatter,

# Description is shown when the command's help is queried directly
'description': "Store the results from one or more 'codechecker-"
"analyze' result files in a database.",
'description': """
Store the results from one or more 'codechecker-analyze' result files in a
database.""",

# Epilogue is shown after the arguments when the help is queried
# directly.
Expand All @@ -86,6 +87,7 @@ def get_argparser_ctor_args():
It can also be used to setup different credential files to
login to the same server with a different user.


The results can be viewed by connecting to such a server in a Web browser or
via 'CodeChecker cmd'.""",

Expand Down Expand Up @@ -159,6 +161,23 @@ def add_arguments_to_parser(parser):
"If multiple prefix is given, the longest match "
"will be removed.")

parser.add_argument('--config',
dest='config_file',
required=False,
help="R|Allow the configuration from an explicit JSON "
"based configuration file. The values configured "
"in the config file will overwrite the values "
"set in the command line. The format of "
"configuration file is:\n"
"{\n"
" \"enabled\": true,\n"
" \"store\": [\n"
" \"--name=run_name\",\n"
" \"--tag=my_tag\",\n"
" \"--url=http://codechecker.my/MyProduct\"\n"
" ]\n"
"}.")

parser.add_argument('-f', '--force',
dest="force",
default=argparse.SUPPRESS,
Expand Down Expand Up @@ -189,7 +208,18 @@ def add_arguments_to_parser(parser):
"'[http[s]://]host:port/Endpoint'.")

logger.add_verbose_arguments(parser)
parser.set_defaults(func=main)
parser.set_defaults(func=main,
func_process_config_file=process_config_file)


def process_config_file(args):
"""
Handler to get config file options.
"""
if args.config_file and os.path.exists(args.config_file):
cfg = util.load_json_or_empty(args.config_file, default={})
if cfg.get("enabled"):
return cfg.get('store', [])


def __get_run_name(input_list):
Expand Down
76 changes: 51 additions & 25 deletions web/server/codechecker_server/cmd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

from codechecker_api_shared.ttypes import DBStatus

from codechecker_common import logger
from codechecker_common import output_formatters
from codechecker_common import util
from codechecker_common import arg, logger, output_formatters, util

from codechecker_server import instance_manager, server
from codechecker_server.database import database
Expand All @@ -51,14 +49,13 @@ def get_argparser_ctor_args():

return {
'prog': 'CodeChecker server',
'formatter_class': argparse.ArgumentDefaultsHelpFormatter,
'formatter_class': arg.RawDescriptionDefaultHelpFormatter,

# Description is shown when the command's help is queried directly
'description': "The CodeChecker Web server is used to handle the "
"storage and navigation of analysis results. A "
"started server can be connected to via a Web "
"browser, or by using the 'CodeChecker cmd' "
"command-line client.",
'description': """
The CodeChecker Web server is used to handle the storage and navigation of
analysis results. A started server can be connected to via a Web browser, or
by using the 'CodeChecker cmd' command-line client.""",

# Help is shown when the "parent" CodeChecker command lists the
# individual subcommands.
Expand Down Expand Up @@ -134,6 +131,23 @@ def add_arguments_to_parser(parser):
help="Skip performing cleanup jobs on the database "
"like removing unused files.")

parser.add_argument('--config',
dest='config_file',
required=False,
help="R|Allow the configuration from an explicit JSON "
"based configuration file. The values configured "
"in the config file will overwrite the values "
"set in the command line. The format of "
"configuration file is: \n"
"{\n"
" \"enabled\": true,\n"
" \"server\": [\n"
" \"--workspace=/home/<username>/workspace\","
"\n"
" \"--port=9090\"\n"
" ]\n"
"}.")

dbmodes = parser.add_argument_group("configuration database arguments")

dbmodes = dbmodes.add_mutually_exclusive_group(required=False)
Expand Down Expand Up @@ -196,11 +210,11 @@ def add_arguments_to_parser(parser):

root_account = parser.add_argument_group(
"root account arguments",
"Servers automatically create a root user to access the server's "
"configuration via the clients. This user is created at first start "
"and saved in the CONFIG_DIRECTORY, and the credentials are printed "
"to the server's standard output. The plaintext credentials are "
"NEVER accessible again.")
"""
Servers automatically create a root user to access the server's configuration
via the clients. This user is created at first start and saved in the
CONFIG_DIRECTORY, and the credentials are printed to the server's standard
output. The plaintext credentials are NEVER accessible again.""")

root_account.add_argument('--reset-root',
dest="reset_root",
Expand Down Expand Up @@ -267,16 +281,17 @@ def add_arguments_to_parser(parser):

database_mgmnt = parser.add_argument_group(
"Database management arguments.",
"""WARNING these commands needs to be called with the same
workspace and configuration arguments as the server so the
configuration database will be found which is required for the
schema migration. Migration can be done without a running server
but pay attention to use the same arguments which will be used to
start the server.
NOTE:
Before migration it is advised to create a full a backup of
the product databases.
""")
"""
WARNING these commands needs to be called with the same workspace and
configuration arguments as the server so the configuration database will be
found which is required for the schema migration. Migration can be done
without a running server but pay attention to use the same arguments which
will be used to start the server.

NOTE:
Before migration it is advised to create a full a backup of the product
databases.
""")

database_mgmnt = database_mgmnt. \
add_mutually_exclusive_group(required=False)
Expand Down Expand Up @@ -414,7 +429,18 @@ def arg_match(options):
# If everything is fine, do call the handler for the subcommand.
main(args)

parser.set_defaults(func=__handle)
parser.set_defaults(func=__handle,
func_process_config_file=process_config_file)


def process_config_file(args):
"""
Handler to get config file options.
"""
if args.config_file and os.path.exists(args.config_file):
cfg = util.load_json_or_empty(args.config_file, default={})
if cfg.get("enabled"):
return cfg.get('server', [])


def print_prod_status(prod_status):
Expand Down
69 changes: 69 additions & 0 deletions web/tests/functional/cli_config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -----------------------------------------------------------------------------
# The CodeChecker Infrastructure
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
# -----------------------------------------------------------------------------

""" Setup for the config test for the web commands. """


import os
import shutil
import sys

from libtest import codechecker
from libtest import env
from libtest import project


# Test workspace should be initialized in this module.
TEST_WORKSPACE = None


def setup_package():
"""Setup the environment for the tests."""

global TEST_WORKSPACE
TEST_WORKSPACE = env.get_workspace('config')

# Set the TEST_WORKSPACE used by the tests.
os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

# Create a basic CodeChecker config for the tests, this should
# be imported by the tests and they should only depend on these
# configuration options.
codechecker_cfg = {
'workspace': TEST_WORKSPACE,
'check_env': env.test_env(TEST_WORKSPACE),
'reportdir': os.path.join(TEST_WORKSPACE, 'reports')
}

# Start or connect to the running CodeChecker server and get connection
# details.
print("This test uses a CodeChecker server... connecting...")
server_access = codechecker.start_or_get_server()
server_access['viewer_product'] = 'config'
codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

# Extend the checker configuration with the server access.
codechecker_cfg.update(server_access)

test_config = {
'codechecker_cfg': codechecker_cfg}

env.export_test_cfg(TEST_WORKSPACE, test_config)


def teardown_package():
""" Delete the workspace associated with this test. """

# TODO: If environment variable is set keep the workspace
# and print out the path.
global TEST_WORKSPACE

check_env = env.import_test_cfg(TEST_WORKSPACE)[
'codechecker_cfg']['check_env']
codechecker.remove_test_package_product(TEST_WORKSPACE, check_env)

print("Removing: " + TEST_WORKSPACE)
shutil.rmtree(TEST_WORKSPACE)
Loading