pf-tools/pf-tools: 14 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Mon Oct 11 10:23:50 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/1482c7d125c6
changeset: 859:1482c7d125c6
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Oct 05 18:01:49 2010 +0200
description:
Coding style on Utils.pm part one ...
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/60c1d81745e6
changeset: 860:60c1d81745e6
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Oct 06 18:37:20 2010 +0200
description:
Style : properly handle system exec with Proc::Reliable
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/941f902c9a6c
changeset: 861:941f902c9a6c
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Oct 06 18:39:00 2010 +0200
description:
properly handle system exec with Proc::Reliable (adding dep also)
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/ea7962d9a3b5
changeset: 862:ea7962d9a3b5
user: "Christophe Caillet <quadchris at free.fr>"
date: Thu Oct 07 16:39:31 2010 +0200
description:
Coding style for PFTools::Utils
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/c38cc07a9cd6
changeset: 863:c38cc07a9cd6
user: "Christophe Caillet <quadchris at free.fr>"
date: Thu Oct 07 16:40:34 2010 +0200
description:
Handle correctly the return value of Mk_sourceslist function
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/04916d702bcc
changeset: 864:04916d702bcc
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 18:51:42 2010 +0200
description:
FIX: dhcpvlan need to be add to deployment hash on host structure
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/0a89a147d2a0
changeset: 865:0a89a147d2a0
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 18:55:11 2010 +0200
description:
FIX: forgotten modifier and more checks
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e44354c37a34
changeset: 866:e44354c37a34
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 18:58:44 2010 +0200
description:
Using Get_uniq_site_from_hostname and removing useless PFTools::Logger
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/61dba20e5982
changeset: 867:61dba20e5982
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 19:24:23 2010 +0200
description:
Remove useless use of PFTools::Logger by replacing Abort by die
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/0bf5fb0a5201
changeset: 868:0bf5fb0a5201
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 19:31:06 2010 +0200
description:
FIX: Avoid a potential use of undefined value
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/0918afc412db
changeset: 869:0918afc412db
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Oct 08 19:32:29 2010 +0200
description:
Remove useless use of PFTools::Logger by replacing Abort by die
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/4cbe94693287
changeset: 870:4cbe94693287
user: "Christophe Caillet <quadchris at free.fr>"
date: Mon Oct 11 12:07:48 2010 +0200
description:
Remove useless check in Init_TOOLS
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/4f479de44c13
changeset: 871:4f479de44c13
user: "Christophe Caillet <quadchris at free.fr>"
date: Mon Oct 11 12:09:21 2010 +0200
description:
Coding style and removing useless use of PFTools::Logger
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/cfc621c05c0f
changeset: 872:cfc621c05c0f
user: "Christophe Caillet <quadchris at free.fr>"
date: Mon Oct 11 12:22:21 2010 +0200
description:
Better with this use :)
diffstat:
3 files changed, 9 insertions(+), 13 deletions(-)
lib/PFTools/VCS/CVS.pm | 1 +
lib/PFTools/VCS/SVN.pm | 10 +++++++---
sbin/mk_sourceslist | 11 +----------
diffs (967 lines):
diff -r 5471a7ec2b40 -r cfc621c05c0f lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm Mon Oct 11 11:37:16 2010 +0200
+++ b/lib/PFTools/Conf/Host.pm Mon Oct 11 12:22:21 2010 +0200
@@ -644,7 +644,7 @@
}
sub __Add_deployment_on_host_entry {
- my ( $type, $host2add, $hostclass, $host_number ) = @_;
+ my ( $type, $host2add, $hostclass, $host_number, $dhcpvlan ) = @_;
my $result = {};
unless( $type or $host2add or $hostclass ) {
@@ -669,6 +669,7 @@
next unless $value;
$result->{$key} = $value;
}
+ $result->{'dhcpvlan'} = $dhcpvlan;
}
return $result;
}
@@ -769,7 +770,7 @@
}
$host_part->{$hostname}->{'deployment'} =
__Add_deployment_on_host_entry (
- $type, $host2add, $hostclass, $host_number,
+ $type, $host2add, $hostclass, $host_number, $dhcpvlan
);
if( $type eq 'host' ) {
$host_part->{$hostname}->{'boot'} = __Add_boot_on_host_entry (
diff -r 5471a7ec2b40 -r cfc621c05c0f lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Mon Oct 11 11:37:16 2010 +0200
+++ b/lib/PFTools/Structqueries.pm Mon Oct 11 12:22:21 2010 +0200
@@ -280,7 +280,7 @@
my ($host_props) = @_;
my ( $bond_cmdline, $cmdline );
- $cmdline = $host_props->{'boot'}->{'cmdline'};
+ $cmdline = $host_props->{'boot'}->{'cmdline'} || "";
foreach my $iface ( sort keys %{ $host_props->{'interfaces'} } ) {
next unless( $iface =~ m{\A bond}xms );
$bond_cmdline = "bonding.mode="
diff -r 5471a7ec2b40 -r cfc621c05c0f lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Mon Oct 11 11:37:16 2010 +0200
+++ b/lib/PFTools/Utils.pm Mon Oct 11 12:22:21 2010 +0200
@@ -21,6 +21,7 @@
use warnings;
use base qw( Exporter );
+use Carp;
use Digest::MD5;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use File::Compare;
@@ -451,9 +452,17 @@
return 1;
}
-sub Resolv ($$;$$$) {
+sub Resolv {
my ( $type_resolve, $hostname, $global_config, $site, $hosttype ) = @_;
+ unless( $type_resolve =~ m{\A (cnf|dns) \Z}xms ) {
+ carp qq{ERROR: Invalid type_resolv $type_resolve};
+ return;
+ }
+ unless( $hostname ) {
+ carp q{ERROR: $hostname MUST BE specified};
+ return;
+ }
if ( $type_resolve eq 'cnf' ) {
if ( !defined $site ) {
my $ref_site_list
@@ -496,7 +505,7 @@
}
}
-sub __Search_and_resolve_IP ($$$$$$$) {
+sub __Search_and_resolve_IP {
my ( $hostname, $site, $line, $separator, $type_resolve, $hash_subst,
$global_config )
= @_;
@@ -505,23 +514,29 @@
my $pos = length $line;
while (
substr( $line, 0, $pos )
- =~ m/^(.*[^A-Za-z0-9.-])?([A-Za-z0-9.-]+)(\\?)(\.$zone)([^A-Za-z0-9.-].*)?$/
- )
- {
+ =~ m{\A
+ (.*[^A-Za-z0-9.-])?
+ ([A-Za-z0-9.-]+)
+ (\\?)
+ (\.$zone)
+ ([^A-Za-z0-9.-].*)?
+ \Z}xmso
+ ) {
my $before = $1;
my $back = $3;
my $match = $2 . $3 . $4;
my $matchback = $2 . $4;
my $after = $5;
my $lengthbefore = defined $before ? length $before : 0;
- if ( $back ne "\\\\" ) {
+ if( $back ne "\\\\" ) {
my $match2 = $match;
- $match2 =~ s/HOSTNAME/$hostname/;
- $match2 =~ s/POPNAME/$hash_subst->{'POPNAME'}/g;
- my $resolved
- = Resolv( $type_resolve, $match2, $global_config, $site );
- if ( scalar $resolved ) {
- if ( $separator eq "DUPLICATE" ) {
+ $match2 =~ s{HOSTNAME}{$hostname};
+ $match2 =~ s{POPNAME}{$hash_subst->{'POPNAME'}}xmsg;
+ my $resolved = Resolv(
+ $type_resolve, $match2, $global_config, $site
+ );
+ if( scalar $resolved ) {
+ if( $separator eq "DUPLICATE" ) {
my $templine = "";
my $templine2;
foreach my $res ( @{$resolved} ) {
@@ -550,13 +565,20 @@
return $line;
}
-sub __Search_and_resolve_IFACE ($$$) {
+sub __Search_and_resolve_IFACE {
my ( $line, $host_props, $hash_subst ) = @_;
my $pos = length $line;
while (
substr( $line, 0, $pos )
- =~ m/^(.*[^A-Za-z0-9.-])?(eth([-.:])([A-Za-z0-9-]+))([^A-Za-z0-9.-].*)?$/
+ =~ m{\A
+ (.*[^A-Za-z0-9.-])?
+ (eth
+ ([-.:])
+ ([A-Za-z0-9-]+)
+ )
+ ([^A-Za-z0-9.-].*)?
+ \Z}xmso
)
{
my $before = $1;
@@ -568,17 +590,17 @@
my $lengthbefore = defined $before ? length $before : 0;
my $vlan2 = $vlan;
- $vlan2 =~ s/POPNAME/$hash_subst->{'POPNAME'}/;
+ $vlan2 =~ s{POPNAME}{$hash_subst->{'POPNAME'}};
my $eth = Get_iface_vlan_from_hostname( $vlan2, $host_props );
- if ( defined $eth ) {
+ if( defined $eth ) {
my $neweth = $eth;
- if ( $type eq "." ) {
- $neweth =~ s/:.*$//;
+ if( $type eq "." ) {
+ $neweth =~ s{:.*\Z}{};
}
- elsif ( $type eq "-" ) {
- $neweth =~ s/[.:].*$//;
+ elsif( $type eq "-" ) {
+ $neweth =~ s{[.:].*\Z}{};
}
substr( $line, $lengthbefore, length $match ) = $neweth;
$pos = $lengthbefore;
@@ -590,7 +612,7 @@
return $line;
}
-sub Search_and_replace ($$$$$$$;$) {
+sub Search_and_replace {
my ( $hostname, $site, $input_file, $type_replace, $pf_config, $separator,
$global_config, $type_resolve )
= @_;
@@ -598,92 +620,97 @@
if ( $type_resolve && $type_resolve eq 'cnf' && !defined $global_config )
{
- Warn( $CODE->{'UNDEF_KEY'},
- "Unable top resolve from configuration structure which is not defined"
- );
- return undef;
+ carp q{ERROR: Unable to resolve from configuration};
+ return;
}
- my $hosttype
- = Get_hosttype_from_hostname( $hostname, $global_config, $site );
+ my $hosttype = Get_hosttype_from_hostname(
+ $hostname, $global_config, $site
+ );
my $subst = Init_SUBST( $hostname, $hosttype, $pf_config );
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
- unless ( open( SRC, $input_file ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable top open file " . $input_file . " : $OS_ERROR" );
- return 0;
+ my $input_hl = IO::File->new( $input_file );
+ unless( $input_hl ) {
+ carp qq{ERROR: Unable to open file $input_file : $OS_ERROR};
+ return;
}
- my @src = <SRC>;
- close(SRC);
+ my @src = <$input_hl>;
+ $input_hl->close();
- foreach my $line (@src) {
- if ( $type_replace eq 'resolver' ) {
- $line = __Search_and_resolve_IP( $hostname, $site, $line,
- $separator, $type_resolve, $subst, $global_config );
+ foreach my $line ( @src ) {
+ if( $type_replace eq 'resolver' ) {
+ $line = __Search_and_resolve_IP(
+ $hostname, $site, $line, $separator,
+ $type_resolve, $subst, $global_config
+ );
}
- elsif ( $type_replace eq 'iface' ) {
+ elsif( $type_replace eq 'iface' ) {
$line = __Search_and_resolve_IFACE( $line, $host_props, $subst );
}
- elsif ( $type_replace eq 'distrib' ) {
- $line =~ s/%DISTSRC%/$host_props->{'deployment'}->{'mode'}/gs;
- $line =~ s/%DISTRIB%/$host_props->{'deployment'}->{'distrib'}/gs;
+ elsif( $type_replace eq 'distrib' ) {
+ $line =~ s{%DISTSRC%}{$host_props->{'deployment'}->{'mode'}}gs;
+ $line =~ s{%DISTRIB%}{$host_props->{'deployment'}->{'distrib'}}gs;
}
push( @{$result}, $line );
}
return $result;
}
-sub Fix_hosts ($$$$$$) {
+sub Fix_hosts {
my ( $hostname, $input_file, $site, $ip_type, $global_config, $pf_config )
= @_;
my $tmp_hosts = [];
- if ( $ip_type !~ /^ipv4$/ ) {
- Warn( $CODE->{'INVALID_VALUE'},
- $ip_type . " is not implemented for fixing " . $input_file );
- return undef;
+ if ( $ip_type !~ m{\A ipv4 \Z}xms ) {
+ carp qq{ERROR: $ip_type is not implemented for fixing $input_file};
+ return;
}
- unless ( open( HOSTS, $input_file ) ) {
- Warn( $CODE->{'OPEN'}, "Unable top open " . $input_file . "\n" );
- return 0;
+ my $input_hl = IO::File->new( $input_file );
+ unless( $input_file ) {
+ carp qq{ERROR: Unable top open $input_file};
+ return;
}
- @{$tmp_hosts} = <HOSTS>;
- close(HOSTS);
+ @{$tmp_hosts} = <$input_hl>;
+ $input_hl->close();
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
+ unless( $host_props ) {
+ carp qq{ERROR: Unknown hostname $hostname};
+ return;
+ }
my $iface_dhcpvlan = Get_iface_vlan_from_hostname(
- $host_props->{'deployment'}->{'dhcpvlan'}, $host_props );
+ $host_props->{'deployment'}->{'dhcpvlan'}, $host_props
+ );
my $ip_deploy = $host_props->{'interfaces'}->{$iface_dhcpvlan}->{'ipv4'};
- $ip_deploy =~ s/\/[\d]+$//;
+ $ip_deploy =~ s{\/[\d]+\Z}{};
foreach ( @{$tmp_hosts} ) {
- next if ( !/$hostname/ );
- s/^127.0.([\d]{1,3}\.[\d]{1,3})/$ip_deploy/;
+ next if ( !m{$hostname} );
+ s{\A 127.0.([\d]{1,3}\.[\d]{1,3})}{$ip_deploy}xms;
}
return $tmp_hosts;
}
-sub Mk_dhcp ($$) {
+sub Mk_dhcp {
my ( $header_file, $site_part ) = @_;
my $dhcp = [];
if ( $header_file ne '' ) {
- if ( !-e $header_file ) {
- Abort( $CODE->{'OPEN'},
- "Unable to open DHCP header file "
- . $header_file
- . " : no such file or directory" );
+ unless( -e $header_file ) {
+ croak qq{ERROR: $header_file no such file or directory};
}
- elsif ( !open( HEAD, $header_file ) ) {
- Abort( $CODE->{'OPEN'},
- "Unable to open DHCP header file " . $header_file );
+ my $header_hl = IO::File->new( $header_file );
+ unless( $header_hl ) {
+ croak qq{ERROR: Unable to open header $header_file : $OS_ERROR};
}
- foreach (<HEAD>) {
+ foreach (<$header_hl>) {
chomp;
push( @{$dhcp}, $_ );
}
- close(HEAD);
+ $header_hl->close();
}
foreach my $vlan ( keys %{$site_part} ) {
@@ -702,7 +729,7 @@
);
}
foreach my $hostclass ( keys %{ $site_part->{$vlan} } ) {
- next if ( $hostclass =~ /^(subnet|netmask|routers)$/ );
+ next if ( $hostclass =~ m{\A (subnet|netmask|routers) \Z}xmso );
my $host_part = $site_part->{$vlan}->{$hostclass};
foreach my $host ( keys %{$host_part} ) {
push( @{$dhcp}, "\thost " . $host . " {" );
@@ -717,35 +744,30 @@
return $dhcp;
}
-sub Mk_sourceslist ($$$$$$$$) {
+sub Mk_sourceslist {
my ( $hostname, $site, $dst, $sections, $template, $backports,
$global_config, $pf_config )
= @_;
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $host_props ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to find hostname "
- . $hostname
- . " on site "
- . $site
- . " : no such host definition" );
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
+ unless( $host_props ) {
+ croak qq{ERROR: Unknown $hostname on $site};
}
my $tpl = Template::Tiny->new( TRIM => 1 );
my $mode = $host_props->{'deployment'}->{'mode'};
- if ( $template eq "" ) {
+ unless( $template ) {
$template = $pf_config->{'path'}->{'templates_dir'} . '/'
. $pf_config->{$mode}->{'sources_list'};
}
- if ( !open( SOURCESTPL, $template ) ) {
- Abort( $CODE->{'OPEN'},
- "Unable to get sources.list template from file " . $template );
- return 1;
+ my $tpl_hl = IO::File->new( $template );
+ unless( $tpl_hl ) {
+ croak qq{ERROR: Unable to open template $template};
}
- my $sources_content = join '', <SOURCESTPL>;
- close(SOURCESTPL);
+ my $sources_content = join '', <$tpl_hl>;
+ $tpl_hl->close();
my $sources_subst = {
'mode' => $host_props->{'deployment'}->{'mode'},
@@ -753,11 +775,12 @@
'default_sections' => $pf_config->{$mode}->{'default_sections'},
'custom_sections' => $sections
};
- $sources_content = $tpl->process( \$sources_content, $sources_subst );
+ $sources_content = $tpl->process(
+ \$sources_content, $sources_subst, \$sources_content
+ );
- if ($backports) {
- my $back_src
- = ( $mode eq 'debian' )
+ if( $backports ) {
+ my $back_src = ( $mode eq 'debian' )
? $mode . "-backports"
: $mode;
$sources_content
@@ -768,30 +791,30 @@
. $pf_config->{$mode}->{'default_sections'} . "\n";
}
- if ( !open( DST, ">" . $dst ) ) {
- warn "Unable to open destination's sources.list " . $dst . "\n";
- return 1;
+ my $dst_hl = IO::File->new( ">".$dst );
+ unless( $dst_hl ) {
+ croak qq{ERROR: Unable to open $dst : $OS_ERROR};
}
- print DST $sources_content;
- close(DST);
- return 0;
+ $dst_hl->print( $sources_content."\n" );
+ $dst_hl->close();
+ return 1;
}
-sub Change_kopt_for_hostname ($$$$$$$) {
+sub Change_kopt_for_hostname {
my ( $hostname, $site, $grub_src, $dst, $grub_version, $global_config,
$pf_config )
= @_;
my $tmp_grub = [];
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
unless( $host_props ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unknown hostname $hostname on site $site" );
+ croak qq{ERROR: Unknown $hostname on $site};
}
my $mode = $host_props->{'deployment'}->{'mode'};
my $cmdline = join( " ", Get_cmdline_from_hostprops($host_props) );
- $cmdline =~ s/^\s*//; # Removing trailing space
+ $cmdline =~ s{\A\s*}{}; # Removing trailing space
$grub_version = "" if ( $grub_version == 1 );
$grub_src = $pf_config->{$mode}->{ 'grub' . $grub_version }
@@ -849,16 +872,12 @@
my ( $hostname, $global_config, $pf_config, $site ) = @_;
my $resolve = 0;
- my $properties
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $properties ) {
- Warn( $CODE->{'UNDEF_KEY'},
- "Unable to find hostname "
- . $hostname
- . " on site "
- . $site
- . " : no such host definition" );
- return undef;
+ my $properties = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
+ unless( $properties ) {
+ carp qq{ERROR: Unknown $hostname on $site};
+ return;
}
my $hostclass = $properties->{'deployment'}->{'hosttype'};
my $interfaces = {};
@@ -1022,25 +1041,19 @@
&& defined( $host_config->{$depend} ) )
{
if ( $depend eq $section ) {
- Warn( $CODE->{'SYNTAX'},
- "["
- . $section
- . "] circular dependancy detected, skipping this depend"
- );
- FlushLog();
+ carp qq{WARN: [$section] circular dependancy};
+# FlushLog();
next;
}
push @{$depends}, $depend;
if ( $host_config->{$depend}->{'action'} eq
'addmount' )
{
- Warn( $CODE->{'OPEN'},
- "["
- . $section
- . "] depends on addmount ["
- . $depend
- . "], it may not work during install!" );
- FlushLog();
+ carp qq{
+ WARN:[$section] depends on addmount [$depend],
+ it may not work during install!
+ };
+# FlushLog();
}
}
@@ -1050,13 +1063,14 @@
# }
}
if ( scalar @{$depends} ) {
- Log( "<" . $section . "> " . join( ' ', @{$depends} ) );
+ print "<" . $section . "> " . join( ' ', @{$depends} )
+ if( ! $options->{'quiet'} );
$errorcount += __Do_updateloop( $host_config, $options,
$hash_subst, $global_config, $depends );
}
}
- Log( "[" . $section . "]" );
- if( ! Exec_action(
+ print "[" . $section . "]" if ( ! $options->{'quiet'} );
+ $errorcount++ if( ! Exec_action(
$host_config->{$section}->{'action'},
$host_config->{$section},
$section,
@@ -1064,14 +1078,14 @@
$hash_subst,
$global_config
)
- )
- {
- FlushLog();
- $errorcount++;
- }
- else {
- DelLog();
- }
+ );
+# {
+# FlushLog();
+# $errorcount++;
+# }
+# else {
+# DelLog();
+# }
$host_config->{$section}->{'done'} = 1;
}
}
@@ -1082,47 +1096,42 @@
my ( $hostname, $site, $options, $global_config, $pf_config ) = @_;
my $errorcount = 0;
- Set_deferredlog();
+# Set_deferredlog();
if ( !VCS_checkout( $hostname, $pf_config, $options ) ) {
Abort( $CODE->{'EXEC'},
"Unable to checkout configuration from VCS system" );
}
- Unset_deferredlog();
- my $hosttype
- = Get_hosttype_from_hostname( $hostname, $global_config, $site );
+# Unset_deferredlog();
+ my $hosttype = Get_hosttype_from_hostname(
+ $hostname, $global_config, $site
+ );
my $hash_subst = Init_SUBST( $hostname, $hosttype, $pf_config );
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $host_props ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to retrieve host properties from hostname " . $hostname );
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
+ unless( $host_props ) {
+ croak qq{ERROR: Unknown hostname $hostname};
}
- $hash_subst->{'DISTRIB'} = Get_distrib_from_hostprops($host_props);
- $hash_subst->{'MODE'} = Get_mode_from_hostprops($host_props);
+ $hash_subst->{'DISTRIB'} = Get_distrib_from_hostprops( $host_props );
+ $hash_subst->{'MODE'} = Get_mode_from_hostprops( $host_props );
if ( !defined $options->{'pkg_type'} ) {
- unless ( $options->{'pkg_type'}
- = Get_pkgtype_from_hostname( $hostname, $global_config, $site ) )
- {
- Abort( $CODE->{'INVALID_VALUE'},
- "Unable to retrieve package type from hostname "
- . $hostname );
+ unless (
+ $options->{'pkg_type'} = Get_pkgtype_from_hostname(
+ $hostname, $global_config, $site
+ )
+ ) {
+ croak qq{ERROR: Unable to retrieve package type from $hostname};
}
}
- my $host_config
- = Get_config_for_hostname_on_site( $hostname, $site, $hash_subst,
- $global_config, $pf_config );
- if ( !defined $host_config ) {
- Abort( $CODE->{'OPEN'},
- "Unable to parse configuration for hostname "
- . $hostname
- . " in site "
- . $site );
+ my $host_config = Get_config_for_hostname_on_site(
+ $hostname, $site, $hash_subst, $global_config, $pf_config
+ );
+ unless( $host_config ) {
+ croak qq{ERROR: Problem when parsing config for $hostname on $site};
}
if ( !$pf_config->{'features'}->{'update'} ) {
- Abort( $CODE->{'OPEN'},
- "Unable to update configuration : update feature is deactivated in pf-tools configuration file"
- );
+ croak q{ERROR: update feature is deactivated in config file};
}
my $sortedkeys;
@@ -1130,11 +1139,12 @@
@{ $host_config->{'__sections_order'} };
$| = 1;
- $errorcount = __Do_updateloop( $host_config, $options, $hash_subst,
- $global_config, $sortedkeys );
+ $errorcount = __Do_updateloop(
+ $host_config, $options, $hash_subst, $global_config, $sortedkeys
+ );
- Log( $errorcount . " error(s) detected." );
- FlushLog();
+ print $errorcount . " error(s) detected.\n";
+# FlushLog();
}
1;
diff -r 5471a7ec2b40 -r cfc621c05c0f lib/PFTools/VCS/CVS.pm
--- a/lib/PFTools/VCS/CVS.pm Mon Oct 11 11:37:16 2010 +0200
+++ b/lib/PFTools/VCS/CVS.pm Mon Oct 11 12:22:21 2010 +0200
@@ -26,8 +26,9 @@
use Carp;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use File::Path qw( make_path remove_tree );
+use Proc::Reliable;
-use PFTools::Logger;
+#use PFTools::Logger;
our @EXPORT = qw(
checkout
@@ -97,16 +98,24 @@
make_path $co_dir
or croak qq{ERROR: Unable to create $co_dir : $OS_ERROR};
- $ret = deferredlogsystem( "cd '" . $co_dir . "';" . $cvs_cmd );
- if ($ret) {
- FlushLog();
- }
- else {
- DelLog();
+# $ret = deferredlogsystem( "cd '" . $co_dir . "';" . $cvs_cmd );
+# if ($ret) {
+# FlushLog();
+# }
+# else {
+# DelLog();
+# }
+ my $exec = Proc::Reliable->new();
+ my( $stdout, $stderr, $status, $msg ) = $exec->run(
+ "cd '" . $co_dir . "';" . $cvs_cmd
+ );
+ print $stdout if( $options->{'verbose'} );
+ if( $status ) {
+ carp qq{ERROR: unable to checkout : $stderr};
+ return;
}
umask($umask);
- # Shell return 0 with success
- return !$ret;
+ return 1;
}
1;
diff -r 5471a7ec2b40 -r cfc621c05c0f lib/PFTools/VCS/SVN.pm
--- a/lib/PFTools/VCS/SVN.pm Mon Oct 11 11:37:16 2010 +0200
+++ b/lib/PFTools/VCS/SVN.pm Mon Oct 11 12:22:21 2010 +0200
@@ -93,13 +93,23 @@
make_path $co_dir
or croak qq{ERROR: Unable to create $co_dir : $OS_ERROR};
- $ret = deferredlogsystem( "cd '" . $co_dir . "';" . $svn_cmd );
- if ($ret) {
- FlushLog();
+ my $exec = Proc::Reliable->new();
+ my( $stdout, $stderr, $status, $msg ) = $exec->run(
+ "cd '" . $co_dir . "';" . $svn_cmd
+ );
+ print $stdout if( $options->{'verbose'} );
+ if( $status ) {
+ carp qq{ERROR: unable to checkout : $stderr};
+ return;
}
- else {
- DelLog();
- }
+
+# $ret = deferredlogsystem( "cd '" . $co_dir . "';" . $svn_cmd );
+# if ($ret) {
+# FlushLog();
+# }
+# else {
+# DelLog();
+# }
umask($umask);
return !$ret;
}
diff -r 5471a7ec2b40 -r cfc621c05c0f sbin/fix_hosts
--- a/sbin/fix_hosts Mon Oct 11 11:37:16 2010 +0200
+++ b/sbin/fix_hosts Mon Oct 11 12:22:21 2010 +0200
@@ -27,7 +27,6 @@
use IO::File;
use Sys::Hostname;
-use PFTools::Logger;
use PFTools::Structqueries;
use PFTools::Utils;
@@ -96,27 +95,12 @@
);
if ( !$PF_CONFIG->{'features'}->{$options->{'type'}} ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Aborting because $options->{'type'} is not activated in PF-Tools" );
+ die "Aborting because $options->{'type'} is not activated in PF-Tools";
}
unless( $options->{'site'} ) {
- unless( $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname(
- $options->{'host'},
- $GLOBAL_STRUCT
- );
- unless( $site_list ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unknown hostname $options->{'host'}" );
- }
- if ( scalar @{$site_list} > 1 ) {
- Abort( $CODE->{'DUPLICATE_VALUE'},
- "Multiple sites for hostname $options->{'host'}" );
- }
- ($options->{'site'}) = @{$site_list};
- }
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
+ || Get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
}
my $fixed_input = Fix_hosts(
@@ -124,18 +108,14 @@
$options->{'site'}, $options->{'type'}, $GLOBAL_STRUCT,
$PF_CONFIG );
unless( $fixed_input ) {
- Abort( $CODE->{'EXEC'},
- "An error occured during fixing file $options->{'output'}" );
+ die "An error occured during fixing file $options->{'input'}";
}
my $output_fh = IO::File->new(">$options->{'output'}")
- or Abort( $CODE->{'OPEN'},
- "Unable to open destination $options->{'output'} : $OS_ERROR" );
+ or die "Unable to open destination $options->{'output'} : $OS_ERROR";
$output_fh->print ( join '', @{$fixed_input} )
- or Abort ( $CODE->{'OPEN'},
- "Unable to write to destination $options->{'output'} : $OS_ERROR" );
+ or die "Unable to write to destination $options->{'output'} : $OS_ERROR";
$output_fh->close()
- or Abort( $CODE->{'OPEN'},
- "Unable to close destination $options->{'output'} : $OS_ERROR" );
+ or die "Unable to close destination $options->{'output'} : $OS_ERROR";
exit 0;
diff -r 5471a7ec2b40 -r cfc621c05c0f sbin/mk_dhcp
--- a/sbin/mk_dhcp Mon Oct 11 11:37:16 2010 +0200
+++ b/sbin/mk_dhcp Mon Oct 11 12:22:21 2010 +0200
@@ -28,7 +28,6 @@
use Getopt::Long qw( :config ignore_case_always bundling );
use IO::File;
-use PFTools::Logger;
use PFTools::Utils;
#####################################
@@ -95,14 +94,13 @@
unless( $options->{'site'} ) {
unless( $PF_CONFIG->{'location'}->{'site'} ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "A site MUST BE defined for building DNS zone forward" );
+ die "A site MUST BE defined for building DNS zone forward";
}
$options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
- Abort( $CODE->{'UNDEF_KEY'}, "Unknown site $options->{'site'}" );
+ die "Unknown site $options->{'site'}";
}
my $DHCP = Mk_dhcp(
@@ -111,13 +109,10 @@
);
my $output_fh = IO::File->new ( '>' . $options->{'output'} )
- or Abort( $CODE->{'OPEN'},
- "Unable to open destination $options->{'output'}: $OS_ERROR" );
+ or die "Unable to open destination $options->{'output'}: $OS_ERROR";
$output_fh->print ( join "\n", @{$DHCP} )
- or Abort( $CODE->{'OPEN'},
- "Unable to write to destination $options->{'output'}: $OS_ERROR" );
+ or die "Unable to write to destination $options->{'output'}: $OS_ERROR";
$output_fh->close()
- or Abort( $CODE->{'OPEN'},
- "Unable to close destination $options->{'output'}: $OS_ERROR" );
+ or die "Unable to close destination $options->{'output'}: $OS_ERROR";
exit 0;
diff -r 5471a7ec2b40 -r cfc621c05c0f sbin/mk_grubopt
--- a/sbin/mk_grubopt Mon Oct 11 11:37:16 2010 +0200
+++ b/sbin/mk_grubopt Mon Oct 11 12:22:21 2010 +0200
@@ -25,7 +25,6 @@
use Getopt::Long qw( :config ignore_case_always bundling );
use Sys::Hostname;
-use PFTools::Logger;
use PFTools::Structqueries;
use PFTools::Utils;
@@ -93,27 +92,12 @@
);
unless( $options->{'site'} ) {
- unless( $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname(
- $options->{'host'},
- $GLOBAL_STRUCT
- );
- unless( $site_list ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unknown hostname $options->{'host'}" );
- }
- if ( scalar @{$site_list} > 1 ) {
- Abort( $CODE->{'DUPLICATE_VALUE'},
- "Multiple sites for hostname $options->{'host'}" );
- }
- ($options->{'site'}) = @{$site_list};
- }
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
+ || Get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
}
unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unknown DHCP site $options->{'site'}" );
+ die "Unknown DHCP site $options->{'site'}";
}
if (
@@ -127,8 +111,7 @@
$PF_CONFIG
)
) {
- Abort( $CODE->{'EXEC'},
- "Unable to change kernel options(s) into file $options->{'src'}" );
+ die "Unable to change kernel options(s) into file $options->{'src'}";
}
exit 0;
diff -r 5471a7ec2b40 -r cfc621c05c0f sbin/mk_interfaces
--- a/sbin/mk_interfaces Mon Oct 11 11:37:16 2010 +0200
+++ b/sbin/mk_interfaces Mon Oct 11 12:22:21 2010 +0200
@@ -29,7 +29,6 @@
use IO::File;
use Sys::Hostname;
-use PFTools::Logger;
use PFTools::Structqueries;
use PFTools::Utils;
@@ -96,22 +95,8 @@
);
unless( $options->{'site'} ) {
- unless( $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname(
- $options->{'host'},
- $GLOBAL_STRUCT
- );
- unless( $site_list ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unknown hostname $options->{'host'}" );
- }
- if ( scalar @{$site_list} > 1 ) {
- Abort( $CODE->{'DUPLICATE_VALUE'},
- "Multiple sites for hostname $options->{'host'}" );
- }
- ($options->{'site'}) = @{$site_list};
- }
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
+ || Get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
}
my $iface = Mk_interfaces(
@@ -121,24 +106,19 @@
$options->{'site'}
);
unless( $iface ) {
- Abort( $CODE->{'EXEC'},
- "Error occured during building interfaces file" );
+ die "Error occured during building interfaces file";
}
my $output_fh = IO::File->new( '>' . $options->{'output'} )
- or Abort( $CODE->{'OPEN'},
- "Unable to open file $options->{'output'} : $OS_ERROR" );
+ or die "Unable to open file $options->{'output'} : $OS_ERROR";
$output_fh->print( join "\n", @HEADER_DEST )
- or Abort( $CODE->{'OPEN'},
- "Unable to write on file $options->{'output'} : $OS_ERROR" );
+ or die "Unable to write on file $options->{'output'} : $OS_ERROR";
foreach my $if ( @{ $iface->{'__order'} } ) {
unless( $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" ) ) {
- Abort( $CODE->{'OPEN'},
- "Unable to write on file $options->{'output'} : $OS_ERROR" );
+ die "Unable to write on file $options->{'output'} : $OS_ERROR";
}
}
$output_fh->close()
- or Abort( $CODE->{'OPEN'},
- "Unable to close file $options->{'output'} : $OS_ERROR" );
+ or die "Unable to close file $options->{'output'} : $OS_ERROR";
exit 0;
diff -r 5471a7ec2b40 -r cfc621c05c0f sbin/mk_sourceslist
--- a/sbin/mk_sourceslist Mon Oct 11 11:37:16 2010 +0200
+++ b/sbin/mk_sourceslist Mon Oct 11 12:22:21 2010 +0200
@@ -150,15 +150,19 @@
$options->{'add'} =~ s/,/ /g;
$SECTIONS .= " " . $options->{'add'};
$SECTIONS =~ s/^\s*//; # Removing trailing space(s)
-Mk_sourceslist(
- $options->{'host'},
- $options->{'site'},
- $options->{'output'},
- $SECTIONS,
- $options->{'tpl'},
- $options->{'backport'},
- $GLOBAL_STRUCT,
- $PF_CONFIG
-);
+if( !
+ Mk_sourceslist(
+ $options->{'host'},
+ $options->{'site'},
+ $options->{'output'},
+ $SECTIONS,
+ $options->{'tpl'},
+ $options->{'backport'},
+ $GLOBAL_STRUCT,
+ $PF_CONFIG
+ )
+) {
+ warn q{ERROR: An error occured during sources.list generation};
+}
exit 0;
More information about the pf-tools-commits
mailing list