JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for TB-SUPPORT Archives


TB-SUPPORT Archives

TB-SUPPORT Archives


TB-SUPPORT@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

TB-SUPPORT Home

TB-SUPPORT Home

TB-SUPPORT  September 2012

TB-SUPPORT September 2012

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Site BDII move

From:

Jens Jensen <[log in to unmask]>

Reply-To:

Testbed Support for GridPP member institutes <[log in to unmask]>

Date:

Fri, 7 Sep 2012 15:22:46 +0100

Content-Type:

multipart/mixed

Parts/Attachments:

Parts/Attachments

text/plain (87 lines) , ldifsort.pl (124 lines) , ldifdiff.pl (295 lines)

John, I have attached what I use for testing upgrades of the CIP (or
rather the BDII which sits in front of the CIP.)


Basically, you do
	ldapsearch -x -LLL -H ldap://${OLDBDIIHOST}:2170/ -b ... \
	>oldbdii.tmp
into a file, for each of the BDIIs.

Then
	ldifsort.pl -k dn oldbdii.tmp >oldbdii.ldif
and similarly s/old/new/, mutatis mutandis.

Finally
	ldifdiff.pl -k dn newbdii.ldif oldbdii.ldif

This'll give you the delta (in LDAP change format), to go from the old
and the new.  Note that it doesn't then tell you what the _old_ value
was.  Also it assumes relatively consistent naming of things (ie DNs).

Sometimes I have masked out numbers (dynamic stuff) by sed'ing numbers
into XXXXXX or something, because numbers generally change from one
snapshot to the next - of course numbers, too, need checking...


Also, don't forget the Flavian test (somewhat customised by me) - you
fail this at your peril (as I know only too well).

#!/bin/ksh
for VO in atlas cms lhcb dteam alice minos mice hone ilc t2k superb na62
snoplus
do echo "***${VO}***"
ldapsearch -LLL -x -H ldap://srmbdii02.gridpp.rl.ac.uk:2170/ -b o=grid \
"(|(&(GlueChunkKey=GlueSEUniqueID=srm-${VO}.gridpp.rl.ac.uk)(|(GlueSAAccessControlBaseRule=ops)(GlueSAAccessControlBaseRule=VO:ops)))(&(GlueChunkKey=GlueSEUniqueID=srm-${VO}.gridpp.rl.ac.uk)(|(GlueVOInfoAccessControlBaseRule=ops)(GlueVOInfoAccessControlBaseRule=VO:ops)))(&(GlueServiceUniqueID=*://srm-${VO}.gridpp.rl.ac.uk*)(GlueServiceVersion=2.*)(GlueServiceType=srm*)))"
\
GlueServiceEndpoint GlueSAPath GlueVOInfoPath
done

Note that the loop isn't really once per VO, it's one per SRM endpoint
(or actually GlueSEUniqueID, but they are required to be SRM endpoint
hostnames).

Learn to identify healthy output - there should be three, four with a
space token for the VO.  As a rule.

Enjoy
--jens




