From 1c91c895c4337910ac7dc5f94c50037c68f51bde Mon Sep 17 00:00:00 2001 From: Gonzalo Rafuls Date: Fri, 7 Feb 2020 03:15:14 -0500 Subject: [PATCH] feat: pbench-server REST API Added pbench-server to be executed by systemctl. Additional changes required on RPM build spec. feat: agent side of transfer REST feat: moved util-scripts to own utils dir final prototype for move_results feat: moved read in chunks and post to copy_results_tb reverted util-scripts changes fixed revert feat: refactored pbench-make-result-tb to python feat: converted copy-results-tb added get on pbench-server for check sum fix: formatting on logger feat: added first test for pbench-server added test for post added tests plus mod gitignore feat: fixed and moved tests around for pbench-server REST feat: fixes to tests plus metadata.log fixure cleanup general refactoring feat: reafactored and added tests feat: gral tests refactoring removed config invocation for agent added host_info entrypoint test feat: tests refactoring feat: added pytests to travis fix: travisyml conflicts fix: removed new line on init fix: travis yml python path fix: travis yml python script fix: added missing libraries for travis fix: added werkzeug library to travis install fix: moved python rpm package to be systems one fix: added system site packages for travis virtualenv feat: added tests and pytest.ini fix: log formatting plus added tests fix: fixes to TCRT tests Addressing review comments Moved agent utils to lib/pbench and config ammendments fix to travis.yml and tests references general refactoring Added libs to pythonpath for travis removed unused import fix to travis configtools import Added _PBENCH_*_CONFIG env variables to travis Fix for fixtures paths fix on test fixture variables fix for travis env yaml fix for server tests Refactored config on server side to accomodate to pytest moved logger to init fixed configtools refactor fix for config fixture install_dir Fix for test copy results fix to server tests Fixes to server tests fixed flake8 issues black lint fixes made config methods blacked Fixes to config Added argparse for move_results plus removed check entrypoint for server Addressing comments from PR Fixes to agent tests fix for test copy result Fixes to test move results fixtures fix to tox pythonpath fix for pytest execution Fixed requirements/removed pytest-flask running pytest via python Fixes to pythonpath for tox fixes to tox pythonpath moved pythonpath to envdir in tox Added build-system to pytproject toml added requires to build-system Fix configtools import fix configtools import moved rpm package to pipy removed sitepackages from tox Fixes to fixtures removed rpy-py-installer Removed rpm for host info modified env from VIRTUAL_ENV to PYTHONPATH Fix for server test setup removed fixtures scope plus redundant packages on test-requirements Added fixture decorator Added pytest-flask package fixes to server conftest blacked fixes to server tests Final fixes to tests blacked fixes to add-metalog-option additional fixes --- .gitignore | 2 + .travis.yml | 2 + agent/config/pbench-agent-default.cfg | 9 +- agent/lib/pbench/__init__.py | 7 + agent/lib/pbench/add_metalog_option.py | 39 ++++ agent/lib/pbench/config.py | 16 ++ agent/lib/pbench/copy_result_tb.py | 71 ++++++ agent/lib/pbench/make_result_tb.py | 124 ++++++++++ agent/lib/pbench/move_results.py | 142 ++++++++++++ agent/lib/pbench/tests/common.py | 19 ++ .../tests/fixtures/config/pbench-agent.cfg | 10 + .../tests/fixtures/copy_result_tb/log.tar.xz | Bin 0 -> 640 bytes .../copy_result_tb/log.tar.xz.md5.check | 1 + .../tests/fixtures/make_result_tb/fixture.log | 1 + .../fixtures/make_result_tb/metadata.log | 8 + .../fixtures/move_results/logs/fixture.log | 1 + .../fixtures/move_results/logs/metadata.log | 9 + agent/lib/pbench/tests/test_copy_result_tb.py | 82 +++++++ agent/lib/pbench/tests/test_make_result_tb.py | 95 ++++++++ agent/lib/pbench/tests/test_move_results.py | 32 +++ doc/CONTRIBUTING.md | 2 + pbench/common/configtools.py | 17 +- pyproject.toml | 7 + pytest.ini | 3 + requirements.txt | 4 + run-unittests | 2 +- server/lib/config/pbench-server-default.cfg | 7 + server/lib/config/pbench-server.cfg.example | 7 + server/lib/pbench_server/__init__.py | 0 server/lib/pbench_server/config.py | 31 +++ server/lib/pbench_server/pbench_server.py | 124 ++++++++++ server/lib/pbench_server/tests/common.py | 7 + server/lib/pbench_server/tests/conftest.py | 36 +++ .../tests/fixtures/config/pbench-server.cfg | 212 ++++++++++++++++++ .../tests/fixtures/upload/log.tar.xz | Bin 0 -> 640 bytes .../fixtures/upload/log.tar.xz.md5.check | 1 + .../lib/pbench_server/tests/test_requests.py | 55 +++++ server/lib/systemd/pbench-server.service | 25 +++ test-requirements.txt | 1 + tox.ini | 24 +- 40 files changed, 1222 insertions(+), 13 deletions(-) create mode 100644 agent/lib/pbench/__init__.py create mode 100755 agent/lib/pbench/add_metalog_option.py create mode 100644 agent/lib/pbench/config.py create mode 100644 agent/lib/pbench/copy_result_tb.py create mode 100644 agent/lib/pbench/make_result_tb.py create mode 100755 agent/lib/pbench/move_results.py create mode 100644 agent/lib/pbench/tests/common.py create mode 100644 agent/lib/pbench/tests/fixtures/config/pbench-agent.cfg create mode 100644 agent/lib/pbench/tests/fixtures/copy_result_tb/log.tar.xz create mode 100644 agent/lib/pbench/tests/fixtures/copy_result_tb/log.tar.xz.md5.check create mode 100644 agent/lib/pbench/tests/fixtures/make_result_tb/fixture.log create mode 100644 agent/lib/pbench/tests/fixtures/make_result_tb/metadata.log create mode 100644 agent/lib/pbench/tests/fixtures/move_results/logs/fixture.log create mode 100644 agent/lib/pbench/tests/fixtures/move_results/logs/metadata.log create mode 100644 agent/lib/pbench/tests/test_copy_result_tb.py create mode 100644 agent/lib/pbench/tests/test_make_result_tb.py create mode 100644 agent/lib/pbench/tests/test_move_results.py create mode 100644 pytest.ini create mode 100644 server/lib/pbench_server/__init__.py create mode 100644 server/lib/pbench_server/config.py create mode 100644 server/lib/pbench_server/pbench_server.py create mode 100644 server/lib/pbench_server/tests/common.py create mode 100644 server/lib/pbench_server/tests/conftest.py create mode 100644 server/lib/pbench_server/tests/fixtures/config/pbench-server.cfg create mode 100644 server/lib/pbench_server/tests/fixtures/upload/log.tar.xz create mode 100644 server/lib/pbench_server/tests/fixtures/upload/log.tar.xz.md5.check create mode 100644 server/lib/pbench_server/tests/test_requests.py create mode 100644 server/lib/systemd/pbench-server.service diff --git a/.gitignore b/.gitignore index 5d03c09ff2..93687d53a6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ dist pip-wheel-metadata AUTHORS ChangeLog +.idea/ +.pytest_cache/ diff --git a/.travis.yml b/.travis.yml index 2ff1aba9c8..1077077249 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ env: - TOXENV=lint - TOXENV=agent - TOXENV=server + - TOXENV=pytest_agent + - TOXENV=pytest_server - TOXENV=py3 before_install: - sudo apt-get update diff --git a/agent/config/pbench-agent-default.cfg b/agent/config/pbench-agent-default.cfg index 608f9b63de..f20c860e53 100644 --- a/agent/config/pbench-agent-default.cfg +++ b/agent/config/pbench-agent-default.cfg @@ -1,15 +1,22 @@ [DEFAULT] version = 002 +pbench_web_server = pbench.example.com [results] user = pbench host_path = http://%(pbench_result_redirector)s/pbench-archive-host webserver = %(pbench_web_server)s -host_info_url = http://%(webserver)s/pbench-results-host-info.versioned/pbench-results-host-info.URL002 +host_info_uri = pbench-results-host-info.versioned/pbench-results-host-info.URL002 +host_info_url = http://%(webserver)s/%(host_info_uri)s dir = /srv/pbench/public_html/incoming scp_opts = -o StrictHostKeyChecking=no ssh_opts = -o StrictHostKeyChecking=no +# REST API entrypoint +api_version = 1 +rest_endpoint = api/v%(api_version)s +server_rest_url = http://%(webserver)s/%(rest_endpoint)s + [pbench-agent] install-dir = %(pbench_install_dir)s pbench_user = pbench diff --git a/agent/lib/pbench/__init__.py b/agent/lib/pbench/__init__.py new file mode 100644 index 0000000000..6b7d91432e --- /dev/null +++ b/agent/lib/pbench/__init__.py @@ -0,0 +1,7 @@ +import logging +import sys + +logger = logging.getLogger(__name__) +logger.addHandler(logging.StreamHandler(sys.stdout)) +logger.propagate = False +logging.basicConfig(level=logging.INFO, format="%(message)s") diff --git a/agent/lib/pbench/add_metalog_option.py b/agent/lib/pbench/add_metalog_option.py new file mode 100755 index 0000000000..a404748688 --- /dev/null +++ b/agent/lib/pbench/add_metalog_option.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# Usage: pbench-add-metalog-option