Skip to content

Commit d79cd84

Browse files
committed
Merge branch 'master' of github.com:giterlizzi/Rex
2 parents ba93496 + 38a0742 commit d79cd84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+563
-140
lines changed

.github/workflows/build_and_test.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
name: build.tar
8080
- name: Extract build tarball
8181
run: tar xvf build.tar
82+
- name: Install packages
83+
run: sudo apt-get install -y augeas-tools libaugeas-dev
8284
- name: Setup Perl
8385
id: perl
8486
uses: shogo82148/actions-setup-perl@v1
@@ -91,7 +93,7 @@ jobs:
9193
key: cache-coverage-deps-${{ steps.perl.outputs.perl-hash }}-${{ env.BUILD_TIMESTAMP }}
9294
restore-keys: cache-coverage-deps-${{ steps.perl.outputs.perl-hash }}-
9395
- name: Install dependencies
94-
run: cpanm --local-lib ${GITHUB_WORKSPACE}/local --installdeps --with-develop --with-all-features --with-suggests .
96+
run: cpanm --local-lib ${GITHUB_WORKSPACE}/local --installdeps --with-develop --with-all-features --with-recommends --with-suggests .
9597
- name: Install coverage dependencies
9698
run: cpanm --local-lib ${GITHUB_WORKSPACE}/local Devel::Cover::Report::Coveralls Pod::Coverage::CountParents
9799
- name: Install App::cpanoutdated
@@ -100,7 +102,7 @@ jobs:
100102
run: cpan-outdated -p | cpanm --local-lib ${GITHUB_WORKSPACE}/local
101103
- name: Run tests with coverage
102104
env:
103-
HARNESS_PERL_SWITCHES: -MDevel::Cover=+ignore,^local/,^t/
105+
HARNESS_PERL_SWITCHES: -MDevel::Cover=+ignore,^local/
104106
run: prove --timer --lib --recurse --jobs $(nproc) --shuffle t/
105107
- name: Report coverage info to Coveralls
106108
env:
@@ -125,7 +127,7 @@ jobs:
125127
- name: Extract build tarball
126128
run: tar xvf build.tar
127129
- name: Install packages
128-
run: sudo apt-get install -y aspell
130+
run: sudo apt-get install -y aspell libaugeas-dev
129131
- name: Setup Perl
130132
id: perl
131133
uses: shogo82148/actions-setup-perl@v1
@@ -164,6 +166,7 @@ jobs:
164166
- windows
165167
perl:
166168
- latest
169+
- '5.38'
167170
- '5.36'
168171
- '5.34'
169172
- '5.32'
@@ -198,15 +201,15 @@ jobs:
198201
with:
199202
perl-version: ${{ matrix.perl }}
200203
distribution: ${{ matrix.os == 'windows' && 'strawberry' || 'default' }}
201-
- name: Preinstall IO::Pty for Mac OS X tests
202-
run: cpanm IO::Pty~'!=1.18'
203-
if: matrix.os == 'macos'
204+
- name: Disable LWP for cpanm on older Strawberry Perls
205+
run: echo "PERL_CPANM_OPT=$env:PERL_CPANM_OPT --no-lwp" >> $env:GITHUB_ENV
206+
if: matrix.os == 'windows' && matrix.perl <= 5.22
204207
- name: Install dependencies
205208
uses: carlkidcrypto/[email protected]
206209
with:
207-
macos: cpanm --installdeps --with-all-features .
208-
linux: cpanm --installdeps --with-all-features .
209-
windows: cpanm --installdeps --with-all-features --without-feature=custom_output --without-feature=rsync .
210+
macos: cpanm --installdeps --with-all-features --with-recommends .
211+
linux: cpanm --installdeps --with-all-features --with-recommends .
212+
windows: cpanm --installdeps --with-all-features --without-feature=custom_output --without-feature=rsync --with-recommends .
210213
- name: Get number of processors
211214
id: cores
212215
uses: SimenB/github-actions-cpu-cores@v2

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ On top of the supported minimum version of Perl, the goal is to support the late
7878
- 5.32.1
7979
- 5.34.1
8080
- 5.36.1
81-
- 5.38.0
81+
- 5.38.2
82+
- 5.40.0
8283

