From dc082b2ce01863a55460f9544efe99a92768d384 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Mon, 4 Dec 2023 12:15:48 +0000 Subject: [PATCH 1/4] expose ensure_group_exists method from iRODS::GroupAdmin --- lib/WTSI/NPG/iRODS/GroupAdmin.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/WTSI/NPG/iRODS/GroupAdmin.pm b/lib/WTSI/NPG/iRODS/GroupAdmin.pm index e5522d45..640fa282 100644 --- a/lib/WTSI/NPG/iRODS/GroupAdmin.pm +++ b/lib/WTSI/NPG/iRODS/GroupAdmin.pm @@ -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 } @@ -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){ From 6a37999653865cd512f50c376b12014e2b612940 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Mon, 4 Dec 2023 14:19:51 +0000 Subject: [PATCH 2/4] tests for ensure_group_exists method in iRODS::GroupAdmin --- t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm b/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm index 6f2b61a8..e560c4d0 100644 --- a/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm +++ b/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm @@ -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) { @@ -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) = @_; From 7c357b1be79e1340337cfd72711daa08705cb727 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Tue, 5 Dec 2023 09:53:59 +0000 Subject: [PATCH 3/4] populate_wtsi_irods_groups creates _human iRODS groups --- bin/populate_wtsi_irods_groups.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/populate_wtsi_irods_groups.pl b/bin/populate_wtsi_irods_groups.pl index ca1c0d32..7158558d 100755 --- a/bin/populate_wtsi_irods_groups.pl +++ b/bin/populate_wtsi_irods_groups.pl @@ -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__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: @@ -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) { @@ -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(); @@ -172,14 +177,19 @@ sub _uid_to_irods_uid { $altered_count++; } + $altered_human_count += $iga->ensure_group_exists("ss_$study_id".'_human') if $study->contaminated_human_dna; + $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 { From 617cba141bc79594bf040c4ab4ade7e049745cd7 Mon Sep 17 00:00:00 2001 From: David K Jackson Date: Wed, 6 Dec 2023 13:51:46 +0000 Subject: [PATCH 4/4] populate_wtsi_irods_groups - remove postifx if for perlcritic --- bin/populate_wtsi_irods_groups.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/populate_wtsi_irods_groups.pl b/bin/populate_wtsi_irods_groups.pl index 7158558d..f76648fa 100755 --- a/bin/populate_wtsi_irods_groups.pl +++ b/bin/populate_wtsi_irods_groups.pl @@ -177,7 +177,9 @@ sub _uid_to_irods_uid { $altered_count++; } - $altered_human_count += $iga->ensure_group_exists("ss_$study_id".'_human') if $study->contaminated_human_dna; + if ($study->contaminated_human_dna) { + $altered_human_count += $iga->ensure_group_exists("ss_$study_id".'_human'); + } $group_count++; }