From 74f1a59bcd4be6011663c746afc839b0e6257311 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 17 Sep 2021 15:43:47 +0200 Subject: [PATCH 01/10] restapi: create bareos-restapi pypi package Also: * Package name is: bareos-restapi * Package path is bareos_restapi * Fixes paths and curl parameter. * Add restapi control script (start, stop, status). * Add helper scripts for testing. * Removed unused configuration files. * Add environment-local for test specific settings. The number of *.in files can be reduced by this. * Find metatags.yaml in module directory. * Reduce imports and requirements. --- rest-api/README.md | 24 ++-- .../__init__.py} | 23 ++-- .../api.ini.example} | 0 rest-api/{ => bareos_restapi}/metatags.yaml | 0 .../models.py} | 19 +++ rest-api/{ => bareos_restapi}/openapi.json | 0 rest-api/requirements.txt | 11 +- rest-api/setup.py | 91 +++++++++++++ systemtests/environment.in | 3 +- .../python-restapi/api/bareos-restapi.py | 1 - .../python-restapi/api/bareosRestapiModels.py | 1 - .../tests/python-restapi/api/curl-auth.sh | 29 ++++ .../tests/python-restapi/api/curl-call.sh | 56 ++++++++ .../tests/python-restapi/api/metatags.yaml | 1 - .../tests/python-restapi/api/restapi.sh | 124 ++++++++++++++++++ .../tests/python-restapi/api/startapi.sh.in | 18 --- .../tests/python-restapi/api/stopapi.sh | 4 - .../tests/python-restapi/environment-local.in | 2 + .../bareos-dir.d/job/BackupCatalog.conf.in | 20 --- .../job/admin-runscript-client-server.conf.in | 27 ---- .../job/admin-runscript-client.conf.in | 16 --- .../job/admin-runscript-server.conf.in | 16 --- ...areos-fd-runscript-client-defaults.conf.in | 16 --- .../backup-bareos-fd-runscript-client.conf.in | 16 --- .../backup-bareos-fd-runscript-server.conf.in | 16 --- .../bareos-dir.d/job/backup-test2-fd.conf | 5 - .../jobdefs/jobdefs-runscript1.conf.in | 17 --- .../jobdefs/jobdefs-runscript2.conf.in | 17 --- .../etc/bareos/bconsole-admin-notls.conf.in | 15 --- .../bareos/bconsole-client-bareos-fd.conf.in | 16 --- .../bconsole-job-backup-bareos-fd.conf.in | 16 --- .../{testrunner.in => testrunner} | 102 +++++++------- systemtests/tests/python-restapi/write.sh | 9 -- 33 files changed, 404 insertions(+), 327 deletions(-) rename rest-api/{bareos-restapi.py => bareos_restapi/__init__.py} (99%) rename rest-api/{api.ini => bareos_restapi/api.ini.example} (100%) rename rest-api/{ => bareos_restapi}/metatags.yaml (100%) rename rest-api/{bareosRestapiModels.py => bareos_restapi/models.py} (96%) rename rest-api/{ => bareos_restapi}/openapi.json (100%) create mode 100644 rest-api/setup.py delete mode 120000 systemtests/tests/python-restapi/api/bareos-restapi.py delete mode 120000 systemtests/tests/python-restapi/api/bareosRestapiModels.py create mode 100755 systemtests/tests/python-restapi/api/curl-auth.sh create mode 100755 systemtests/tests/python-restapi/api/curl-call.sh delete mode 120000 systemtests/tests/python-restapi/api/metatags.yaml create mode 100755 systemtests/tests/python-restapi/api/restapi.sh delete mode 100755 systemtests/tests/python-restapi/api/startapi.sh.in delete mode 100755 systemtests/tests/python-restapi/api/stopapi.sh create mode 100644 systemtests/tests/python-restapi/environment-local.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client-server.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-server.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client-defaults.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-server.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-test2-fd.conf delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript1.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript2.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bconsole-admin-notls.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bconsole-client-bareos-fd.conf.in delete mode 100644 systemtests/tests/python-restapi/etc/bareos/bconsole-job-backup-bareos-fd.conf.in rename systemtests/tests/python-restapi/{testrunner.in => testrunner} (59%) delete mode 100755 systemtests/tests/python-restapi/write.sh diff --git a/rest-api/README.md b/rest-api/README.md index b505f6fe35b..87266569477 100644 --- a/rest-api/README.md +++ b/rest-api/README.md @@ -14,23 +14,23 @@ a Bareos director. ### Installation -Copy the rest-api directory to any place outside the source-tree and change into it. - -Change into the copied directory with _requirements.txt_, _bareos-restapi.py_ and _api.ini_ -* We recommend to create a dedicated Python environment for the installation: +We recommend to create a dedicated Python environment for the installation in an own directory: ``` python3 -m venv env # Activate the virtual environment inside the directory source env/bin/activate # Install dependencies into the virtual environment -pip install -r requirements.txt +pip install -i https://test.pypi.org/simple/ python-bareos-restapi ``` -Note: _requirements.txt_ contains a list of needed Python-modules, which will get installed by pip. The module _sslpsk==1.0.0_ is commented, because it requires an installed gcc and header files to be installed. Uncomment, if you want encrypted communication between the API and the Bareos director. +Note: The optional module _sslpsk_ can be installed manually, if you want encrypted communication between the API and the Bareos director. ### Configuration -Configure your Bareos Server in _api.ini_ adapting these 3 lines of configuration, so that it points to your director: + +The module directory contains a sample ini-file. Change into this directory (something like */lib/python3.x/site-packages/bareosRestapiModels* on most operating systems) and copy _api.ini.sample_ to _api.ini_ and adapt it to your director. Make sure to generate an own secret-key for the _JWT_ section. + +Your director configuration in _api.ini_ should look like: ``` [Director] Name=bareos-dir @@ -38,13 +38,14 @@ Address=127.0.0.1 Port=9101 ``` -Note: you will need a _named console_ (user/password) to acces the Bareos director using this API. Read more about Consoles here: +Note: you will need a *named console* (user/password) to acces the Bareos director using this API. Read more about Consoles here: https://docs.bareos.org/Configuration/Director.html#console-resource -TODO: add possibility to connect to a choice of directors ### Start the backend server +From inside the module directory run: + ``` uvicorn bareos-restapi:app --reload ``` @@ -63,4 +64,7 @@ The Swagger documentation also contains CURL statements for all available endpoi The API will be extended by some methods provided by the Bareos console, that are not yet implemented. It is also planned to add delete / update options for configuration in the director and REST API. If you are interested in support and / or funding enhancements, please visit https://www.bareos.com -TODO: response model are not defined / documented yet. +TODO: +- define and document response model +- add possibility to connect to a choice of directors +- add start-script with ini-file name as parameter diff --git a/rest-api/bareos-restapi.py b/rest-api/bareos_restapi/__init__.py similarity index 99% rename from rest-api/bareos-restapi.py rename to rest-api/bareos_restapi/__init__.py index 3875dc31c0f..5bbfd3292e9 100644 --- a/rest-api/bareos-restapi.py +++ b/rest-api/bareos_restapi/__init__.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + +# # BAREOS - Backup Archiving REcovery Open Sourced # # Copyright (C) 2020-2020 Bareos GmbH & Co. KG @@ -22,20 +24,20 @@ # Author: Maik Aussendorf # +import configparser from datetime import datetime, timedelta -from typing import Optional, List from fastapi import Depends, FastAPI, HTTPException, status, Response, Path, Body, Query from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from jose import JWTError, jwt -from passlib.context import CryptContext -from pydantic import BaseModel, Field, PositiveInt -from enum import Enum -import pathlib +import os from packaging import version -import bareos.bsock -import configparser +from passlib.context import CryptContext +from pydantic import BaseModel +from typing import Optional import yaml -from bareosRestapiModels import * + +import bareos.bsock +from bareos_restapi.models import * # Read config from api.ini config = configparser.ConfigParser() @@ -52,7 +54,10 @@ userDirectors = {} users_db = {} -with open("metatags.yaml", "r") as stream: +# Load metatags.yaml from the same directory. +with open( + os.path.dirname(os.path.realpath(__file__)) + "/metatags.yaml", "r" +) as stream: tags_metadata = yaml.safe_load(stream) pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") diff --git a/rest-api/api.ini b/rest-api/bareos_restapi/api.ini.example similarity index 100% rename from rest-api/api.ini rename to rest-api/bareos_restapi/api.ini.example diff --git a/rest-api/metatags.yaml b/rest-api/bareos_restapi/metatags.yaml similarity index 100% rename from rest-api/metatags.yaml rename to rest-api/bareos_restapi/metatags.yaml diff --git a/rest-api/bareosRestapiModels.py b/rest-api/bareos_restapi/models.py similarity index 96% rename from rest-api/bareosRestapiModels.py rename to rest-api/bareos_restapi/models.py index c6ec9b77416..05bafdb3ff6 100644 --- a/rest-api/bareosRestapiModels.py +++ b/rest-api/bareos_restapi/models.py @@ -1,3 +1,22 @@ +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + from pydantic import BaseModel, Field, PositiveInt from enum import Enum import pathlib diff --git a/rest-api/openapi.json b/rest-api/bareos_restapi/openapi.json similarity index 100% rename from rest-api/openapi.json rename to rest-api/bareos_restapi/openapi.json diff --git a/rest-api/requirements.txt b/rest-api/requirements.txt index 76cfa96f391..5d54a2116b8 100644 --- a/rest-api/requirements.txt +++ b/rest-api/requirements.txt @@ -1,13 +1,10 @@ -dataclasses fastapi +packaging +passlib pydantic python-bareos -# This will require gcc and some headerfiles -#sslpsk -starlette==0.13.6 python-jose -uvicorn +# python-multipart: used by fastapi python-multipart -passlib -packaging pyyaml +uvicorn diff --git a/rest-api/setup.py b/rest-api/setup.py new file mode 100644 index 00000000000..8ce8f90836e --- /dev/null +++ b/rest-api/setup.py @@ -0,0 +1,91 @@ +#!/usr/bin/python +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + + +import os +import re +import glob +from setuptools import find_packages, setup + + +def get_version(): + base_dir = os.path.abspath(os.path.dirname(__file__)) + + try: + with open( + os.path.join(base_dir, "bareos_restapi", "VERSION.txt") + ) as version_file: + # read version + # and adapt it according to + # https://www.python.org/dev/peps/pep-0440/. + fullversion = version_file.read().strip() + __version__ = re.compile(r"~pre([0-9]+).*").sub(r".dev\1", fullversion) + except IOError: + # Fallback version. + # First protocol implemented + # has been introduced with this version. + __version__ = "20.0.4" + + return __version__ + + +setup( + name="bareos-restapi", + version=get_version(), + license="AGPLv3", + author="Bareos Team", + author_email="packager@bareos.com", + packages=find_packages(), + package_data={ + "bareos_restapi": [ + "metatags.yaml", + "openapi.json", + "api.ini.example", + "VERSION.txt", + ], + }, + # data_files=[('etc/bareos/restapi',['etc/restapi.ini'])], + url="https://github.com/bareos/bareos/", + # What does your project relate to? + keywords="bareos, REST API", + description="REST API for Bareos console access.", + long_description=open("README.md").read(), + long_description_content_type="text/markdown", + python_requires=">=3.6", + install_requires=[ + "fastapi", + "packaging", + "passlib", + "pydantic", + "python-bareos", + "python-jose", + # python-multipart: used by fastapi + "python-multipart", + "pyyaml", + "uvicorn", + ], + classifiers=[ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: System :: Archiving :: Backup", + ], +) diff --git a/systemtests/environment.in b/systemtests/environment.in index d6269972b6b..e6959bf153a 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -1,6 +1,7 @@ -PROJECT_SOURCE_DIR=@PROJECT_SOURCE_DIR@ +CMAKE_SOURCE_DIR=@CMAKE_SOURCE_DIR@ CMAKE_BINARY_DIR=@CMAKE_BINARY_DIR@ +PROJECT_SOURCE_DIR=@PROJECT_SOURCE_DIR@ PROJECT_BINARY_DIR=@PROJECT_BINARY_DIR@ bin=@bin@ sbin=@sbin@ diff --git a/systemtests/tests/python-restapi/api/bareos-restapi.py b/systemtests/tests/python-restapi/api/bareos-restapi.py deleted file mode 120000 index 97861626eda..00000000000 --- a/systemtests/tests/python-restapi/api/bareos-restapi.py +++ /dev/null @@ -1 +0,0 @@ -../../../../rest-api/bareos-restapi.py \ No newline at end of file diff --git a/systemtests/tests/python-restapi/api/bareosRestapiModels.py b/systemtests/tests/python-restapi/api/bareosRestapiModels.py deleted file mode 120000 index 48c2c65f17d..00000000000 --- a/systemtests/tests/python-restapi/api/bareosRestapiModels.py +++ /dev/null @@ -1 +0,0 @@ -../../../../rest-api/bareosRestapiModels.py \ No newline at end of file diff --git a/systemtests/tests/python-restapi/api/curl-auth.sh b/systemtests/tests/python-restapi/api/curl-auth.sh new file mode 100755 index 00000000000..c1768a2ae84 --- /dev/null +++ b/systemtests/tests/python-restapi/api/curl-auth.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2021-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +. $(dirname "$BASH_SOURCE")/../environment-local + +USERNAME=${1:-admin-tls} +PASSWORD=${2:-secret} + +curl --silent -X POST "${REST_API_URL}/token" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "username=admin-tls&password=secret" | grep access_token | cut -d '"' -f 4 diff --git a/systemtests/tests/python-restapi/api/curl-call.sh b/systemtests/tests/python-restapi/api/curl-call.sh new file mode 100755 index 00000000000..e3b405c2ab2 --- /dev/null +++ b/systemtests/tests/python-restapi/api/curl-call.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2021-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +set -e +set -o pipefail +set -u + +cd $(dirname "$BASH_SOURCE") +#. ../environment +. ../environment-local + +# $1: method (POST, GET) +# $2: endpoint_url +# $3: string to grep for +# $4: extra curl options +# $5: repeat n times with a pause of 1 second between tries to get the result + +method="$1" +shift +endpoint="$1" +shift +curl_extra_options="$@" + +if [ -z "${REST_API_TOKEN:-}" ]; then + REST_API_TOKEN=$(./curl-auth.sh) +fi + +url="${REST_API_URL}/${endpoint}" + +RC=0 +# curl doesn't like empty string "" as option, will exit with code 3 +curl_cmd="curl -w \nHTTP_CODE=%{http_code}\n -s -X ${method} $url" +OUT=$(${curl_cmd} -H "Content-Type: application/json" -H "accept: application/json" -H "Authorization: Bearer $REST_API_TOKEN" "$@") || RC=$? + +printf "$OUT\n" +exit $RC diff --git a/systemtests/tests/python-restapi/api/metatags.yaml b/systemtests/tests/python-restapi/api/metatags.yaml deleted file mode 120000 index eed0ccdc515..00000000000 --- a/systemtests/tests/python-restapi/api/metatags.yaml +++ /dev/null @@ -1 +0,0 @@ -../../../../rest-api/metatags.yaml \ No newline at end of file diff --git a/systemtests/tests/python-restapi/api/restapi.sh b/systemtests/tests/python-restapi/api/restapi.sh new file mode 100755 index 00000000000..0fd67374d2f --- /dev/null +++ b/systemtests/tests/python-restapi/api/restapi.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +# +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2021-2021 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +set -e +set -u + +cd $(dirname "$BASH_SOURCE") +. ../environment +. ../environment-local + +if [ "${PYTHONPATH:-}" ]; then + export PYTHONPATH=${CMAKE_SOURCE_DIR}/rest-api/:$PYTHONPATH +else + export PYTHONPATH=${CMAKE_SOURCE_DIR}/rest-api/ +fi + +start() +{ + printf "Starting bareos-restapi: " + + if lsof -i:$REST_API_PORT >/dev/null; then + printf " FAILED (port $REST_API_PORT already in use)\n" + exit 1 + fi + + $PYTHON_EXECUTABLE -m uvicorn bareos_restapi:app --port ${REST_API_PORT} > ../log/bareos-restapi.log 2>&1 & + PID=$! + + WAIT=10 + while ! curl --silent ${REST_API_URL}/token >/dev/null; do + if ! ps -p $PID >/dev/null; then + printf " FAILED\n" + exit 1 + fi + + WAIT=$[$WAIT-1] + if [ "$WAIT" -le 0 ]; then + printf " FAILED\n" + exit 2 + fi + + printf "." + sleep 1 + done + echo $PID > api.pid + printf " OK (PORT=${REST_API_PORT}, PID=$PID)\n" +} + +stop() +{ + printf "Stopping bareos-restapi: " + if [ -e api.pid ]; then + PID=$(cat api.pid) + kill $PID + rm api.pid + printf "OK\n" + return + fi + printf "OK (already stopped)\n" +} + +status() +{ + printf "bareos-restapi: " + if ! lsof -i:$REST_API_PORT >/dev/null; then + printf "not running\n" + exit 1 + fi + PORTPID=$(lsof -t -i:$REST_API_PORT) + PID=$(cat api.pid) + if [ "$PORTPID" != "$PID" ]; then + printf "running with unexpected PID (expected PID=$PID, running PID=$PORTPID)\n" + exit 1 + fi + printf "running (PORT=${REST_API_PORT}, PID=$PID)\n" + exit 0 +} + +case "$1" in + start) + start + ;; + + stop) + stop + ;; + + restart) + stop + sleep 1 + start + ;; + + status) + status + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/systemtests/tests/python-restapi/api/startapi.sh.in b/systemtests/tests/python-restapi/api/startapi.sh.in deleted file mode 100755 index 523add0f786..00000000000 --- a/systemtests/tests/python-restapi/api/startapi.sh.in +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -. ../environment - -if [ "${PROJECT_SOURCE_DIR}" ] && [ -e "${PROJECT_SOURCE_DIR}/../python-bareos/" ]; then - PYTHONPATH=${PYTHONPATH:-} - if [ "$PYTHONPATH" ]; then - export PYTHONPATH=${PROJECT_SOURCE_DIR}/../python-bareos/:$PYTHONPATH - else - export PYTHONPATH=${PROJECT_SOURCE_DIR}/../python-bareos/ - fi - PYTHONPATH=/root/git/bareos/python-bareos/bareos:$PYTHONPATH - PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-python} -fi - -uvicorn bareos-restapi:app --port @restapi_port@ > ../log/bareos-restapi.log 2>&1 & -PID=$! -echo @restapi_port@ > api.port -echo $PID > api.pid diff --git a/systemtests/tests/python-restapi/api/stopapi.sh b/systemtests/tests/python-restapi/api/stopapi.sh deleted file mode 100755 index 1126c957a09..00000000000 --- a/systemtests/tests/python-restapi/api/stopapi.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -PID=`cat api.pid` -kill $PID -rm api.pid diff --git a/systemtests/tests/python-restapi/environment-local.in b/systemtests/tests/python-restapi/environment-local.in new file mode 100644 index 00000000000..f52e035d7fd --- /dev/null +++ b/systemtests/tests/python-restapi/environment-local.in @@ -0,0 +1,2 @@ +REST_API_PORT=@restapi_port@ +REST_API_URL=http://127.0.0.1:${REST_API_PORT} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in deleted file mode 100644 index 1da2a7af657..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in +++ /dev/null @@ -1,20 +0,0 @@ -Job { - Name = "BackupCatalog" - Description = "Backup the catalog database (after the nightly save)" - JobDefs = "DefaultJob" - Level = Full - FileSet="Catalog" - - # This creates an ASCII copy of the catalog - # Arguments to make_catalog_backup.pl are: - # make_catalog_backup.pl - RunBeforeJob = "@scriptdir@/make_catalog_backup.pl MyCatalog" - - # This deletes the copy of the catalog - RunAfterJob = "@scriptdir@/delete_catalog_backup" - - # This sends the bootstrap via mail for disaster recovery. - # Should be sent to another system, please change recipient accordingly - Write Bootstrap = "|@bindir@/bsmtp -h @smtp_host@ -f \"\(Bareos\) \" -s \"Bootstrap for Job %j\" @job_email@" # (#01) - Priority = 11 # run after main backup -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client-server.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client-server.conf.in deleted file mode 100644 index 4931cd4cce0..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client-server.conf.in +++ /dev/null @@ -1,27 +0,0 @@ -Job { - Name = "admin-runscript-client-server" - JobDefs = "DefaultJob" - Type = Admin - RunScript { - RunsWhen = Before - Runs On Failure = Yes - #Runs On Client = Yes - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } - RunScript { - RunsWhen = Before - Runs On Failure = Yes - Runs On Client = No - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client.conf.in deleted file mode 100644 index 979c0ab573d..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-client.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -Job { - Name = "admin-runscript-client" - JobDefs = "DefaultJob" - Type = Admin - RunScript { - RunsWhen = Before - Runs On Failure = Yes - #Runs On Client = Yes - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-server.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-server.conf.in deleted file mode 100644 index fc911866989..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/admin-runscript-server.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -Job { - Name = "admin-runscript-server" - JobDefs = "DefaultJob" - Type = Admin - RunScript { - RunsWhen = Before - Runs On Failure = Yes - Runs On Client = No - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client-defaults.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client-defaults.conf.in deleted file mode 100644 index b949da66520..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client-defaults.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -Job { - Name = "backup-bareos-fd-runscript-client-defaults" - JobDefs = "DefaultJob" - Type = Backup - RunScript { - RunsWhen = Before - #Runs On Failure = Yes - #Runs On Client = Yes - #FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client.conf.in deleted file mode 100644 index 32a3376996e..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-client.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -Job { - Name = "backup-bareos-fd-runscript-client" - JobDefs = "DefaultJob" - Type = Backup - RunScript { - RunsWhen = Before - Runs On Failure = Yes - Runs On Client = Yes - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-server.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-server.conf.in deleted file mode 100644 index dcc847f0212..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd-runscript-server.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -Job { - Name = "backup-bareos-fd-runscript-server" - JobDefs = "DefaultJob" - Type = Backup - RunScript { - RunsWhen = Before - Runs On Failure = Yes - Runs On Client = No - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-test2-fd.conf b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-test2-fd.conf deleted file mode 100644 index 10750189267..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-test2-fd.conf +++ /dev/null @@ -1,5 +0,0 @@ -Job { - Name = "backup-test2-fd" - JobDefs = "DefaultJob" - Client = "test2-fd" -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript1.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript1.conf.in deleted file mode 100644 index e5e9b97bffc..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript1.conf.in +++ /dev/null @@ -1,17 +0,0 @@ -JobDefs { - Name = "jobdefs-runscript1" - Type = Admin - Messages = Standard - RunScript { - RunsWhen = Before - Runs On Client = No - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'jobdefs=jobdefs-runscript1' 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } - Jobdefs = "DefaultJob" -} - diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript2.conf.in b/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript2.conf.in deleted file mode 100644 index b0ae3c2f685..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/jobdefs-runscript2.conf.in +++ /dev/null @@ -1,17 +0,0 @@ -JobDefs { - Name = "jobdefs-runscript2" - Type = Admin - Messages = Standard - RunScript { - RunsWhen = Before - Runs On Client = No - FailJobOnError = Yes - # %d Daemon’s name (Such as host-dir or host-fd) - # %n Job name - # %t Job type (Backup, …) - # %i Job Id - Command = "@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/write.sh @working_dir@/jobid-%i-runscript.log 'jobdefs=jobdefs-runscript2' 'daemon=%d' 'jobname=%n' 'jobtype=%t' 'jobid=%i'" - } - JobDefs = "jobdefs-runscript1" -} - diff --git a/systemtests/tests/python-restapi/etc/bareos/bconsole-admin-notls.conf.in b/systemtests/tests/python-restapi/etc/bareos/bconsole-admin-notls.conf.in deleted file mode 100644 index a504b011362..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bconsole-admin-notls.conf.in +++ /dev/null @@ -1,15 +0,0 @@ -# -# Bareos User Agent (or Console) Configuration File -# - -Director { - Name = @basename@-dir - DIRport = @dir_port@ - Address = @hostname@ - Password = "INVALID" -} - -Console { - name = admin-notls - password = secret -} diff --git a/systemtests/tests/python-restapi/etc/bareos/bconsole-client-bareos-fd.conf.in b/systemtests/tests/python-restapi/etc/bareos/bconsole-client-bareos-fd.conf.in deleted file mode 100644 index 541eea8283d..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bconsole-client-bareos-fd.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -# -# Bareos User Agent (or Console) Configuration File -# - -Director { - Name = @basename@-dir - DIRport = @dir_port@ - Address = @hostname@ - Password = "INVALID" -} - -Console { - name = client-bareos-fd - password = secret -} - diff --git a/systemtests/tests/python-restapi/etc/bareos/bconsole-job-backup-bareos-fd.conf.in b/systemtests/tests/python-restapi/etc/bareos/bconsole-job-backup-bareos-fd.conf.in deleted file mode 100644 index 5f2baa8b8c2..00000000000 --- a/systemtests/tests/python-restapi/etc/bareos/bconsole-job-backup-bareos-fd.conf.in +++ /dev/null @@ -1,16 +0,0 @@ -# -# Bareos User Agent (or Console) Configuration File -# - -Director { - Name = @basename@-dir - DIRport = @dir_port@ - Address = @hostname@ - Password = "INVALID" -} - -Console { - name = job-backup-bareos-fd - password = secret -} - diff --git a/systemtests/tests/python-restapi/testrunner.in b/systemtests/tests/python-restapi/testrunner similarity index 59% rename from systemtests/tests/python-restapi/testrunner.in rename to systemtests/tests/python-restapi/testrunner index 0dc13b33313..7c49e0c2da8 100755 --- a/systemtests/tests/python-restapi/testrunner.in +++ b/systemtests/tests/python-restapi/testrunner @@ -1,15 +1,16 @@ #!/bin/bash set -e +set -o pipefail set -u # TestName="$(basename "$(pwd)")" export TestName -JobName=backup-bareos-fd #shellcheck source=../environment.in . ./environment +#shellcheck source=environment-local.in +. ./environment-local -JobName=backup-bareos-fd #shellcheck source=../scripts/functions . "${rscripts}"/functions "${rscripts}"/cleanup @@ -24,51 +25,50 @@ start_test start_bareos function endpoint_check { -# $1: method -# $2: endpoint-url +# $1: method (POST, GET) +# $2: endpoint_url # $3: string to grep for # $4: extra curl options # $5: repeat n times with a pause of 1 second between tries to get the result -if [ -z "$5" ]; then - maxTry=1 -else - maxTry=$5 -fi +method="$1" +endpoint_url="$2" +search="$3" +curl_extra_options="${4:-}" +maxTry=${5:-1} + +url="${REST_API_URL}/$2" + +printf \ +'curl --silent --show-error --write-out "%s" \ + -H "Content-Type: application/json" \ + -H "accept: application/json" \ + -H "Authorization: Bearer %s" \ + -X %s \ + %s \ + %s\n\n +' "\n%{http_code}\n" "$TOKEN" "$method" "$url" "$curl_extra_options" > ${tmp}/curl.sh -url="http://127.0.0.1:@restapi_port@/$2" -echo "curl -w \"\n%{http_code}\n\" -s -X $1 $url -H \"accept: application/json\" -H \"Authorization: Bearer $TOKEN\" \"$4\" " >> ${tmp}/../log/curl.log # curl doesn't like empty string "" as option, will exit with code 3 i=0 found="false" -while [ $i -lt $maxTry ] && [ $found == "false" ] -do - if [ -z "$4" ] - then - curl -w "\n%{http_code}\n" -s -X $1 $url -H "accept: application/json" -H "Authorization: Bearer $TOKEN" > ${tmp}/curl.out - else - curl -w "\n%{http_code}\n" -s -X $1 $url -H "accept: application/json" -H "Authorization: Bearer $TOKEN" "$4" > ${tmp}/curl.out - fi +while [ $i -lt $maxTry ] && [ $found == "false" ]; do + cat ${tmp}/curl.sh >> ${tmp}/../log/curl.log + source ${tmp}/curl.sh > ${tmp}/curl.out cat ${tmp}/curl.out >> ${tmp}/../log/curl.log - echo "Search for \"$3\"" >> ${tmp}/../log/curl.log - set +e - grep -q "$3" ${tmp}/curl.out - resultCode=$? - set -e - echo $resultCode >> ${tmp}/../log/curl.log - echo "------------" >> ${tmp}/../log/curl.log - - if [ $resultCode -ne 0 ] - then print_debug "ERROR getting endpoint $2 with method $1, try $i of $maxTry" - else found=true - fi - if [ $maxTry -gt 1 ] && [ $found == "false" ]; then + printf 'Searching for "%s": ' "$search" >> ${tmp}/../log/curl.log + if grep -q "$search" ${tmp}/curl.out; then + found="true" + printf "found\n" >> ${tmp}/../log/curl.log + printf -- "--------------------------------------\n\n" >> ${tmp}/../log/curl.log + else + print_debug "ERROR getting endpoint $2 with method $1, try $i of $maxTry" + i=$[$i+1] sleep 1 fi - i=$[$i+1] done if [ $found == "false" ]; then - print_debug "ERROR getting endpoint $2 with method $1 in $maxTry tries, expectected output: \"$3\"" + print_debug "ERROR getting endpoint $2 with method $1 in $maxTry tries, expected output: \"$3\"" exit 1 fi } @@ -78,14 +78,12 @@ done ## TODO: error handling / make sure api gets stopped mkdir -p etc/bareos/bareos-dir.d/schedule mkdir -p etc/bareos/bareos-dir.d/user -cd api -./startapi.sh -sleep 3 -echo "api started" -TOKEN=`curl -X POST "http://127.0.0.1:@restapi_port@/token" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=&username=admin-tls&password=secret&scope=&client_id=&client_secret=" | grep access_token | cut -d '"' -f 4` -#echo $TOKEN -endpoint_check POST "configuration/clients" newClient.$$ "-d {\"name\":\"newClient.$$-fd\",\"address\": \"127.0.0.1\", \"password\": \"string\"}" 1 + +api/restapi.sh start + +TOKEN=$(api/curl-auth.sh) endpoint_check GET "configuration/clients/bareos-fd" bareos-fd "" 1 +endpoint_check POST "configuration/clients" newClient.$$ "-d '{\"name\":\"newClient.$$-fd\", \"address\": \"127.0.0.1\", \"password\": \"string\"}'" 1 endpoint_check GET "configuration/clients" newClient "" 1 endpoint_check GET "configuration/jobs" backup-bareos-fd "" 1 endpoint_check GET "configuration/jobs/backup-bareos-fd" backup-bareos-fd "" 1 @@ -95,7 +93,7 @@ endpoint_check GET "configuration/jobdefs" DefaultJob "" 1 endpoint_check GET "configuration/jobdefs/DefaultJob" DefaultJob "" 1 endpoint_check GET "configuration/pools" Full "" 1 endpoint_check GET "configuration/pools/Full" Full "" 1 -endpoint_check POST "configuration/schedules" mysched.$$ "-d {\"name\":\"mysched.$$\",\"enabled\":\"no\"}" 1 +endpoint_check POST "configuration/schedules" mysched.$$ "-d '{\"name\":\"mysched.$$\",\"enabled\":\"no\"}'" 1 endpoint_check GET "configuration/schedules" mysched "" 1 # On some endpoints director returns empty strings, in this case we grep for http status code 204 (empty document by intention) endpoint_check PUT "control/schedules/disable/mysched.$$" 204 "" 1 @@ -108,19 +106,19 @@ endpoint_check GET "configuration/profiles" operator "" 1 endpoint_check GET "configuration/profiles/operator" operator "" 1 endpoint_check GET "configuration/profiles" operator "" 1 endpoint_check GET "configuration/profiles/operator" operator "" 1 -endpoint_check POST "configuration/users" string "-d {\"name\":\"myuser$$\",\"description\":\"string\"}" 1 +endpoint_check POST "configuration/users" string "-d '{\"name\":\"myuser$$\",\"description\":\"string\"}'" 1 endpoint_check GET "configuration/users" myuser$$ "" 1 endpoint_check GET "configuration/users/myuser$$" myuser$$ "" 1 endpoint_check GET "control/clients" bareos-fd "" 1 endpoint_check GET "control/clients/1" test2-fd "" 1 endpoint_check PUT "control/clients/disable/bareos-fd" 204 "" 1 endpoint_check PUT "control/clients/enable/bareos-fd" 204 "" 1 -endpoint_check POST "control/jobs/run" jobid "-d {\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}" 1 -endpoint_check POST "control/jobs/run" jobid "-d {\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}" 1 +endpoint_check POST "control/jobs/run" jobid "-d '{\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}'" 1 +endpoint_check POST "control/jobs/run" jobid "-d '{\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}'" 1 endpoint_check PUT "control/jobs/cancel/2" 200 "" 1 endpoint_check POST "control/jobs/rerun/2" "jobid" "" 1 # try non-existing job -endpoint_check GET "control/jobs/26544" "not found" "" 1 +endpoint_check GET "control/jobs/999999" "not found" "" 1 endpoint_check GET "control/jobs/1" "jobstatus" "" 1 endpoint_check GET "control/jobs/totals" "jobs" "" 1 endpoint_check GET "control/jobs" "jobs" "" 1 @@ -128,16 +126,15 @@ endpoint_check GET "control/jobs/logs/1" "joblog" "" 1 endpoint_check GET "control/jobs/files/1" "filenames" "" 1 # sometimes Full hasn't finished, we retry until restore works sleep 3 -endpoint_check POST "control/jobs/restore" "jobid" "-d {\"jobControl\":{\"client\":\"bareos-fd\",\"selectAllDone\":\"yes\"}}" 10 -# TODO: loop here until jobid 1 has finished instead of sleep +endpoint_check POST "control/jobs/restore" "jobid" "-d '{\"jobControl\":{\"client\":\"bareos-fd\",\"selectAllDone\":\"yes\"}}'" 10 # TODO: loop here until jobid 1 has finished instead of sleep endpoint_check DELETE "control/jobs/1" "deleted" "" 1 endpoint_check DELETE "control/jobs/63535" "No job" "" 1 endpoint_check GET "control/volumes" "volumes" "" 1 # label volume fails inside centos7 container - TODO find out why -endpoint_check POST "control/volumes" 204 "-d {\"volume\":\"Full-$$\",\"pool\":\"Full\",\"storage\":\"File\"} " 5 -endpoint_check PATCH "control/volumes/Full-$$" "Recycle" "-d {\"pool\":\"Full\",\"volstatus\":\"Recycle\"} " 5 -endpoint_check PUT "control/volumes/Full-$$" 204 "-d {\"volume\":\"Full-00$$\",\"storage\":\"File\",\"pool\":\"Full\",\"encrypt\":\"yes\"} " 5 +endpoint_check POST "control/volumes" 204 "-d '{\"volume\":\"Full-$$\",\"pool\":\"Full\",\"storage\":\"File\"}'" 5 +endpoint_check PATCH "control/volumes/Full-$$" "Recycle" "-d '{\"pool\":\"Full\",\"volstatus\":\"Recycle\"}'" 5 +endpoint_check PUT "control/volumes/Full-$$" 204 "-d '{\"volume\":\"Full-00$$\",\"storage\":\"File\",\"pool\":\"Full\",\"encrypt\":\"yes\"}'" 5 endpoint_check GET "control/volumes/1" "mediaid" "" 1 endpoint_check GET "control/volumes/188" "No volume" "" 1 endpoint_check GET "control/pools" "pools" "" 1 @@ -147,8 +144,7 @@ endpoint_check GET "control/directors/version" "bareos-dir" "" 1 endpoint_check GET "control/directors/time" "year" "" 1 endpoint_check PUT "control/directors/reload" "success" "" 1 -./stopapi.sh -cd - +api/restapi.sh stop #check_for_zombie_jobs storage=File client=bareos-fd diff --git a/systemtests/tests/python-restapi/write.sh b/systemtests/tests/python-restapi/write.sh deleted file mode 100755 index 1d81aa90b4f..00000000000 --- a/systemtests/tests/python-restapi/write.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -file=$1 -shift - -printf "date=%s\n" "$(LANG=C date)" | tee --append $file -for i in "$@"; do - echo "$i" | tee --append $file -done From eb071528f1b58f3c97d0d97b2ef117d6c71c3c04 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Mon, 30 Aug 2021 19:17:14 +0200 Subject: [PATCH 02/10] restapi: let PUT return code 200 instead of 204 (No Content) by default. If using return 204, content have to be None, which is not the case in this code. --- rest-api/bareos_restapi/__init__.py | 35 +++++------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/rest-api/bareos_restapi/__init__.py b/rest-api/bareos_restapi/__init__.py index 5bbfd3292e9..1f446c6267f 100644 --- a/rest-api/bareos_restapi/__init__.py +++ b/rest-api/bareos_restapi/__init__.py @@ -4,7 +4,7 @@ # # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# Copyright (C) 2020-2021 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -291,8 +291,7 @@ def switch_resource( % (componentType, resourceName, CONFIG_DIRECTOR_NAME, e) }, ) - # json result from director is empty - response.status_code = 204 + response.status_code = 200 return (True, responseDict) @@ -506,10 +505,6 @@ def enable_client( componentType="client", enable=True, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage @@ -531,10 +526,6 @@ def disable_client( componentType="client", enable=False, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage @@ -826,10 +817,6 @@ def enable_job( componentType="job", enable=True, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage @@ -851,10 +838,6 @@ def disable_job( componentType="job", enable=False, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage @@ -1273,7 +1256,7 @@ def read_volume( return {"message": "No volume with id %d found" % volume_id} -@app.post("/control/volumes", status_code=204, tags=["volumes", "control"]) +@app.post("/control/volumes", status_code=200, tags=["volumes", "control"]) def label_volume( *, response: Response, @@ -1416,7 +1399,7 @@ def import_volume( return responseDict -@app.put("/control/volumes/{volume_name}", status_code=204, tags=["volumes", "control"]) +@app.put("/control/volumes/{volume_name}", status_code=200, tags=["volumes", "control"]) def relabel_volume( *, response: Response, @@ -1443,7 +1426,7 @@ def relabel_volume( % (CONFIG_DIRECTOR_NAME, e) } # Director delivers empty response - response.status_code = 204 + response.status_code = 200 return responseDict @@ -1681,10 +1664,6 @@ def enable_schedule( componentType="schedule", enable=True, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage @@ -1706,10 +1685,6 @@ def disable_schedule( componentType="schedule", enable=False, ) - if result: - response.status_code = 204 # ok, but empty return-string - else: - response.status_code = 500 return jsonMessage From 24efa7608366740e25d5a4b5537211dc5669091f Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Mon, 30 Aug 2021 19:20:17 +0200 Subject: [PATCH 03/10] systemtest restapi: put response code 200 PUT operations now return response code 200. Before, it have been 204 (No Content). Adapted the systemtest accordingly. --- systemtests/tests/python-restapi/testrunner | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/systemtests/tests/python-restapi/testrunner b/systemtests/tests/python-restapi/testrunner index 7c49e0c2da8..fb53f1a4117 100755 --- a/systemtests/tests/python-restapi/testrunner +++ b/systemtests/tests/python-restapi/testrunner @@ -68,6 +68,8 @@ while [ $i -lt $maxTry ] && [ $found == "false" ]; do fi done if [ $found == "false" ]; then + printf "NOT FOUND\n" >> ${tmp}/../log/curl.log + printf -- "--------------------------------------\n\n" >> ${tmp}/../log/curl.log print_debug "ERROR getting endpoint $2 with method $1 in $maxTry tries, expected output: \"$3\"" exit 1 fi @@ -96,8 +98,8 @@ endpoint_check GET "configuration/pools/Full" Full "" 1 endpoint_check POST "configuration/schedules" mysched.$$ "-d '{\"name\":\"mysched.$$\",\"enabled\":\"no\"}'" 1 endpoint_check GET "configuration/schedules" mysched "" 1 # On some endpoints director returns empty strings, in this case we grep for http status code 204 (empty document by intention) -endpoint_check PUT "control/schedules/disable/mysched.$$" 204 "" 1 -endpoint_check PUT "control/schedules/enable/mysched.$$" 204 "" 1 +endpoint_check PUT "control/schedules/disable/mysched.$$" 200 "" 1 +endpoint_check PUT "control/schedules/enable/mysched.$$" 200 "" 1 endpoint_check GET "configuration/storages" File "" 1 endpoint_check GET "configuration/storages/File" File "" 1 endpoint_check GET "configuration/consoles" admin-tls "" 1 @@ -111,8 +113,8 @@ endpoint_check GET "configuration/users" myuser$$ "" 1 endpoint_check GET "configuration/users/myuser$$" myuser$$ "" 1 endpoint_check GET "control/clients" bareos-fd "" 1 endpoint_check GET "control/clients/1" test2-fd "" 1 -endpoint_check PUT "control/clients/disable/bareos-fd" 204 "" 1 -endpoint_check PUT "control/clients/enable/bareos-fd" 204 "" 1 +endpoint_check PUT "control/clients/disable/bareos-fd" 200 "" 1 +endpoint_check PUT "control/clients/enable/bareos-fd" 200 "" 1 endpoint_check POST "control/jobs/run" jobid "-d '{\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}'" 1 endpoint_check POST "control/jobs/run" jobid "-d '{\"jobControl\":{\"job\":\"backup-bareos-fd\",\"joblevel\":\"Full\"}}'" 1 endpoint_check PUT "control/jobs/cancel/2" 200 "" 1 @@ -132,9 +134,9 @@ endpoint_check DELETE "control/jobs/1" "deleted" "" 1 endpoint_check DELETE "control/jobs/63535" "No job" "" 1 endpoint_check GET "control/volumes" "volumes" "" 1 # label volume fails inside centos7 container - TODO find out why -endpoint_check POST "control/volumes" 204 "-d '{\"volume\":\"Full-$$\",\"pool\":\"Full\",\"storage\":\"File\"}'" 5 +endpoint_check POST "control/volumes" 200 "-d '{\"volume\":\"Full-$$\",\"pool\":\"Full\",\"storage\":\"File\"}'" 5 endpoint_check PATCH "control/volumes/Full-$$" "Recycle" "-d '{\"pool\":\"Full\",\"volstatus\":\"Recycle\"}'" 5 -endpoint_check PUT "control/volumes/Full-$$" 204 "-d '{\"volume\":\"Full-00$$\",\"storage\":\"File\",\"pool\":\"Full\",\"encrypt\":\"yes\"}'" 5 +endpoint_check PUT "control/volumes/Full-$$" 200 "-d '{\"volume\":\"Full-00$$\",\"storage\":\"File\",\"pool\":\"Full\",\"encrypt\":\"yes\"}'" 5 endpoint_check GET "control/volumes/1" "mediaid" "" 1 endpoint_check GET "control/volumes/188" "No volume" "" 1 endpoint_check GET "control/pools" "pools" "" 1 From d34c22dd18ceb7bcb648e32281a56bf5cc8b5472 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Wed, 8 Sep 2021 17:53:00 +0200 Subject: [PATCH 04/10] restapi: publish to pypi --- .github/workflows/publish_restapi_to_pypi.yml | 49 +++++++++++++++ .../publish_restapi_to_test-pypi.yml | 59 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/workflows/publish_restapi_to_pypi.yml create mode 100644 .github/workflows/publish_restapi_to_test-pypi.yml diff --git a/.github/workflows/publish_restapi_to_pypi.yml b/.github/workflows/publish_restapi_to_pypi.yml new file mode 100644 index 00000000000..1b2219df395 --- /dev/null +++ b/.github/workflows/publish_restapi_to_pypi.yml @@ -0,0 +1,49 @@ +name: "[Release] bareos-restapi -> https://pypi.org/" + +on: + push: + tags: + - Release/* + +jobs: + build-and-publish: + name: "Build bareos-restapi and publish it to https://pypi.org/" + runs-on: ubuntu-20.04 + + steps: + - name: "Checkout source" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: "Checkout tags" + # for get-version.sh, an unshallow git checkout with tags is needed. + run: git fetch --tag + + - name: "Set up Python" + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: "Build python package" + run: | + pip install --user wheel + cd rest-api + # sdist mangles around with version information. + # We replace ~pre with dev, as this will not be modified. + # (pre will be replaced with rc). + ../docs/manuals/source/get-version.sh > bareos_restapi/VERSION.txt + printf "Version: %s\n" $(cat bareos_restapi/VERSION.txt) + python setup.py sdist bdist_wheel + + - name: "Create artifact" + # creating an artifact is not required for publishing to pypi. + uses: actions/upload-artifact@v2 + with: + path: rest-api/dist/ + + - name: "Publish to pypi.org" + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + password: ${{ secrets.restapi_pypi_password }} + packages_dir: python-bareos/dist/ diff --git a/.github/workflows/publish_restapi_to_test-pypi.yml b/.github/workflows/publish_restapi_to_test-pypi.yml new file mode 100644 index 00000000000..4f0859f0d69 --- /dev/null +++ b/.github/workflows/publish_restapi_to_test-pypi.yml @@ -0,0 +1,59 @@ +name: "bareos-restapi -> https://test.pypi.org/" + +# +# build a bareos-restapi dev package +# for every change in master, +# affecting the relevant files. +# + +on: + push: + branches: + - master + paths: + - rest-api/** + - .github/workflows/publish_restapi_to_test-pypi.yml + +jobs: + build-and-publish: + name: "Build bareos-restapi and publish it to https://test.pypi.org/" + runs-on: ubuntu-20.04 + + steps: + - name: "Checkout source" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: "Checkout tags" + # for get-version.sh, an unshallow git checkout with tags is needed. + run: git fetch --tag + + - name: "Set up Python" + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: "Build python package" + run: | + pip install --user wheel + cd rest-api + # sdist mangles around with version information. + # We replace ~pre with dev, as this will not be modified. + # (pre will be replaced with rc). + ../docs/manuals/source/get-version.sh > bareos_restapi/VERSION.txt + printf "Version: %s\n" $(cat bareos_restapi/VERSION.txt) + python setup.py sdist bdist_wheel + + - name: "Create artifact" + # creating an artifact is not required for publishing to pypi. + uses: actions/upload-artifact@v2 + with: + path: rest-api/dist/ + + - name: "Publish to test.pypi.org" + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + repository_url: https://test.pypi.org/legacy/ + password: ${{ secrets.restapi_test_pypi_password }} + packages_dir: rest-api/dist/ From 88e2ca79b1d62195d04ce6b99cce9bbe8ea267c8 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Wed, 8 Sep 2021 19:09:52 +0200 Subject: [PATCH 05/10] restapi: update documentation Update the documentation. Move chapter to the end of API chapter. --- docs/manuals/source/DeveloperGuide/api.rst | 125 +++++++++++---------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/docs/manuals/source/DeveloperGuide/api.rst b/docs/manuals/source/DeveloperGuide/api.rst index 2a2f6d50c0b..2d2e4c023fe 100644 --- a/docs/manuals/source/DeveloperGuide/api.rst +++ b/docs/manuals/source/DeveloperGuide/api.rst @@ -432,63 +432,6 @@ Example of a JSON-RPC Error Response (``void UAContext::error_msg(const char *fmt, ...)``). Messages and the result so far will be part of the error response object. -.. _sec:REST: - -REST API --------- - -Introduction -~~~~~~~~~~~~ -This is an experimental and preliminary backend for development purposes. The endpoints are subject to review and may change in the future. - -It provides a REST API using `fastapi `_ and python-bareos to connect to -a Bareos director. It supports the :command:`configure add` commands to create configuration for clients, jobs, filesets and some more resources. It also provides endpoints to query job information and job control (i.e. start / restart jobs, trigger restores). - -Python3 is needed to run the REST API. - -Installation -~~~~~~~~~~~~ -Use pip to install: -:command:`pip3 install python-bareos-restapi` -This will also install dependencies like fastapi, uvicorn and some more. - - -Configuration -~~~~~~~~~~~~~ - -Configure your Bareos Server in :file:`api.ini` adapting these 3 lines of configuration: - -.. code-block:: cfg - - [Director] - Name=bareos-dir - Address=127.0.0.1 - Port=9101 - -To configure the webserver uvicorn (e.g. adapt used network interfaces, ports), read the `uvicorn -documentation `_. The default port is 8000 and the default interface is the loopback device. - -Start the backend server -~~~~~~~~~~~~~~~~~~~~~~~~ - -:command:`uvicorn bareos-restapi:app --reload` - -Serve the Swagger UI to explore the REST API: ``_ -Alternatively you can use the redoc format: ``_ - - -Browse -~~~~~~ - -The Swagger UI contains documentation and online-tests. Use "authorize" to connect to your Bareos director using a named console. Read here to learn how to configure -a named console: :ref:`DirectorResourceConsole` - -The Swagger documentation also contains CURL statements for all available endpoints. - -Future work -~~~~~~~~~~~ - -The API will be extended by some methods provided by the Bareos console, that are not yet implemented. It is also planned to add delete / update options for configuration in the director and REST API. If you are interested in support and / or funding enhancements, please visit ``_ .. _sec:bvfs: @@ -864,3 +807,71 @@ Example for directory browsing using bvfs 1 1067 127 z Glnc IHo B GHH GHH A NVkY BAA BrA BaKDT2 BaKDT2 BaKDT2 A A C 928EB+EJGFtWD7wQ8bVjew Incremental-0007 0 # multiple versions of the file bareos-dir have been backed up. + + + +.. _sec:REST: + +REST API +-------- + +Introduction +~~~~~~~~~~~~ +This is an experimental and preliminary backend for development purposes. The endpoints are subject to review and may change in the future. + +It provides a REST API using `fastapi `_ and python-bareos to connect to +a Bareos director. It supports the :command:`configure add` commands to create configuration for clients, jobs, filesets and some more resources. It also provides endpoints to query job information and job control (i.e. start / restart jobs, trigger restores). + +Python >= 3 is needed to run the REST API. + +Installation +~~~~~~~~~~~~ +Use pip to install: + +.. code-block:: shell-session + + pip install bareos-restapi + + +This will also install dependencies like fastapi, uvicorn and some more. + + +Configuration +~~~~~~~~~~~~~ + +Configure your Bareos Server in :file:`api.ini` adapting these 3 lines of configuration: + +.. code-block:: cfg + + [Director] + Name=bareos-dir + Address=127.0.0.1 + Port=9101 + +To configure the webserver uvicorn (e.g. adapt used network interfaces, ports), read the `uvicorn +documentation `_. The default port is 8000 and the default interface is the loopback device. + +Start the backend server +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: shell-session + + uvicorn bareos_restapi:app --reload + + +Serve the Swagger UI to explore the REST API: ``_ +Alternatively you can use the redoc format: ``_ + + +Browse +~~~~~~ + +The Swagger UI contains documentation and online-tests. Use "authorize" to connect to your Bareos director using a named console. Read here to learn how to configure +a named console: :ref:`DirectorResourceConsole` + +The Swagger documentation also contains CURL statements for all available endpoints. + +Future work +~~~~~~~~~~~ + +The API will be extended by some methods provided by the Bareos console, that are not yet implemented. It is also planned to add delete / update options for configuration in the director and REST API. If you are interested in support and / or funding enhancements, please visit ``_ From 52bf39eb9a0b44eac2d5557371b6685d72a15d34 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 8 Oct 2021 08:29:01 +0200 Subject: [PATCH 06/10] restapi: renamed systemtest python-restapi --- systemtests/tests/CMakeLists.txt | 2 +- systemtests/tests/{python-restapi => restapi}/CMakeLists.txt | 3 ++- systemtests/tests/{python-restapi => restapi}/api/api.ini.in | 0 systemtests/tests/{python-restapi => restapi}/api/curl-auth.sh | 0 systemtests/tests/{python-restapi => restapi}/api/curl-call.sh | 0 systemtests/tests/{python-restapi => restapi}/api/restapi.sh | 0 .../tests/{python-restapi => restapi}/environment-local.in | 0 .../etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../etc/bareos/bareos-dir.d/client/bareos-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/client/test2-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/console/admin-tls.conf | 0 .../etc/bareos/bareos-dir.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/Catalog.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in | 0 .../etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in | 0 .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf | 0 .../etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Daemon.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Standard.conf.in | 0 .../etc/bareos/bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../etc/bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../etc/bareos/bareos-dir.d/profile/all.conf | 0 .../etc/bareos/bareos-dir.d/profile/operator.conf | 0 .../etc/bareos/bareos-dir.d/storage/File.conf.in | 0 .../etc/bareos/bareos-fd.d/client/myself.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-fd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/device/FileStorage.conf | 0 .../etc/bareos/bareos-sd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-sd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-sd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole-admin-tls.conf.in | 0 .../{python-restapi => restapi}/etc/bareos/bconsole.conf.in | 0 systemtests/tests/{python-restapi => restapi}/testrunner | 0 .../testrunner_container_centos7.in | 0 39 files changed, 3 insertions(+), 2 deletions(-) rename systemtests/tests/{python-restapi => restapi}/CMakeLists.txt (94%) rename systemtests/tests/{python-restapi => restapi}/api/api.ini.in (100%) rename systemtests/tests/{python-restapi => restapi}/api/curl-auth.sh (100%) rename systemtests/tests/{python-restapi => restapi}/api/curl-call.sh (100%) rename systemtests/tests/{python-restapi => restapi}/api/restapi.sh (100%) rename systemtests/tests/{python-restapi => restapi}/environment-local.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/client/test2-fd.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/console/admin-tls.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/profile/all.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bconsole-admin-tls.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{python-restapi => restapi}/testrunner (100%) rename systemtests/tests/{python-restapi => restapi}/testrunner_container_centos7.in (100%) diff --git a/systemtests/tests/CMakeLists.txt b/systemtests/tests/CMakeLists.txt index c3b759bbe96..b1bcdd206d2 100644 --- a/systemtests/tests/CMakeLists.txt +++ b/systemtests/tests/CMakeLists.txt @@ -60,9 +60,9 @@ add_subdirectory(py2plug-fd-vmware) add_subdirectory(py2plug-sd) add_subdirectory(python-bareos) add_subdirectory(python-pam) -add_subdirectory(python-restapi) add_subdirectory(quota-softquota) add_subdirectory(reload) +add_subdirectory(restapi) add_subdirectory(scheduler-backup) add_subdirectory(sparse-file) add_subdirectory(spool) diff --git a/systemtests/tests/python-restapi/CMakeLists.txt b/systemtests/tests/restapi/CMakeLists.txt similarity index 94% rename from systemtests/tests/python-restapi/CMakeLists.txt rename to systemtests/tests/restapi/CMakeLists.txt index 4390ef7338e..2f24a112be2 100644 --- a/systemtests/tests/python-restapi/CMakeLists.txt +++ b/systemtests/tests/restapi/CMakeLists.txt @@ -22,9 +22,10 @@ check_pymodule_available(3 fastapi) check_pymodule_available(3 uvicorn) find_program(CURL curl) -# python-restapi-test does not work on installed files and needs some modules +# restapi does not work on installed files and needs some modules if(PYTHON_EXECUTABLE AND CURL + AND PYTHON AND PYMODULE_3_FASTAPI_FOUND AND PYMODULE_3_UVICORN_FOUND AND NOT RUN_SYSTEMTESTS_ON_INSTALLED_FILES diff --git a/systemtests/tests/python-restapi/api/api.ini.in b/systemtests/tests/restapi/api/api.ini.in similarity index 100% rename from systemtests/tests/python-restapi/api/api.ini.in rename to systemtests/tests/restapi/api/api.ini.in diff --git a/systemtests/tests/python-restapi/api/curl-auth.sh b/systemtests/tests/restapi/api/curl-auth.sh similarity index 100% rename from systemtests/tests/python-restapi/api/curl-auth.sh rename to systemtests/tests/restapi/api/curl-auth.sh diff --git a/systemtests/tests/python-restapi/api/curl-call.sh b/systemtests/tests/restapi/api/curl-call.sh similarity index 100% rename from systemtests/tests/python-restapi/api/curl-call.sh rename to systemtests/tests/restapi/api/curl-call.sh diff --git a/systemtests/tests/python-restapi/api/restapi.sh b/systemtests/tests/restapi/api/restapi.sh similarity index 100% rename from systemtests/tests/python-restapi/api/restapi.sh rename to systemtests/tests/restapi/api/restapi.sh diff --git a/systemtests/tests/python-restapi/environment-local.in b/systemtests/tests/restapi/environment-local.in similarity index 100% rename from systemtests/tests/python-restapi/environment-local.in rename to systemtests/tests/restapi/environment-local.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/client/test2-fd.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/client/test2-fd.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/client/test2-fd.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/client/test2-fd.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/console/admin-tls.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/console/admin-tls.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/console/admin-tls.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/console/admin-tls.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/profile/all.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/profile/all.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/profile/all.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/profile/all.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/restapi/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/restapi/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/restapi/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/restapi/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/restapi/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/restapi/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/restapi/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/restapi/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bconsole-admin-tls.conf.in b/systemtests/tests/restapi/etc/bareos/bconsole-admin-tls.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bconsole-admin-tls.conf.in rename to systemtests/tests/restapi/etc/bareos/bconsole-admin-tls.conf.in diff --git a/systemtests/tests/python-restapi/etc/bareos/bconsole.conf.in b/systemtests/tests/restapi/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/python-restapi/etc/bareos/bconsole.conf.in rename to systemtests/tests/restapi/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/python-restapi/testrunner b/systemtests/tests/restapi/testrunner similarity index 100% rename from systemtests/tests/python-restapi/testrunner rename to systemtests/tests/restapi/testrunner diff --git a/systemtests/tests/python-restapi/testrunner_container_centos7.in b/systemtests/tests/restapi/testrunner_container_centos7.in similarity index 100% rename from systemtests/tests/python-restapi/testrunner_container_centos7.in rename to systemtests/tests/restapi/testrunner_container_centos7.in From ee41aee51255aad418bffa0d5bd93850cdb778f2 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 17 Sep 2021 14:21:49 +0200 Subject: [PATCH 07/10] restapi: renamed rest-api to restapi --- .github/workflows/publish_restapi_to_pypi.yml | 4 ++-- .github/workflows/publish_restapi_to_test-pypi.yml | 8 ++++---- {rest-api => restapi}/LICENSE | 0 {rest-api => restapi}/README.md | 2 +- {rest-api => restapi}/bareos_restapi/__init__.py | 0 {rest-api => restapi}/bareos_restapi/api.ini.example | 0 {rest-api => restapi}/bareos_restapi/metatags.yaml | 0 {rest-api => restapi}/bareos_restapi/models.py | 0 {rest-api => restapi}/bareos_restapi/openapi.json | 0 {rest-api => restapi}/requirements.txt | 0 {rest-api => restapi}/setup.py | 0 systemtests/tests/restapi/api/restapi.sh | 4 ++-- 12 files changed, 9 insertions(+), 9 deletions(-) rename {rest-api => restapi}/LICENSE (100%) rename {rest-api => restapi}/README.md (97%) rename {rest-api => restapi}/bareos_restapi/__init__.py (100%) rename {rest-api => restapi}/bareos_restapi/api.ini.example (100%) rename {rest-api => restapi}/bareos_restapi/metatags.yaml (100%) rename {rest-api => restapi}/bareos_restapi/models.py (100%) rename {rest-api => restapi}/bareos_restapi/openapi.json (100%) rename {rest-api => restapi}/requirements.txt (100%) rename {rest-api => restapi}/setup.py (100%) diff --git a/.github/workflows/publish_restapi_to_pypi.yml b/.github/workflows/publish_restapi_to_pypi.yml index 1b2219df395..8f50b8eec09 100644 --- a/.github/workflows/publish_restapi_to_pypi.yml +++ b/.github/workflows/publish_restapi_to_pypi.yml @@ -28,7 +28,7 @@ jobs: - name: "Build python package" run: | pip install --user wheel - cd rest-api + cd restapi # sdist mangles around with version information. # We replace ~pre with dev, as this will not be modified. # (pre will be replaced with rc). @@ -40,7 +40,7 @@ jobs: # creating an artifact is not required for publishing to pypi. uses: actions/upload-artifact@v2 with: - path: rest-api/dist/ + path: restapi/dist/ - name: "Publish to pypi.org" uses: pypa/gh-action-pypi-publish@v1.4.2 diff --git a/.github/workflows/publish_restapi_to_test-pypi.yml b/.github/workflows/publish_restapi_to_test-pypi.yml index 4f0859f0d69..1354d5ad716 100644 --- a/.github/workflows/publish_restapi_to_test-pypi.yml +++ b/.github/workflows/publish_restapi_to_test-pypi.yml @@ -11,7 +11,7 @@ on: branches: - master paths: - - rest-api/** + - restapi/** - .github/workflows/publish_restapi_to_test-pypi.yml jobs: @@ -37,7 +37,7 @@ jobs: - name: "Build python package" run: | pip install --user wheel - cd rest-api + cd restapi # sdist mangles around with version information. # We replace ~pre with dev, as this will not be modified. # (pre will be replaced with rc). @@ -49,11 +49,11 @@ jobs: # creating an artifact is not required for publishing to pypi. uses: actions/upload-artifact@v2 with: - path: rest-api/dist/ + path: restapi/dist/ - name: "Publish to test.pypi.org" uses: pypa/gh-action-pypi-publish@v1.4.2 with: repository_url: https://test.pypi.org/legacy/ password: ${{ secrets.restapi_test_pypi_password }} - packages_dir: rest-api/dist/ + packages_dir: restapi/dist/ diff --git a/rest-api/LICENSE b/restapi/LICENSE similarity index 100% rename from rest-api/LICENSE rename to restapi/LICENSE diff --git a/rest-api/README.md b/restapi/README.md similarity index 97% rename from rest-api/README.md rename to restapi/README.md index 87266569477..1e49aa4965a 100644 --- a/rest-api/README.md +++ b/restapi/README.md @@ -21,7 +21,7 @@ python3 -m venv env # Activate the virtual environment inside the directory source env/bin/activate # Install dependencies into the virtual environment -pip install -i https://test.pypi.org/simple/ python-bareos-restapi +pip install bareos-restapi ``` Note: The optional module _sslpsk_ can be installed manually, if you want encrypted communication between the API and the Bareos director. diff --git a/rest-api/bareos_restapi/__init__.py b/restapi/bareos_restapi/__init__.py similarity index 100% rename from rest-api/bareos_restapi/__init__.py rename to restapi/bareos_restapi/__init__.py diff --git a/rest-api/bareos_restapi/api.ini.example b/restapi/bareos_restapi/api.ini.example similarity index 100% rename from rest-api/bareos_restapi/api.ini.example rename to restapi/bareos_restapi/api.ini.example diff --git a/rest-api/bareos_restapi/metatags.yaml b/restapi/bareos_restapi/metatags.yaml similarity index 100% rename from rest-api/bareos_restapi/metatags.yaml rename to restapi/bareos_restapi/metatags.yaml diff --git a/rest-api/bareos_restapi/models.py b/restapi/bareos_restapi/models.py similarity index 100% rename from rest-api/bareos_restapi/models.py rename to restapi/bareos_restapi/models.py diff --git a/rest-api/bareos_restapi/openapi.json b/restapi/bareos_restapi/openapi.json similarity index 100% rename from rest-api/bareos_restapi/openapi.json rename to restapi/bareos_restapi/openapi.json diff --git a/rest-api/requirements.txt b/restapi/requirements.txt similarity index 100% rename from rest-api/requirements.txt rename to restapi/requirements.txt diff --git a/rest-api/setup.py b/restapi/setup.py similarity index 100% rename from rest-api/setup.py rename to restapi/setup.py diff --git a/systemtests/tests/restapi/api/restapi.sh b/systemtests/tests/restapi/api/restapi.sh index 0fd67374d2f..3abcd05a2f7 100755 --- a/systemtests/tests/restapi/api/restapi.sh +++ b/systemtests/tests/restapi/api/restapi.sh @@ -29,9 +29,9 @@ cd $(dirname "$BASH_SOURCE") . ../environment-local if [ "${PYTHONPATH:-}" ]; then - export PYTHONPATH=${CMAKE_SOURCE_DIR}/rest-api/:$PYTHONPATH + export PYTHONPATH=${CMAKE_SOURCE_DIR}/restapi/:$PYTHONPATH else - export PYTHONPATH=${CMAKE_SOURCE_DIR}/rest-api/ + export PYTHONPATH=${CMAKE_SOURCE_DIR}/restapi/ fi start() From ceab808fae99dcec1431a8cadf3abdf5d0c482f7 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Wed, 8 Sep 2021 18:37:52 +0200 Subject: [PATCH 08/10] python-bareos: update github actions script Adapt github action publish script to correspond to publish script for bareos-restapi. --- ...e-to-pypi.yml => publish_python-bareos_to_pypi.yml} | 6 +++--- ...pypi.yml => publish_python-bareos_to_test-pypi.yml} | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) rename .github/workflows/{publish-release-to-pypi.yml => publish_python-bareos_to_pypi.yml} (92%) rename .github/workflows/{publish-to-test-pypi.yml => publish_python-bareos_to_test-pypi.yml} (87%) diff --git a/.github/workflows/publish-release-to-pypi.yml b/.github/workflows/publish_python-bareos_to_pypi.yml similarity index 92% rename from .github/workflows/publish-release-to-pypi.yml rename to .github/workflows/publish_python-bareos_to_pypi.yml index 7a263b43d00..3e09deabd84 100644 --- a/.github/workflows/publish-release-to-pypi.yml +++ b/.github/workflows/publish_python-bareos_to_pypi.yml @@ -8,7 +8,7 @@ on: jobs: build-and-publish: name: "Build python-bareos and publish it to https://pypi.org/" - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: "Checkout source" @@ -21,7 +21,7 @@ jobs: run: git fetch --tag - name: "Set up Python" - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: 3.7 @@ -43,7 +43,7 @@ jobs: path: python-bareos/dist/ - name: "Publish to pypi.org" - uses: pypa/gh-action-pypi-publish@v1.1.0 + uses: pypa/gh-action-pypi-publish@v1.4.2 with: password: ${{ secrets.pypi_password }} packages_dir: python-bareos/dist/ diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish_python-bareos_to_test-pypi.yml similarity index 87% rename from .github/workflows/publish-to-test-pypi.yml rename to .github/workflows/publish_python-bareos_to_test-pypi.yml index 0928e5d6b83..45422a96fd2 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish_python-bareos_to_test-pypi.yml @@ -3,7 +3,7 @@ name: "python-bareos -> https://test.pypi.org/" # # build a python-bareos dev package # for every change in master, -# affecting python-bareos. +# affecting the relevant files. # on: @@ -12,12 +12,12 @@ on: - master paths: - python-bareos/** - - .github/workflows/publish-to-test-pypi.yml + - .github/workflows/publish_python-bareos_to_test-pypi.yml jobs: build-and-publish: name: "Build python-bareos and publish it to https://test.pypi.org/" - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: "Checkout source" @@ -30,7 +30,7 @@ jobs: run: git fetch --tag - name: "Set up Python" - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: 3.7 @@ -52,7 +52,7 @@ jobs: path: python-bareos/dist/ - name: "Publish to test.pypi.org" - uses: pypa/gh-action-pypi-publish@v1.1.0 + uses: pypa/gh-action-pypi-publish@v1.4.2 with: repository_url: https://test.pypi.org/legacy/ password: ${{ secrets.test_pypi_password }} From e16121dcbf70f1233ad8a2121f2e41e5f5e04918 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Fri, 8 Oct 2021 08:29:53 +0200 Subject: [PATCH 09/10] systemtest restapi: enable automatic testing The test has been skipped during automatic testing, as it has been marked as "broken". After the recent changes, we enable automatic testing again. --- systemtests/tests/restapi/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/systemtests/tests/restapi/CMakeLists.txt b/systemtests/tests/restapi/CMakeLists.txt index 2f24a112be2..eb03184a6ec 100644 --- a/systemtests/tests/restapi/CMakeLists.txt +++ b/systemtests/tests/restapi/CMakeLists.txt @@ -31,9 +31,6 @@ if(PYTHON_EXECUTABLE AND NOT RUN_SYSTEMTESTS_ON_INSTALLED_FILES ) create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME}) - set_tests_properties( - ${SYSTEMTEST_PREFIX}${BASENAME} PROPERTIES LABELS "broken" - ) else() create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME} DISABLED) endif() From a8070b38a330271d756742892448b61077b8e89a Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Mon, 11 Oct 2021 11:42:33 +0200 Subject: [PATCH 10/10] systemtest: check requirements for restapi are met The testrunner for system:restapi now checks that modules listed in requirements.txt are installed and skips the test otherwise. --- systemtests/tests/restapi/testrunner | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/systemtests/tests/restapi/testrunner b/systemtests/tests/restapi/testrunner index fb53f1a4117..2a9e5a935c2 100755 --- a/systemtests/tests/restapi/testrunner +++ b/systemtests/tests/restapi/testrunner @@ -11,6 +11,12 @@ export TestName #shellcheck source=environment-local.in . ./environment-local +requirements="${CMAKE_SOURCE_DIR}/restapi/requirements.txt" + +"${PYTHON_EXECUTABLE}" -c \ + "import pkg_resources;pkg_resources.require(open('$requirements',mode='r'))" \ + || exit 77 + #shellcheck source=../scripts/functions . "${rscripts}"/functions "${rscripts}"/cleanup