8384
### Backwards compatibility
8485

ChangeLog

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ Revision history for Rex
1818

1919
[REVISION]
2020

21+
1.15.0 2024-11-05 Ferenc Erki <[email protected]>
22+
- No code changes since the 1.14.3.2-TRIAL release
23+
24+
1.14.3.2-TRIAL 2024-11-03 Ferenc Erki <[email protected]>
25+
[BUG FIXES]
26+
- Fix precedence warning after perl-5.41.4
27+
- Fix missing argument warnings from Text::Wrap
28+
- Fix memory detection warnings on Solaris
29+
30+
1.14.3.1-TRIAL 2024-10-30 Ferenc Erki <[email protected]>
31+
[BUG FIXES]
32+
- Return only the first found command
33+
- Fix inconsistent augtool wrapper usage
34+
- Fix Config::Augeas detection
35+
- Fix on_change in update_system command on Redhat
36+
37+
[NEW FEATURES]
38+
- Add config option to prepend Augeas commands
39+
- Add config option to control local Augeas backend
40+
2141
1.14.3 2023-08-05 Ferenc Erki <[email protected]>
2242
- No code changes since the 1.14.2.3-TRIAL release
2343

dist.ini

+13
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ overwrite = 1
7676

7777
[Prereqs]
7878
perl = 5.12.5
79+
Text::Wrap = != 2023.0509
7980
YAML = != 1.25
8081

8182
[Prereqs / DevelopRequires]
@@ -97,6 +98,12 @@ DBI = 0
9798
-description = Support describing host groups in XML format
9899
XML::LibXML = 0
99100

101+
[OptionalFeature / parallel_forkmanager]
102+
-description = Support Parallel::ForkManager to distribute tasks
103+
-relationship = recommends
104+
Parallel::ForkManager = 0
105+
Moo = >= 1.001000
106+
100107
[OptionalFeature / rsync]
101108
-description = Support rsync tasks
102109
Expect = 0
@@ -112,6 +119,12 @@ File::LibMagic = 0
112119
-relationship = suggests
113120
-description = Test MySQL commands
114121
Test::mysqld = 0
122+
DBD::mysql = 0
123+
124+
[OptionalFeature / use_config_augeas]
125+
-relationship = suggests
126+
-description = Run Augeas commands with Config::Augeas
127+
Config::Augeas = 0
115128

116129
[Test::MinimumVersion]
117130
max_target_perl = 5.12.5

lib/Rex/Commands/Augeas.pm

+24-21
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,10 @@ use Rex::Commands::Fs;
5151
use Rex::Commands::File;
5252
use Rex::Helper::Path;
5353
use Rex::Helper::Run;
54-
use IO::String;
54+
use Module::Load::Conditional qw(can_load);
5555

56-
my $has_config_augeas = 0;
57-
58-
BEGIN {
59-
use Rex::Require;
60-
if ( Config::Augeas->is_loadable ) {
61-
Config::Augeas->use;
62-
$has_config_augeas = 1;
63-
}
64-
}
56+
my $has_config_augeas =
57+
can_load( modules => { 'Config::Augeas' => undef } ) ? 1 : 0;
6558

6659
@EXPORT = qw(augeas);
6760

