diff --git a/docs/dump-openapi-spec.py b/docs/dump-openapi-spec.py index 8e35e71e44214222f67ea4cd65c331c57c4b7f01..964489e83af35cf1cd2df09aef3b869417d2f2ec 100644 --- a/docs/dump-openapi-spec.py +++ b/docs/dump-openapi-spec.py @@ -6,9 +6,7 @@ import lso config_filename = os.path.join(os.path.dirname(__file__), "..", "config.json.example") -output_filename = os.path.join( - os.path.dirname(__file__), "source", "_static", "openapi.json" -) +output_filename = os.path.join(os.path.dirname(__file__), "source", "_static", "openapi.json") os.environ["SETTINGS_FILENAME"] = config_filename app = lso.create_app() diff --git a/docs/source/conf.py b/docs/source/conf.py index 1be1927aa3d4a5927e8aa07d234c9a79fa93f784..c937decfb950fe541f11c53e1ea9a882e3b1b3b0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -16,9 +16,7 @@ import json import os import sys -sys.path.insert( - 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "lso")) -) +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "lso"))) class RenderAsJSON(Directive): @@ -37,7 +35,7 @@ class RenderAsJSON(Directive): return [ addnodes.desc_name(text=member_name), - addnodes.desc_content("", literal), + addnodes.desc_content("", literal) ] @@ -57,7 +55,7 @@ extensions = [ "sphinx_rtd_theme", "sphinx.ext.autodoc", "sphinx.ext.coverage", - "sphinx.ext.todo", + "sphinx.ext.todo" ] templates_path = ["templates"] @@ -67,9 +65,7 @@ exclude_patterns = [] html_theme = "sphinx_rtd_theme" html_static_path = ["_static"] -html_theme_options = { - "style_nav_header_background": "rgb(0 63 95)", -} +html_theme_options = {"style_nav_header_background": "rgb(0 63 95)"} html_css_files = ["custom.css"] html_logo = "_static/geant_logo_white.svg" diff --git a/lso/__init__.py b/lso/__init__.py index 4a0a358b4bc37d3ef9c2520e9a19f63f44933d51..2d752ef48be81ce5eeba3563f3497f9de9a5fa56 100644 --- a/lso/__init__.py +++ b/lso/__init__.py @@ -18,11 +18,7 @@ def create_app() -> FastAPI: app = FastAPI() app.add_middleware( - CORSMiddleware, - allow_origins=["*"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], + CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"] ) app.include_router(default_router, prefix="/api") diff --git a/lso/config.py b/lso/config.py index a2eec0607bf992b0edc931670d8adf8212b9d094..ddc1781cc5c184715265094970653867e659cbda 100644 --- a/lso/config.py +++ b/lso/config.py @@ -15,9 +15,7 @@ from pydantic import BaseModel CONFIG_SCHEMA = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", - "properties": { - "ansible_playbooks_root_dir": {"type": "string"}, - }, + "properties": {"ansible_playbooks_root_dir": {"type": "string"}}, "required": ["ansible_playbooks_root_dir"], "additionalProperties": False, } diff --git a/lso/environment.py b/lso/environment.py index f8baddfcc65d31f95e5185d29a2119d6b88c3af0..f50d645165a50170b47eae5d47200b7e5de129da 100644 --- a/lso/environment.py +++ b/lso/environment.py @@ -15,15 +15,9 @@ LOGGING_DEFAULT_CONFIG = { "level": "DEBUG", "formatter": "simple", "stream": "ext://sys.stdout", - }, - }, - "loggers": { - "resource_management": { - "level": "DEBUG", - "handlers": ["console"], - "propagate": False, - }, + } }, + "loggers": {"resource_management": {"level": "DEBUG", "handlers": ["console"], "propagate": False}}, "root": {"level": "INFO", "handlers": ["console"]}, } diff --git a/lso/playbook.py b/lso/playbook.py index 0ada50b35af83487686d739442bd0397892ad7b3..32155c5b0f8d148528154e02787ba59e37d969dd 100644 --- a/lso/playbook.py +++ b/lso/playbook.py @@ -44,11 +44,7 @@ def playbook_launch_error(reason: str, status_code: int = status.HTTP_400_BAD_RE def _run_playbook_proc( - job_id: str, - playbook_path: str, - extra_vars: dict, - inventory: dict[str, Any] | str, - callback: str, + job_id: str, playbook_path: str, extra_vars: dict, inventory: dict[str, Any] | str, callback: str ) -> None: """Run a playbook, internal function. @@ -58,11 +54,7 @@ def _run_playbook_proc( :param str callback: Callback URL to return output to when execution is completed. :param dict[str, Any] | str inventory: Ansible inventory to run the playbook against. """ - ansible_playbook_run = ansible_runner.run( - playbook=playbook_path, - inventory=inventory, - extravars=extra_vars, - ) + ansible_playbook_run = ansible_runner.run(playbook=playbook_path, inventory=inventory, extravars=extra_vars) payload = { "status": ansible_playbook_run.status, diff --git a/test/routes/test_playbook.py b/test/routes/test_playbook.py index 658b0e0840ed4e27eb6ea13e27c43a413a16f095..84391821f3543496363434bdea24764fef1789fc 100644 --- a/test/routes/test_playbook.py +++ b/test/routes/test_playbook.py @@ -18,27 +18,10 @@ def test_playbook_endpoint_dict_inventory_success(client: TestClient, mocked_ans "playbook_name": "placeholder.yaml", "callback": TEST_CALLBACK_URL, "inventory": { - "_meta": { - "vars": { - "host1.local": { - "foo": "bar", - }, - "host2.local": { - "hello": "world", - }, - }, - }, - "all": { - "hosts": { - "host1.local": None, - "host2.local": None, - }, - }, - }, - "extra_vars": { - "dry_run": True, - "commit_comment": "I am a robot!", + "_meta": {"vars": {"host1.local": {"foo": "bar"}, "host2.local": {"hello": "world"}}}, + "all": {"hosts": {"host1.local": None, "host2.local": None}}, }, + "extra_vars": {"dry_run": True, "commit_comment": "I am a robot!"}, } with patch("lso.playbook.ansible_runner.run", new=mocked_ansible_runner_run) as _: @@ -60,11 +43,7 @@ def test_playbook_endpoint_str_inventory_success(client: TestClient, mocked_ansi params = { "playbook_name": "placeholder.yaml", "callback": TEST_CALLBACK_URL, - "inventory": { - "all": { - "hosts": "host1.local\nhost2.local\nhost3.local", - }, - }, + "inventory": {"all": {"hosts": "host1.local\nhost2.local\nhost3.local"}}, } with patch("lso.playbook.ansible_runner.run", new=mocked_ansible_runner_run) as _: @@ -85,19 +64,8 @@ def test_playbook_endpoint_invalid_host_vars(client: TestClient, mocked_ansible_ "playbook_name": "placeholder.yaml", "callback": TEST_CALLBACK_URL, "inventory": { - "_meta": { - "host_vars": { - "host1.local": { - "foo": "bar", - }, - "host2.local": { - "hello": "world", - }, - }, - }, - "all": { - "hosts": "host1.local\nhost2.local\nhost3.local", - }, + "_meta": {"host_vars": {"host1.local": {"foo": "bar"}, "host2.local": {"hello": "world"}}}, + "all": {"hosts": "host1.local\nhost2.local\nhost3.local"}, }, } @@ -122,16 +90,8 @@ def test_playbook_endpoint_invalid_hosts(client: TestClient, mocked_ansible_runn "playbook_name": "placeholder.yaml", "callback": TEST_CALLBACK_URL, "inventory": { - "_meta": { - "vars": { - "host1.local": { - "foo": "bar", - }, - }, - }, - "all": { - "hosts": ["host1.local", "host2.local", "host3.local"], - }, + "_meta": {"vars": {"host1.local": {"foo": "bar"}}}, + "all": {"hosts": ["host1.local", "host2.local", "host3.local"]}, }, } diff --git a/test/test_config.py b/test/test_config.py index 00875eae7d8bd4281ab470e7faa251d9012506da..25a41fa45279ad9e65f6ae58f8ebfcd278fe4f22 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -22,12 +22,7 @@ def test_validate_testenv_config(data_config_filename: str) -> None: @pytest.mark.parametrize( - "bad_config", - [ - {"name": "bad version", "version": 123}, - {"name": "missing version"}, - {"version": "missing name"}, - ], + "bad_config", [{"name": "bad version", "version": 123}, {"name": "missing version"}, {"version": "missing name"}] ) def test_bad_config(bad_config: dict) -> None: with tempfile.NamedTemporaryFile(mode="w") as file: