Skip to content

Commit

Permalink
Add an identifier field for associating devices based on CID
Browse files Browse the repository at this point in the history
  • Loading branch information
plars committed Dec 1, 2023
1 parent c79d645 commit d477ea4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
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_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
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,21 @@ def _run_control(self, cmd, timeout=60):
"{}@{}".format(control_user, control_host),
cmd,
]
try:
output = subprocess.check_output(
ssh_cmd, stderr=subprocess.STDOUT, timeout=timeout
)
except subprocess.CalledProcessError as e:
raise ProvisioningError(e.output)
logger.debug("Running (on controller): '%s'", ssh_cmd)
with subprocess.Popen(
ssh_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
) as proc:
try:
output = proc.communicate(timeout=timeout)[0]
except subprocess.TimeoutExpired:
proc.kill()
output = proc.communicate(timeout=timeout)[0]
if proc.returncode != 0:
logger.error("Error while running: %s", ssh_cmd)
raise ProvisioningError(output)
return output

def _copy_to_control(self, local_file, remote_file):
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 d477ea4

Please sign in to comment.