Skip to content

Commit 9372981

Browse files
authored
[CLI] Cluster logs CLI improvements: new log labels + test coverage increasing (#14459)
* Cluster logs improvements * Unit tests added * Labels for processing deletion errors
1 parent 74538f7 commit 9372981

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/lightning_app/utilities/cluster_logs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class _ClusterLogEventLabels:
2626
issuer: Optional[str] = None
2727
error: Optional[str] = None
2828
errorVerbose: Optional[str] = None
29+
dir: Optional[str] = None
30+
bucket: Optional[str] = None
31+
prefix: Optional[str] = None
32+
loki_s3: Optional[str] = None
2933

3034

3135
@dataclass
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from unittest import mock
2+
from unittest.mock import MagicMock
3+
4+
from click.testing import CliRunner
5+
from lightning_cloud.openapi import Externalv1Cluster
6+
7+
from lightning_app.cli.cmd_clusters import ClusterList
8+
from lightning_app.cli.lightning_cli import cluster_logs
9+
10+
11+
@mock.patch("lightning_app.cli.lightning_cli.LightningClient", MagicMock())
12+
@mock.patch("lightning_app.cli.cmd_clusters.LightningClient", MagicMock())
13+
@mock.patch("lightning_app.cli.lightning_cli.AWSClusterManager.get_clusters")
14+
def test_show_logs_errors(get_clusters):
15+
"""Test that the CLI prints the errors for the show logs command."""
16+
17+
runner = CliRunner()
18+
19+
# Run without arguments
20+
get_clusters.return_value = ClusterList([])
21+
result = runner.invoke(cluster_logs, [])
22+
23+
assert result.exit_code == 2
24+
assert "Usage: logs" in result.output
25+
26+
# No clusters
27+
get_clusters.return_value = ClusterList([])
28+
result = runner.invoke(cluster_logs, ["NonExistentCluster"])
29+
30+
assert result.exit_code == 1
31+
assert "Error: You don't have any clusters" in result.output
32+
33+
# One cluster
34+
clusters = ClusterList([Externalv1Cluster(name="MyFakeCluster", id="MyFakeCluster")])
35+
get_clusters.return_value = clusters
36+
37+
result = runner.invoke(cluster_logs, ["MyFakeClusterTwo"])
38+
39+
assert result.exit_code == 1
40+
assert "Please select one of the following: [MyFakeCluster]" in str(result.output)

0 commit comments

Comments
 (0)