From b396b5b7626d9ab44da2d8ffadb2773ada24d97d Mon Sep 17 00:00:00 2001 From: ybonatakis Date: Thu, 13 Jun 2024 13:13:14 +0200 Subject: [PATCH] Provide parallel_one_host_only via workers config file --- docs/WritingTests.asciidoc | 4 ++-- etc/openqa/workers.ini | 12 ++++++++++++ lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm | 5 ++--- lib/OpenQA/Worker.pm | 2 +- t/24-worker-overall.t | 10 ++++++++++ t/24-worker-settings.t | 16 ++++++++++++++++ t/data/24-worker-overall/workers.ini | 4 ++++ t/data/24-worker-settings/workers.ini | 4 ++++ 8 files changed, 51 insertions(+), 6 deletions(-) diff --git a/docs/WritingTests.asciidoc b/docs/WritingTests.asciidoc index 158f5c049f86..991b89f3138e 100644 --- a/docs/WritingTests.asciidoc +++ b/docs/WritingTests.asciidoc @@ -672,8 +672,8 @@ eventually workers can be held back for the cluster. It is possible to ensure that all jobs within the same _parallel_ cluster are executed on the same worker host. This is useful for connecting the SUTs without having to connect the physical worker hosts. Use `PARALLEL_ONE_HOST_ONLY=1` to -enable this. Note that adding this setting in `workers.ini` has currently *no* -effect. +enable this. This setting can be applied as a test variable during the time +of scheduling as well as in the worker configuration file `workers.ini`. WARNING: You need to provide enough worker slots on single worker hosts to fit an entire cluster. So this feature is mainly intended to workaround situations diff --git a/etc/openqa/workers.ini b/etc/openqa/workers.ini index 28685760ecce..f925552039a0 100644 --- a/etc/openqa/workers.ini +++ b/etc/openqa/workers.ini @@ -5,7 +5,10 @@ [global] # space separated list of webuis to connect to (empty defaults to localhost) #HOST = http://openqa.example.host +HOST = http://localhost:9526 +# Ensure that Multimachine jobs are scheduled on the same worker host. +#PARALLEL_ONE_HOST_ONLY = 1 # Specify a cache directory for assets and tests to sync them automatically via # http/rsync; the specified path is just an example but what you would usually # use on a normal setup @@ -83,6 +86,15 @@ # The section ids are the instance of the workers. # The key/value pairs will appear in vars.json +[1] +WORKER_CLASS = qemu_x86_64_staging,qemu_x86_64,tap + +[2] +WORKER_CLASS = qemu_x86_64_staging,qemu_x86_64,tap +#PARALLEL_ONE_HOST_ONLY = 1 +[3] +WORKER_CLASS = qemu_x86_64_staging,qemu_x86_64,tap + #[1] #WORKER_CLASS = 64bit-ipmi diff --git a/lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm b/lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm index 172b5bc9ba76..b7096aecfa78 100644 --- a/lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm +++ b/lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm @@ -173,10 +173,10 @@ sub create { my ($self) = @_; my $validation = $self->validation; my @validation_params - = qw(cpu_arch cpu_modelname cpu_opmode cpu_flags mem_max isotovideo_interface_version websocket_api_version worker_class); + = qw(cpu_arch cpu_modelname cpu_opmode cpu_flags mem_max isotovideo_interface_version websocket_api_version worker_class parallel_one_host_only); $validation->required($_) for qw(host instance cpu_arch mem_max worker_class); $validation->optional($_) - for qw(cpu_modelname cpu_opmode cpu_flags isotovideo_interface_version job_id websocket_api_version); + for qw(cpu_modelname cpu_opmode cpu_flags isotovideo_interface_version job_id websocket_api_version parallel_one_host_only); return $self->reply->validation_error({format => 'json'}) if $validation->has_error; my $host = $validation->param('host'); @@ -184,7 +184,6 @@ sub create { my $job_ids = $validation->every_param('job_id'); my $caps = {}; $caps->{$_} = $validation->param($_) for @validation_params; - my $id; try { $id = $self->_register($self->schema, $host, $instance, $caps, $job_ids); diff --git a/lib/OpenQA/Worker.pm b/lib/OpenQA/Worker.pm index 0bd2fa6c3243..d84e6414e401 100644 --- a/lib/OpenQA/Worker.pm +++ b/lib/OpenQA/Worker.pm @@ -212,7 +212,7 @@ sub capabilities ($self) { = join(',', map { 'qemu_' . $_ } @{$supported_archs_by_cpu_archs{$caps->{cpu_arch}} // [$caps->{cpu_arch}]}); # TODO: check installed qemu and kvm? } - + $caps->{parallel_one_host_only} = $global_settings->{PARALLEL_ONE_HOST_ONLY} if exists $global_settings->{PARALLEL_ONE_HOST_ONLY}; return $self->{_caps} = $caps; } diff --git a/t/24-worker-overall.t b/t/24-worker-overall.t index 50bd97f82d70..9e5a98900693 100755 --- a/t/24-worker-overall.t +++ b/t/24-worker-overall.t @@ -142,6 +142,16 @@ subtest 'capabilities' => sub { # clear cached capabilities delete $worker->{_caps}; + subtest 'capabilities include PARALLEL_ONE_HOST_ONLY setting if present' => sub { + my $worker2 = OpenQA::Worker->new({instance => 2, verbose => 1}); + my $capabilities2 = $worker2->capabilities; + # ignore keys which are not always present and also not strictly required anyways + delete $capabilities->{cpu_flags}; + delete $capabilities->{cpu_opmode}; + delete $capabilities->{cpu_modelname}; + is $capabilities2->{parallel_one_host_only}, 1, 'capabilities contain expected information'; + }; + subtest 'deduce worker class from CPU architecture' => sub { delete $global_settings->{WORKER_CLASS}; $global_settings->{ARCH} = 'aarch64'; diff --git a/t/24-worker-settings.t b/t/24-worker-settings.t index d7d300b4f89e..1d62c448251a 100644 --- a/t/24-worker-settings.t +++ b/t/24-worker-settings.t @@ -110,6 +110,22 @@ subtest 'instance-specific settings' => sub { }, 'global settings (instance 2)' ) or diag explain $settings2->global_settings; + my $settings3 = OpenQA::Worker::Settings->new(3); + is_deeply( + $settings3->global_settings, + { + CRITICAL_LOAD_AVG_THRESHOLD => 40, + GLOBAL => 'setting', + WORKER_HOSTNAME => '127.0.0.1', + WORKER_CLASS => 'qemu_aarch64', + LOG_LEVEL => 'test', + LOG_DIR => 'log/dir', + PARALLEL_ONE_HOST_ONLY => 1, + RETRY_DELAY => 5, + RETRY_DELAY_IF_WEBUI_BUSY => 60, + }, + 'global settings (instance 3)' + ) or diag explain $settings2->global_settings; }; subtest 'settings file with errors' => sub { diff --git a/t/data/24-worker-overall/workers.ini b/t/data/24-worker-overall/workers.ini index a6b4cecdfa35..591174532837 100644 --- a/t/data/24-worker-overall/workers.ini +++ b/t/data/24-worker-overall/workers.ini @@ -7,3 +7,7 @@ LOG_LEVEL = debug [1] WORKER_CLASS = qemu_i386,qemu_x86_64 + +[2] +WORKER_CLASS = qemu_i386,qemu_x86_64 +PARALLEL_ONE_HOST_ONLY = 1 diff --git a/t/data/24-worker-settings/workers.ini b/t/data/24-worker-settings/workers.ini index 8f07019c726e..e9523cf4b258 100644 --- a/t/data/24-worker-settings/workers.ini +++ b/t/data/24-worker-settings/workers.ini @@ -16,6 +16,10 @@ FOO = bar RETRY_DELAY = 10 RETRY_DELAY_IF_WEBUI_BUSY = 120 +[3] +WORKER_CLASS = qemu_aarch64 +PARALLEL_ONE_HOST_ONLY = 1 + [http://localhost:9527] HOST_SPECIFIC = setting (localhost)