Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lightning_app/utilities/cluster_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class _ClusterLogEventLabels:
issuer: Optional[str] = None
error: Optional[str] = None
errorVerbose: Optional[str] = None
dir: Optional[str] = None
bucket: Optional[str] = None
prefix: Optional[str] = None
loki_s3: Optional[str] = None


@dataclass
Expand Down
40 changes: 40 additions & 0 deletions tests/tests_app/cli/test_cmd_show_cluster_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from unittest import mock
from unittest.mock import MagicMock

from click.testing import CliRunner
from lightning_cloud.openapi import Externalv1Cluster

from lightning_app.cli.cmd_clusters import ClusterList
from lightning_app.cli.lightning_cli import cluster_logs


@mock.patch("lightning_app.cli.lightning_cli.LightningClient", MagicMock())
@mock.patch("lightning_app.cli.cmd_clusters.LightningClient", MagicMock())
@mock.patch("lightning_app.cli.lightning_cli.AWSClusterManager.get_clusters")
def test_show_logs_errors(get_clusters):
"""Test that the CLI prints the errors for the show logs command."""

runner = CliRunner()

# Run without arguments
get_clusters.return_value = ClusterList([])
result = runner.invoke(cluster_logs, [])

assert result.exit_code == 2
assert "Usage: logs" in result.output

# No clusters
get_clusters.return_value = ClusterList([])
result = runner.invoke(cluster_logs, ["NonExistentCluster"])

assert result.exit_code == 1
assert "Error: You don't have any clusters" in result.output

# One cluster
clusters = ClusterList([Externalv1Cluster(name="MyFakeCluster", id="MyFakeCluster")])
get_clusters.return_value = clusters

result = runner.invoke(cluster_logs, ["MyFakeClusterTwo"])

assert result.exit_code == 1
assert "Please select one of the following: [MyFakeCluster]" in str(result.output)