-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Add Legacy command displaying new CLI counterparts #10115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
77a4c5a
show error for legacy cli commands
ephraimbuddy 7ef98f9
apply review suggestions
ephraimbuddy 20fa879
fixup! apply review suggestions and add tests
ephraimbuddy c5c8cfa
fixup! fixup! apply review suggestions and add tests
ephraimbuddy 6026750
fixup! fixup! fixup! apply review suggestions and add tests
ephraimbuddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from argparse import ArgumentError | ||
|
|
||
| COMMAND_MAP = { | ||
| "worker": "celery worker", | ||
| "flower": "celery flower", | ||
| "trigger_dag": "dags trigger", | ||
| "delete_dag": "dags delete", | ||
| "show_dag": "dags show", | ||
| "list_dag": "dags list", | ||
| "dag_status": "dags status", | ||
| "backfill": "dags backfill", | ||
| "list_dag_runs": "dags list_runs", | ||
| "pause": "dags pause", | ||
| "unpause": "dags unpause", | ||
| "test": "tasks test", | ||
| "clear": "tasks clear", | ||
| "list_tasks": "tasks list", | ||
| "task_failed_deps": "tasks failed_deps", | ||
| "task_state": "tasks state", | ||
| "run": "tasks run", | ||
| "render": "tasks render", | ||
| "initdb": "db init", | ||
| "resetdb": "db reset", | ||
| "upgradedb": "db upgrade", | ||
| "checkdb": "db check", | ||
| "shell": "db shell", | ||
| "pool": "pools", | ||
| "list_users": "users list", | ||
| "create_user": "users create", | ||
| "delete_user": "users delete" | ||
| } | ||
|
|
||
|
|
||
| def check_legacy_command(action, value): | ||
| """ Checks command value and raise error if value is in removed command """ | ||
| new_command = COMMAND_MAP.get(value) | ||
| if new_command is not None: | ||
| msg = f"`airflow {value}` command, has been removed, please use `airflow {new_command}`" | ||
| raise ArgumentError(action, msg) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| import contextlib | ||
| import io | ||
| import unittest | ||
| from argparse import ArgumentError | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from airflow.cli import cli_parser | ||
| from airflow.cli.commands import config_command | ||
| from airflow.cli.commands.legacy_commands import COMMAND_MAP, check_legacy_command | ||
|
|
||
| LEGACY_COMMANDS = ["worker", "flower", "trigger_dag", "delete_dag", "show_dag", "list_dag", | ||
| "dag_status", "backfill", "list_dag_runs", "pause", "unpause", "test", | ||
| "clear", "list_tasks", "task_failed_deps", "task_state", "run", | ||
| "render", "initdb", "resetdb", "upgradedb", "checkdb", "shell", "pool", | ||
| "list_users", "create_user", "delete_user"] | ||
|
|
||
|
|
||
| class TestCliDeprecatedCommandsValue(unittest.TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.parser = cli_parser.get_parser() | ||
|
|
||
| def test_should_display_value(self): | ||
| with self.assertRaises(SystemExit) as cm_exception, \ | ||
| contextlib.redirect_stderr(io.StringIO()) as temp_stderr: | ||
| config_command.get_value(self.parser.parse_args(['worker'])) | ||
|
|
||
| self.assertEqual(2, cm_exception.exception.code) | ||
| self.assertIn( | ||
| "`airflow worker` command, has been removed, " | ||
| "please use `airflow celery worker`, see help above.", | ||
| temp_stderr.getvalue().strip() | ||
| ) | ||
|
|
||
| def test_command_map(self): | ||
| for item in LEGACY_COMMANDS: | ||
| self.assertIsNotNone(COMMAND_MAP[item]) | ||
|
|
||
| def test_check_legacy_command(self): | ||
| action = MagicMock() | ||
| with self.assertRaises(ArgumentError) as e: | ||
| check_legacy_command(action, 'list_users') | ||
| self.assertEqual( | ||
| str(e.exception), | ||
| "argument : `airflow list_users` command, has been removed, please use `airflow users list`") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.