Skip to content

Commit 912b206

Browse files
feat(agents): declare which driver specs need a per-node agent key
Adds agent_key_node to AbstractPoolDriverSpec (None by default), overridden by ExordosLocalHyperDriverSpec to return its node. Lets callers ensure a key generically instead of branching on isinstance(driver_spec, ExordosLocalHyperDriverSpec).
1 parent 1bd6204 commit 912b206

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

gcl_sdk/agents/universal/drivers/pool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ class AbstractPoolDriverSpec(
335335
):
336336
"""Base class for all pool driver specs."""
337337

338+
@property
339+
def agent_key_node(self) -> sys_uuid.UUID | None:
340+
"""Node uuid whose agent authenticates with a per-node encryption
341+
key, or None if this driver kind's agent doesn't need one."""
342+
return None
343+
338344

339345
class LibvirtPoolDriverSpec(AbstractPoolDriverSpec):
340346
KIND = "libvirt"
@@ -378,6 +384,10 @@ class ExordosLocalHyperDriverSpec(LibvirtPoolDriverSpec):
378384

379385
node = properties.property(types.UUID(), required=True)
380386

387+
@property
388+
def agent_key_node(self) -> sys_uuid.UUID | None:
389+
return self.node
390+
381391

382392
class DummyPoolDriverSpec(AbstractPoolDriverSpec):
383393
KIND = "dummy"

gcl_sdk/tests/unit/agents/drivers/test_pool_driver.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,23 @@ def test_local_pool_agent_driver_lists_pool_normally(self, tmp_path):
122122

123123
listed = local_drv.list("pool")
124124
assert [r.uuid for r in listed] == [pool_uuid]
125+
126+
127+
class TestDriverSpecAgentKeyNode:
128+
def test_exordos_local_hyper_declares_its_node(self):
129+
node = sys_uuid.uuid4()
130+
spec = pool_driver.ExordosLocalHyperDriverSpec(
131+
connection_uri="qemu:///system", node=node
132+
)
133+
134+
assert spec.agent_key_node == node
135+
136+
@pytest.mark.parametrize(
137+
"spec",
138+
[
139+
pool_driver.LibvirtPoolDriverSpec(connection_uri="qemu+tcp://127.0.0.1/system"),
140+
pool_driver.DummyPoolDriverSpec(),
141+
],
142+
)
143+
def test_other_kinds_declare_no_node(self, spec):
144+
assert spec.agent_key_node is None

0 commit comments

Comments
 (0)