Skip to content

Commit 4e82941

Browse files
justinpakzadYour friendly bot
authored andcommitted
[v3-2-test] Added plugins command to airflowctl (#64935)
* Added plugins command into airflowctl * Add missing docstring to test (cherry picked from commit bfa22c0) Co-authored-by: Justin Pakzad <114518232+justinpakzad@users.noreply.github.com>
1 parent 59cb280 commit 4e82941

8 files changed

Lines changed: 257 additions & 64 deletions

File tree

airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def date_param():
124124
"variables delete --variable-key=test_import_var_with_desc",
125125
# Version command
126126
"version --remote",
127+
# Plugins command
128+
"plugins list",
129+
"plugins list-import-errors",
127130
]
128131

129132
DATE_PARAM_1 = date_param()

airflow-ctl/docs/images/command_hashes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
main:65249416abad6ad24c276fb44326ae15
1+
main:27a22c00dcf32e7a1a4f06672dc8e3c8
22
assets:b3ae2b933e54528bf486ff28e887804d
33
auth:d79e9c7d00c432bdbcbc2a86e2e32053
44
backfill:bbce9859a2d1ce054ad22db92dea8c05
@@ -11,4 +11,5 @@ pools:03fc7d948cbecf16ff8d640eb8f0ce43
1111
providers:1c0afb2dff31d93ab2934b032a2250ab
1212
variables:0354f8f4b0dde1c3771ed1568692c6ae
1313
version:31f4efdf8de0dbaaa4fac71ff7efecc3
14+
plugins:118ea0beda9b3935eedc67b0511f7e4a
1415
auth login:9fe2bb1dd5c602beea2eefb33a2b20a8

airflow-ctl/docs/images/output_main.svg

Lines changed: 67 additions & 63 deletions
Loading
Lines changed: 105 additions & 0 deletions
Loading

airflow-ctl/src/airflowctl/api/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
DagsOperations,
5353
JobsOperations,
5454
LoginOperations,
55+
PluginsOperations,
5556
PoolsOperations,
5657
ProvidersOperations,
5758
ServerResponseError,
@@ -415,6 +416,12 @@ def xcom(self):
415416
"""Operations related to XComs."""
416417
return XComOperations(self)
417418

419+
@lru_cache() # type: ignore[prop-decorator]
420+
@property
421+
def plugins(self):
422+
"""Operations related to plugins."""
423+
return PluginsOperations(self)
424+
418425

419426
# API Client Decorator for CLI Actions
420427
@contextlib.contextmanager

airflow-ctl/src/airflowctl/api/operations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
ImportErrorCollectionResponse,
6060
ImportErrorResponse,
6161
JobCollectionResponse,
62+
PluginCollectionResponse,
63+
PluginImportErrorCollectionResponse,
6264
PoolBody,
6365
PoolCollectionResponse,
6466
PoolPatchBody,
@@ -889,3 +891,19 @@ def delete(
889891
return key
890892
except ServerResponseError as e:
891893
raise e
894+
895+
896+
class PluginsOperations(BaseOperations):
897+
"""Plugins operations."""
898+
899+
def list(self) -> PluginCollectionResponse | ServerResponseError:
900+
"""List all plugins from the API server."""
901+
return super().execute_list(path="plugins", data_model=PluginCollectionResponse)
902+
903+
def list_import_errors(self) -> PluginImportErrorCollectionResponse | ServerResponseError:
904+
"""List plugin import errors from the API server."""
905+
try:
906+
self.response = self.client.get("plugins/importErrors")
907+
return PluginImportErrorCollectionResponse.model_validate_json(self.response.content)
908+
except ServerResponseError as e:
909+
raise e

airflow-ctl/tests/airflow_ctl/api/test_operations.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
ImportErrorResponse,
8080
JobCollectionResponse,
8181
JobResponse,
82+
PluginCollectionResponse,
83+
PluginImportErrorCollectionResponse,
84+
PluginImportErrorResponse,
85+
PluginResponse,
8286
PoolBody,
8387
PoolCollectionResponse,
8488
PoolResponse,
@@ -1703,3 +1707,53 @@ def handle_request(request: httpx.Request) -> httpx.Response:
17031707
map_index=self.map_index,
17041708
)
17051709
assert response == self.key
1710+
1711+
1712+
class TestPluginsOperations:
1713+
plugin_response = PluginResponse(
1714+
name="test-plugin",
1715+
macros=[],
1716+
flask_blueprints=[],
1717+
fastapi_apps=[],
1718+
fastapi_root_middlewares=[],
1719+
external_views=[],
1720+
react_apps=[],
1721+
appbuilder_views=[],
1722+
appbuilder_menu_items=[],
1723+
global_operator_extra_links=[],
1724+
operator_extra_links=[],
1725+
source="test-source",
1726+
listeners=[],
1727+
timetables=[],
1728+
)
1729+
plugin_collection_response = PluginCollectionResponse(plugins=[plugin_response], total_entries=1)
1730+
plugin_import_error_response = PluginImportErrorResponse(
1731+
source="plugins/test_plugin.py", error="something went wrong"
1732+
)
1733+
plugin_import_error_collection_response = PluginImportErrorCollectionResponse(
1734+
import_errors=[plugin_import_error_response], total_entries=1
1735+
)
1736+
1737+
def test_list(self):
1738+
"""Test listing plugins"""
1739+
1740+
def handle_request(request: httpx.Request) -> httpx.Response:
1741+
assert request.url.path == ("/api/v2/plugins")
1742+
return httpx.Response(200, json=json.loads(self.plugin_collection_response.model_dump_json()))
1743+
1744+
client = make_api_client(transport=httpx.MockTransport(handle_request))
1745+
response = client.plugins.list()
1746+
assert response == self.plugin_collection_response
1747+
1748+
def test_list_import_errors(self):
1749+
"""Test listing plugin import errors"""
1750+
1751+
def handle_request(request: httpx.Request) -> httpx.Response:
1752+
assert request.url.path == "/api/v2/plugins/importErrors"
1753+
return httpx.Response(
1754+
200, json=json.loads(self.plugin_import_error_collection_response.model_dump_json())
1755+
)
1756+
1757+
client = make_api_client(transport=httpx.MockTransport(handle_request))
1758+
response = client.plugins.list_import_errors()
1759+
assert response == self.plugin_import_error_collection_response

scripts/in_container/run_capture_airflowctl_help.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"providers",
4848
"variables",
4949
"version",
50+
"plugins",
5051
]
5152

5253
SUBCOMMANDS = [

0 commit comments

Comments
 (0)