From 58c0613811e0b09689887fa539d57a549ccc848c Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Thu, 26 Oct 2023 17:01:19 -0500 Subject: [PATCH 1/3] Make the agent send all known queues, not just advertised ones --- agent/testflinger_agent/agent.py | 9 +++------ agent/testflinger_agent/tests/test_agent.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/agent/testflinger_agent/agent.py b/agent/testflinger_agent/agent.py index a9f049b6..78b2d5d4 100644 --- a/agent/testflinger_agent/agent.py +++ b/agent/testflinger_agent/agent.py @@ -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): """ @@ -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): """ diff --git a/agent/testflinger_agent/tests/test_agent.py b/agent/testflinger_agent/tests/test_agent.py index 591f9a38..02eeaf38 100644 --- a/agent/testflinger_agent/tests/test_agent.py +++ b/agent/testflinger_agent/tests/test_agent.py @@ -23,6 +23,7 @@ def agent(self): "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"), @@ -203,3 +204,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"], + } + ) From 0de027aed08ac682c69e3615425736457ef84819 Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Thu, 26 Oct 2023 17:03:42 -0500 Subject: [PATCH 2/3] Mock requests in test setup to speed up agent tests --- agent/testflinger_agent/tests/test_agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agent/testflinger_agent/tests/test_agent.py b/agent/testflinger_agent/tests/test_agent.py index 02eeaf38..1773f4fd 100644 --- a/agent/testflinger_agent/tests/test_agent.py +++ b/agent/testflinger_agent/tests/test_agent.py @@ -16,7 +16,7 @@ class TestClient: @pytest.fixture - def agent(self): + def agent(self, requests_mock): self.tmpdir = tempfile.mkdtemp() self.config = { "agent_id": "test01", @@ -31,6 +31,8 @@ def agent(self): } 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 From 47b1a2e0f5a9b396937aff21f0238d3b7f34fd98 Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Thu, 26 Oct 2023 17:04:46 -0500 Subject: [PATCH 3/3] Add list of queues with links to the agent_details template --- server/src/templates/agent_detail.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/src/templates/agent_detail.html b/server/src/templates/agent_detail.html index 684980e6..60ac80b4 100644 --- a/server/src/templates/agent_detail.html +++ b/server/src/templates/agent_detail.html @@ -2,17 +2,27 @@ {% set active_page = 'agents' %} {% block content %}
+

Agent Name: {{ agent.name }}
State: {{ agent.state }}
Location: {{ agent.location }}
Last Updated: {{ agent.updated_at.strftime('%Y-%m-%d %H:%M:%S') }}
-
-
+

+

+ Queues: +

    + {% for queue in agent.queues %} +
  • {{ queue }}
  • + {% endfor %} +
+

+

Agent Log:

{{ agent.log|join('\n') }}
+

{% endblock %} \ No newline at end of file