-
-
Notifications
You must be signed in to change notification settings - Fork 275
feat: rename LG_TOKEN to LG_RESERVATION #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -86,6 +86,17 @@ def __str__(self): | |||||
| return f"{self.message}:\n{errors_combined}" | ||||||
|
|
||||||
|
|
||||||
| def _get_reservation_id_from_env(): | ||||||
| reservation_id = os.environ.get("LG_RESERVATION") | ||||||
| if reservation_id: | ||||||
| return reservation_id | ||||||
|
|
||||||
| reservation_id = os.environ.get("LG_TOKEN") | ||||||
| if reservation_id: | ||||||
| print("warning: LG_TOKEN is deprecated; use LG_RESERVATION instead", file=sys.stderr) | ||||||
| return reservation_id | ||||||
|
|
||||||
|
|
||||||
| @attr.s(eq=False) | ||||||
| class ClientSession: | ||||||
| """The ClientSession encapsulates all the actions a Client can invoke on | ||||||
|
|
@@ -438,19 +449,19 @@ def _match_places(self, pattern): | |||||
| """ | ||||||
| result = set() | ||||||
|
|
||||||
| # reservation token lookup | ||||||
| token = None | ||||||
| # reservation id lookup | ||||||
| reservation_id = None | ||||||
| if pattern.startswith("+"): | ||||||
| token = pattern[1:] | ||||||
| if not token: | ||||||
| token = os.environ.get("LG_TOKEN", None) | ||||||
| if not token: | ||||||
| reservation_id = pattern[1:] | ||||||
| if not reservation_id: | ||||||
| reservation_id = _get_reservation_id_from_env() | ||||||
| if not reservation_id: | ||||||
| return [] | ||||||
| for name, place in self.places.items(): | ||||||
| if place.reservation == token: | ||||||
| if place.reservation == reservation_id: | ||||||
| result.add(name) | ||||||
| if not result: | ||||||
| raise UserError(f"reservation token {token} matches nothing") | ||||||
| raise UserError(f"reservation id {reservation_id} matches nothing") | ||||||
| return list(result) | ||||||
|
|
||||||
| # name and alias lookup | ||||||
|
|
@@ -1572,28 +1583,28 @@ async def create_reservation(self): | |||||
|
|
||||||
| res = Reservation.from_pb2(response.reservation) | ||||||
| if self.args.shell: | ||||||
| print(f"export LG_TOKEN={res.token}") | ||||||
| print(f"export LG_RESERVATION={res.id}") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to export the old |
||||||
| else: | ||||||
| print(f"Reservation '{res.token}':") | ||||||
| print(f"Reservation '{res.id}':") | ||||||
| res.show(level=1) | ||||||
| if self.args.wait: | ||||||
| if not self.args.shell: | ||||||
| print("Waiting for allocation...") | ||||||
| await self._wait_reservation(res.token, verbose=False) | ||||||
| await self._wait_reservation(res.id, verbose=False) | ||||||
|
|
||||||
| async def cancel_reservation(self): | ||||||
| token: str = self.args.token | ||||||
| reservation_id: str = getattr(self.args, "reservation-id") | ||||||
|
|
||||||
| request = labgrid_coordinator_pb2.CancelReservationRequest(token=token) | ||||||
| request = labgrid_coordinator_pb2.CancelReservationRequest(token=reservation_id) | ||||||
|
|
||||||
| try: | ||||||
| await self.stub.CancelReservation(request) | ||||||
| except grpc.aio.AioRpcError as e: | ||||||
| raise ServerError(e.details()) | ||||||
|
|
||||||
| async def _wait_reservation(self, token: str, verbose=True): | ||||||
| async def _wait_reservation(self, reservation_id: str, verbose=True): | ||||||
| while True: | ||||||
| request = labgrid_coordinator_pb2.PollReservationRequest(token=token) | ||||||
| request = labgrid_coordinator_pb2.PollReservationRequest(token=reservation_id) | ||||||
|
|
||||||
| try: | ||||||
| response: labgrid_coordinator_pb2.PollReservationResponse = await self.stub.PollReservation(request) | ||||||
|
|
@@ -1609,8 +1620,8 @@ async def _wait_reservation(self, token: str, verbose=True): | |||||
| break | ||||||
|
|
||||||
| async def wait_reservation(self): | ||||||
| token = self.args.token | ||||||
| await self._wait_reservation(token) | ||||||
| reservation_id = getattr(self.args, "reservation-id") | ||||||
| await self._wait_reservation(reservation_id) | ||||||
|
|
||||||
| async def print_reservations(self): | ||||||
| request = labgrid_coordinator_pb2.GetReservationsRequest() | ||||||
|
|
@@ -1622,7 +1633,7 @@ async def print_reservations(self): | |||||
| raise ServerError(e.details()) | ||||||
|
|
||||||
| for res in sorted(reservations, key=lambda x: (-x.prio, x.created)): | ||||||
| print(f"Reservation '{res.token}':") | ||||||
| print(f"Reservation '{res.id}':") | ||||||
| res.show(level=1) | ||||||
|
|
||||||
| async def export(self, place, target): | ||||||
|
|
@@ -2210,11 +2221,11 @@ def get_parser(auto_doc_mode=False) -> "argparse.ArgumentParser | AutoProgramArg | |||||
| subparser.set_defaults(func=ClientSession.create_reservation) | ||||||
|
|
||||||
| subparser = subparsers.add_parser("cancel-reservation", help="cancel a reservation") | ||||||
| subparser.add_argument("token", type=str, nargs="?") | ||||||
| subparser.add_argument("reservation-id", type=str, nargs="?", help="the reservation id (previously called token)") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and we can replace the various |
||||||
| subparser.set_defaults(func=ClientSession.cancel_reservation) | ||||||
|
|
||||||
| subparser = subparsers.add_parser("wait", help="wait for a reservation to be allocated") | ||||||
| subparser.add_argument("token", type=str, nargs="?") | ||||||
| subparser.add_argument("reservation-id", type=str, nargs="?", help="the reservation id (previously called token)") | ||||||
| subparser.set_defaults(func=ClientSession.wait_reservation) | ||||||
|
|
||||||
| subparser = subparsers.add_parser("reservations", help="list current reservations") | ||||||
|
|
@@ -2257,7 +2268,6 @@ def main(): | |||||
| state = os.environ.get("STATE", None) | ||||||
| state = os.environ.get("LG_STATE", state) | ||||||
| initial_state = os.environ.get("LG_INITIAL_STATE", None) | ||||||
| token = os.environ.get("LG_TOKEN", None) | ||||||
|
|
||||||
| parser = get_parser() | ||||||
|
|
||||||
|
|
@@ -2281,11 +2291,12 @@ def main(): | |||||
| if args.initial_state is None: | ||||||
| args.initial_state = initial_state | ||||||
|
|
||||||
| if args.command in ["cancel-reservation", "wait"] and args.token is None: | ||||||
| if token: | ||||||
| args.token = token | ||||||
| if args.command in ["cancel-reservation", "wait"] and getattr(args, "reservation-id") is None: | ||||||
| reservation_id = _get_reservation_id_from_env() | ||||||
| if reservation_id: | ||||||
| setattr(args, "reservation-id", reservation_id) | ||||||
| else: | ||||||
| print("Please provide a token", file=sys.stderr) | ||||||
| print("Please provide a reservation id (previously called token)", file=sys.stderr) | ||||||
| exit(1) | ||||||
|
|
||||||
| if args.verbose: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should export why we are forcing people to change to
LG_RESERVATIONin all workflows/scripts/CLI usage. IMO this is needed becauseLG_TOKENimplies a security property (which is not present here) since the meaning ofTOKENhas changed over the last few years. Additional explanation or links are welcome as well.