Skip to content

Commit

Permalink
experiment: Unify perl linting rules
Browse files Browse the repository at this point in the history
Testing the perltidy config from os-autoinst/os-autoinst-common#30
  • Loading branch information
josegomezr committed Oct 25, 2023
1 parent 576c710 commit 2db8105
Show file tree
Hide file tree
Showing 83 changed files with 1,705 additions and 1,159 deletions.
7 changes: 4 additions & 3 deletions .perltidyrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# # See <https://github.com/houseabsolute/perl-code-tidyall/issues/84>.
--character-encoding=none
--no-valign
# 120 characters would be desired but it is not feasible right now
#-l=120 # 120 characters per line

# TBD: openqa defines: -l=120 vs -l=160 in os-autoinst-distri-opensuse
# taking the most relaxed for now.

-l=160
-fbl # don't change blank lines
-fnl # don't remove new lines
-nsfs # no spaces before semicolons
-baao # space after operators
-bbao # space before operators
Expand Down
11 changes: 7 additions & 4 deletions OpenQA/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ sub start_ws ($self) {
message => sub ($self, $msg) {
$self->pass_message_from_ws_client_to_isotovideo($id, $msg);
});
$self->on(finish => sub {
$self->on(
finish => sub {
$self->handle_ws_client_disconnects($id);
});
});
}