@@ -81,9 +74,15 @@ sub augeas {
8174

8275
my $is_ssh = Rex::is_ssh();
8376
my $aug; # Augeas object (non-SSH only)
84-
if ( !$is_ssh && $has_config_augeas ) {
77+
78+
my $use_augtool =
79+
!$has_config_augeas || Rex::Config->get_local_augeas_backend eq 'augtool';
80+
81+
if ( !$is_ssh && !$use_augtool ) {
8582
Rex::Logger::debug("Creating Config::Augeas Object");
8683
$aug = Config::Augeas->new;
84+
my $commands_to_prepend = Rex::Config->get_augeas_commands_prepend();
85+
$aug->srun( join qq(\n), @{$commands_to_prepend} );
8786
}
8887

8988
my $on_change; # Any code to run on change
@@ -107,7 +106,7 @@ This modifies the keys given in @options in $file.
107106
$on_change = delete $config_option->{on_change}
108107
if ref $config_option->{on_change} eq 'CODE';
109108

110-
if ( $is_ssh || !$has_config_augeas ) {
109+
if ( $is_ssh || $use_augtool ) {
111110
my @commands;
112111
for my $key ( keys %{$config_option} ) {
113112
Rex::Logger::debug( "modifying $key -> " . $config_option->{$key} );
@@ -152,7 +151,7 @@ Remove an entry.
152151
for my $aug_key (@options) {
153152
Rex::Logger::debug("deleting $aug_key");
154153

155-
if ( $is_ssh || !$has_config_augeas ) {
154+
if ( $is_ssh || $use_augtool ) {
156155
push @commands, "rm $aug_key\n";
157156
}
158157
else {
@@ -161,7 +160,7 @@ Remove an entry.
161160
}
162161
}
163162

164-
if ( $is_ssh || !$has_config_augeas ) {
163+
if ( $is_ssh || $use_augtool ) {
165164
my $result = _run_augtool(@commands);
166165
$ret = $result->{return};
167166
$changed = $result->{changed};
@@ -202,7 +201,7 @@ Insert an item into the file. Here, the order of the options is important. If th
202201
pop @options;
203202
}
204203

205-
if ( $is_ssh || !$has_config_augeas ) {
204+
if ( $is_ssh || $use_augtool ) {
206205
my $position = ( exists $opts->{"before"} ? "before" : "after" );
207206
unless ( exists $opts->{$position} ) {
208207
Rex::Logger::info(
@@ -271,9 +270,9 @@ Dump the contents of a file to STDOUT.
271270
my $file = shift @options;
272271
my $aug_key = $file;
273272

274-
if ( $is_ssh || !$has_config_augeas ) {
275-
my @list = i_exec "augtool", "print", $aug_key;
276-
print join( "\n", @list ) . "\n";
273+
if ( $is_ssh || $use_augtool ) {
274+
my $output = _run_augtool("print $aug_key");
275+
say $output->{'return'};
277276
}
278277
else {
279278
$aug->print($aug_key);
@@ -298,7 +297,7 @@ Check if an item exists.
298297
my $aug_key = $file;
299298
my $val = $options[0] || "";
300299

301-
if ( $is_ssh || !$has_config_augeas ) {
300+
if ( $is_ssh || $use_augtool ) {
302301
my @paths;
303302
my $result = _run_augtool("match $aug_key");
304303
for my $line ( split "\n", $result->{return} ) {
@@ -355,7 +354,7 @@ Returns the value of the given item.
355354
elsif ( $action eq "get" ) {
356355
my $file = shift @options;
357356

358-
if ( $is_ssh || !$has_config_augeas ) {
357+
if ( $is_ssh || $use_augtool ) {
359358
my @lines;
360359
my $result = _run_augtool("get $file");
361360
for my $line ( split "\n", $result->{return} ) {
@@ -394,8 +393,12 @@ sub _run_augtool {
394393
unless can_run "augtool";
395394
my $rnd_file = get_tmp_file;
396395
my $fh = Rex::Interface::File->create;
396+
397+
my $commands_to_prepend = Rex::Config->get_augeas_commands_prepend();
398+
unshift @commands, @{$commands_to_prepend};
399+
397400
$fh->open( ">", $rnd_file );
398-
$fh->write($_) foreach (@commands);
401+
$fh->write( $_ . qq(\n) ) foreach (@commands);
399402
$fh->close;
400403
my ( $return, $error ) = i_run "augtool --file $rnd_file --autosave",
401404
sub { @_ }, fail_ok => 1;

lib/Rex/Config.pm

+46-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ our (
7373
$use_template_ng, $use_rex_kvm_agent,
7474
$autodie, $task_chaining_cmdline_args,
7575
$waitpid_blocking_sleep_time, $write_utf8_files,
76-
$default_auth,
76+
$default_auth, $augeas_commands_prepend,
77+
$local_augeas_backend,
7778
);
7879

7980
# some defaults
@@ -1632,6 +1633,50 @@ sub get_default_auth {
16321633
return $default_auth // 1;
16331634
}
16341635

1636+
=head2 set_augeas_commands_prepend
1637+
1638+
=head2 get_augeas_commands_prepend
1639+
1640+
Sets and gets the value of the C<$augeas_commands_prepend> configuration variable.
1641+
1642+
This controls the list of commands Rex should prepend at the beginning of the command file for Augeas operations.
1643+
1644+
Default is C<[]>.
1645+
1646+
=cut
1647+
1648+
sub set_augeas_commands_prepend {
1649+
my $self = shift;
1650+
$augeas_commands_prepend = shift;
1651+
return $augeas_commands_prepend;
1652+
}
1653+
1654+
sub get_augeas_commands_prepend {
1655+
return $augeas_commands_prepend // [];
1656+
}
1657+
1658+
=head2 set_local_augeas_backend
1659+
1660+
=head2 get_local_augeas_backend
1661+
1662+
Sets and gets the value of the C<$local_augeas_backend> configuration variable.
1663+
1664+
This controls which Augeas backend to use for local operations, C<augtool> or C<Config::Augeas>.
1665+
1666+
Default is C<Config::Augeas>.
1667+
1668+
=cut
1669+
1670+
sub set_local_augeas_backend {
1671+
my $self = shift;
1672+
$local_augeas_backend = shift;
1673+
return $local_augeas_backend;
1674+
}
1675+
1676+
sub get_local_augeas_backend {
1677+
return $local_augeas_backend // 'Config::Augeas';
1678+
}
1679+
16351680
=head2 register_set_handler($handler_name, $code)
16361681
16371682
Register a handler that gets called by I<set>.

lib/Rex/Hardware/Memory.pm

+24-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use warnings;
99

1010
our $VERSION = '9999.99.99_99'; # VERSION
1111

12+
use English qw(-no_match_vars);
1213
use Rex::Hardware::Host;
1314
use Rex::Commands::Run;
1415
use Rex::Helper::Run;
@@ -54,25 +55,34 @@ sub get {
5455
elsif ( $os eq "SunOS" ) {
5556
my @data = i_run "echo ::memstat | mdb -k", fail_ok => 1;
5657

57-
my ($free_cache) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
58-
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
59-
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;
58+
if ( $CHILD_ERROR == 0 ) {
59+
my ($free_cache) =
60+
map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
61+
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
62+
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;
6063

61-
my $free = $free_cache + $free_list;
64+
my $free = $free_cache + $free_list;
6265

6366
#my ($total, $total_e) = grep { $_=$1 if /^Memory Size: (\d+) ([a-z])/i } i_run "prtconf";
64-
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;
67+
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;
6568

66-
&$convert( $free, "M" );
67-
&$convert( $total, "M" );
68-
my $used = $total - $free;
69-
70-
$data = {
71-
used => $used,
72-
total => $total,
73-
free => $free,
74-
};
69+
&$convert( $free, "M" );
70+
&$convert( $total, "M" );
71+
my $used = $total - $free;
7572

73+
$data = {
74+
used => $used,
75+
total => $total,
76+
free => $free,
77+
};
78+
}
79+
else {
80+
$data = {
81+
used => 0,
82+
total => 0,
83+
free => 0,
84+
};
85+
}
7686
}
7787
elsif ( $os eq "OpenBSD" ) {
7888
my $mem_str = i_run "top -d1 | grep Memory:", fail_ok => 1;

lib/Rex/Interface/Exec/Base.pm

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ sub can_run {
6565
return $cache->get($cache_key_name);
6666
}
6767

68-
my $output = Rex::Helper::Run::i_run "$check_with_command $command",
68+
my @output = Rex::Helper::Run::i_run "$check_with_command $command",
6969
fail_ok => 1;
7070

7171
next if ( $? != 0 );
7272

73-
next if ( !is_file($output) );
73+
next if ( !is_file( $output[0] ) );
7474

75-
$cache->set( $cache_key_name, $output );
75+
$cache->set( $cache_key_name, $output[0] );
7676

77-
return $output;
77+
return $output[0];
7878
}
7979

8080
return undef;

0 commit comments

Comments
 (0)