Skip to content

Commit

Permalink
Merge pull request #168 from canonical/agent-identifier-field
Browse files Browse the repository at this point in the history
Add an identifier field for associating devices based on CID
  • Loading branch information
plars authored Dec 7, 2023
2 parents c79d645 + 7ffbd59 commit aa83f42
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions agent/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ The following configuration options are supported:

- Unique identifier for this agent

- **identifier**:

- Additional identifier such as a serial number that will be sent to the server and can be used for cross-referencing with other systems

- **polling_interval**:

- Time to sleep between polling for new tests (default: 10s)
Expand Down
7 changes: 6 additions & 1 deletion agent/testflinger_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def _post_initial_agent_data(self):
self._post_advertised_images()

queues = self.client.config.get("job_queues", [])
self.client.post_agent_data({"queues": queues, "location": location})
identifier = self.client.config.get("identifier")
agent_data = {"queues": queues, "location": location}
if identifier:
agent_data["identifier"] = identifier

self.client.post_agent_data(agent_data)

def _post_advertised_queues(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions agent/testflinger_agent/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

SCHEMA_V1 = {
voluptuous.Required("agent_id"): str,
voluptuous.Optional("identifier"): str,
voluptuous.Optional("location"): str,
voluptuous.Required("polling_interval", default=10): int,
voluptuous.Required("server_address"): str,
voluptuous.Required(
Expand Down
2 changes: 2 additions & 0 deletions agent/testflinger_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def agent(self, requests_mock):
self.tmpdir = tempfile.mkdtemp()
self.config = {
"agent_id": "test01",
"identifier": "12345-123456",
"polling_interval": "2",
"server_address": "127.0.0.1:8000",
"job_queues": ["test"],
Expand Down Expand Up @@ -215,6 +216,7 @@ def test_post_agent_data(self, agent):
agent._post_initial_agent_data()
mock_post_agent_data.assert_called_with(
{
"identifier": self.config["identifier"],
"queues": self.config["job_queues"],
"location": self.config["location"],
}
Expand Down
2 changes: 2 additions & 0 deletions agent/testflinger_agent/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

GOOD_CONFIG = """
agent_id: test01
identifier: 12345-123456
polling_interval: 10
server_address: 127.0.0.1:8000
location: earth
job_queues:
- test
"""
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/testflinger-agent-conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The following configuration options are supported by the Testflinger Agent:
- Description
* - ``agent_id``
- Unique identifier for this agent
* - ``identifier``
- Additional identifier such as a serial number that will be sent to the server and can be used for cross-referencing with other systems
* - ``polling_interval``
- Time to sleep between polling for new tests (default: 10s)
* - ``server_address``
Expand Down

0 comments on commit aa83f42

Please sign in to comment.