Changeset 71

Show
Ignore:
Timestamp:
12/16/09 22:36:32 (4 years ago)
Author:
depesz
Message:

db-tests framework. Currently tests plperl if it works sanely

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/omnipitr/lib/OmniPITR/Archive.pm

    r69 r71  
    22use strict; 
    33use warnings; 
     4use base qw( OmniPITR::Program ); 
    45use Carp; 
    5 use OmniPITR::Log
     6use File::Spec
    67use Getopt::Long; 
    7 use Data::Dumper; 
    8  
    9 sub new { 
    10     my $class = shift; 
    11     my $self = bless {}, $class; 
    12     $self->read_args(); 
    13     $self->validate_args(); 
    14     return $self; 
    15 } 
    168 
    179sub run { 
     
    2416 
    2517    my %args = (); 
    26     croak('Error while reading command line arguments. Please check documentation in doc/omnipitr-archive.pod'
     18    croak( 'Error while reading command line arguments. Please check documentation in doc/omnipitr-archive.pod'
    2719        unless GetOptions( 
    28             \%args, 
    29             'data-dir|D=s', 
    30             'dst-local|dl=s@', 
    31             'dst-remote|dr=s@', 
    32             'temp-dir|t=s', 
    33             'log|l=s', 
    34             'state-dir|s=s', 
    35             'pid-file=s', 
    36             'verbose|v', 
    37             'help|?', 
     20        \%args, 
     21        'data-dir|D=s', 
     22        'dst-local|dl=s@', 
     23        'dst-remote|dr=s@', 
     24        'temp-dir|t=s', 
     25        'log|l=s', 
     26        'state-dir|s=s', 
     27        'pid-file=s', 
     28        'verbose|v' 
    3829        ); 
    39     croak('--log was not provided - cannot continue.') unless $args{'log'}; 
     30    croak( '--log was not provided - cannot continue.' ) unless $args{ 'log' }; 
     31 
     32    for my $key ( qw( data-dir temp-dir state-dir pid-file verbose ) ) { 
     33        $self->{ $key } = $args{ $key }; 
     34    } 
     35 
     36    for my $type ( qw( local remote ) ) { 
     37        my $D = []; 
     38        $self->{ 'destination' }->{ $type } = $D; 
     39 
     40        next unless defined $args{ 'dst-' . $type }; 
     41 
     42        my %temp_for_uniq = (); 
     43        my @items = grep { !$temp_for_uniq{ $_ }++ } @{ $args{ 'dst-' . $type } }; 
     44 
     45        for my $item ( @items ) { 
     46            my $current = { 'compression' => 'none', }; 
     47            if ( $item =~ s/\A(gzip|bzip2|lzma)\%// ) { 
     48                $current->{ 'compression' } = $1; 
     49            } 
     50            $current->{ 'path' } = $item; 
     51            push @{ $D }, $current; 
     52        } 
     53    } 
    4054 
    4155    # We do it here so it will actually work for reporing problems in validation 
    42     $self->{'log'} = OmniPITR::Log->new( $args{'log'} ); 
    43      
     56    $self->{ 'log' }          = OmniPITR::Log->new( $args{ 'log' } ); 
     57    $self->{ 'log_template' } = OmniPITR::Log->new( $args{ 'log_template' } ); 
     58 
     59    return; 
     60
     61 
     62sub validate_args { 
     63    my $self = shift; 
     64 
     65    $self->log->fatal( "--data-dir was not provided!" ) unless defined $self->{ 'data-dir' }; 
     66    $self->log->fatal( "Given data-dir (%s) is not valid", $self->{ 'data-dir' } ) unless -d $self->{ 'data-dir' } && -f File::Spec->catfile( $self->{ 'data-dir' }, 'PG_VERSION' ); 
     67 
     68    my $dst_count = scalar( @{ $self->{ 'destination' }->{ 'local' } } ) + scalar( @{ $self->{ 'destination' }->{ 'remote' } } ); 
     69    $self->log->fatal( "No --dst-* has been provided!" ) if 0 == $dst_count; 
     70 
     71    if ( 1 < $dst_count ) { 
     72        $self->log->fatal( "More than 1 --dst-* has been provided, but no --state-dir!" ) if !$self->{ 'state-dir' }; 
     73        $self->log->fatal( "Given --state-dir (%s) does not exist",     $self->{ 'state-dir' } ) unless -e $self->{ 'state-dir' }; 
     74        $self->log->fatal( "Given --state-dir (%s) is not a directory", $self->{ 'state-dir' } ) unless -d $self->{ 'state-dir' }; 
     75        $self->log->fatal( "Given --state-dir (%s) is not writable",    $self->{ 'state-dir' } ) unless -w $self->{ 'state-dir' }; 
     76    } 
     77 
     78    return; 
    4479} 
    4580 
    46811; 
    47  
  • trunk/omnipitr/lib/OmniPITR/Log.pm

    r69 r71  
    1616    my $class                 = shift; 
    1717    my ( $filename_template ) = @_; 
     18    croak( 'Logfile name template was not provided!' ) unless $filename_template; 
     19 
    1820    my $self                  = bless {}, $class; 
    1921