From 237983d77d06c15a30b965be2823a5c8a3612f34 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sun, 25 May 2025 19:26:20 +0200 Subject: [PATCH 1/8] Add extra test runners --- .github/workflows/build_and_test.yml | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 51ad28bb8..b0d2bca9b 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -212,3 +212,61 @@ jobs: uses: SimenB/github-actions-cpu-cores@v2 - name: Run tests run: prove --timer --lib --recurse --jobs ${{ steps.cores.outputs.count }} --shuffle t/ + + tests-extra-runners: + needs: build + + strategy: + fail-fast: false + matrix: + os: + - dragonflybsd + - freebsd + - netbsd + - openbsd + - solaris + + runs-on: ubuntu-latest + + timeout-minutes: 20 + + steps: + - name: Download build results + uses: actions/download-artifact@v4 + with: + name: build.tar + - name: Extract build tarball + run: tar xvf build.tar + - name: Set environment variables based on OS + uses: thaitype/actions-switch-case@v1 + id: env_cmd + with: + default: 'echo Using default environment' + conditionals-with-values: | + ${{ matrix.os == 'dragonflybsd' }} => setenv LANG C + ${{ matrix.os == 'solaris' }} => export PATH=/usr/perl5/bin:/usr/gnu/bin:$PATH + - name: Set system setup command based on OS + uses: thaitype/actions-switch-case@v1 + id: system_cmd + with: + default: '$VM_INSTALL_CMD augeas git' + conditionals-with-values: | + ${{ matrix.os == 'solaris' }} => $VM_INSTALL_CMD developer/gcc/gcc-c developer/versioning/git system/management/augeas + - name: Set cpanm setup command based on OS + uses: thaitype/actions-switch-case@v1 + id: cpanm_cmd + with: + default: '$VM_INSTALL_CMD p5-App-cpanminus' + conditionals-with-values: | + ${{ matrix.os == 'openbsd' }} => cpan install App::cpanminus + ${{ matrix.os == 'solaris' }} => cpan install App::cpanminus + - name: Run tests on ${{ matrix.os }} + uses: jenseng/dynamic-uses@v1 + with: + uses: vmactions/${{ matrix.os }}-vm@v1 + with: | + { + "envs": "LANG PERL_CPANM_OPT VM_INSTALL_CMD", + "prepare": "cd $GITHUB_WORKSPACE; ${{ steps.env_cmd.outputs.match }}; ${{ steps.system_cmd.outputs.match }}; ${{ steps.cpanm_cmd.outputs.match }}; cpanm --installdeps --with-all-features .; cpanm Parallel::ForkManager", + "run": "cd $GITHUB_WORKSPACE; ${{ steps.env_cmd.outputs.match }}; prove --timer --lib --recurse --jobs 4 --shuffle t/" + } From 0ea8377c8db7871ce5d4545788cd73de34b31b2c Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Thu, 29 May 2025 18:38:59 +0200 Subject: [PATCH 2/8] Fix FQDN parsing --- ChangeLog | 1 + lib/Rex/Hardware/Host.pm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dd658d465..f3979718f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Fix FQDN parsing [DOCUMENTATION] diff --git a/lib/Rex/Hardware/Host.pm b/lib/Rex/Hardware/Host.pm index 24a37968d..e10856b3d 100644 --- a/lib/Rex/Hardware/Host.pm +++ b/lib/Rex/Hardware/Host.pm @@ -57,7 +57,7 @@ sub get { else { my @out = i_run "hostname -f 2>/dev/null", fail_ok => 1; - if ( $? == 0 ) { + if ( $? == 0 && defined $out[0] ) { ( $hostname, $domain ) = split( /\./, $out[0], 2 ); } else { From dbdc91f3e5fc0aa4e4836a1b4d34d4d27eccff73 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 26 May 2025 16:27:46 +0200 Subject: [PATCH 3/8] Mark Augeas tests as TODO on NetBSD --- t/augeas.t | 63 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/t/augeas.t b/t/augeas.t index b745236cc..7abbf6c9c 100755 --- a/t/augeas.t +++ b/t/augeas.t @@ -9,11 +9,14 @@ use Test::More; use Test::Warnings; use Test::Output; +use English qw(-no_match_vars); use File::Temp qw(tmpnam); use Module::Load::Conditional qw(check_install); use Rex::Commands::Augeas; use Rex::Commands::Run; +$::QUIET = 1; + my $augeas_binary = 'augtool'; my $augeas_module = 'Config::Augeas'; @@ -41,51 +44,59 @@ for my $backend (@augeas_backends) { Rex::Config->set_local_augeas_backend($backend); subtest "Simplelines lens with $backend" => sub { - plan tests => 7; + TODO: { + local $TODO = undef; + + if ( $OSNAME eq 'netbsd' ) { + $TODO = 'Augeas tests fail on NetBSD'; + } + + plan tests => 7; - Rex::Config->set_augeas_commands_prepend( - [ "transform Simplelines incl $file", 'load', ] ); + Rex::Config->set_augeas_commands_prepend( + [ "transform Simplelines incl $file", 'load', ] ); - my $path = '/files' . $file . '/1'; + my $path = '/files' . $file . '/1'; - is( -e $file, undef, 'test file does not exist yet' ); + is( -e $file, undef, 'test file does not exist yet' ); - # modify + # modify - augeas modify => $path => $test_value; + augeas modify => $path => $test_value; - is( -e $file, 1, 'test file created' ); + is( -e $file, 1, 'test file created' ); - # exists + # exists - my $has_first_entry = augeas exists => $path; + my $has_first_entry = augeas exists => $path; - is( $has_first_entry, 1, 'first entry exists' ); + is( $has_first_entry, 1, 'first entry exists' ); - # get + # get - my $retrieved_value = augeas get => $path; + my $retrieved_value = augeas get => $path; - is( $retrieved_value, $test_value, 'test value retrieved' ); + is( $retrieved_value, $test_value, 'test value retrieved' ); - # dump + # dump - stdout_is( - sub { augeas dump => $path }, - qq($path = "$test_value"\n), - 'correct dump output' - ); + stdout_is( + sub { augeas dump => $path }, + qq($path = "$test_value"\n), + 'correct dump output' + ); - # remove + # remove - augeas remove => $path; + augeas remove => $path; - my $still_has_first_entry = augeas exists => $path; + my $still_has_first_entry = augeas exists => $path; - is( $still_has_first_entry, 0, 'first entry removed' ); + is( $still_has_first_entry, 0, 'first entry removed' ); - unlink $file; + unlink $file; - is( -e $file, undef, 'test file cleaned up' ); + is( -e $file, undef, 'test file cleaned up' ); + } }; } From 335b0ad67529263f2d2464bc121147fe6a7773da Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Tue, 27 May 2025 18:17:50 +0200 Subject: [PATCH 4/8] Handle SMBios errors gracefully --- ChangeLog | 1 + lib/Rex/Inventory/SMBios.pm | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ChangeLog b/ChangeLog index f3979718f..26d5a6eab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ Revision history for Rex [BUG FIXES] - Fix FQDN parsing + - Handle SMBios errors gracefully [DOCUMENTATION] diff --git a/lib/Rex/Inventory/SMBios.pm b/lib/Rex/Inventory/SMBios.pm index bbb8d0a51..746483f70 100644 --- a/lib/Rex/Inventory/SMBios.pm +++ b/lib/Rex/Inventory/SMBios.pm @@ -13,6 +13,7 @@ use Data::Dumper; use Rex::Logger; use Rex::Commands::Run; use Rex::Helper::Run; +use English qw(-no_match_vars); use Rex::Inventory::SMBios::BaseBoard; use Rex::Inventory::SMBios::Bios; @@ -115,6 +116,12 @@ sub _read_smbios { my @data = i_run( "smbios", fail_ok => 1 ); + if ( $CHILD_ERROR != 0 ) { + Rex::Logger::debug('Error running smbios. Output:'); + Rex::Logger::debug( join "\n", @data ); + return; + } + my ( $current_section, %section, $key, $val, %cur_data ); for my $line (@data) { next if ( $line =~ /^$/ ); From 76d80b9fc2a68a17ef75ad4751096e67feb49667 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Tue, 27 May 2025 18:19:29 +0200 Subject: [PATCH 5/8] Fix parsing free memory on Solaris --- ChangeLog | 1 + lib/Rex/Hardware/Memory.pm | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 26d5a6eab..61ff88a92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Revision history for Rex [BUG FIXES] - Fix FQDN parsing - Handle SMBios errors gracefully + - Fix parsing free memory on Solaris [DOCUMENTATION] diff --git a/lib/Rex/Hardware/Memory.pm b/lib/Rex/Hardware/Memory.pm index 6f6030773..975b322f9 100644 --- a/lib/Rex/Hardware/Memory.pm +++ b/lib/Rex/Hardware/Memory.pm @@ -58,7 +58,8 @@ sub get { if ( $CHILD_ERROR == 0 ) { my ($free_cache) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data; - my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data; + my ($free_list) = + map { /\D+\d+\s+(\d+)/ } grep { /^Free (\s+|\(freel)/ } @data; my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data; my $free = $free_cache + $free_list; From f76913fffc26e0ef0debe32e1e67e808af89ea0c Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Wed, 28 May 2025 17:25:46 +0200 Subject: [PATCH 6/8] Fix shared variable lockfile on Solaris --- ChangeLog | 1 + lib/Rex/Shared/Var/Common.pm | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61ff88a92..1e0db9518 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ Revision history for Rex - Fix FQDN parsing - Handle SMBios errors gracefully - Fix parsing free memory on Solaris + - Fix shared variable lockfile on Solaris [DOCUMENTATION] diff --git a/lib/Rex/Shared/Var/Common.pm b/lib/Rex/Shared/Var/Common.pm index 20be9d34f..2055927fe 100644 --- a/lib/Rex/Shared/Var/Common.pm +++ b/lib/Rex/Shared/Var/Common.pm @@ -26,8 +26,8 @@ our $LOCK_FILE = File::Spec->catfile( File::Spec->tmpdir(), "vars.db.lock.$PARENT_PID" ); sub __lock { - sysopen( my $dblock, $LOCK_FILE, O_RDONLY | O_CREAT ) or die($!); - flock( $dblock, LOCK_EX ) or die($!); + sysopen( my $dblock, $LOCK_FILE, O_RDWR | O_CREAT ) or die($!); + flock( $dblock, LOCK_EX ) or die($!); my $ret = $_[0]->(); From 4f56d5aa386c45ce9873b18ee8fd2ae71f6dd25c Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Fri, 30 May 2025 16:21:32 +0200 Subject: [PATCH 7/8] Refactor internal PATH --- lib/Rex/Config.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Rex/Config.pm b/lib/Rex/Config.pm index 6f52335cb..6ba00ecac 100644 --- a/lib/Rex/Config.pm +++ b/lib/Rex/Config.pm @@ -750,10 +750,15 @@ sub set_path { sub get_path { if ( !$path ) { - return ( - "/bin", "/sbin", "/usr/bin", - "/usr/sbin", "/usr/local/bin", "/usr/local/sbin", - "/usr/pkg/bin", "/usr/pkg/sbin" + return qw( + /bin + /sbin + /usr/bin + /usr/sbin + /usr/local/bin + /usr/local/sbin + /usr/pkg/bin + /usr/pkg/sbin ); } return @{$path}; From a7e06a2f60ad5bdbdbc2bd59e62862de744af23b Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Wed, 28 May 2025 18:46:22 +0200 Subject: [PATCH 8/8] Prefer GNU tools on Solaris --- ChangeLog | 1 + lib/Rex/Config.pm | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1e0db9518..666311eeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ Revision history for Rex - Handle SMBios errors gracefully - Fix parsing free memory on Solaris - Fix shared variable lockfile on Solaris + - Prefer GNU tools on Solaris [DOCUMENTATION] diff --git a/lib/Rex/Config.pm b/lib/Rex/Config.pm index 6ba00ecac..4b51e8be3 100644 --- a/lib/Rex/Config.pm +++ b/lib/Rex/Config.pm @@ -731,6 +731,7 @@ The value should be set as an array reference, and will be dereferenced as such Default is qw( + /usr/gnu/bin /bin /sbin /usr/bin @@ -751,6 +752,7 @@ sub set_path { sub get_path { if ( !$path ) { return qw( + /usr/gnu/bin /bin /sbin /usr/bin