Created
September 15, 2020 19:55
-
-
Save jimklimov/0f91c5a21751ef21f116742b3ad9aaf5 to your computer and use it in GitHub Desktop.
Snippet for BSConfig.pm selector of suitable OBS workers per job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add-on logic for OBS server config to allow only certain hosts to build certain projects | |
# For specific build constraints, for example to require a specific | |
# security level of the workers. | |
# Return 0 (false) if this worker is not suitable for this job. | |
# Return 1 (true) to allow execution of this job on this worker. | |
# Used from bs_dispatch via | |
# { next if !$BSConfig::dispatch_constraint->($ic->{$job}, $workerinfo{$idle}); } | |
# | |
use Data::Dumper; | |
our $dispatch_constraint = sub { | |
my ($job, $worker) = @_; | |
# | |
### Example to "require a specific security level of the workers" | |
### by using a hostlabel: | |
### return 0 unless (grep {$_ eq "OBS_WORKER_SECURITY_LEVEL_1"} @{$worker->{'hostlabel'} || []}); | |
warn("Considering worker labels: " . Dumper(@{$worker->{'hostlabel'} || []}) . " against job: " . Dumper($job) ); | |
### UPDATE: See data dumps below, can match by {'file'} for these usecases | |
if ($job->{'package'} =~ m/preinstall/i ) { | |
return 0 unless (grep {$_ eq "preinstallimage"} @{$worker->{'hostlabel'} || []}); | |
warn("Matched preinstallimage job on suitable worker"); | |
} elsif ($job->{'package'} =~ m/-image/i || $job->{'repository'} =~ m/_Images$/ ) { | |
return 0 unless (grep {$_ eq "simpleimage"} @{$worker->{'hostlabel'} || []}); | |
warn("Matched simpleimage job on suitable worker"); | |
} elsif (grep {$_ eq "preinstallimage" || $_ eq "simpleimage"} @{$worker->{'hostlabel'} || []}) { | |
# image jobs were assigned above for such worker, so this is a non-image job... | |
return 0 unless (grep {$_ eq "anybuild"} @{$worker->{'hostlabel'} || []}); | |
warn("Matched anybuild job on suitable worker despite it also handling image builds"); | |
} else { | |
warn("Defaulted to allowing anything on this worker"); | |
} | |
return 1; | |
}; | |
1; | |
######################## | |
Example data dump: | |
Considering worker labels: $VAR1 = 'simpleimage'; | |
$VAR2 = 'preinstallimage'; | |
against job: $VAR1 = { | |
'readytime' => 1600192033, | |
'needed' => '0', | |
'reposerver' => 'http://obs.local:5252', | |
'srcmd5' => 'ba0d7623caab900dfb019183d59a387f', | |
'package' => 'ovadevel-image', | |
'project' => 'productproject:master:proprietary:images', | |
'revtime' => 1600191947, | |
'debuginfo' => '1', | |
'disturl' => 'obs://local/productproject:master:proprietary:images/Debian_10.0_Images/ba0d7623caab900dfb019183d59a387f-ovadevel-image', | |
'bcnt' => '1', | |
'verifymd5' => 'ba0d7623caab900dfb019183d59a387f', | |
'path' => [ | |
{ | |
'project' => 'productproject:master:proprietary:images', | |
'repository' => 'Debian_10.0_Images', | |
'server' => 'http://obs.local:5252' | |
}, | |
{ | |
'server' => 'http://obs.local:5252', | |
'repository' => 'Debian_10.0', | |
'project' => 'productproject:master:proprietary' | |
}, | |
{ | |
'project' => 'productproject:master', | |
'repository' => 'Debian_10.0', | |
'server' => 'http://obs.local:5252' | |
}, | |
{ | |
'server' => 'http://obs.local:5252', | |
'project' => 'Pool:master', | |
'repository' => 'Debian_10.0' | |
}, | |
{ | |
'server' => 'http://obs.local:5252', | |
'repository' => 'Debian_10.0', | |
'project' => 'Pool:PreinstallImages' | |
}, | |
{ | |
'repository' => 'standard', | |
'project' => 'Debian:10.0', | |
'server' => 'http://obs.local:5252' | |
} | |
], | |
'file' => 'simpleimage', | |
'job' => 'productproject:master:proprietary:images::Debian_10.0_Images::ovadevel-image-ba0d7623caab900dfb019183d59a387f', | |
'versrel' => '2020.09.15-17.45.47-241', | |
'arch' => 'x86_64', | |
'reason' => 'source change', | |
'srcserver' => 'http://obs.local:5352', | |
'release' => '241.1', | |
'repository' => 'Debian_10.0_Images', | |
'rev' => '241' | |
}; | |
Matched simpleimage job on suitable worker at BSConfig.pm line 232. | |
2020-09-15 19:48:23: assignjob x86_64/productproject:master:proprietary:images::Debian_10.0_Images::ovadevel-image-ba0d7623caab900dfb019183d59a387f -> x86_64:obs-imagebuilder:4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment