Skip to content

Commit

Permalink
Provide parallel_one_host_only via workers config file
Browse files Browse the repository at this point in the history
  • Loading branch information
b10n1k committed Jun 17, 2024
1 parent 21904f8 commit b396b5b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/WritingTests.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions etc/openqa/workers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,17 @@ 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');
my $instance = $validation->param('instance');
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/Worker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions t/24-worker-overall.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 16 additions & 0 deletions t/24-worker-settings.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions t/data/24-worker-overall/workers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions t/data/24-worker-settings/workers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b396b5b

Please sign in to comment.