pf-tools commit: r849 [ccaillet-guest] - in /branches/next-gen/lib/PFTools: Disk.pm Structqueries.pm Update.pm Update/Addmount.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Aug 26 10:25:57 UTC 2010
Author: ccaillet-guest
Date: Thu Aug 26 10:25:55 2010
New Revision: 849
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=849
Log:
Validation of addmount action
Modified:
branches/next-gen/lib/PFTools/Disk.pm
branches/next-gen/lib/PFTools/Structqueries.pm
branches/next-gen/lib/PFTools/Update.pm
branches/next-gen/lib/PFTools/Update/Addmount.pm
Modified: branches/next-gen/lib/PFTools/Disk.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Disk.pm?rev=849&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Disk.pm (original)
+++ branches/next-gen/lib/PFTools/Disk.pm Thu Aug 26 10:25:55 2010
@@ -108,7 +108,7 @@
my $struct = {};
if ( ! open ( FSTAB, $fstab_file ) ) {
- Warn ( $CODE->{'OPEN'}, "Unable to open /etc/fstab" );
+ Warn ( $CODE->{'OPEN'}, "Unable to open ".$fstab_file );
return undef;
}
my @current_fstab = <FSTAB>;
@@ -121,6 +121,8 @@
# Removing trailing spaces
$line =~ s/^\s*//;
$line =~ s/\s*$//;
+ # Skipping empty lines
+ next if ( $line =~ /^$/ );
my ( $src_mnt, $mnt_pt, $type, $opt_mnt, $dump, $pass ) = split ( /\s+/, $line );
push ( @{$struct->{'__mnt_order'}}, $mnt_pt );
$struct->{$mnt_pt} = {
Modified: branches/next-gen/lib/PFTools/Structqueries.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Structqueries.pm?rev=849&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Structqueries.pm (original)
+++ branches/next-gen/lib/PFTools/Structqueries.pm Thu Aug 26 10:25:55 2010
@@ -36,6 +36,7 @@
our @EXPORT = qw(
Get_zone_from_hostname
+ Get_zone_from_site_GLOBAL
Get_hosttype_from_hostname
Get_iface_vlan_from_hostname
Get_site_from_hostname
Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=849&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Thu Aug 26 10:25:55 2010
@@ -49,6 +49,7 @@
use PFTools::Update::Removefile;
use PFTools::Update::Removedir;
use PFTools::Logger;
+use PFTools::Packages;
###########################################
# Global vars
Modified: branches/next-gen/lib/PFTools/Update/Addmount.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Addmount.pm?rev=849&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Addmount.pm (original)
+++ branches/next-gen/lib/PFTools/Update/Addmount.pm Thu Aug 26 10:25:55 2010
@@ -70,7 +70,7 @@
my ( $host, $global_config ) = @_;
my $ip = $host;
- $host =~ /^([^\.]+)\..*$/;
+ $host =~ /^([^\.]+)(\..*)?$/;
my $zone = Get_zone_from_hostname ( $1, $global_config );
if ( ! defined $zone ) {
Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve zone for hostname ".$host );
@@ -96,7 +96,6 @@
}
if ( ! isipaddr ( $ip ) ) {
my $resolved = Resolv_hostname_from_GLOBAL ( $ip, $global_config, $site, $zone, $hosttype );
- print Dumper $resolved;
if ( ! defined $resolved ) {
Warn ( $CODE->{'RESOLV'}, "Unknown host ".$host );
return undef;
@@ -191,30 +190,31 @@
}
my $current_proc = Build_structure_from_fstab ( "/proc/mounts" );
if ( ! defined $current_fstab ) {
- Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
+ Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /proc/mounts" );
return undef;
}
my $addfstab = 0;
if ( ! defined $current_fstab->{$dest} ) {
- print "Adding entry $dest\n";
- print Dumper $add_mount;
- foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
- $current_fstab->{$dest}->{$key} = $add_mount->{$key};
- }
- $current_fstab->{$dest} = {};
-# $current_fstab->{$dest} = $add_mount;
+ foreach my $key ( 'source', 'dest', 'fstype', 'options', 'dump', 'pass' ) {
+ $current_fstab->{$dest}->{$key} = ( defined $add_mount->{$key} )
+ ? $add_mount->{$key}
+ : 0;
+ }
+ push ( @{$current_fstab->{'__mnt_order'}}, $dest );
$addfstab = 1;
- print "Now we have fstab structure ...\n";
- print Dumper $current_fstab."\n";
}
else {
foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
- $addfstab = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
+ if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} ) {
+ $current_fstab->{$dest}->{$key} = $add_mount->{$key};
+ $addfstab = 1;
+ }
}
}
my $addproc = 0;
if ( ! defined $current_proc->{$dest} ) {
+ print "$dest entry is not defined into current_proc\n";
$addproc = 1;
}
else {
@@ -239,19 +239,16 @@
Mkdir_action ( $ref_section, $dest, $options, $hash_subst, $global_config );
}
if ( $addfstab ) {
- print "Need to add entry in fstab ...\n";
my $tmp = Get_tmp_dest ("/etc/fstab");
unless ( open ( NEWFSTAB, ">".$tmp ) ) {
Warn( $CODE->{'OPEN'}, "Unable to create tmp dest " . $tmp );
return 1;
}
-# $current_fstab->{$dest} = $add_mount;
my $new_fstab = Build_fstab_from_structure ( $current_fstab );
- print NEWFSTAB join ( "", @{$new_fstab} );
+ print NEWFSTAB join ( "\n", @{$new_fstab} );
close ( NEWFSTAB );
if ( $options->{'diff'} ) {
- diff ( '/etc/fstab', $tmp, { STYLE => 'Unified' } );
-# deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
+ print diff ( '/etc/fstab', $tmp, { STYLE => 'Unified' } );
}
if ( ! $options->{'simul'} ) {
if ( ! move ( $tmp, "/etc/fstab" ) ) {
@@ -261,12 +258,18 @@
}
}
if ( $addproc ) {
- print "Need to do some actions ...\n";
+ my $remount = 1;
+ if ( defined $current_proc->{$dest} ) {
+ foreach my $key ( 'source', 'dest', 'fstype' ) {
+ $remount = 0 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
+ }
+ }
if ( $options->{'diff'} ) {
foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
my $value = $current_proc->{$dest}->{$key} || '?';
if ( $key eq 'options' ) {
- Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $current_fstab->{$dest}->{$key} ne $add_mount->{$key} );
+ Log ( $key." ".$value." -> ".$add_mount->{$key} )
+ if ( $current_fstab->{$dest}->{$key} ne $add_mount->{$key} || ! defined $current_proc->{$dest}->{$key} );
}
else {
Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $value ne $add_mount->{$key} );
@@ -274,36 +277,28 @@
}
}
if ( ! $options->{'simul'} && ! $options->{'noaction'} ) {
- # Unmounting fs
- my $remount = 1;
- foreach my $key ( 'source', 'dest', 'fstype' ) {
- $remount = 0 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
- }
if ( $remount ) {
my $cmd = "mount -o 'remount,".$add_mount->{'options'}."' '".$dest."'";
-# if ( deferredlogsystem( $cmd ) ) {
-# Warn( $CODE->{'OPEN'},
-# "Unable to remount ".$dest." with options ".$add_mount->{'options'} );
-# return 1;
-# }
- print "Need to execute $cmd\n";
+ if ( deferredlogsystem( $cmd ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to remount ".$dest." with options ".$add_mount->{'options'} );
+ return 1;
+ }
}
else {
my $umount = ( $add_mount->{'source'} ne $current_proc->{$dest}->{'source'} )
? $current_proc->{$dest}->{'source'}
: $add_mount->{'source'};
-# if ( deferredlogsystem( "umount '".$umount."'" ) ) {
-# Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
-# return 1;
-# }
- print "Unmounting --> $umount\n";
+ if ( deferredlogsystem( "umount '".$umount."'" ) ) {
+ Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
+ return 1;
+ }
my $mount_cmd = "mount -t '".$add_mount->{'fstype'}."' - o '".$add_mount->{'options'}."' '"
.$add_mount->{'source'}."' '".$add_mount->{'dest'}."'";
-# if ( deferredlogsystem ( $mount_cmd ) ) {
-# Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
-# return 1;
-# }
- print "Mounting with command --> $mount_cmd\n";
+ if ( deferredlogsystem ( $mount_cmd ) ) {
+ Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
+ return 1;
+ }
}
}
}
More information about the pf-tools-commits
mailing list