Skip to content

Commit 1ab0abd

Browse files
authored
Merge pull request #1469 from labgrid-project/grpc
Move from crossbar/autobahn to gRPC
2 parents f472ae7 + ab8f79a commit 1ab0abd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3900
-1267
lines changed

.crossbar/.gitignore

-3
This file was deleted.

.crossbar/config-anonymous.yaml

-47
This file was deleted.

.github/workflows/reusable-unit-tests.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
${{ runner.os }}-pip-
3131
- name: Install system dependencies
3232
run: |
33-
sudo apt-get install -yq libow-dev openssh-server openssh-client libsnappy-dev graphviz openocd
33+
sudo apt-get install -yq libow-dev openssh-server openssh-client graphviz openocd
3434
sudo mkdir -p /var/cache/labgrid/runner && sudo chown runner /var/cache/labgrid/runner
3535
- name: Prepare local SSH
3636
run: |
@@ -46,17 +46,14 @@ jobs:
4646
- name: Install labgrid
4747
run: |
4848
pip install -e ".[dev]"
49-
- name: Install crossbar in virtualenv
50-
run: |
51-
virtualenv -p python3 crossbar-venv
52-
crossbar-venv/bin/pip install -r crossbar-requirements.txt
5349
- name: Lint with pylint
50+
if: inputs.python-version != '3.8'
5451
run: |
5552
pylint --list-msgs-enabled
5653
pylint labgrid
5754
- name: Test with pytest
5855
run: |
59-
pytest --cov-config .coveragerc --cov=labgrid --local-sshmanager --ssh-username runner --crossbar-venv crossbar-venv -k "not test_docker_with_daemon"
56+
pytest --cov-config .coveragerc --cov=labgrid --local-sshmanager --ssh-username runner -k "not test_docker_with_daemon"
6057
- name: Build documentation
6158
run: |
6259
make -C doc clean

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
/.pytest_cache/
1919
/htmlcov/
2020
/labgrid/_version.py
21-
/dockerfiles/staging/crossbar/*
22-
!/dockerfiles/staging/crossbar/places_example.yaml
21+
/dockerfiles/staging/coordinator/*
22+
!/dockerfiles/staging/coordinator/places_example.yaml
2323
/.idea

CHANGES.rst

+51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
1+
Release 24.1 (Unreleased)
2+
-------------------------
3+
As announced
4+
`before <https://github.com/labgrid-project/labgrid/discussions/1467#discussioncomment-10314852>`_,
5+
this is the first release using gRPC instead of crossbar/autobahn for
6+
communication between client/exporter and coordinator.
7+
8+
Crossbar/autobahn are unfortunately not very well maintained anymore. The
9+
crossbar component was moved to its own virtualenv to cope with the high number
10+
of dependencies leading to conflicts. Support for Python 3.13 is still not
11+
available in a crossbar release on PyPI.
12+
13+
That's why labgrid moves to gRPC with this release. gRPC is a well maintained
14+
RPC framework with a lot of users. As a side effect, the message transfer is
15+
more performant and the import times are shorter.
16+
17+
New Features in 24.1
18+
~~~~~~~~~~~~~~~~~~~~
19+
- All components can be installed into the same virtualenv again.
20+
21+
Bug fixes in 24.1
22+
~~~~~~~~~~~~~~~~~
23+
24+
FIXME
25+
26+
Breaking changes in 24.1
27+
~~~~~~~~~~~~~~~~~~~~~~~~
28+
Maintaining support for both crossbar/autobahn as well as gRPC in labgrid would
29+
be a lot of effort due to the different architectures of those frameworks.
30+
Therefore, a hard migration to gRPC is deemed the lesser issue.
31+
32+
Due to the migration, 24.1 includes the following breaking changes:
33+
34+
- The labgrid environment config option ``crossbar_url`` was renamed to
35+
``coordinator_address``. The environment variable ``LG_CROSSBAR`` was renamed
36+
to ``LG_COORDINATOR``.
37+
- The labgrid environment config option ``crossbar_realm`` is now obsolete as
38+
well as the environment variable ``LG_CROSSBAR_REALM``.
39+
- The coordinator is available as ``labgrid-coordinator`` (instead of
40+
``crossbar start``). No additional configuration file is required.
41+
- The systemd services in ``contrib/systemd/`` were updated.
42+
43+
Other breaking changes include:
44+
45+
FIXME
46+
47+
Known issues in 24.1
48+
~~~~~~~~~~~~~~~~~~~~
49+
50+
FIXME
51+
152
Release 24.0 (Released Aug 12, 2024)
253
------------------------------------
354

contrib/README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Quick Start
1313
$ source venv/bin/activate
1414
venv $ pip install -r contrib/requirements-webapp.txt
1515
venv $ ./contrib/labgrid-webapp --help
16-
usage: labgrid-webapp [-h] [--crossbar URL] [--port PORT] [--proxy PROXY]
16+
usage: labgrid-webapp [-h] [--coordinator ADDRESS] [--port PORT] [--proxy PROXY]
1717
1818
Labgrid webapp
1919
2020
options:
2121
-h, --help show this help message and exit
22-
--crossbar URL, -x URL
23-
Crossbar websocket URL (default: ws://127.0.0.1:20408/ws)
22+
--coordinator ADDRESS, -x ADDRESS
23+
Coordinator address as HOST[:PORT] (default: 127.0.0.1:20408)
2424
--port PORT Port to serve on
2525
--proxy PROXY, -P PROXY
2626

contrib/completion/labgrid-client.bash

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# options top level and subcommands support
44
_labgrid_shared_options="--help"
5-
_labgrid_main_opts_with_value="@(-x|--crossbar|-c|--config|-p|--place|-s|--state|-i|--initial-state|-P|--proxy)"
5+
_labgrid_main_opts_with_value="@(-x|--coordinator|-c|--config|-p|--place|-s|--state|-i|--initial-state|-P|--proxy)"
66

77
# Parses labgrid-client arguments
88
# Sets arg to subcommand, excluding options and their values.
99
# Sets last_arg_opt_with_value to true if the last argument is an option requiring a value, else
1010
# false.
1111
# Sets base_cmd to the labgrid-client base command up to subcommand and removes trailing
12-
# option requiring a value - useful to call 'labgrid-client complete' with place/crossbar/proxy set
12+
# option requiring a value - useful to call 'labgrid-client complete' with place/coordinator/proxy set
1313
# Before calling this function, make sure arg, base_cmd and last_arg_opt_with_value are local
1414
_labgrid_parse_args()
1515
{
@@ -867,7 +867,7 @@ _labgrid_client()
867867
case "$cur" in
868868
--*)
869869
# top level args completion
870-
local options="--crossbar \
870+
local options="--coordinator \
871871
--config \
872872
--place \
873873
--state \

contrib/coordinator-statsd.py

+22-23
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242

4343
import sys
4444
import argparse
45-
import statsd
4645
import os
47-
import labgrid.remote.client
4846
import time
4947
import asyncio
50-
import txaio
48+
49+
from labgrid.remote.client import start_session, Error
50+
from labgrid.remote.generated import labgrid_coordinator_pb2
51+
from labgrid.remote.common import Reservation
52+
import statsd
5153

5254

5355
def inc_gauge(gauges, key):
@@ -56,12 +58,13 @@ def inc_gauge(gauges, key):
5658

5759

5860
async def report_reservations(session, tags, gauges):
59-
reservations = await session.call("org.labgrid.coordinator.get_reservations")
61+
request = labgrid_coordinator_pb2.GetReservationsRequest()
6062

61-
for token, config in reservations.items():
62-
state = config["state"]
63+
response = await session.stub.GetReservations(request)
64+
reservations = [Reservation.from_pb2(x) for x in response.reservations]
6365

64-
groups = config.get("filters", {})
66+
for reservation in reservations:
67+
groups = reservation.filters
6568

6669
if not groups:
6770
groups = {"": {}}
@@ -72,7 +75,7 @@ async def report_reservations(session, tags, gauges):
7275
".".join(
7376
["reservations", group_name]
7477
+ [group.get(t, "") for t in tags]
75-
+ [state]
78+
+ [reservation.state.name]
7679
),
7780
)
7881

@@ -94,10 +97,10 @@ def main():
9497
)
9598
parser.add_argument(
9699
"-x",
97-
"--crossbar",
98-
metavar="URL",
99-
help="Crossbar URL for the coordinator",
100-
default=os.environ.get("LG_CROSSBAR", "ws://127.0.0.1:20408/ws"),
100+
"--coordinator",
101+
metavar="ADDRESS",
102+
help="Coordinator address as HOST[:PORT]. Default is %(default)s",
103+
default=os.environ.get("LG_COORDINATOR", "127.0.0.1:20408"),
101104
)
102105
parser.add_argument(
103106
"--period",
@@ -142,8 +145,8 @@ def main():
142145

143146
args = parser.parse_args()
144147

145-
txaio.use_asyncio()
146-
txaio.config.loop = asyncio.get_event_loop()
148+
loop = asyncio.new_event_loop()
149+
asyncio.set_event_loop(loop)
147150

148151
statsd_client = None
149152
gauges = {}
@@ -175,22 +178,18 @@ def main():
175178

176179
next_time = time.monotonic() + args.period
177180
try:
178-
extra = {}
179-
session = labgrid.remote.client.start_session(
180-
args.crossbar,
181-
os.environ.get("LG_CROSSBAR_REALM", "realm1"),
182-
extra,
183-
)
181+
session = start_session(args.coordinator, loop=loop)
184182
try:
185-
session.loop.run_until_complete(
183+
loop.run_until_complete(
186184
asyncio.gather(
187185
report_places(session, args.tags, gauges),
188186
report_reservations(session, args.tags, gauges),
189187
)
190188
)
191189
finally:
192-
session.leave()
193-
except labgrid.remote.client.Error as e:
190+
loop.run_until_complete(session.stop())
191+
loop.run_until_complete(session.close())
192+
except Error as e:
194193
print(f"Error communicating with labgrid: {e}")
195194
continue
196195

contrib/labgrid-webapp

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import argparse
3+
import asyncio
34
import logging
45
import os
56
import sys
@@ -118,11 +119,11 @@ def main():
118119
formatter_class=argparse.RawDescriptionHelpFormatter,
119120
)
120121
parser.add_argument(
121-
'--crossbar',
122+
'--coordinator',
122123
'-x',
123124
metavar='URL',
124-
default=os.environ.get('LG_CROSSBAR', 'ws://127.0.0.1:20408/ws'),
125-
help='Crossbar websocket URL (default: %(default)s)',
125+
default=os.environ.get('LG_COORDINATOR', '127.0.0.1:20408'),
126+
help='Coordinator address as HOST[:PORT] (default: %(default)s)',
126127
)
127128
parser.add_argument('--port', type=int, default=8800, help='Port to serve on')
128129
parser.add_argument('--proxy', '-P', help='Proxy connections via given ssh host')
@@ -132,16 +133,20 @@ def main():
132133
if args.proxy:
133134
proxymanager.force_proxy(args.proxy)
134135

136+
loop = asyncio.new_event_loop()
137+
asyncio.set_event_loop(loop)
138+
135139
try:
136140
session = start_session(
137-
args.crossbar, os.environ.get('LG_CROSSBAR_REALM', 'realm1'), {},
141+
args.coordinator,
142+
loop=loop,
138143
)
139144
except ConnectionRefusedError:
140-
logger.fatal('Unable to connect to labgrid crossbar')
145+
logger.fatal('Unable to connect to labgrid coordinator')
141146
return
142147

143148
server = uvicorn.Server(config=uvicorn.Config(
144-
loop=session.loop,
149+
loop=loop,
145150
host='0.0.0.0',
146151
port=args.port,
147152
app=app,
@@ -153,7 +158,11 @@ def main():
153158
if route.path not in reserved_routes:
154159
logger.info(f' - {route.path}')
155160

156-
session.loop.run_until_complete(server.serve())
161+
try:
162+
loop.run_until_complete(server.serve())
163+
finally:
164+
loop.run_until_complete(session.stop())
165+
loop.run_until_complete(session.close())
157166

158167

159168
if __name__ == '__main__':

0 commit comments

Comments
 (0)