Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Revision history for Rex
- Fix parsing FreeBSD memory details
- Recognize laundry memory on FreeBSD
- Fix command existence checks without which
- Fix hostgroup membership list

[DOCUMENTATION]

Expand Down
10 changes: 9 additions & 1 deletion lib/Rex/Group.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use attributes;
use Rex::Group::Entry::Server;

use vars qw(%groups);
use List::Util 1.45 qw(uniq);
use List::Util 1.45 qw(any uniq);
use Data::Dumper;

sub new {
Expand All @@ -24,8 +24,16 @@ sub new {
my $self = {@_};

bless( $self, $proto );

for my $srv ( @{ $self->{servers} } ) {
$srv->append_to_group( $self->{name} );

for my $group ( keys %groups ) {

if ( any { $_ eq $srv } $groups{$group}->get_servers ) {
$srv->append_to_group($group);
}
}
}

return $self;
Expand Down
32 changes: 31 additions & 1 deletion t/group.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use Test::More tests => 99;
use Test::More tests => 102;
use Test::Warnings;
use Test::Exception;
use Test::Deep;

use Rex -feature => '0.31';
use Rex::Group;
Expand Down Expand Up @@ -83,3 +84,32 @@ is( *{$function_ref}->(), $function_result, 'calling custom function' );

dies_ok( sub { Rex::Commands::evaluate_hostname('s[78]') },
'die on invalid hostgroup expression' );

# group membership

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 $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 ];
}
}

for my $host ( keys %{$expected_groups_for} ) {
cmp_bag(
$groups_of->{$host},
$expected_groups_for->{$host},
"correct host groups for host $host"
);
}