Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit d4c2c76

Browse files
authored
Merge pull request #353 from jumpstarter-dev/selector-only
treewide: use str typed selector directly
2 parents c119d30 + b9e3528 commit d4c2c76

11 files changed

Lines changed: 26 additions & 43 deletions

File tree

docs/source/cli/run-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ the base class will attempt to:
4646
1. Use a local connection based on the `JUMPSTARTER_HOST` environment variable
4747
2. Use an existing lease based on the `JMP_LEASE` environment variable, and existing credentials.
4848
See the cli reference for [jmp lease request](../cli-reference/jmp.md#jmp-lease-request).
49-
3. Request a lease based on the `filter_labels` provided in the test class.
49+
3. Request a lease based on the `selector` provided in the test class.
5050

5151
```{eval-rst}
5252
.. autoclass:: jumpstarter_testing.pytest.JumpstarterTest

examples/soc-pytest/jumpstarter_example_soc_pytest/test_on_rpi4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
class TestResource(JumpstarterTest):
17-
filter_labels = {"board": "rpi4"}
17+
selector = "board=rpi4"
1818

1919
@pytest.fixture()
2020
def console(self, client):

packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import asyncclick as click
44
from jumpstarter_cli_common.exceptions import handle_exceptions
55

6-
from .common import opt_config, opt_selector_simple, selector_to_labels
7-
from jumpstarter.common import MetadataFilter
6+
from .common import opt_config, opt_selector_simple
87
from jumpstarter.common.utils import launch_shell
98

109

@@ -18,9 +17,7 @@ def client_shell(config, selector: str, lease_name):
1817

1918
exit_code = 0
2019

21-
with config.lease(
22-
metadata_filter=MetadataFilter(labels=selector_to_labels(selector)), lease_name=lease_name
23-
) as lease:
20+
with config.lease(selector=selector, lease_name=lease_name) as lease:
2421
with lease.serve_unix() as path:
2522
with lease.monitor():
2623
exit_code = launch_shell(path, "remote", config.drivers.allow, config.drivers.unsafe)

packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
)
2525

2626

27-
def selector_to_labels(selector: str):
28-
# TODO: support complex selectors (e.g. !=)
29-
return dict([term.split("=") for term in selector.split(",")])
30-
31-
3227
class ClientParamType(click.ParamType):
3328
name = "client"
3429

packages/jumpstarter-driver-dutlink/examples/dutlink.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from jumpstarter.common.utils import env
99

1010
# initialize client from exporter config
11-
# from jumpstarter.common import MetadataFilter
1211
# from jumpstarter.config.client import ClientConfigV1Alpha1
13-
# with ClientConfigV1Alpha1.load("default").lease(metadata_filter=MetadataFilter()) as lease:
12+
# with ClientConfigV1Alpha1.load("default").lease(selector="example.com/board=dutlink") as lease:
1413
# with lease.connect() as client:
1514

1615
# initialize client from environment

packages/jumpstarter-driver-tftp/examples/tftp_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class TestResource(JumpstarterTest):
11-
filter_labels = {"board": "rpi4"}
11+
selector = "board=rpi4"
1212

1313
@pytest.fixture()
1414
def setup_tftp(self, client):

packages/jumpstarter-testing/jumpstarter_testing/pytest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pytest
66

7-
from jumpstarter.common import MetadataFilter
87
from jumpstarter.common.utils import env
98
from jumpstarter.config.client import ClientConfigV1Alpha1
109

@@ -19,7 +18,7 @@ class JumpstarterTest:
1918
2019
Looks for the `JUMPSTARTER_HOST` environment variable to connect to an
2120
established Jumpstarter shell, otherwise it will try to acquire a lease
22-
for a single exporter using the filter_labels annotation.
21+
for a single exporter using the selector annotation.
2322
i.e.:
2423
2524
.. code-block:: python
@@ -33,7 +32,7 @@ class JumpstarterTest:
3332
log = logging.getLogger(__name__)
3433
3534
class TestResource(JumpstarterTest):
36-
filter_labels = {"board":"rpi4"}
35+
selector = "board=rpi4"
3736
3837
@pytest.fixture()
3938
def console(self, client):
@@ -49,17 +48,17 @@ def test_setup_device(self, client, console):
4948
5049
"""
5150

52-
filter_labels: ClassVar[dict[str, str]]
51+
selector: ClassVar[str]
5352

5453
@pytest.fixture(scope="class")
5554
def client(self):
5655
try:
5756
with env() as client:
5857
yield client
5958
except RuntimeError:
60-
labels = getattr(self, "filter_labels", {})
59+
selector = getattr(self, "selector", None)
6160
config = ClientConfigV1Alpha1.load("default")
62-
with config.lease(metadata_filter=MetadataFilter(labels=labels)) as lease:
61+
with config.lease(selector=selector) as lease:
6362
with lease.connect() as client:
6463
yield client
6564
# BUG workaround: make sure that grpc servers get the client/lease release properly

packages/jumpstarter/jumpstarter/client/lease.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .exceptions import LeaseError
1919
from jumpstarter.client import client_from_path
2020
from jumpstarter.client.grpc import ClientService
21-
from jumpstarter.common import MetadataFilter, TemporaryUnixListener
21+
from jumpstarter.common import TemporaryUnixListener
2222
from jumpstarter.common.condition import condition_false, condition_message, condition_present_and_equal, condition_true
2323
from jumpstarter.common.grpc import translate_grpc_exceptions
2424
from jumpstarter.common.streams import connect_router_stream
@@ -31,7 +31,7 @@
3131
class Lease(AbstractContextManager, AbstractAsyncContextManager):
3232
channel: Channel
3333
timeout: int = 1800
34-
metadata_filter: MetadataFilter = field(default_factory=MetadataFilter)
34+
selector: str
3535
portal: BlockingPortal
3636
namespace: str
3737
name: str | None = field(default=None)
@@ -52,17 +52,16 @@ def __post_init__(self):
5252

5353
async def _create(self):
5454
duration = timedelta(seconds=self.timeout)
55-
selector = ",".join(("{}={}".format(label[0], label[1]) for label in self.metadata_filter.labels.items()))
5655

57-
logger.debug("Creating lease request for selector %s for duration %s", selector, duration)
56+
logger.debug("Creating lease request for selector %s for duration %s", self.selector, duration)
5857
with translate_grpc_exceptions():
5958
self.name = (
6059
await self.svc.CreateLease(
61-
selector=selector,
60+
selector=self.selector,
6261
duration=timedelta(seconds=self.timeout),
6362
)
6463
).name
65-
logger.info("Created lease request for selector %s for duration %s", selector, duration)
64+
logger.info("Created lease request for selector %s for duration %s", self.selector, duration)
6665

6766
async def get(self):
6867
with translate_grpc_exceptions():
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .metadata import Metadata, MetadataFilter
1+
from .metadata import Metadata
22
from .tempfile import TemporarySocket, TemporaryTcpListener, TemporaryUnixListener
33

4-
__all__ = ["Metadata", "MetadataFilter", "TemporarySocket", "TemporaryUnixListener", "TemporaryTcpListener"]
4+
__all__ = ["Metadata", "TemporarySocket", "TemporaryUnixListener", "TemporaryTcpListener"]

packages/jumpstarter/jumpstarter/common/metadata.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ class Metadata:
1212
@property
1313
def name(self):
1414
return self.labels.get("jumpstarter.dev/name", "unknown")
15-
16-
17-
@dataclass(kw_only=True, slots=True)
18-
class MetadataFilter:
19-
labels: dict[str, str] = field(default_factory=dict)

0 commit comments

Comments
 (0)