Skip to content

Commit

Permalink
remote/coordinator: make listing address configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Luebbe <[email protected]>
  • Loading branch information
jluebbe committed Jun 11, 2024
1 parent 2c3d1af commit 0e44d75
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions labgrid/remote/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
import argparse
import logging
import os
import asyncio
import itertools
import inspect
Expand Down Expand Up @@ -865,7 +867,7 @@ async def CreateReservation(self, request, context):
return res.as_pb2()


async def serve(cleanup) -> None:
async def serve(listen, cleanup) -> None:
server = grpc.aio.server(
options=[
('grpc.keepalive_time_ms', 30000), # Send keepalive ping every 30 seconds
Expand All @@ -875,12 +877,11 @@ async def serve(cleanup) -> None:
('grpc.keepalive_permit_without_calls', 1), # Allow keepalive pings even when there are no calls
],
)
logging.debug("Created dummy labgrid coordinator")
coordinator = Coordinator()
labgrid_coordinator_pb2_grpc.add_LabgridServicer_to_server(
coordinator, server
)
server.add_insecure_port("[::]:20408")
server.add_insecure_port(listen)
logging.debug("Starting server")
await server.start()
logging.debug("Coordinator ready")
Expand All @@ -894,12 +895,32 @@ async def server_graceful_shutdown():
await server.wait_for_termination()

def main():
logging.basicConfig(level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument(
'-l',
'--listen',
metavar='HOST:PORT',
type=str,
default=os.environ.get("LG_COORDINATOR", "[::]:20408"),
help="coordinator listening host and port"
)
parser.add_argument(
'-d',
'--debug',
action='store_true',
default=False,
help="enable debug mode"
)

args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)

loop = asyncio.get_event_loop()
cleanup = []
loop.set_debug(True)
try:
loop.run_until_complete(serve(cleanup))
loop.run_until_complete(serve(args.listen, cleanup))
finally:
loop.run_until_complete(*cleanup)

Expand Down

0 comments on commit 0e44d75

Please sign in to comment.