Skip to content

Commit

Permalink
Merge pull request #148 from canonical/send_all_queues_in_agent_data
Browse files Browse the repository at this point in the history
Send all queues in agent data
  • Loading branch information
plars authored Oct 31, 2023
2 parents d4fec20 + 47b1a2e commit a669c17
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
9 changes: 3 additions & 6 deletions agent/testflinger_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ def _post_initial_agent_data(self):
"""Post the initial agent data to the server once on agent startup"""

location = self.client.config.get("location", "")
advertised_queues = self._post_advertised_queues()
self._post_advertised_queues()
self._post_advertised_images()

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

def _post_advertised_queues(self):
"""
Expand All @@ -50,7 +48,6 @@ def _post_advertised_queues(self):
advertised_queues = self.client.config.get("advertised_queues", {})
if advertised_queues:
self.client.post_queues(advertised_queues)
return advertised_queues

def _post_advertised_images(self):
"""
Expand Down
18 changes: 17 additions & 1 deletion agent/testflinger_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@

class TestClient:
@pytest.fixture
def agent(self):
def agent(self, requests_mock):
self.tmpdir = tempfile.mkdtemp()
self.config = {
"agent_id": "test01",
"polling_interval": "2",
"server_address": "127.0.0.1:8000",
"job_queues": ["test"],
"location": "nowhere",
"execution_basedir": self.tmpdir,
"logging_basedir": self.tmpdir,
"results_basedir": os.path.join(self.tmpdir, "results"),
"test_string": "ThisIsATest",
}
testflinger_agent.configure_logging(self.config)
client = _TestflingerClient(self.config)
requests_mock.get(rmock.ANY)
requests_mock.post(rmock.ANY)
yield _TestflingerAgent(client)
# Inside tests, we patch rmtree so that we can check files after the
# run, so we need to clean up the tmpdirs here
Expand Down Expand Up @@ -203,3 +206,16 @@ def test_recovery_failed(self, agent, requests_mock):
assert agent.check_offline()
if os.path.exists(OFFLINE_FILE):
os.unlink(OFFLINE_FILE)

def test_post_agent_data(self, agent):
# Make sure we post the initial agent data
with patch.object(
testflinger_agent.client.TestflingerClient, "post_agent_data"
) as mock_post_agent_data:
agent._post_initial_agent_data()
mock_post_agent_data.assert_called_with(
{
"queues": self.config["job_queues"],
"location": self.config["location"],
}
)
14 changes: 12 additions & 2 deletions server/src/templates/agent_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
{% set active_page = 'agents' %}
{% block content %}
<div class="center">
<p>
Agent Name: {{ agent.name }}<br>
State: {{ agent.state }}<br>
Location: {{ agent.location }}<br>
Last Updated: {{ agent.updated_at.strftime('%Y-%m-%d %H:%M:%S') }}<br>
<br>
<br>
</p>
<p>
Queues:
<ul>
{% for queue in agent.queues %}
<li><a href="/queues/{{ queue }}">{{ queue }}</a></li>
{% endfor %}
</ul>
</p>
<p>
Agent Log:
<div class="center scrollable">
<span style="white-space: pre-line">
{{ agent.log|join('\n') }}
</span>
</div>
</p>
</div>
{% endblock %}

0 comments on commit a669c17

Please sign in to comment.