From c0eb3cbd3f7cdfec88f29efde089c0d715cd3c97 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Fri, 11 Aug 2023 11:57:24 +0200 Subject: [PATCH] status server uris sync up When user sets only one of the status server values (uri, listen) Then the avocado will stop working because it will listen on different uri than the messages will be sent. This change will synchronize these values if the user sets only one of them. Reference: #5740 Signed-off-by: Jan Richter --- avocado/plugins/runner_nrunner.py | 28 +++++++++++++++++-- selftests/functional/plugin/runner_nrunner.py | 16 +++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 selftests/functional/plugin/runner_nrunner.py diff --git a/avocado/plugins/runner_nrunner.py b/avocado/plugins/runner_nrunner.py index b0ad4d7778..df37be70bb 100644 --- a/avocado/plugins/runner_nrunner.py +++ b/avocado/plugins/runner_nrunner.py @@ -36,6 +36,8 @@ from avocado.core.task.runtime import RuntimeTaskGraph from avocado.core.task.statemachine import TaskStateMachine, Worker +DEFAULT_SERVER_URI = "127.0.0.1:8888" + class RunnerInit(Init): @@ -69,12 +71,14 @@ def initialize(self): help_msg = ( 'URI where status server will listen on. Usually a "HOST:PORT" ' - 'string. This is only effective if "status_server_auto" is disabled' + 'string. This is only effective if "status_server_auto" is disabled. ' + 'If "status_server_uri" is not set, the value from "status_server_listen " ' + "will be used." ) settings.register_option( section=section, key="status_server_listen", - default="127.0.0.1:8888", + default=DEFAULT_SERVER_URI, metavar="HOST:PORT", help_msg=help_msg, ) @@ -84,11 +88,13 @@ def initialize(self): 'a "HOST:PORT" string. Use this if your status server ' "is in another host, or different port. This is only " 'effective if "status_server_auto" is disabled' + 'If "status_server_listen" is not set. Value from "status_server_uri" ' + "will be used." ) settings.register_option( section=section, key="status_server_uri", - default="127.0.0.1:8888", + default=DEFAULT_SERVER_URI, metavar="HOST:PORT", help_msg=help_msg, ) @@ -229,7 +235,23 @@ def _determine_status_server(self, test_suite, config_key): return os.path.join(self.status_server_dir.name, ".status_server.sock") return test_suite.config.get(config_key) + def _sync_status_server_urls(self, config): + server_listen = config.get("run.status_server_listen") + server_uri = config.get("run.status_server_uri") + if not config.get("run.status_server_auto"): + if ( + server_uri is not DEFAULT_SERVER_URI + and server_listen is DEFAULT_SERVER_URI + ): + config["run.status_server_listen"] = server_uri + if ( + server_uri is DEFAULT_SERVER_URI + and server_listen is not DEFAULT_SERVER_URI + ): + config["run.status_server_uri"] = server_listen + def _create_status_server(self, test_suite, job): + self._sync_status_server_urls(test_suite.config) listen = self._determine_status_server(test_suite, "run.status_server_listen") # pylint: disable=W0201 self.status_repo = StatusRepo(job.unique_id) diff --git a/selftests/functional/plugin/runner_nrunner.py b/selftests/functional/plugin/runner_nrunner.py new file mode 100644 index 0000000000..0fcdf9b0c5 --- /dev/null +++ b/selftests/functional/plugin/runner_nrunner.py @@ -0,0 +1,16 @@ +from avocado.core.exit_codes import AVOCADO_ALL_OK +from avocado.utils import process +from selftests.utils import AVOCADO, TestCaseTmpDir + + +class NrunnerTest(TestCaseTmpDir): + def test_status_server_uri(self): + result = process.run( + f"{AVOCADO} run " + f"--job-results-dir {self.tmpdir.name} " + f"--disable-sysinfo --status-server-disable-auto " + f"--status-server-uri 127.0.0.1:9999 " + f"examples/tests/true", + ) + self.assertIn("PASS 1 ", result.stdout_text) + self.assertEqual(result.exit_status, AVOCADO_ALL_OK)