On 06/09/2012 15:09, Chris Brew wrote:
> Hi John,
> 
> You're probably a bit beyond this point but I'm still proud of the script-fu
> that generated this for comparing the output of two site bdiis:
> 
> comm -3  <(ldapsearch -x -H ldap://<OLD_BDII_NAME>:2170 -b
> mds-vo-name=<SITE_NAME>,o=grid | sed -ne '1{h;n;};/^ /!{x;p;};/^ /{H;g;s/\n
> //;h;};${g;s/\n //;p;}' | grep '^dn: ' | sort) <(ldapsearch -x -H
> ldap://<NEW_BDII_NAME>:2170 -b mds-vo-name=<SITE_NAME>,o=grid | sed -ne
> '1{h;n;};/^ /!{x;p;};/^ /{H;g;s/\n //;h;};${g;s/\n //;p;}' | grep '^dn: ' |
> sort)
> 
> Yours,
> Chris (who says it's only perl that looks like line noise) Brew.
> 
>> -----Original Message-----
>> From: Testbed Support for GridPP member institutes [mailto:TB-
>> [log in to unmask]] On Behalf Of John Hill
>> Sent: 06 September 2012 15:01
>> To: [log in to unmask]
>> Subject: Site BDII move
>>
>> This morning I started the move to a new Site BDII at Cambridge (SL6,
>> EMI-2). MyEGI and NAGIOS have both noticed the change of machine, but
>> GSTAT hasn't as yet. Is this just a matter of being patient? Is there
>> anywhere else I should be checking to ensure that the new Site BDII is
>> recognised and working correctly before I shut down the old one?
>> Thanks,
>> John


-- 
Scanned by iCritical.



#! /usr/bin/perl # $Id: ldifsort.pl,v 1.9 2005/04/03 20:20:24 subbarao Exp $ =head1 NAME ldifsort.pl - Sorts an LDIF file by the specified key attribute. The sorted version is written to standard output. =head1 DESCRIPTION Sorts an LDIF file by the specified key attribute. =head1 SYNOPSIS ldifsort.pl B<-k keyattr> [B<-andc>] file.ldif =over 4 =item B<-k> Specifies the key attribute for making sort comparisons. If 'dn' is specified, sorting is done by the full DN string, which can be composed of different attributes for different entries. =item B<-a> Specifies that attributes within a given entry should also be sorted. This has the side effect of removing all comments and line continuations in the LDIF file. =item B<-n> Specifies numeric comparisons on the key attribute. Otherwise string comparisons are done. =item B<-d> Specifies that the key attribute is a DN. Comparisons are done on a DN-normalized version of attribute values. This is the default behavior if 'dn' is passed as the argument to B<-k>. =item B<-c> Specifies case-insensitive comparisons on the key attribute. This is the default behavior if 'dn' is passed as the argument to B<-k>. =back =head1 AUTHOR Kartik Subbarao E<lt>[log in to unmask]<gt> =cut use Net::LDAP::Util qw(canonical_dn); use MIME::Base64; use Getopt::Std; use strict; my %args; getopts("k:andc", \%args); my $keyattr = $args{k}; my $sortattrs = $args{a}; my $ciscmp = $args{c}; my $ldiffile = $ARGV[0]; die "usage: $0 -k keyattr [-n] [-d] [-c] ldiffile\n" unless $keyattr && $ldiffile; $/ = ""; open(LDIFH, $ldiffile) || die "$ldiffile: $!\n"; my $pos = 0; my @valuepos; while (<LDIFH>) { my $value; 1 while s/^($keyattr:.*)?\n /$1/im; # Handle line continuations if (/^$keyattr(::?) (.*)$/im) { $value = $2; $value = decode_base64($value) if $1 eq '::'; } $value = lc($value) if $ciscmp; push @valuepos, [ $value, $pos ]; $pos = tell; } sub cmpattr { $a->[0] cmp $b->[0] } sub cmpattrnum { $a->[0] <=> $b->[0] } my %canonicaldns; sub cmpdn { my $cadn = ($canonicaldns{$a->[0]} ||= lc(canonical_dn($a->[0]))); my $cbdn = ($canonicaldns{$b->[0]} ||= lc(canonical_dn($b->[0]))); $cadn cmp $cbdn; } my $cmpfunc; if ($args{d} || lc($keyattr) eq 'dn') { $cmpfunc = \&cmpdn } elsif ($args{n}) { $cmpfunc = \&cmpattrnum } else { $cmpfunc = \&cmpattr; } my @sorted; @sorted = sort $cmpfunc @valuepos; foreach my $valuepos (@sorted) { seek(LDIFH, $valuepos->[1], 0); my $entry = <LDIFH>; if ($sortattrs) { $entry =~ s/\n //mg; # collapse line continuations my @lines = grep(!/^#/, split(/\n/, $entry)); my $dn = shift(@lines); print "$dn\n", join("\n", sort @lines), "\n\n"; } else { print $entry; print "\n" if $entry !~ /\n\n$/; } }
#! /usr/bin/perl # $Id: ldifdiff.pl,v 3.7 2005/03/15 14:22:45 subbarao Exp $ =head1 NAME ldifdiff.pl -- Generates LDIF change diff between two sorted LDIF files. =head1 DESCRIPTION ldifdiff.pl takes as input two sorted LDIF files, source and target, and generates on standard output the LDIF changes needed to transform the target into the source. =head1 SYNOPSIS ldifdiff.pl B<-k|--keyattr keyattr> [B<-a|--sourceattrs attr1,attr2,...>] [B<-c|--ciscmp attr1,...>] [B<--dnattrs attr1,...>] [B<--sharedattrs attr1,...>] B<sourcefile> B<targetfile> =head1 OPTIONS =over 4 =item B<-k|--keyattr> keyattr Specifies the key attribute to use when comparing source and target entries. Entries in both LDIF files must be sorted by this attribute for comparisons to be meaningful. F<ldifsort.pl> can be used to sort LDIF files by a given attribute. =item B<-a|--sourceattrs attr1,attr2,...> (Optional) Specifies a list of attributes to consider when comparing source and target entries. By default, all attributes are considered. =item B<-c|--ciscmp attr1,...> (Optional) Compare values of the specified attributes case-insensitively. By default, comparisons are case-sensitive. =item B<--dnattrs attr1,...> (Optional) Specifies a list of attributes to be treated as DNs when being compared. The default set is manager, member, owner and uniqueMember. =item B<--sharedattrs attr1,...> (Optional) Specifies a list of attribues to be treated as "shared" attributes, where the source may not be a sole authoritative source. When modifying these attributes, separate "delete" and "add" LDIF changes are generated, instead of a single "replace" change. The default set is objectClass. =item B<sourcefile> Specifies the source LDIF file. =item B<targetfile> Specifies the target LDIF file. =back =cut use Net::LDAP; use Net::LDAP::LDIF; use Net::LDAP::Util qw(canonical_dn); use Getopt::Long; use strict; my @sourceattrs; my (%ciscmp, %dnattrs, %sharedattrs); my $keyattr; GetOptions('a|sourceattrs=s' => sub { @sourceattrs = split(/,/, $_[1]) }, 'c|ciscmp=s' => sub { my @a = split(/,/,lc $_[1]); @ciscmp{@a} = (1) x @a }, 'dnattrs=s' => sub { my @a = split(/,/,lc $_[1]); @dnattrs{@a} = (1) x @a }, 'k|keyattr=s' => \$keyattr, 'sharedattrs=s' => sub {my @a=split(/,/,lc $_[1]);@sharedattrs{@a}=(1) x @a} ); %ciscmp = (objectclass => 1, manager => 1, member => 1, owner => 1, uniquemember => 1) unless keys %ciscmp; %dnattrs = (manager => 1, member => 1, owner => 1, uniquemember => 1) unless keys %dnattrs; %sharedattrs = (objectclass => 1) unless keys %sharedattrs; my ($sourcefile, $targetfile); $sourcefile = shift; $targetfile = shift; die "usage: $0 -k|--keyattr keyattr [-a|--sourceattrs attr1,attr2,...] [-c|--ciscmp attr1,...] [--dnattrs attr1,...] [--sharedattrs attr1,...] sourcefile targetfile\n" unless $keyattr && $sourcefile && $targetfile; my $source = Net::LDAP::LDIF->new($sourcefile) or die "Can't open LDIF file $sourcefile: $!\n"; my $target = Net::LDAP::LDIF->new($targetfile) or die "Can't open LDIF file $targetfile: $!\n"; my $ldifout = Net::LDAP::LDIF->new('-', 'w'); $ldifout->{change} = 1; $ldifout->{wrap} = 78; diff($source, $target); exit; # Gets the relative distinguished name (RDN) attribute sub rdnattr { ($_[0]->dn =~ /^(.*?)=/)[0] } # Gets the relative distinguished name (RDN) value sub rdnval { my $rv = ($_[0]->dn =~ /=(.*)/)[0]; $rv =~ s/(?<!\\),.*//; $rv } sub cmpEntries {     my ($a, $b) = @_;     if ($keyattr =~ /^dn$/i) { return lc(canonical_dn($a->dn)) cmp lc(canonical_dn($b->dn)) }     else { my $aval = $a->get_value($keyattr); my $bval = $b->get_value($keyattr); if ($ciscmp{$keyattr}) { $aval = lc($aval); $bval = lc($bval); } return $aval cmp $bval; } } # Diffs two LDIF data sources sub diff { my ($source, $target) = @_; my ($sourceentry, $targetentry, $incr_source, $incr_target, @ldifchanges); $sourceentry = $source->read_entry(); $targetentry = $target->read_entry(); while () { # End of all data last if !$sourceentry && !$targetentry; # End of source data, but more target data. Delete. if (!$sourceentry && $targetentry) { $targetentry->delete; $ldifout->write_entry($targetentry); $incr_target = 1, next; } # End of target data, but more data in source. Add. if ($sourceentry && !$targetentry) { $ldifout->write_entry($sourceentry);             $incr_source = 1, next; } # Check if the current source entry has a higher sort position than # the current target. If so, we interpret this to mean that the # target entry no longer exists on the source. Issue a delete to LDAP. if (cmpEntries($sourceentry, $targetentry) > 0) { $targetentry->delete; $ldifout->write_entry($targetentry);             $incr_target = 1, next; } # Check if the current target entry has a higher sort position than # the current source entry. If so, we interpret this to mean that the # source entry doesn't exist on the target. Issue an add to LDAP. if (cmpEntries($targetentry, $sourceentry) > 0) { $ldifout->write_entry($sourceentry);             $incr_source = 1, next; } # When we get here, we're dealing with the same person in $sourceentry # and $targetentry. Compare the data and generate the update. # If a modRDN is necessary, it needs to happen before other mods if (lc(canonical_dn($sourceentry->dn)) ne lc(canonical_dn($targetentry->dn))) { my $rdnattr = rdnattr($sourceentry); my $rdnval = rdnval($sourceentry); $targetentry->{changetype} = 'modrdn'; $targetentry->add(newrdn => "$rdnattr=$rdnval", deleteoldrdn => '1'); $ldifout->write_entry($targetentry); $targetentry->delete('newrdn'); $targetentry->delete('deleteoldrdn'); delete($targetentry->{changetype}); $targetentry->dn($sourceentry->dn); $targetentry->replace($rdnattr, $sourceentry->get_value($rdnattr)) if $sourceentry->exists($rdnattr); } # Check for differences and generate LDIF as appropriate updateFromEntry($sourceentry, $targetentry, @sourceattrs); $ldifout->write_entry($targetentry) if @{$targetentry->{changes}}; $incr_source = 1, $incr_target = 1, next;     } continue { if ($incr_source) { $sourceentry = $source->read_entry(); $incr_source = 0; } if ($incr_target) { $targetentry = $target->read_entry(); $incr_target = 0; }     } } # Generate LDIF to update $target with information in $source. # Optionally restrict the set of attributes to consider. sub updateFromEntry { my ($source, $target, @attrs) = @_; my ($attr, $val, $ldifstr); unless (@attrs) { # add all source entry attributes @attrs = $source->attributes; # add any other attributes we haven't seen from the target entry foreach my $tattr ($target->attributes) { push(@attrs, $tattr) unless grep(/^$tattr$/i, @attrs) } } $target->{changetype} = 'modify'; foreach $attr (@attrs) { my $lcattr = lc $attr; next if $lcattr eq 'dn'; # Can't handle modrdn here # Build lists of unique values in the source and target, to # speed up comparisons. my @sourcevals = $source->get_value($attr); my @targetvals = $target->get_value($attr); my (%sourceuniqvals, %targetuniqvals); foreach (@sourcevals) { my ($origval, $val) = ($_, $_); $val = lc $val if $ciscmp{$lcattr}; # Get rid of spaces after non-escaped commas in DN attrs $val =~ s/(?<!\\),\s+/,/g if $dnattrs{$lcattr}; $sourceuniqvals{$val} = $origval; } foreach (@targetvals) { my ($origval, $val) = ($_, $_); $val = lc $val if $ciscmp{$lcattr}; # Get rid of spaces after non-escaped commas in DN attrs $val =~ s/(?<!\\),\s+/,/g if $dnattrs{$lcattr}; $targetuniqvals{$val} = $origval; } foreach my $val (keys %sourceuniqvals) { if (exists $targetuniqvals{$val}) { delete $sourceuniqvals{$val}; delete $targetuniqvals{$val}; } } # Move on if there are no differences next unless keys(%sourceuniqvals) || keys(%targetuniqvals); # Make changes as appropriate if ($sharedattrs{$lcattr}) { # For 'shared' attributes (e.g. objectclass) where $source may not # be a sole authoritative source, we issue separate delete and # add modifications instead of a single replace. $target->delete($attr => [ values(%targetuniqvals) ]) if keys(%targetuniqvals); $target->add($attr => [ values(%sourceuniqvals) ]) if keys(%sourceuniqvals); } else { # Issue a replace or delete as needed if (@sourcevals) { $target->replace($attr => [ @sourcevals ]) } else { $target->delete($attr) } } } # Get rid of the "changetype: modify" if there were no changes delete($target->{changetype}) unless @{$target->{changes}}; } =back =head1 AUTHOR Kartik Subbarao E<lt>[log in to unmask]<gt> =cut

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
April 2002
March 2002
February 2002
January 2002


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager