Skip to content

Commit

Permalink
Merge pull request #294 from dkj/NPG-1644
Browse files Browse the repository at this point in the history
populate_wtsi_irods_groups creates _human iRODS groups
  • Loading branch information
kjsanger authored Dec 7, 2023
2 parents 9946efa + 617cba1 commit 60006a7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
20 changes: 16 additions & 4 deletions bin/populate_wtsi_irods_groups.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
sequencing tracked in the ML warehouse, the iRODS group will be left
empty (except for the iRODS groupadmin user).
Studies which are marked as have samples contaminated with human which
should be removed will have an ss_<study_id>_human iRODS group created
when they do not exist - population of this group is performed outside
this process and should be tracked in an auditable manner by a ticket.
Script runs to perform such updates when no arguments are given.
Options:
Expand Down Expand Up @@ -72,7 +77,7 @@
exit 0;
},
'logconf=s' => \$log4perl_config,
'study=i' => \@study_ids,
'study_id=i' => \@study_ids,
'verbose' => \$verbose) or die "\n$what_on_earth\n";

if ($log4perl_config) {
Expand Down Expand Up @@ -141,7 +146,7 @@ sub _uid_to_irods_uid {
my $studies = $mlwh->resultset('Study')->search($query,
{order_by => 'id_study_lims'});

my ($group_count, $altered_count) = (0, 0);
my ($group_count, $altered_count, $altered_human_count) = (0, 0, 0);
while (my $study = $studies->next){
my $study_id = $study->id_study_lims;
my $dag_str = $study->data_access_group || q();
Expand Down Expand Up @@ -172,14 +177,21 @@ sub _uid_to_irods_uid {
$altered_count++;
}

if ($study->contaminated_human_dna) {
$altered_human_count += $iga->ensure_group_exists("ss_$study_id".'_human');
}

$group_count++;
}

$log->debug("Altered $altered_count groups");
$log->debug("Created $altered_human_count _human groups");

$log->info("When considering $group_count Sequencescape studies, ",
"$altered_count iRODS groups were created or their ",
'membership altered (by ', $iga->_user, ')');
$altered_count.' iRODS "ss_*" groups were created or their ',
'membership altered, and '.$altered_human_count,
' "ss_?????_human" groups were created (by ',
$iga->_user, ')');

# Find both gid and member uids for each group
sub find_group_ids {
Expand Down
13 changes: 10 additions & 3 deletions lib/WTSI/NPG/iRODS/GroupAdmin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,22 @@ sub _op_g_u {
return;
}

sub _ensure_existence_of_group {
=head2 ensure_group_exists
Given a group ensure that it exists in iRODS by making it if it does not, and adding this admin user to it to ensure admin rights on it are retained. Return true if a group is created.
=cut

sub ensure_group_exists {
my($self,$group)=@_;
$self->__croak_on_bad_group_name($group);
if ( any {$group eq $_} $self->lg){ return;}
if ($self->dry_run) {
$self->info("Dry run: mkgroup '$group'");
$self->info("Dry run: mkgroup '$group' and then atg...");
}
else {
$self->_push_pump_trim_split(qq(mkgroup "$group"\n));
$self->_op_g_u('atg',$group, $self->_user); #add this user to empty group (first) so admin rights to operate on it are retained
}
return 1; #return true if we make a group
}
Expand All @@ -212,7 +219,7 @@ Given a group and list of members will ensure that the group exists and contains

sub set_group_membership {
my($self,$group,@members)=@_;
my $altered = $self->_ensure_existence_of_group($group);
my $altered = $self->ensure_group_exists($group);
my @orig_members = $self->lg($group);
$self->debug("Members of $group: ", join q(, ), @orig_members);
if (@orig_members){
Expand Down
41 changes: 40 additions & 1 deletion t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sub setup_test : Test(setup) {
sub teardown_test : Test(teardown) {
my ($self) = @_;

$self->remove_irods_groups($test_irods, @irods_groups);
$self->remove_irods_groups($test_irods, @irods_groups, q(ss_newempty));

if ($self->have_admin_rights) {
foreach my $user (@irods_users) {
Expand Down Expand Up @@ -93,6 +93,45 @@ sub lg : Test(5) {
'Empty string group throw';
}

sub ensure_group_exists: Test(6) {
my ($self) = @_;

my $irods = WTSI::NPG::iRODS->new(environment => \%ENV,
strict_baton_version => 0);
SKIP: {
if (not $self->have_admin_rights) {
skip 'No admin rights to create test groups', 5;
}

my $zone = $irods->find_zone_name($irods->working_collection);
my $user = $irods->get_irods_user;

my $iga = WTSI::NPG::iRODS::GroupAdmin->new;

throws_ok { $iga->lg('ss_newempty') } qr/does not exist/sm,
'Non-existent group throw for ss_newempty';

my$created=0;
lives_ok {
$created=$iga->ensure_group_exists('ss_newempty');
} 'Create new group ss_newempty';
ok($created, "Reports that group has been created");

my @observed_members = sort $iga->lg('ss_newempty');
my @expected_members = ("$user#$zone");
is_deeply(\@observed_members, \@expected_members,
'Has expected admin user automatically added') or
diag explain \@observed_members;

$created=1;
lives_ok {
$created=$iga->ensure_group_exists('ss_newempty');
} 'Safe to run on existing group';

ok(!$created, "Reports that group has not been created");
}
}

sub set_group_membership : Test(5) {
my ($self) = @_;

Expand Down

0 comments on commit 60006a7

Please sign in to comment.