From 6daa2c65dcf63c63286a6b2cac96cfd48230ae4a Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 27 Sep 2023 14:49:07 -0700 Subject: [PATCH 1/6] Use PyScaffold to set up a project structure Signed-off-by: Zack Cerza --- .coveragerc | 28 ++ .gitignore | 108 +++---- .readthedocs.yml | 27 ++ AUTHORS.md | 6 + CHANGELOG.md | 7 + CONTRIBUTING.md | 302 ++++++++++++++++++ Dockerfile | 3 +- LICENSE.txt | 21 ++ docs/Makefile | 29 ++ docs/_static/.gitignore | 1 + docs/authors.md | 4 + docs/changelog.md | 4 + docs/conf.py | 304 +++++++++++++++++++ docs/contributing.md | 4 + docs/index.md | 26 ++ docs/license.md | 5 + docs/readme.md | 4 + docs/requirements.txt | 7 + pyproject.toml | 9 + requirements.txt | 10 - setup.cfg | 135 ++++++++ setup.py | 21 ++ src/teuthology_api/__init__.py | 16 + src/{ => teuthology_api}/config.py | 0 src/{ => teuthology_api}/main.py | 0 src/{ => teuthology_api}/routes/kill.py | 0 src/{ => teuthology_api}/routes/login.py | 0 src/{ => teuthology_api}/routes/logout.py | 0 src/{ => teuthology_api}/routes/suite.py | 0 src/{ => teuthology_api}/schemas/base.py | 0 src/{ => teuthology_api}/schemas/kill.py | 0 src/{ => teuthology_api}/schemas/schedule.py | 0 src/{ => teuthology_api}/schemas/suite.py | 0 src/{ => teuthology_api}/services/helpers.py | 0 src/{ => teuthology_api}/services/kill.py | 0 src/{ => teuthology_api}/services/suite.py | 0 start_container.sh | 4 +- tests/conftest.py | 10 + tox.ini | 93 ++++++ 39 files changed, 1116 insertions(+), 72 deletions(-) create mode 100644 .coveragerc create mode 100644 .readthedocs.yml create mode 100644 AUTHORS.md create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.txt create mode 100644 docs/Makefile create mode 100644 docs/_static/.gitignore create mode 100644 docs/authors.md create mode 100644 docs/changelog.md create mode 100644 docs/conf.py create mode 100644 docs/contributing.md create mode 100644 docs/index.md create mode 100644 docs/license.md create mode 100644 docs/readme.md create mode 100644 docs/requirements.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/teuthology_api/__init__.py rename src/{ => teuthology_api}/config.py (100%) rename src/{ => teuthology_api}/main.py (100%) rename src/{ => teuthology_api}/routes/kill.py (100%) rename src/{ => teuthology_api}/routes/login.py (100%) rename src/{ => teuthology_api}/routes/logout.py (100%) rename src/{ => teuthology_api}/routes/suite.py (100%) rename src/{ => teuthology_api}/schemas/base.py (100%) rename src/{ => teuthology_api}/schemas/kill.py (100%) rename src/{ => teuthology_api}/schemas/schedule.py (100%) rename src/{ => teuthology_api}/schemas/suite.py (100%) rename src/{ => teuthology_api}/services/helpers.py (100%) rename src/{ => teuthology_api}/services/kill.py (100%) rename src/{ => teuthology_api}/services/suite.py (100%) create mode 100644 tests/conftest.py create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..9025686 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,28 @@ +# .coveragerc to control coverage.py +[run] +branch = True +source = teuthology_api +# omit = bad_file.py + +[paths] +source = + src/ + */site-packages/ + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/.gitignore b/.gitignore index 48da22b..3d98dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,63 +1,55 @@ -.vscode/ -# Byte-compiled / optimized / DLL files -__pycache__/ +# Temporary and binary files +*~ *.py[cod] -*$py.class - -# C extensions *.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg +*.cfg +!.isort.cfg +!setup.cfg +*.orig +*.log +*.pot +__pycache__/* +.cache/* +.*.swp +*/.ipynb_checkpoints/* +.DS_Store + +# Project files +.ropeproject +.project +.pydevproject +.settings +.idea +.vscode +tags + +# Package files *.egg +*.eggs/ +.installed.cfg +*.egg-info + +# Unittest and coverage +htmlcov/* +.coverage +.coverage.* +.tox +junit*.xml +coverage.xml +.pytest_cache/ + +# Build and docs folder/files +build/* +dist/* +sdist/* +docs/api/* +docs/_rst/* +docs/_build/* +cover/* MANIFEST -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json \ No newline at end of file +# Per-project virtualenvs +.venv*/ +.conda*/ +.python-version +venv diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..a2bcab3 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,27 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Build documentation with MkDocs +#mkdocs: +# configuration: mkdocs.yml + +# Optionally build your docs in additional formats such as PDF +formats: + - pdf + +build: + os: ubuntu-22.04 + tools: + python: "3.11" + +python: + install: + - requirements: docs/requirements.txt + - {path: ., method: pip} diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..781f952 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,6 @@ +# Contributors + +* Vallari Agrawal [val.agl002@gmail.com](mailto:val.agl002@gmail.com) +* Kamoltat Sirivadhna [ksirivad@redhat.com](mailto:ksirivad@redhat.com) +* Devansh3712 [devanshamity@gmail.com](mailto:devanshamity@gmail.com) +* Zack Cerza [zack@redhat.com](mailto:zack@redhat.com) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..205cc5e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## Version 0.1 (development) + +- Feature A added +- FIX: nasty bug #1729 fixed +- add your changes here! diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0fabd95 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,302 @@ +# Contributing + +Welcome to `teuthology-api` contributor's guide. + +This document focuses on getting any potential contributor familiarized with +the development processes, but [other kinds of contributions] are also appreciated. + +If you are new to using [git] or have never collaborated in a project previously, +please have a look at [contribution-guide.org]. Other resources are also +listed in the excellent [guide created by FreeCodeCamp] [^contrib1]. + +Please notice, all users and contributors are expected to be **open, +considerate, reasonable, and respectful**. When in doubt, +[Python Software Foundation's Code of Conduct] is a good reference in terms of +behavior guidelines. + +## Issue Reports + +If you experience bugs or general issues with `teuthology-api`, please have a look +on the [issue tracker]. +If you don't see anything useful there, please feel free to fire an issue report. + +:::{tip} +Please don't forget to include the closed issues in your search. +Sometimes a solution was already reported, and the problem is considered +**solved**. +::: + +New issue reports should include information about your programming environment +(e.g., operating system, Python version) and steps to reproduce the problem. +Please try also to simplify the reproduction steps to a very minimal example +that still illustrates the problem you are facing. By removing other factors, +you help us to identify the root cause of the issue. + +## Documentation Improvements + +You can help improve `teuthology-api` docs by making them more readable and coherent, or +by adding missing information and correcting mistakes. + +`teuthology-api` documentation uses [Sphinx] as its main documentation compiler. +This means that the docs are kept in the same repository as the project code, and +that any documentation update is done in the same way was a code contribution. + +We use [CommonMark] with [MyST] extensions as our documentation format. + +When working on documentation changes in your local machine, you can +compile them using [tox] : + +``` +tox -e docs +``` + +and use Python's built-in web server for a preview in your web browser +(`http://localhost:8000`): + +``` +python3 -m http.server --directory 'docs/_build/html' +``` + +## Code Contributions + +```{todo} Please include a reference or explanation about the internals of the project. + + An architecture description, design principles or at least a summary of the + main concepts will make it easy for potential contributors to get started + quickly. +``` + +### Submit an issue + +Before you work on any non-trivial code contribution it's best to first create +a report in the [issue tracker] to start a discussion on the subject. +This often provides additional considerations and avoids unnecessary work. + +### Create an environment + +Before you start coding, we recommend creating an isolated [virtual environment] +to avoid any problems with your installed Python packages. +This can easily be done via either [virtualenv]: + +``` +virtualenv +source /bin/activate +``` + +or [Miniconda]: + +``` +conda create -n teuthology-api python=3 six virtualenv pytest pytest-cov +conda activate teuthology-api +``` + +### Clone the repository + +1. Create an user account on GitHub if you do not already have one. + +2. Fork the project [repository]: click on the *Fork* button near the top of the + page. This creates a copy of the code under your account on GitHub. + +3. Clone this copy to your local disk: + + ``` + git clone git@github.com:YourLogin/teuthology-api.git + cd teuthology-api + ``` + +4. You should run: + + ``` + pip install -U pip setuptools -e . + ``` + + to be able to import the package under development in the Python REPL. + +5. Install [pre-commit]: + + ``` + pip install pre-commit + pre-commit install + ``` + + `teuthology-api` comes with a lot of hooks configured to automatically help the + developer to check the code being written. + +### Implement your changes + +1. Create a branch to hold your changes: + + ``` + git checkout -b my-feature + ``` + + and start making changes. Never work on the main branch! + +2. Start your work on this branch. Don't forget to add [docstrings] to new + functions, modules and classes, especially if they are part of public APIs. + +3. Add yourself to the list of contributors in `AUTHORS.rst`. + +4. When you’re done editing, do: + + ``` + git add + git commit + ``` + + to record your changes in [git]. + + Please make sure to see the validation messages from [pre-commit] and fix + any eventual issues. + This should automatically use [flake8]/[black] to check/fix the code style + in a way that is compatible with the project. + + :::{important} + Don't forget to add unit tests and documentation in case your + contribution adds an additional feature and is not just a bugfix. + + Moreover, writing a [descriptive commit message] is highly recommended. + In case of doubt, you can check the commit history with: + + ``` + git log --graph --decorate --pretty=oneline --abbrev-commit --all + ``` + + to look for recurring communication patterns. + ::: + +5. Please check that your changes don't break any unit tests with: + + ``` + tox + ``` + + (after having installed [tox] with `pip install tox` or `pipx`). + + You can also use [tox] to run several other pre-configured tasks in the + repository. Try `tox -av` to see a list of the available checks. + +### Submit your contribution + +1. If everything works fine, push your local branch to the remote server with: + + ``` + git push -u origin my-feature + ``` + +2. Go to the web page of your fork and click "Create pull request" + to send your changes for review. + + Find more detailed information in [creating a PR]. You might also want to open + the PR as a draft first and mark it as ready for review after the feedbacks + from the continuous integration (CI) system or any required fixes. + +### Troubleshooting + +The following tips can be used when facing problems to build or test the +package: + +1. Make sure to fetch all the tags from the upstream [repository]. + The command `git describe --abbrev=0 --tags` should return the version you + are expecting. If you are trying to run CI scripts in a fork repository, + make sure to push all the tags. + You can also try to remove all the egg files or the complete egg folder, i.e., + `.eggs`, as well as the `*.egg-info` folders in the `src` folder or + potentially in the root of your project. + +2. Sometimes [tox] misses out when new dependencies are added, especially to + `setup.cfg` and `docs/requirements.txt`. If you find any problems with + missing dependencies when running a command with [tox], try to recreate the + `tox` environment using the `-r` flag. For example, instead of: + + ``` + tox -e docs + ``` + + Try running: + + ``` + tox -r -e docs + ``` + +3. Make sure to have a reliable [tox] installation that uses the correct + Python version (e.g., 3.7+). When in doubt you can run: + + ``` + tox --version + # OR + which tox + ``` + + If you have trouble and are seeing weird errors upon running [tox], you can + also try to create a dedicated [virtual environment] with a [tox] binary + freshly installed. For example: + + ``` + virtualenv .venv + source .venv/bin/activate + .venv/bin/pip install tox + .venv/bin/tox -e all + ``` + +4. [Pytest can drop you] in an interactive session in the case an error occurs. + In order to do that you need to pass a `--pdb` option (for example by + running `tox -- -k --pdb`). + You can also setup breakpoints manually instead of using the `--pdb` option. + +## Maintainer tasks + +### Releases + +If you are part of the group of maintainers and have correct user permissions +on [PyPI], the following steps can be used to release a new version for +`teuthology-api`: + +1. Make sure all unit tests are successful. +2. Tag the current commit on the main branch with a release tag, e.g., `v1.2.3`. +3. Push the new tag to the upstream [repository], + e.g., `git push upstream v1.2.3` +4. Clean up the `dist` and `build` folders with `tox -e clean` + (or `rm -rf dist build`) + to avoid confusion with old builds and Sphinx docs. +5. Run `tox -e build` and check that the files in `dist` have + the correct version (no `.dirty` or [git] hash) according to the [git] tag. + Also check the sizes of the distributions, if they are too big (e.g., > + 500KB), unwanted clutter may have been accidentally included. +6. Run `tox -e publish -- --repository pypi` and check that everything was + uploaded to [PyPI] correctly. + +[^contrib1]: Even though, these resources focus on open source projects and + communities, the general ideas behind collaborating with other developers + to collectively create software are general and can be applied to all sorts + of environments, including private companies and proprietary code bases. + + +[black]: https://pypi.org/project/black/ +[commonmark]: https://commonmark.org/ +[contribution-guide.org]: http://www.contribution-guide.org/ +[creating a pr]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request +[descriptive commit message]: https://chris.beams.io/posts/git-commit +[docstrings]: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html +[first-contributions tutorial]: https://github.com/firstcontributions/first-contributions +[flake8]: https://flake8.pycqa.org/en/stable/ +[git]: https://git-scm.com +[github web interface]: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/editing-files-in-your-repository +[github's code editor]: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/editing-files-in-your-repository +[github's fork and pull request workflow]: https://guides.github.com/activities/forking/ +[guide created by freecodecamp]: https://github.com/freecodecamp/how-to-contribute-to-open-source +[miniconda]: https://docs.conda.io/en/latest/miniconda.html +[myst]: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html +[other kinds of contributions]: https://opensource.guide/how-to-contribute +[pre-commit]: https://pre-commit.com/ +[pypi]: https://pypi.org/ +[pyscaffold's contributor's guide]: https://pyscaffold.org/en/stable/contributing.html +[pytest can drop you]: https://docs.pytest.org/en/stable/usage.html#dropping-to-pdb-python-debugger-at-the-start-of-a-test +[python software foundation's code of conduct]: https://www.python.org/psf/conduct/ +[restructuredtext]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/ +[sphinx]: https://www.sphinx-doc.org/en/master/ +[tox]: https://tox.readthedocs.io/en/stable/ +[virtual environment]: https://realpython.com/python-virtual-environments-a-primer/ +[virtualenv]: https://virtualenv.pypa.io/en/stable/ +[repository]: https://github.com/ceph/teuthology-api +[issue tracker]: https://github.com/ceph/teuthology-api/issues diff --git a/Dockerfile b/Dockerfile index 29d97ef..bea0162 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,7 @@ RUN apt-get update && \ COPY .teuthology.yaml /root WORKDIR /teuthology_api -COPY requirements.txt *.env start_container.sh /teuthology_api/ -RUN pip3 install -r requirements.txt COPY . /teuthology_api/ +RUN pip3 install -e . CMD sh /teuthology_api/start_container.sh diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..3d6e931 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 IBM Corp. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..31655dd --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,29 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build +AUTODOCDIR = api + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1) +$(error "The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/") +endif + +.PHONY: help clean Makefile + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +clean: + rm -rf $(BUILDDIR)/* $(AUTODOCDIR) + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_static/.gitignore b/docs/_static/.gitignore new file mode 100644 index 0000000..3c96363 --- /dev/null +++ b/docs/_static/.gitignore @@ -0,0 +1 @@ +# Empty directory diff --git a/docs/authors.md b/docs/authors.md new file mode 100644 index 0000000..ced47d0 --- /dev/null +++ b/docs/authors.md @@ -0,0 +1,4 @@ +```{include} ../AUTHORS.md +:relative-docs: docs/ +:relative-images: +``` diff --git a/docs/changelog.md b/docs/changelog.md new file mode 100644 index 0000000..6e2f0fb --- /dev/null +++ b/docs/changelog.md @@ -0,0 +1,4 @@ +```{include} ../CHANGELOG.md +:relative-docs: docs/ +:relative-images: +``` diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..01bc4b4 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,304 @@ +# This file is execfile()d with the current directory set to its containing dir. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import os +import sys +import shutil + +# -- Path setup -------------------------------------------------------------- + +__location__ = os.path.dirname(__file__) + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.join(__location__, "../src")) + +# -- Run sphinx-apidoc ------------------------------------------------------- +# This hack is necessary since RTD does not issue `sphinx-apidoc` before running +# `sphinx-build -b html . _build/html`. See Issue: +# https://github.com/readthedocs/readthedocs.org/issues/1139 +# DON'T FORGET: Check the box "Install your project inside a virtualenv using +# setup.py install" in the RTD Advanced Settings. +# Additionally it helps us to avoid running apidoc manually + +try: # for Sphinx >= 1.7 + from sphinx.ext import apidoc +except ImportError: + from sphinx import apidoc + +output_dir = os.path.join(__location__, "api") +module_dir = os.path.join(__location__, "../src/teuthology_api") +try: + shutil.rmtree(output_dir) +except FileNotFoundError: + pass + +try: + import sphinx + + cmd_line = f"sphinx-apidoc --implicit-namespaces -f -o {output_dir} {module_dir}" + + args = cmd_line.split(" ") + if tuple(sphinx.__version__.split(".")) >= ("1", "7"): + # This is a rudimentary parse_version to avoid external dependencies + args = args[1:] + + apidoc.main(args) +except Exception as e: + print("Running `sphinx-apidoc` failed!\n{}".format(e)) + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.autosummary", + "sphinx.ext.viewcode", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.ifconfig", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + + +# Enable markdown +extensions.append("myst_parser") + +# Configure MyST-Parser +myst_enable_extensions = [ + "amsmath", + "colon_fence", + "deflist", + "dollarmath", + "html_image", + "linkify", + "replacements", + "smartquotes", + "substitution", + "tasklist", +] + +# The suffix of source filenames. +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = "teuthology-api" +copyright = "2023, IBM Corp." + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# version: The short X.Y version. +# release: The full version, including alpha/beta/rc tags. +# If you don’t need the separation provided between version and release, +# just set them both to the same value. +try: + from teuthology_api import __version__ as version +except ImportError: + version = "" + +if not version or version.lower() == "unknown": + version = os.getenv("READTHEDOCS_VERSION", "unknown") # automatically set by RTD + +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".venv"] + +# The reST default role (used for this markup: `text`) to use for all documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If this is True, todo emits a warning for each TODO entries. The default is False. +todo_emit_warnings = True + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "sidebar_width": "300px", + "page_width": "1200px" +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = "" + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = "teuthology-api-doc" + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ("letterpaper" or "a4paper"). + # "papersize": "letterpaper", + # The font size ("10pt", "11pt" or "12pt"). + # "pointsize": "10pt", + # Additional stuff for the LaTeX preamble. + # "preamble": "", +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ("index", "user_guide.tex", "teuthology-api Documentation", "Zack Cerza", "manual") +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = "" + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + +# -- External mapping -------------------------------------------------------- +python_version = ".".join(map(str, sys.version_info[0:2])) +intersphinx_mapping = { + "sphinx": ("https://www.sphinx-doc.org/en/master", None), + "python": ("https://docs.python.org/" + python_version, None), + "matplotlib": ("https://matplotlib.org", None), + "numpy": ("https://numpy.org/doc/stable", None), + "sklearn": ("https://scikit-learn.org/stable", None), + "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), + "setuptools": ("https://setuptools.pypa.io/en/stable/", None), + "pyscaffold": ("https://pyscaffold.org/en/stable", None), +} + +print(f"loading configurations for {project} {version} ...", file=sys.stderr) diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..fc1b213 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,4 @@ +```{include} ../CONTRIBUTING.md +:relative-docs: docs/ +:relative-images: +``` diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..c85ae11 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,26 @@ +# teuthology-api + + +## Contents + +```{toctree} +:maxdepth: 2 + +Overview +Contributions & Help +License +Authors +Changelog +Module Reference +``` + +## Indices and tables + +* {ref}`genindex` +* {ref}`modindex` +* {ref}`search` + +[Sphinx]: http://www.sphinx-doc.org/ +[Markdown]: https://daringfireball.net/projects/markdown/ +[reStructuredText]: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html +[MyST]: https://myst-parser.readthedocs.io/en/latest/ diff --git a/docs/license.md b/docs/license.md new file mode 100644 index 0000000..b231201 --- /dev/null +++ b/docs/license.md @@ -0,0 +1,5 @@ +# License + +```{literalinclude} ../LICENSE.txt +:language: text +``` diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..2cb706b --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,4 @@ +```{include} ../README.md +:relative-docs: docs/ +:relative-images: +``` diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..6d3479a --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,7 @@ +# Requirements file for ReadTheDocs, check .readthedocs.yml. +# To build the module reference correctly, make sure every external package +# under `install_requires` in `setup.cfg` is also listed here! +sphinx>=3.2.1 +sphinx_rtd_theme +m2r +myst-parser[linkify] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..89a5bed --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[build-system] +# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD! +requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +# For smarter version schemes and other configuration options, +# check out https://github.com/pypa/setuptools_scm +version_scheme = "no-guess-dev" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 4c32b7b..0000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -fastapi -uvicorn[standard] -gunicorn -httpx -itsdangerous -black -pydantic-settings -# Temporarily, using teuthology without monkey patching the thread -git+https://github.com/ceph/teuthology@teuth-api#egg=teuthology[test] -# Original: git+https://github.com/ceph/teuthology#egg=teuthology[test] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b2a08ed --- /dev/null +++ b/setup.cfg @@ -0,0 +1,135 @@ +# This file is used to configure your project. +# Read more about the various options under: +# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html +# https://setuptools.pypa.io/en/latest/references/keywords.html + +[metadata] +name = teuthology-api +description = A REST API to execute teuthology commands +author = Vallari Agrawal +author_email = val.agl002@gmail.com +license = MIT +license_files = LICENSE.txt +long_description = file: README.rst +long_description_content_type = text/x-rst; charset=UTF-8 +url = https://github.com/pyscaffold/pyscaffold/ +# Add here related links, for example: +project_urls = + Documentation = https://teuthology-api.readthedocs.io/ +# Source = https://github.com/pyscaffold/pyscaffold/ +# Changelog = https://pyscaffold.org/en/latest/changelog.html +# Tracker = https://github.com/pyscaffold/pyscaffold/issues +# Conda-Forge = https://anaconda.org/conda-forge/pyscaffold +# Download = https://pypi.org/project/PyScaffold/#files +# Twitter = https://twitter.com/PyScaffold + +# Change if running only on Windows, Mac or Linux (comma-separated) +platforms = Linux + +# Add here all kinds of additional classifiers as defined under +# https://pypi.org/classifiers/ +classifiers = + Development Status :: 4 - Beta + Programming Language :: Python + + +[options] +zip_safe = False +packages = find_namespace: +include_package_data = True +package_dir = + =src + +# Require a min/specific Python version (comma-separated conditions) +# python_requires = >=3.8 + +# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0. +# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in +# new major versions. This works if the required packages follow Semantic Versioning. +# For more information, check out https://semver.org/. +install_requires = + importlib-metadata; python_version<"3.8" + fastapi + uvicorn[standard] + gunicorn + httpx + itsdangerous + pydantic-settings + # Temporarily, using teuthology without monkey patching the thread + teuthology @ git+https://github.com/ceph/teuthology@teuth-api#egg=teuthology[test]" + # Original: git+https://github.com/ceph/teuthology#egg=teuthology[test] + + +[options.packages.find] +where = src +exclude = + tests + +[options.extras_require] +# Add here additional requirements for extra features, to install with: +# `pip install teuthology-api[PDF]` like: +# PDF = ReportLab; RXP + +# Add here test requirements (semicolon/line-separated) +testing = + setuptools + pytest + pytest-cov + +[options.entry_points] +# Add here console scripts like: +# console_scripts = +# script_name = teuthology_api.module:function +# For example: +# console_scripts = +# fibonacci = teuthology_api.skeleton:run +# And any other entry points, for example: +# pyscaffold.cli = +# awesome = pyscaffoldext.awesome.extension:AwesomeExtension + +[tool:pytest] +# Specify command line options as you would do when invoking pytest directly. +# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml +# in order to write a coverage file that can be read by Jenkins. +# CAUTION: --cov flags may prohibit setting breakpoints while debugging. +# Comment those flags to avoid this pytest issue. +addopts = + --cov teuthology_api --cov-report term-missing + --verbose +norecursedirs = + dist + build + .tox +testpaths = tests +# Use pytest markers to select/deselect specific tests +# markers = +# slow: mark tests as slow (deselect with '-m "not slow"') +# system: mark end-to-end system tests + +[devpi:upload] +# Options for the devpi: PyPI server and packaging tool +# VCS export must be deactivated since we are using setuptools-scm +no_vcs = 1 +formats = bdist_wheel + +[flake8] +# Some sane defaults for the code style checker flake8 +max_line_length = 88 +extend_ignore = E203, W503 +# ^ Black-compatible +# E203 and W503 have edge cases handled by black +exclude = + .tox + build + dist + .eggs + docs/conf.py + +[pyscaffold] +# PyScaffold's parameters when the project was created. +# This will be used when updating. Do not change! +version = 4.5 +package = teuthology_api +extensions = + markdown + no_skeleton diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..db661a6 --- /dev/null +++ b/setup.py @@ -0,0 +1,21 @@ +""" + Setup file for teuthology-api. + Use setup.cfg to configure your project. + + This file was generated with PyScaffold 4.5. + PyScaffold helps you to put up the scaffold of your new Python project. + Learn more under: https://pyscaffold.org/ +""" +from setuptools import setup + +if __name__ == "__main__": + try: + setup(use_scm_version={"version_scheme": "no-guess-dev"}) + except: # noqa + print( + "\n\nAn error occurred while building the project, " + "please ensure you have the most updated version of setuptools, " + "setuptools_scm and wheel with:\n" + " pip install -U setuptools setuptools_scm wheel\n\n" + ) + raise diff --git a/src/teuthology_api/__init__.py b/src/teuthology_api/__init__.py new file mode 100644 index 0000000..ada9e02 --- /dev/null +++ b/src/teuthology_api/__init__.py @@ -0,0 +1,16 @@ +import sys + +if sys.version_info[:2] >= (3, 8): + # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` + from importlib.metadata import PackageNotFoundError, version # pragma: no cover +else: + from importlib_metadata import PackageNotFoundError, version # pragma: no cover + +try: + # Change here if project is renamed and does not equal the package name + dist_name = "teuthology-api" + __version__ = version(dist_name) +except PackageNotFoundError: # pragma: no cover + __version__ = "unknown" +finally: + del version, PackageNotFoundError diff --git a/src/config.py b/src/teuthology_api/config.py similarity index 100% rename from src/config.py rename to src/teuthology_api/config.py diff --git a/src/main.py b/src/teuthology_api/main.py similarity index 100% rename from src/main.py rename to src/teuthology_api/main.py diff --git a/src/routes/kill.py b/src/teuthology_api/routes/kill.py similarity index 100% rename from src/routes/kill.py rename to src/teuthology_api/routes/kill.py diff --git a/src/routes/login.py b/src/teuthology_api/routes/login.py similarity index 100% rename from src/routes/login.py rename to src/teuthology_api/routes/login.py diff --git a/src/routes/logout.py b/src/teuthology_api/routes/logout.py similarity index 100% rename from src/routes/logout.py rename to src/teuthology_api/routes/logout.py diff --git a/src/routes/suite.py b/src/teuthology_api/routes/suite.py similarity index 100% rename from src/routes/suite.py rename to src/teuthology_api/routes/suite.py diff --git a/src/schemas/base.py b/src/teuthology_api/schemas/base.py similarity index 100% rename from src/schemas/base.py rename to src/teuthology_api/schemas/base.py diff --git a/src/schemas/kill.py b/src/teuthology_api/schemas/kill.py similarity index 100% rename from src/schemas/kill.py rename to src/teuthology_api/schemas/kill.py diff --git a/src/schemas/schedule.py b/src/teuthology_api/schemas/schedule.py similarity index 100% rename from src/schemas/schedule.py rename to src/teuthology_api/schemas/schedule.py diff --git a/src/schemas/suite.py b/src/teuthology_api/schemas/suite.py similarity index 100% rename from src/schemas/suite.py rename to src/teuthology_api/schemas/suite.py diff --git a/src/services/helpers.py b/src/teuthology_api/services/helpers.py similarity index 100% rename from src/services/helpers.py rename to src/teuthology_api/services/helpers.py diff --git a/src/services/kill.py b/src/teuthology_api/services/kill.py similarity index 100% rename from src/services/kill.py rename to src/teuthology_api/services/kill.py diff --git a/src/services/suite.py b/src/teuthology_api/services/suite.py similarity index 100% rename from src/services/suite.py rename to src/teuthology_api/services/suite.py diff --git a/start_container.sh b/start_container.sh index 1dbb424..4c31cb1 100644 --- a/start_container.sh +++ b/start_container.sh @@ -11,5 +11,5 @@ cd /teuthology_api/src/ if [ "$DEPLOYMENT" = "development" ]; then uvicorn main:app --reload --port $PORT --host $HOST else - gunicorn -c /teuthology_api/gunicorn_config.py main:app -fi \ No newline at end of file + gunicorn -c /teuthology_api/gunicorn_config.py teuthology_api.main:app +fi diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..8f9e147 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,10 @@ +""" + Dummy conftest.py for teuthology_api. + + If you don't know what this is for, just leave it empty. + Read more about conftest.py under: + - https://docs.pytest.org/en/stable/fixture.html + - https://docs.pytest.org/en/stable/writing_plugins.html +""" + +# import pytest diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..69f8159 --- /dev/null +++ b/tox.ini @@ -0,0 +1,93 @@ +# Tox configuration file +# Read more under https://tox.wiki/ +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + +[tox] +minversion = 3.24 +envlist = default +isolated_build = True + + +[testenv] +description = Invoke pytest to run automated tests +setenv = + TOXINIDIR = {toxinidir} +passenv = + HOME + SETUPTOOLS_* +extras = + testing +commands = + pytest {posargs} + + +# # To run `tox -e lint` you need to make sure you have a +# # `.pre-commit-config.yaml` file. See https://pre-commit.com +# [testenv:lint] +# description = Perform static analysis and style checks +# skip_install = True +# deps = pre-commit +# passenv = +# HOMEPATH +# PROGRAMDATA +# SETUPTOOLS_* +# commands = +# pre-commit run --all-files {posargs:--show-diff-on-failure} + + +[testenv:{build,clean}] +description = + build: Build the package in isolation according to PEP517, see https://github.com/pypa/build + clean: Remove old distribution files and temporary build artifacts (./build and ./dist) +# https://setuptools.pypa.io/en/stable/build_meta.html#how-to-use-it +skip_install = True +changedir = {toxinidir} +deps = + build: build[virtualenv] +passenv = + SETUPTOOLS_* +commands = + clean: python -c 'import shutil; [shutil.rmtree(p, True) for p in ("build", "dist", "docs/_build")]' + clean: python -c 'import pathlib, shutil; [shutil.rmtree(p, True) for p in pathlib.Path("src").glob("*.egg-info")]' + build: python -m build {posargs} +# By default, both `sdist` and `wheel` are built. If your sdist is too big or you don't want +# to make it available, consider running: `tox -e build -- --wheel` + + +[testenv:{docs,doctests,linkcheck}] +description = + docs: Invoke sphinx-build to build the docs + doctests: Invoke sphinx-build to run doctests + linkcheck: Check for broken links in the documentation +passenv = + SETUPTOOLS_* +setenv = + DOCSDIR = {toxinidir}/docs + BUILDDIR = {toxinidir}/docs/_build + docs: BUILD = html + doctests: BUILD = doctest + linkcheck: BUILD = linkcheck +deps = + -r {toxinidir}/docs/requirements.txt + # ^ requirements.txt shared with Read The Docs +commands = + sphinx-build --color -b {env:BUILD} -d "{env:BUILDDIR}/doctrees" "{env:DOCSDIR}" "{env:BUILDDIR}/{env:BUILD}" {posargs} + + +[testenv:publish] +description = + Publish the package you have been developing to a package index server. + By default, it uses testpypi. If you really want to publish your package + to be publicly accessible in PyPI, use the `-- --repository pypi` option. +skip_install = True +changedir = {toxinidir} +passenv = + # See: https://twine.readthedocs.io/en/latest/ + TWINE_USERNAME + TWINE_PASSWORD + TWINE_REPOSITORY + TWINE_REPOSITORY_URL +deps = twine +commands = + python -m twine check dist/* + python -m twine upload {posargs:--repository {env:TWINE_REPOSITORY:testpypi}} dist/* From cb7a49dc8feb4d8289b814d065b8c479b1e6962d Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 17 Oct 2023 18:54:12 -0600 Subject: [PATCH 2/6] Fix some imports Signed-off-by: Zack Cerza --- src/teuthology_api/main.py | 3 ++- src/teuthology_api/routes/kill.py | 8 +++++--- src/teuthology_api/routes/suite.py | 10 ++++++---- src/teuthology_api/schemas/kill.py | 2 +- src/teuthology_api/schemas/schedule.py | 2 +- src/teuthology_api/schemas/suite.py | 2 +- src/teuthology_api/services/helpers.py | 7 +++++-- src/teuthology_api/services/kill.py | 6 ++++-- src/teuthology_api/services/suite.py | 4 +++- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/teuthology_api/main.py b/src/teuthology_api/main.py index b04fba8..598e286 100644 --- a/src/teuthology_api/main.py +++ b/src/teuthology_api/main.py @@ -3,9 +3,10 @@ from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from starlette.middleware.sessions import SessionMiddleware -from routes import suite, kill, login, logout from dotenv import load_dotenv +from teuthology_api.routes import suite, kill, login, logout + load_dotenv() DEPLOYMENT = os.getenv("DEPLOYMENT") diff --git a/src/teuthology_api/routes/kill.py b/src/teuthology_api/routes/kill.py index 8f6412a..9062f7e 100644 --- a/src/teuthology_api/routes/kill.py +++ b/src/teuthology_api/routes/kill.py @@ -1,8 +1,10 @@ import logging + from fastapi import APIRouter, Depends, Request -from services.kill import run -from services.helpers import get_token -from schemas.kill import KillArgs + +from teuthology_api.services.kill import run +from teuthology_api.services.helpers import get_token +from teuthology_api.schemas.kill import KillArgs log = logging.getLogger(__name__) diff --git a/src/teuthology_api/routes/suite.py b/src/teuthology_api/routes/suite.py index e803879..8233ecf 100644 --- a/src/teuthology_api/routes/suite.py +++ b/src/teuthology_api/routes/suite.py @@ -1,9 +1,11 @@ -from fastapi import APIRouter, HTTPException, Depends -from services.suite import run -from services.helpers import get_token -from schemas.suite import SuiteArgs import logging +from fastapi import APIRouter, HTTPException, Depends + +from teuthology_api.services.suite import run +from teuthology_api.services.helpers import get_token +from teuthology_api.schemas.suite import SuiteArgs + log = logging.getLogger(__name__) router = APIRouter( diff --git a/src/teuthology_api/schemas/kill.py b/src/teuthology_api/schemas/kill.py index 267cfe3..772e1e5 100644 --- a/src/teuthology_api/schemas/kill.py +++ b/src/teuthology_api/schemas/kill.py @@ -1,7 +1,7 @@ from typing import Union from pydantic import Field -from .base import BaseArgs +from teuthology_api.schemas.base import BaseArgs class KillArgs(BaseArgs): diff --git a/src/teuthology_api/schemas/schedule.py b/src/teuthology_api/schemas/schedule.py index c337d7a..4eaeb54 100644 --- a/src/teuthology_api/schemas/schedule.py +++ b/src/teuthology_api/schemas/schedule.py @@ -1,7 +1,7 @@ from typing import Union from pydantic import Field -from .base import BaseArgs +from teuthology_api.schemas.base import BaseArgs class SchedulerArgs(BaseArgs): diff --git a/src/teuthology_api/schemas/suite.py b/src/teuthology_api/schemas/suite.py index ee90db1..409e219 100644 --- a/src/teuthology_api/schemas/suite.py +++ b/src/teuthology_api/schemas/suite.py @@ -1,7 +1,7 @@ from typing import Union from pydantic import Field -from .base import BaseArgs +from teuthology_api.schemas.base import BaseArgs class SuiteArgs(BaseArgs): diff --git a/src/teuthology_api/services/helpers.py b/src/teuthology_api/services/helpers.py index a17d542..8864d7b 100644 --- a/src/teuthology_api/services/helpers.py +++ b/src/teuthology_api/services/helpers.py @@ -2,11 +2,14 @@ import logging import os import uuid -from config import settings + from fastapi import HTTPException, Request -from requests.exceptions import HTTPError + +from teuthology_api.config import settings + import teuthology import requests # Note: import requests after teuthology +from requests.exceptions import HTTPError PADDLES_URL = os.getenv("PADDLES_URL") diff --git a/src/teuthology_api/services/kill.py b/src/teuthology_api/services/kill.py index 053e95a..aa1b157 100644 --- a/src/teuthology_api/services/kill.py +++ b/src/teuthology_api/services/kill.py @@ -1,8 +1,10 @@ -from fastapi import HTTPException, Request -from services.helpers import logs_run, get_username, get_run_details import teuthology.kill import logging +from fastapi import HTTPException, Request + +from teuthology_api.services.helpers import logs_run, get_username, get_run_details + log = logging.getLogger(__name__) diff --git a/src/teuthology_api/services/suite.py b/src/teuthology_api/services/suite.py index bfe09c1..7e251da 100644 --- a/src/teuthology_api/services/suite.py +++ b/src/teuthology_api/services/suite.py @@ -1,8 +1,10 @@ from datetime import datetime import logging import teuthology.suite + from fastapi import HTTPException -from services.helpers import logs_run, get_run_details + +from teuthology_api.services.helpers import logs_run, get_run_details log = logging.getLogger(__name__) From d533c0afa18d400f7584fe7c2097483fcff722ea Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 18 Oct 2023 13:16:53 -0600 Subject: [PATCH 3/6] README.md: Tweak some formatting Signed-off-by: Zack Cerza --- README.md | 62 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 9603378..c938501 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ # Teuthology API -A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuthology/en/latest/commands/list.html). +A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuthology/en/latest/commands/list.html). ## Setup -#### Option 1: (teuthology docker setup) +### Option 1: (teuthology docker setup) 1. Clone [teuthology](https://github.com/ceph/teuthology) and [teuthology-api](https://github.com/VallariAg/teuthology-api). -2. Rename `.env.dev` file to `.env`. +2. Rename `.env.dev` file to `.env`. 3. Configure secrets: - - 3.1. Create a Github OAuth Application by following [these](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) instructions. Set "Homepage URL" as `http://localhost:8082/` and "Authorization callback URL" as `http://localhost:8082/login/callback/`. + + 3.1. Create a Github OAuth Application by following [these](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) instructions. Set "Homepage URL" as `http://localhost:8082/` and "Authorization callback URL" as `http://localhost:8082/login/callback/`. 3.2. Ensure [ceph](https://github.com/ceph) belongs in your public list of organizations[[ref](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-membership-in-organizations/about-organization-membership)]. By default your membership is set private, change that to public by following [these](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-membership-in-organizations/publicizing-or-hiding-organization-membership) steps. 3.3. Save `CLIENT_ID` and `CLIENT_SECRET` from your Github OAuth App to your local `.env` file as `GH_CLIENT_ID` and `GH_CLIENT_SECRET`. 4. Add the following to [teuthology's docker-compose](https://github.com/ceph/teuthology/blob/main/docs/docker-compose/docker-compose.yml) services. + ``` teuthology_api: build: @@ -36,7 +37,6 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth healthcheck: test: [ "CMD", "curl", "-f", "http://0.0.0.0:8082" ] ``` - [optional] For developement use: Add following things in `teuthology_api` container: ``` @@ -47,13 +47,14 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth - ../../../teuthology-api:/teuthology_api/:rw ``` `DEPLOYMENT: development` would run the server in `--reload` mode (server would restart when changes are made in `/src` dir) and `volumes` would mount host directory to docker's directory (local changes would reflect in docker container). -3. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose). + +5. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose). ## Documentation The documentation can be accessed at http://localhost:8082/docs after running the application. -Note: To run commands, authenticate by visiting `http://localhost:8082/login` through browser and follow the github authentication steps (this stores the auth token in browser cookies). +Note: To run commands, authenticate by visiting `http://localhost:8082/login` through browser and follow the github authentication steps (this stores the auth token in browser cookies). ### Route `/` @@ -66,28 +67,29 @@ Returns `{"root": "success", "session": { }}`. POST `/suite/`: schedules a run. -Two query parameters: +Two query parameters: - `dry_run` (boolean) - Do a dry run; do not schedule anything. - `logs` (boolean) - Send scheduling logs in response. -Example: -``` -curl --location --request POST 'http://localhost:8082/suite?dry_run=false&logs=true' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "--ceph": "wip-dis-testing-2", - "--ceph-repo": "https://github.com/ceph/ceph-ci.git", - "--kernel": "distro", - "--limit": "2", - "--newest": "0", - "--machine-type": "testnode", - "--num": "1", - "--priority": "70", - "--suite": "teuthology:no-ceph", - "--suite-branch": "wip-dis-testing-2", - "--suite-repo": "https://github.com/ceph/ceph-ci.git", - "--teuthology-branch": "main", - "--verbose": "1", - "--user": "vallariag" - }' -``` +Example + + curl --location --request POST 'http://localhost:8082/suite?dry_run=false&logs=true' \ + --header 'Content-Type: application/json' \ + --data-raw '{ + "--ceph": "wip-dis-testing-2", + "--ceph-repo": "https://github.com/ceph/ceph-ci.git", + "--kernel": "distro", + "--limit": "2", + "--newest": "0", + "--machine-type": "testnode", + "--num": "1", + "--priority": "70", + "--suite": "teuthology:no-ceph", + "--suite-branch": "wip-dis-testing-2", + "--suite-repo": "https://github.com/ceph/ceph-ci.git", + "--teuthology-branch": "main", + "--verbose": "1", + "--user": "vallariag" + }' + +xxx From 63871706437d966c24557760f106ed0ce97be4be Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 12 Oct 2023 15:28:18 -0600 Subject: [PATCH 4/6] Add and apply a pre-commit configuration Signed-off-by: Zack Cerza --- .env.dev | 4 ++-- .github/workflows/black.yaml | 2 +- .github/workflows/integration.yaml | 2 +- .pre-commit-config.yaml | 11 +++++++++++ .teuthology.yaml | 2 +- docs/conf.py | 5 +---- gh-actions/start.sh | 2 +- gunicorn_config.py | 5 ++--- 8 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.env.dev b/.env.dev index 8aa1f0f..234fb90 100644 --- a/.env.dev +++ b/.env.dev @@ -10,6 +10,6 @@ GH_TOKEN_URL='https://github.com/login/oauth/access_token' GH_FETCH_MEMBERSHIP_URL='https://api.github.com/user/memberships/orgs/ceph' #Session Related Stuff -## SESSION_SECRET_KEY is used to encrypt session data +## SESSION_SECRET_KEY is used to encrypt session data ## and it's prod value should be kept secret. -SESSION_SECRET_KEY=my-secret-key \ No newline at end of file +SESSION_SECRET_KEY=my-secret-key diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml index a061a8e..de97f25 100644 --- a/.github/workflows/black.yaml +++ b/.github/workflows/black.yaml @@ -10,4 +10,4 @@ jobs: - uses: psf/black@stable with: options: "--check --verbose" - src: "./src" \ No newline at end of file + src: "./src" diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 1f8458f..64e7b5d 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -8,4 +8,4 @@ jobs: - uses: actions/checkout@v2 - name: Start teuthology & teuthology-api run: ./start.sh - working-directory: ./gh-actions \ No newline at end of file + working-directory: ./gh-actions diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..48ee030 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black diff --git a/.teuthology.yaml b/.teuthology.yaml index 35c887a..daf22e3 100644 --- a/.teuthology.yaml +++ b/.teuthology.yaml @@ -4,4 +4,4 @@ lock_server: http://paddles:8080 results_server: http://paddles:8080 results_ui_server: http://pulpito:8081/ reserve_machines: 0 -lab_domain: '' \ No newline at end of file +lab_domain: '' diff --git a/docs/conf.py b/docs/conf.py index 01bc4b4..fc49c3e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -176,10 +176,7 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -html_theme_options = { - "sidebar_width": "300px", - "page_width": "1200px" -} +html_theme_options = {"sidebar_width": "300px", "page_width": "1200px"} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] diff --git a/gh-actions/start.sh b/gh-actions/start.sh index b7552e2..7bd37e1 100755 --- a/gh-actions/start.sh +++ b/gh-actions/start.sh @@ -22,4 +22,4 @@ if [ ! -d "$folder" ] ; then " >> teuthology/docs/docker-compose/docker-compose.yml fi cd teuthology/docs/docker-compose -./start.sh \ No newline at end of file +./start.sh diff --git a/gunicorn_config.py b/gunicorn_config.py index a23e7a9..411b855 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -7,9 +7,8 @@ bind = f'{host}:{port}' workers = cpu_count() -worker_class = 'uvicorn.workers.UvicornWorker' +worker_class = "uvicorn.workers.UvicornWorker" # loglevel = 'debug' accesslog = os.path.expanduser("~/teuthology-api.access.log") -# errorlog = os.path.expanduser("~/teuthology-api.error.log") - +# errorlog = os.path.expanduser("~/teuthology-api.error.log") From 2b92e432ca1f2525807ba359d631bcd158488be1 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 20 Oct 2023 13:36:21 -0600 Subject: [PATCH 5/6] README.md: Document non-containerized setup Signed-off-by: Zack Cerza --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c938501..993950e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth context: ../../../teuthology-api ports: - 8082:8080 - environment: + environment: TEUTHOLOGY_API_SERVER_HOST: 0.0.0.0 TEUTHOLOGY_API_SERVER_PORT: 8080 PADDLES_URL: http://localhost:8080 @@ -41,15 +41,27 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth Add following things in `teuthology_api` container: ``` teuthology_api: - environment: + environment: DEPLOYMENT: development - volumes: + volumes: - ../../../teuthology-api:/teuthology_api/:rw ``` - `DEPLOYMENT: development` would run the server in `--reload` mode (server would restart when changes are made in `/src` dir) and `volumes` would mount host directory to docker's directory (local changes would reflect in docker container). + `DEPLOYMENT: development` would run the server in `--reload` mode (server would restart when changes are made in `/src` dir) and `volumes` would mount host directory to docker's directory (local changes would reflect in docker container). 5. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose). +### Option 2: Non-containerized with venv and pip + +1. Clone [teuthology-api](https://github.com/VallariAg/teuthology-api) and `cd` into it. + +2. Create a virtualenv: `python3 -m venv venv` + +3. Activate the virtualenv: `source ./venv/bin/activate` + +4. Build the project: `pip install -e .` + +5. Start the server: `gunicorn -c gunicorn_config.py teuthology_api.main:app` + ## Documentation The documentation can be accessed at http://localhost:8082/docs after running the application. From 9af4dae0879ec9aac7b89b09dbe63cc0244fdf4f Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 23 Oct 2023 15:56:08 -0600 Subject: [PATCH 6/6] README.md: Use ceph org for github URLs Signed-off-by: Zack Cerza --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 993950e..f30c764 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth ### Option 1: (teuthology docker setup) -1. Clone [teuthology](https://github.com/ceph/teuthology) and [teuthology-api](https://github.com/VallariAg/teuthology-api). +1. Clone [teuthology](https://github.com/ceph/teuthology) and [teuthology-api](https://github.com/ceph/teuthology-api). 2. Rename `.env.dev` file to `.env`. 3. Configure secrets: @@ -52,7 +52,7 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth ### Option 2: Non-containerized with venv and pip -1. Clone [teuthology-api](https://github.com/VallariAg/teuthology-api) and `cd` into it. +1. Clone [teuthology-api](https://github.com/ceph/teuthology-api) and `cd` into it. 2. Create a virtualenv: `python3 -m venv venv`