Skip to content

Commit 4372c0c

Browse files
committed
handle shell warning when the lease has been transferred
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-sonnet-4.6
1 parent a3ed954 commit 4372c0c

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

python/packages/jumpstarter-cli/jumpstarter_cli/shell.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ async def _shell_with_signal_handling( # noqa: C901
275275
# Lease expired naturally (e.g. during beforeLease hook)
276276
# — exit gracefully instead of showing a scary error
277277
pass
278+
elif lease_used.lease_transferred:
279+
raise ExporterOfflineError(
280+
"Lease has been transferred to another client. Session is no longer valid."
281+
) from None
278282
else:
279283
raise ExporterOfflineError("Connection to exporter lost") from None
280284
else:

python/packages/jumpstarter-cli/jumpstarter_cli/update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ def update_lease(
4343
Update a lease
4444
4545
Update the duration, begin time, and/or owner of an existing lease.
46-
At least one of --duration, --begin-time, or --to_client must be specified.
46+
At least one of --duration, --begin-time, or --to-client must be specified.
4747
48-
To transfer a lease to another client in the same namespace, use the --to_client option.
48+
To transfer a lease to another client in the same namespace, use the --to-client option.
4949
5050
Updating the begin time of an already active lease is not allowed.
5151
"""
5252

5353
if duration is None and begin_time is None and to_client is None:
54-
raise click.UsageError("At least one of --duration, --begin-time, or --client must be specified")
54+
raise click.UsageError("At least one of --duration, --begin-time, or --to-client must be specified")
5555

5656
client_path = f"namespaces/{config.metadata.namespace}/clients/{to_client}" if to_client else None
5757

python/packages/jumpstarter/jumpstarter/client/lease.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Lease(ContextManagerMixin, AsyncContextManagerMixin):
6363
default=None, init=False
6464
) # Called when lease is ending
6565
lease_ended: bool = field(default=False, init=False) # Set when lease expires naturally
66+
lease_transferred: bool = field(default=False, init=False) # Set when lease is transferred to another client
6667

6768
def __post_init__(self):
6869
if hasattr(super(), "__post_init__"):
@@ -293,7 +294,15 @@ async def handle_async(self, stream):
293294
attempt += 1
294295
continue
295296
# Exporter went offline or lease ended - log and exit gracefully
296-
logger.warning("Connection to exporter lost: %s", e.details())
297+
if "permission denied" in str(e.details()).lower():
298+
self.lease_transferred = True
299+
logger.warning(
300+
"Lease %s has been transferred to another client. "
301+
"Your session is no longer valid.",
302+
self.name,
303+
)
304+
else:
305+
logger.warning("Connection to exporter lost: %s", e.details())
297306
return
298307
async with connect_router_stream(
299308
response.router_endpoint, response.router_token, stream, self.tls_config, self.grpc_options

0 commit comments

Comments
 (0)