sub broadcast_message_to_websocket_clients ($self) {
Expand All @@ -70,10 +71,12 @@ sub broadcast_message_to_websocket_clients ($self) {
return $self->render(json => {status => 'boradcast done'}) unless $outstanding_transactions;

for (keys %$clients) {
$clients->{$_}->send({json => $message}, sub {
$clients->{$_}->send(
{json => $message},
sub {
return undef if (($outstanding_transactions -= 1) > 0);
return $self->render(json => {status => 'boradcast done'});
});
});
}

return $self;
Expand Down
55 changes: 33 additions & 22 deletions OpenQA/Isotovideo/CommandHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ sub _pass_command_to_backend_unless_paused ($self, $response, $backend_cmd) {
die 'isotovideo: we need to implement a backend queue' if $self->backend_requester;
$self->backend_requester($self->answer_fd);

$self->_send_to_cmd_srv({
$self->_send_to_cmd_srv(
{
$backend_cmd => $response,
current_api_function => $backend_cmd,
});
});
$self->_send_to_backend({cmd => $backend_cmd, arguments => $response});
$self->current_api_function($backend_cmd);
}
Expand Down Expand Up @@ -173,9 +174,9 @@ sub _handle_command_report_timeout ($self, $response, @) {
}

sub _handle_command_is_configured_to_pause_on_timeout ($self, $response, @) {
$self->_respond({
ret => ($self->_is_configured_to_pause_on_timeout($response) ? 1 : 0)
});
$self->_respond(
{
ret => ($self->_is_configured_to_pause_on_timeout($response) ? 1 : 0)});
}

sub _handle_command_set_pause_at_test ($self, $response, @) {
Expand Down Expand Up @@ -225,8 +226,9 @@ sub _handle_command_resume_test_execution ($self, $response, @) {
my $postponed_command = $self->postponed_command;
my $postponed_answer_fd = $self->postponed_answer_fd;

diag($self->reason_for_pause ?
'isotovideo: test execution will be resumed'
diag(
$self->reason_for_pause
? 'isotovideo: test execution will be resumed'
: 'isotovideo: resuming test execution requested but not paused anyways'
);
$self->_send_to_cmd_srv({resume_test_execution => $postponed_command});
Expand All @@ -245,10 +247,12 @@ sub _handle_command_resume_test_execution ($self, $response, @) {

# if no command has been postponed (because paused due to timeout or on set_current_test) just return 1
if (!$postponed_command) {
myjsonrpc::send_json($postponed_answer_fd, {
myjsonrpc::send_json(
$postponed_answer_fd,
{
ret => ($response->{options} // 1),
new_needles => $response->{new_needles},
});
});
$self->postponed_answer_fd(undef);
return;
}
Expand All @@ -271,12 +275,13 @@ sub _handle_command_set_current_test ($self, $response, @) {
$self->current_test_name($test_name);
$self->status('running');
$self->current_test_full_name($full_test_name);
$self->_send_to_cmd_srv({
$self->_send_to_cmd_srv(
{
set_current_test => $test_name,
current_test_full_name => $full_test_name,
});
});

if ($pause_test_name
if ( $pause_test_name
&& $test_name
&& $full_test_name
&& ($pause_test_name eq $test_name || $pause_test_name eq $full_test_name))
Expand Down Expand Up @@ -307,30 +312,35 @@ sub _handle_command_check_screen ($self, $response, @) {
check => $response->{check},
);
my $current_api_function = $response->{check} ? 'check_screen' : 'assert_screen';
$self->_send_to_cmd_srv({
$self->_send_to_cmd_srv(
{
check_screen => \%arguments,
current_api_function => $current_api_function,
});
$self->tags($bmwqemu::backend->_send_json(
});
$self->tags(
$bmwqemu::backend->_send_json(
{
cmd => 'set_tags_to_assert',
arguments => \%arguments,
})->{tags});
}
)->{tags});
$self->current_api_function($current_api_function);
}

sub _handle_command_set_assert_screen_timeout ($self, $response, @) {
my $timeout = $response->{timeout};
$self->_send_to_cmd_srv({set_assert_screen_timeout => $timeout});
$bmwqemu::backend->_send_json({
$bmwqemu::backend->_send_json(
{
cmd => 'set_assert_screen_timeout',
arguments => $timeout,
});
});
$self->_respond_ok();
}

sub _handle_command_status ($self, $response, @) {
$self->_respond({
$self->_respond(
{
tags => $self->tags,
running => $self->current_test_name,
current_test_full_name => $self->current_test_full_name,
Expand All @@ -342,15 +352,16 @@ sub _handle_command_status ($self, $response, @) {
test_execution_paused => $self->reason_for_pause,
devel_mode_major_version => $OpenQA::Isotovideo::Interface::developer_mode_major_version,
devel_mode_minor_version => $OpenQA::Isotovideo::Interface::developer_mode_minor_version,
});
});
}

sub _handle_command_version ($self, $response, @) {
$self->_respond({
$self->_respond(
{
test_git_hash => $bmwqemu::vars{TEST_GIT_HASH},
needles_git_hash => $bmwqemu::vars{NEEDLES_GIT_HASH},
version => $OpenQA::Isotovideo::Interface::version,
});
});
}

sub _handle_command_read_serial ($self, $response, @) {
Expand Down
9 changes: 6 additions & 3 deletions OpenQA/Isotovideo/NeedleDownloader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ sub _add_download ($self, $needle, $extension, $path_param) {
if (my $target_last_modified = $target_stat->[9] // $target_stat->[8]) {
$target_last_modified = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime($target_last_modified));
if ($target_last_modified ge $latest_update) {
bmwqemu::diag("skipping downloading new needle: $download_target seems already up-to-date (last update: $target_last_modified > $latest_update)");
bmwqemu::diag(
"skipping downloading new needle: $download_target seems already up-to-date (last update: $target_last_modified > $latest_update)");
return;
}
}
}

push(@{$self->files_to_download}, {
push(
@{$self->files_to_download},
{
target => $download_target,
url => Mojo::URL->new($self->openqa_url . $needle->{$path_param}),
});
});
}

sub _download_file ($self, $download) {
Expand Down
16 changes: 10 additions & 6 deletions OpenQA/Isotovideo/Runner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ sub _read_response ($self, $rsp, $fd) {
if (!defined $rsp) {
fctwarn sprintf("THERE IS NOTHING TO READ %d %d %d", fileno($fd), fileno($self->testfd), fileno($self->cmd_srv_fd));
$self->loop(0);
} elsif ($fd == $self->command_handler->backend_out_fd) {
}
elsif ($fd == $self->command_handler->backend_out_fd) {
$self->command_handler->send_to_backend_requester({ret => $rsp->{rsp}});
} else {
}
else {
$self->command_handler->process_command($fd, $rsp);
}
}
Expand Down Expand Up @@ -115,22 +117,24 @@ sub handle_commands ($self) {
backend_fd => $self->backend->process->channel_in,
backend_out_fd => $self->backend->process->channel_out,
);
$command_handler->on(tests_done => sub (@) {
$command_handler->on(
tests_done => sub (@) {
CORE::close($self->testfd);
$self->testfd(undef);
$self->stop_autotest();
$self->loop(0);
});
});
# uncoverable statement count:1
# uncoverable statement count:2
# uncoverable statement count:3
# uncoverable statement count:4
$command_handler->on(signal => sub ($event, $sig) {
$command_handler->on(
signal => sub ($event, $sig) {
$self->backend->stop if defined $self->backend; # uncoverable statement
$self->stop_commands("received signal $sig"); # uncoverable statement
$self->stop_autotest(); # uncoverable statement
_exit(1); # uncoverable statement
});
});
$self->setup_signal_handler;

$self->command_handler($command_handler);
Expand Down
14 changes: 11 additions & 3 deletions OpenQA/Isotovideo/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,21 @@ sub handle_generated_assets ($command_handler, $clean_shutdown) {
push @toextract, _store_asset($i, $name, $dir);
}
if ($bmwqemu::vars{UEFI} && $bmwqemu::vars{PUBLISH_PFLASH_VARS}) {
push(@toextract, {pflash_vars => 1,
push(
@toextract,
{
pflash_vars => 1,
name => $bmwqemu::vars{PUBLISH_PFLASH_VARS},
dir => 'assets_public',
format => 'qcow2'});
format => 'qcow2'
});
}
if (@toextract && !$clean_shutdown) {
bmwqemu::serialize_state(component => 'isotovideo', msg => 'unable to handle generated assets: machine not shut down when uploading disks', error => 1);
bmwqemu::serialize_state(
component => 'isotovideo',
msg => 'unable to handle generated assets: machine not shut down when uploading disks',
error => 1
);
return 1;
}
}
Expand Down
34 changes: 14 additions & 20 deletions OpenQA/Qemu/BlockDev.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,15 @@ sub gen_cmdline ($self) {
# The first blockdev defines the data store, we only use files, but in
# theory it could be a http address, ISCSI or a link to an object store
# item (like Ceph).
push(@cmdl, ('-blockdev',
join(',', ('driver=file',
'node-name=' . $self->node_name . FILE_POSTFIX,
'filename=' . $self->file,
'cache.no-flush=on'))));
push(@cmdl, ('-blockdev', join(',', ('driver=file', 'node-name=' . $self->node_name . FILE_POSTFIX, 'filename=' . $self->file, 'cache.no-flush=on'))));
# The second blockdev tells QEMU what format we are using i.e. qcow2.
push(@cmdl, ('-blockdev',
join(',', ('driver=' . $self->driver,
'node-name=' . $self->node_name,
'file=' . $self->node_name . FILE_POSTFIX,
'cache.no-flush=on',
'discard=unmap'))));
push(
@cmdl,
(
'-blockdev',
join(',',
('driver=' . $self->driver, 'node-name=' . $self->node_name, 'file=' . $self->node_name . FILE_POSTFIX, 'cache.no-flush=on', 'discard=unmap')))
);

return @cmdl;
}
Expand Down Expand Up @@ -171,13 +168,15 @@ sub gen_unlink_list ($self) {
}

sub _to_map ($self) {
return {driver => $self->driver,
return {
driver => $self->driver,
file => $self->file,
node_name => $self->node_name,
size => $self->size,
needs_creating => $self->needs_creating,
implicit => $self->implicit,
snapshot => $self->snapshot->sequence};
snapshot => $self->snapshot->sequence
};
}

sub _from_map ($self, $drives, $snap_conf) {
Expand All @@ -186,13 +185,8 @@ sub _from_map ($self, $drives, $snap_conf) {
$self->backing_file(OpenQA::Qemu::BlockDev->new()->_from_map(\@rest, $snap_conf))
if @rest > 0;

return $self->driver($this->{driver})
->file($this->{file})
->node_name($this->{node_name})
->size($this->{size})
->needs_creating($this->{needs_creating})
->implicit($this->{implicit})
->snapshot($snap_conf->get_snapshot(sequence => $this->{snapshot}));
return $self->driver($this->{driver})->file($this->{file})->node_name($this->{node_name})->size($this->{size})->needs_creating($this->{needs_creating})
->implicit($this->{implicit})->snapshot($snap_conf->get_snapshot(sequence => $this->{snapshot}));
}

sub deduce_driver ($self) { $self->driver($self->file =~ qr/\.(qcow2|vmdk)/ ? "$1" : 'raw') }
Expand Down
Loading

0 comments on commit 2db8105

Please sign in to comment.