Skip to content

Commit c2016a2

Browse files
authored
Merge pull request #5917 from Martchus/check-ovs-service
Avoid incomplete jobs if Open vSwitch related service is not running
2 parents 54de77b + eeb2e67 commit c2016a2

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

lib/OpenQA/Worker.pm

+15-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sub new ($class, $cli_options) {
9595
$self->{_pool_directory_lock_fd} = undef;
9696
$self->{_shall_terminate} = 0;
9797
$self->{_finishing_off} = undef;
98+
$self->{_ovs_dbus_service_name} = $ENV{OVS_DBUS_SERVICE_NAME} // 'org.opensuse.os_autoinst.switch';
9899

99100
return $self;
100101
}
@@ -601,6 +602,14 @@ sub is_qemu_running ($self) {
601602
return undef;
602603
}
603604

605+
sub is_ovs_dbus_service_running ($self) {
606+
eval { defined &Net::DBus::system or require Net::DBus };
607+
return 0 if $@;
608+
my $bus = ($self->{_system_dbus} //= Net::DBus->system(nomainloop => 1));
609+
my $service = eval { defined $bus->get_service('org.opensuse.os_autoinst.switch') };
610+
return !$@ && $service;
611+
}
612+
604613
# checks whether the worker is available
605614
# note: This is used to check certain error conditions *before* starting a job to prevent incompletes and
606615
# being able to propagate the brokenness to the web UIs.
@@ -623,7 +632,12 @@ sub check_availability ($self) {
623632
}
624633

625634
# auto-detect worker address if not specified explicitly
626-
return 'Unable to determine worker address (WORKER_HOSTNAME)' unless $self->settings->auto_detect_worker_address;
635+
my $settings = $self->settings;
636+
return 'Unable to determine worker address (WORKER_HOSTNAME)' unless $settings->auto_detect_worker_address;
637+
638+
# check org.opensuse.os_autoinst.switch if it is a MM-capable worker slot
639+
return "D-Bus service '$self->{_ovs_dbus_service_name}' is not running"
640+
if $settings->has_class('tap') && !$self->is_ovs_dbus_service_running;
627641

628642
return undef;
629643
}

lib/OpenQA/Worker/Settings.pm

+5
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,9 @@ sub is_local_worker ($self) {
132132
return $self->{_local} = 1;
133133
}
134134

135+
sub has_class ($self, $worker_class) {
136+
my $c = $self->{_worker_classes} //= {map { $_ => 1 } split(',', $self->global_settings->{WORKER_CLASS} // '')};
137+
return exists $c->{$worker_class};
138+
}
139+
135140
1;

t/24-worker-overall.t

+22
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ my $load_avg_file = simulate_load('0.93 0.95 10.25 2/2207 1212', 'worker-overall
7878
use Mojo::Base -base;
7979
has availability_error => 'Cache service info error: Connection refused';
8080
}
81+
{
82+
package Test::FakeDBus; # uncoverable statement count:2
83+
use Mojo::Base -base, -signatures;
84+
has mock_service_value => 1;
85+
sub get_service ($self, $service_name) { $self->mock_service_value }
86+
}
8187

88+
my $dbus_mock = Test::MockModule->new('Net::DBus', no_auto => 1);
89+
$dbus_mock->define(system => sub (@) { Test::FakeDBus->new });
8290
my $cache_service_client_mock = Test::MockModule->new('OpenQA::CacheService::Client');
8391
$cache_service_client_mock->redefine(info => sub { Test::FakeCacheServiceClientInfo->new });
8492

@@ -546,6 +554,20 @@ subtest 'checking worker address' => sub {
546554
is $global_settings->{WORKER_HOSTNAME}, 'localhost', '"localhost" assumed as WORKER_HOSTNAME for local worker';
547555
};
548556

557+
subtest 'check availability of Open vSwitch related D-Bus service' => sub {
558+
delete $worker->settings->{_worker_classes};
559+
$worker->settings->global_settings->{WORKER_CLASS} = 'foo,tap,bar';
560+
ok $worker->settings->has_class('tap'), 'worker has tap class';
561+
is $worker->check_availability, undef, 'worker considered available if D-Bus service available';
562+
563+
$worker->{_system_dbus}->mock_service_value(undef);
564+
like $worker->check_availability, qr/D-Bus/, 'worker considered broken if D-Bus service not available';
565+
566+
delete $worker->settings->{_worker_classes};
567+
$worker->settings->global_settings->{WORKER_CLASS} = 'foo,bar';
568+
is $worker->check_availability, undef, 'worker considered always available if not a tap worker';
569+
};
570+
549571
subtest 'handle client status changes' => sub {
550572
my $fake_client = OpenQA::Worker::WebUIConnection->new('some-host', {apikey => 'foo', apisecret => 'bar'});
551573
my $fake_client_2

0 commit comments

Comments
 (0)