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
It adds PARALLEL_ONE_HOST_ONLY in the worker's capabilities.
Whenever the config is updated the worker will update its capabilities to the
database and if this already exists, it will fail in the case where the config
removes it. So it needs to be deleted if its val is not defined.

Signed-off-by: ybonatakis <[email protected]>
  • Loading branch information
b10n1k committed Jun 27, 2024
1 parent 21904f8 commit 2d60cc4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 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
4 changes: 4 additions & 0 deletions etc/openqa/workers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# space separated list of webuis to connect to (empty defaults to localhost)
#HOST = http://openqa.example.host

# Enable to restrict any multi-machine jobs taken by this worker host to only run here.
# Disabled by default.
#PARALLEL_ONE_HOST_ONLY = 0

# 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
3 changes: 2 additions & 1 deletion lib/OpenQA/Schema/Result/Workers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ sub update_caps {
my ($self, $workercaps) = @_;

for my $cap (keys %{$workercaps}) {
$self->set_property(uc $cap, $workercaps->{$cap}) if $workercaps->{$cap};
$self->set_property(uc $cap, $workercaps->{$cap}) if exists $workercaps->{$cap};
}
}

Expand All @@ -108,6 +108,7 @@ sub delete_properties {
sub set_property {

my ($self, $key, $val) = @_;
return $self->properties->search({key => $key})->delete unless defined $val;

my $r = $self->properties->find_or_new(
{
Expand Down
7 changes: 3 additions & 4 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);
$validation->optional($_) 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};
return $self->{_caps} = $caps;
}

Expand Down
13 changes: 12 additions & 1 deletion t/24-worker-overall.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ subtest 'capabilities' => sub {
delete $capabilities->{cpu_flags};
delete $capabilities->{cpu_opmode};
delete $capabilities->{cpu_modelname};
delete $capabilities->{parallel_one_host_only};

is_deeply(
[sort keys %$capabilities],
Expand All @@ -142,11 +143,21 @@ subtest 'capabilities' => sub {
# clear cached capabilities
delete $worker->{_caps};

subtest 'capabilities include PARALLEL_ONE_HOST_ONLY setting if present' => sub {
$global_settings->{PARALLEL_ONE_HOST_ONLY} = 1;
$capabilities = $worker->capabilities;
is $capabilities->{parallel_one_host_only}, 1, 'capabilities contain expected information';
delete $global_settings->{PARALLEL_ONE_HOST_ONLY};
};
delete $worker->{_caps};

subtest 'deduce worker class from CPU architecture' => sub {
delete $global_settings->{WORKER_CLASS};
$global_settings->{ARCH} = 'aarch64';

my $capabilities = $worker->capabilities;
my $capabilities = $worker->capabilities;
delete $capabilities->{parallel_one_host_only};

is_deeply(
[sort keys %$capabilities],
[
Expand Down

0 comments on commit 2d60cc4

Please sign in to comment.