From 490cb14c8dfdbe586353f49b1c6c81ad50a0ff35 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 16 Jun 2025 15:27:28 +0200 Subject: [PATCH 1/2] Test members of all hostgroups --- t/group.t | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/t/group.t b/t/group.t index 285a74d88..7982eb1d0 100755 --- a/t/group.t +++ b/t/group.t @@ -5,7 +5,7 @@ use warnings; our $VERSION = '9999.99.99_99'; # VERSION -use Test::More tests => 102; +use Test::More tests => 103; use Test::Warnings; use Test::Exception; use Test::Deep; @@ -90,26 +90,25 @@ dies_ok( sub { Rex::Commands::evaluate_hostname('s[78]') }, group first => qw(one two); group second => qw(two three); -my $expected_groups_for = { - one => [qw(first)], - two => [qw(first second)], - three => [qw(second)], +my $expected_results_for = { + first => { + one => [qw(first)], + two => [qw(first second)], + }, + second => { + two => [qw(first second)], + three => [qw(second)], + }, }; -my $groups_of; - for my $group (qw(first second)) { my @hosts = Rex::Group->get_group($group); for my $host (@hosts) { - $groups_of->{ $host->to_s } = [ $host->groups ]; + cmp_bag( + [ $host->groups ], + $expected_results_for->{$group}->{$host}, + "correct host groups for host $host in group $group" + ); } } - -for my $host ( keys %{$expected_groups_for} ) { - cmp_bag( - $groups_of->{$host}, - $expected_groups_for->{$host}, - "correct host groups for host $host" - ); -} From d0d8747d43c1527056a29ab3dcbc9ab6d257bbda Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 16 Jun 2025 15:31:51 +0200 Subject: [PATCH 2/2] Fix hostgroup membership list for all groups --- ChangeLog | 1 + lib/Rex/Group.pm | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8ce63016..195122060 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Fix hostgroup membership list for all groups [DOCUMENTATION] diff --git a/lib/Rex/Group.pm b/lib/Rex/Group.pm index c447b932c..ced01a936 100644 --- a/lib/Rex/Group.pm +++ b/lib/Rex/Group.pm @@ -15,7 +15,7 @@ use attributes; use Rex::Group::Entry::Server; use vars qw(%groups); -use List::Util 1.45 qw(any uniq); +use List::Util 1.45 qw(uniq); use Data::Dumper; sub new { @@ -30,8 +30,11 @@ sub new { for my $group ( keys %groups ) { - if ( any { $_ eq $srv } $groups{$group}->get_servers ) { - $srv->append_to_group($group); + for my $host ( $groups{$group}->get_servers ) { + if ( $host eq $srv ) { + $host->append_to_group( $self->{name} ); + $srv->append_to_group($group); + } } } }