-
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.
add activate-launchplan command to pyflyte
Signed-off-by: Artem Petrov <[email protected]>
- Loading branch information
Showing
3 changed files
with
88 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,61 @@ | ||
import click | ||
from flytekit.models.launch_plan import LaunchPlanState | ||
|
||
from flytekit.clis.sdk_in_container.helpers import get_and_save_remote_with_click_context | ||
|
||
_activate_launchplan_help = """ | ||
The activate-launchplan command activates a specified or the latest version of the launchplan and disables a previous version. | ||
- ``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("activate-launchplan", help=_activate_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.argument( | ||
"launchplan", | ||
required=True, | ||
type=str, | ||
) | ||
@click.argument( | ||
"launchplan-version", | ||
required=False, | ||
type=str, | ||
default=None, | ||
) | ||
@click.pass_context | ||
def activate_launchplan( | ||
ctx: click.Context, | ||
project: str, | ||
domain: str, | ||
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, | ||
) | ||
remote.client.update_launch_plan(id=launchplan.id, state=LaunchPlanState.ACTIVE) | ||
click.secho(f"\n Launchplan was activated: {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
25 changes: 25 additions & 0 deletions
25
tests/flytekit/unit/cli/pyflyte/test_activate_launchplan.py
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,25 @@ | ||
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) | ||
def test_pyflyte_activate_launchplan(mock_remote): | ||
mock_remote.generate_console_url.return_value = "ex" | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
result = runner.invoke( | ||
pyflyte.main, | ||
[ | ||
"activate-launchplan", | ||
"-p", | ||
"flytesnacks", | ||
"-d", | ||
"development", | ||
"daily", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
assert "Launchplan was activated: " in result.output |