-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: add activate-launchplan command to pyflyte (#1588)
* add activate-launchplan command to pyflyte Signed-off-by: Artem Petrov <[email protected]> * fix linting Signed-off-by: Artem Petrov <[email protected]> * rework launchplan command Signed-off-by: Artem Petrov <[email protected]> * fix linting Signed-off-by: Artem Petrov <[email protected]> --------- Signed-off-by: Artem Petrov <[email protected]> Signed-off-by: Fabio Graetz <[email protected]>
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,74 @@ | ||
import click | ||
|
||
from flytekit.clis.sdk_in_container.helpers import get_and_save_remote_with_click_context | ||
from flytekit.models.launch_plan import LaunchPlanState | ||
|
||
_launchplan_help = """ | ||
The launchplan command activates or deactivates a specified or the latest version of the launchplan. | ||
If ``--activate`` is chosen then the previous version of the launchplan will be deactivated. | ||
- ``launchplan`` refers to the name of the Launchplan | ||
- ``launchplan_version`` is optional and should be a valid version for a Launchplan version. If not specified the latest will be used. | ||
""" | ||
|
||
|
||
@click.command("launchplan", help=_launchplan_help) | ||
@click.option( | ||
"-p", | ||
"--project", | ||
required=False, | ||
type=str, | ||
default="flytesnacks", | ||
help="Fecth launchplan from this project", | ||
) | ||
@click.option( | ||
"-d", | ||
"--domain", | ||
required=False, | ||
type=str, | ||
default="development", | ||
help="Fetch launchplan from this domain", | ||
) | ||
@click.option( | ||
"--activate/--deactivate", | ||
required=True, | ||
type=bool, | ||
is_flag=True, | ||
help="Activate or Deactivate the launchplan", | ||
) | ||
@click.argument( | ||
"launchplan", | ||
required=True, | ||
type=str, | ||
) | ||
@click.argument( | ||
"launchplan-version", | ||
required=False, | ||
type=str, | ||
default=None, | ||
) | ||
@click.pass_context | ||
def launchplan( | ||
ctx: click.Context, | ||
project: str, | ||
domain: str, | ||
activate: bool, | ||
launchplan: str, | ||
launchplan_version: str, | ||
): | ||
remote = get_and_save_remote_with_click_context(ctx, project, domain) | ||
try: | ||
launchplan = remote.fetch_launch_plan( | ||
project=project, | ||
domain=domain, | ||
name=launchplan, | ||
version=launchplan_version, | ||
) | ||
state = LaunchPlanState.ACTIVE if activate else LaunchPlanState.INACTIVE | ||
remote.client.update_launch_plan(id=launchplan.id, state=state) | ||
click.secho( | ||
f"\n Launchplan was set to {LaunchPlanState.enum_to_string(state)}: {launchplan.name}:{launchplan.id.version}", | ||
fg="green", | ||
) | ||
except StopIteration as e: | ||
click.secho(f"{e.value}", fg="red") |
This file contains 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 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,34 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
from mock import mock | ||
|
||
from flytekit.clis.sdk_in_container import pyflyte | ||
from flytekit.remote import FlyteRemote | ||
|
||
|
||
@mock.patch("flytekit.clis.sdk_in_container.helpers.FlyteRemote", spec=FlyteRemote) | ||
@pytest.mark.parametrize( | ||
("action", "expected_state"), | ||
[ | ||
("activate", "ACTIVE"), | ||
("deactivate", "INACTIVE"), | ||
], | ||
) | ||
def test_pyflyte_launchplan(mock_remote, action, expected_state): | ||
mock_remote.generate_console_url.return_value = "ex" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
result = runner.invoke( | ||
pyflyte.main, | ||
[ | ||
"launchplan", | ||
f"--{action}", | ||
"-p", | ||
"flytesnacks", | ||
"-d", | ||
"development", | ||
"daily", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
assert f"Launchplan was set to {expected_state}: " in result.output |