From 016a94742824cf1c4eb06c9a6a2ec6913c45a60d Mon Sep 17 00:00:00 2001 From: daniceexi Date: Wed, 31 Jul 2013 07:05:18 -0400 Subject: [PATCH 1/4] Change the insert_dd function for handling the initrd hacking. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 43 ++++++++++----- xCAT-server/lib/xcat/plugins/geninitrd.pm | 4 ++ xCAT-server/lib/xcat/plugins/sles.pm | 67 +++++++++++++---------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index e836eed19..524c8bbad 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2512,19 +2512,26 @@ sub insert_dd { } elsif ( grep (/LZMA compressed data/, @format)) { $initrdfmt = "lzma"; } else { - my $rsp; - push @{$rsp->{data}}, "Could not handle the format of the initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); + # check whether it can be handled by xz + $cmd = "xz -t $img"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Could not handle the format of the initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } else { + $initrdfmt = "lzma"; + } } if ($initrdfmt eq "gzip") { $cmd = "gunzip -c $img > $dd_dir/initrd"; } elsif ($initrdfmt eq "lzma") { - if (! -x "/usr/bin/lzma") { + if (! -x "/usr/bin/xz") { my $rsp; - push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not lzma command."; + push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not xz command."; xCAT::MsgUtils->message("E", $rsp, $callback); return (); } @@ -2698,7 +2705,7 @@ sub insert_dd { xCAT::Utils->runcmd($cmd, -1); if ($::RUNCMD_RC != 0) { my $rsp; - push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the depdency for the drivers in the initrd."; + push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the drivers depdency for $kernelver in the initrd."; xCAT::MsgUtils->message("I", $rsp, $callback); } } @@ -3004,7 +3011,7 @@ sub insert_dd { if ($initrdfmt eq "gzip") { $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|gzip -9 -c - > $dd_dir/initrd.img"; } elsif ($initrdfmt eq "lzma") { - $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|lzma -C crc32 -9 > $dd_dir/initrd.img"; + $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|xz --format=lzma -C crc32 -9 > $dd_dir/initrd.img"; } xCAT::Utils->runcmd($cmd, -1); @@ -3072,13 +3079,23 @@ sub insert_dd { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',',@inserted_dd)."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@inserted_dd)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } + } + xCAT::MsgUtils->message("I", $rsp, $callback); return @inserted_dd; diff --git a/xCAT-server/lib/xcat/plugins/geninitrd.pm b/xCAT-server/lib/xcat/plugins/geninitrd.pm index ec13e052a..a364a6210 100644 --- a/xCAT-server/lib/xcat/plugins/geninitrd.pm +++ b/xCAT-server/lib/xcat/plugins/geninitrd.pm @@ -7,6 +7,7 @@ BEGIN use strict; use lib "$::XCATROOT/lib/perl"; +use File::Path; use File::Copy; use xCAT::MsgUtils; use xCAT::TableUtils; @@ -127,6 +128,9 @@ sub geninitrd { $tftpdir = $t_entry; } my $tftppath = "$tftpdir/xcat/osimage/$osimage"; + unless (-d $tftppath) { + mkpath $tftppath; + } if ($arch =~ /x86/) { if ($osvers =~ /(^ol[0-9].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)/) { $kernelpath = "$tftppath/vmlinuz"; diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 75d31229b..b2e9cf4c1 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1802,9 +1802,9 @@ sub insert_dd () { } # get the new kernel if it exists in the update distro - my @new_kernels = <$dd_dir/rpm/boot/vmlinuz*>; + my @new_kernels = <$dd_dir/rpm/boot/vmlinu*>; foreach my $new_kernel (@new_kernels) { - if (-r $new_kernel && $new_kernel =~ /\/vmlinuz-(.*(x86_64|ppc64))$/) { + if (-r $new_kernel && $new_kernel =~ /\/vmlinu[zx]-(.*(x86_64|ppc64|default))$/) { $new_kernel_ver = $1; $cmd = "/bin/mv -f $new_kernel $dd_dir/rpm/newkernel"; xCAT::Utils->runcmd($cmd, -1); @@ -1928,34 +1928,32 @@ sub insert_dd () { } } } # end of loading drivers from rpm packages - } - # Create the dir for driver update disk - mkpath("$dd_dir/initrd_img/cus_driverdisk"); + # Create the dir for driver update disk + mkpath("$dd_dir/initrd_img/cus_driverdisk"); - # insert the driver update disk into the cus_driverdisk dir - foreach my $dd (@dd_list) { - copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); - } + # insert the driver update disk into the cus_driverdisk dir + foreach my $dd (@dd_list) { + copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); + } - # Repack the initrd - # In order to avoid the runcmd add the '2>&1' at end of the cpio - # cmd, the echo cmd is added at the end - $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC != 0) { - my $rsp; - push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); - } + # Repack the initrd + # In order to avoid the runcmd add the '2>&1' at end of the cpio + # cmd, the echo cmd is added at the end + $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } - # zip the initrd - #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); - $cmd = "gzip -f $dd_dir/initrd"; - xCAT::Utils->runcmd($cmd, -1); + # zip the initrd + #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); + $cmd = "gzip -f $dd_dir/initrd"; + xCAT::Utils->runcmd($cmd, -1); - if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) { if ($arch =~/ppc/) { if (-r "$dd_dir/rpm/newkernel") { # if there's new kernel from update distro, then use it @@ -1999,12 +1997,21 @@ sub insert_dd () { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',', sort(@dd_list))."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@dd_list)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; + } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } } xCAT::MsgUtils->message("I", $rsp, $callback); From dab5a33b3f5b40b2ad2c09c9023371d9a59ca44a Mon Sep 17 00:00:00 2001 From: immarvin Date: Thu, 1 Aug 2013 01:23:45 -0700 Subject: [PATCH 2/4] fix defect 3724 makehosts should report error/warning messages when entrys in hosts table are not correct --- xCAT-server/lib/xcat/plugins/hosts.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/hosts.pm b/xCAT-server/lib/xcat/plugins/hosts.pm index c5d34d775..d5e100f5b 100644 --- a/xCAT-server/lib/xcat/plugins/hosts.pm +++ b/xCAT-server/lib/xcat/plugins/hosts.pm @@ -254,6 +254,12 @@ sub add_hosts_content { { addnode $callback, $nodename, $ip, $ref->{hostnames}, $domain; } + else + { + my $rsp; + push @{$rsp->{data}}, "Invalid IP Addr \'$_->{ip}\' for node \'$_->{node}\'."; + xCAT::MsgUtils->message("E", $rsp, $callback); + } if (defined($ref->{otherinterfaces})) { addotherinterfaces $callback, $nodename, $ref->{otherinterfaces}, $domain; From a81d66c1240a5b72634ce1517d39e4cdd2831532 Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 1 Aug 2013 12:07:30 -0400 Subject: [PATCH 3/4] add tabdump -n for auditlog and eventlog --- xCAT-server/lib/xcat/plugins/tabutils.pm | 120 ++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 36d91dc8b..9cf8b00fc 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -558,6 +558,7 @@ sub tabdump my $OPTW; my $VERSION; my $FILENAME; + my $NUMBERENTRIES; my $tabdump_usage = sub { my $exitcode = shift @_; @@ -565,6 +566,7 @@ sub tabdump push @{$rsp{data}}, "Usage: tabdump [-d] [table]"; push @{$rsp{data}}, " tabdump [table]"; push @{$rsp{data}}, " tabdump [-f ] [table]"; + push @{$rsp{data}}, " tabdump [-n <# of records>] [auditlog | eventlog]"; push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [table]"; push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [-f ] [table]"; push @{$rsp{data}}, " tabdump [-?|-h|--help]"; @@ -578,10 +580,14 @@ sub tabdump if ($args) { @ARGV = @{$args}; } + Getopt::Long::Configure("posix_default"); + Getopt::Long::Configure("no_gnu_compat"); + Getopt::Long::Configure("bundling"); if (!GetOptions( 'h|?|help' => \$HELP, 'v|version' => \$VERSION, + 'n|lines=i' => \$NUMBERENTRIES, 'd' => \$DESC, 'f=s' => \$FILENAME, 'w=s@' => \$OPTW, @@ -601,8 +607,23 @@ sub tabdump if ($HELP) { $tabdump_usage->(0); return; } + if (($NUMBERENTRIES) && ($DESC)) { + $cb->({error => "You cannot use the -n and -d flag together. ",errorcode=>1}); + return 1; + } + + if (($NUMBERENTRIES) && ($OPTW)) { + $cb->({error => "You cannot use the -n and -w flag together. ",errorcode=>1}); + return 1; + } + if (($NUMBERENTRIES) && ($FILENAME)) { + $cb->({error => "You cannot use the -n and -f flag together. ",errorcode=>1}); + return 1; + } + if (scalar(@ARGV)>1) { $tabdump_usage->(1); return; } + my %rsp; # If no arguments given, we display a list of the tables if (!scalar(@ARGV)) { @@ -626,9 +647,18 @@ sub tabdump } # get the table name $table = $ARGV[0]; + + # if -n can only be the auditlog or eventlog + if ($NUMBERENTRIES) { + if (!( $table =~ /^auditlog/ ) && (!($table =~ /^eventlog/))){ + $cb->({error => "$table table is not supported in tabdump -n. You may only use this option on the auditlog or the eventlog.",errorcode=>1}); + return 1; + } + } + # do not allow teal tables if ( $table =~ /^x_teal/ ) { - $cb->({error => "$table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1}); + $cb->({error => "$table table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1}); return 1; } if ($DESC) { # only show the attribute descriptions, not the values @@ -665,6 +695,15 @@ sub tabdump $cb->({error => "No such table: $table",errorcode=>1}); return 1; } + # + # if tabdump -n auditlog|eventlog + # + if (defined $NUMBERENTRIES ) { + my $rc=tabdump_numberentries($table,$cb,$NUMBERENTRIES); + return $rc; + } + + my $recs; my @ents; my @attrarray; @@ -717,6 +756,81 @@ sub tabdump } } } +# +# display input number of records for the table requested tabdump -n +# +sub tabdump_numberentries { + my $table = shift; + my $cb = shift; + my $numberentries = shift; # either number of records to display + my $attrrecid="recid"; + + my $VERBOSE = shift; + my $rc=0; + my $tab = xCAT::Table->new($table); + unless ($tab) { + $cb->({error => "Unable to open $table",errorcode=>4}); + return 1; + } + my $DBname = xCAT::Utils->get_DBName; + my @attribs = ($attrrecid); + my @ents=$tab->getAllAttribs(@attribs); + if (@ents) { # anything to process + # find smallest and largest recid, note table is not ordered by recid after + # a while + my $smallrid; + my $largerid; + foreach my $rid (@ents) { + if (!(defined $smallrid)) { + $smallrid=$rid; + } + if (!(defined $largerid)) { + $largerid=$rid; + } + if ($rid->{$attrrecid} < $smallrid->{$attrrecid}) { + $smallrid=$rid; + } + if ($rid->{$attrrecid} > $largerid->{$attrrecid}) { + $largerid=$rid; + } + } + my $RECID; + #determine recid to show all records after + $RECID= $largerid->{$attrrecid} - $numberentries ; + $rc=tabdump_recid($table,$cb,$RECID, $attrrecid); + } else { + my %rsp; + push @{$rsp{data}}, "Nothing to display from $table."; + $rsp{errorcode} = $rc; + $cb->(\%rsp); + } + return $rc; +} +# Display requested recored +# if rec id does not exist error +sub tabdump_recid { + my $table = shift; + my $cb = shift; + my $recid = shift; + my $rc=0; + # check which database so can build the correct Where clause + my $tab = xCAT::Table->new($table); + unless ($tab) { + $cb->({error => "Unable to open $table",errorcode=>4}); + return 1; + } + my $DBname = xCAT::Utils->get_DBName; + my @recs; + my $attrrecid="recid"; + # display the output + if ($DBname =~ /^DB2/) { + @recs=$tab->getAllAttribsWhere("\"$attrrecid\">$recid", 'ALL'); + } else { + @recs=$tab->getAllAttribsWhere("$attrrecid>$recid", 'ALL'); + } + output_table($table,$cb,$tab,\@recs); + return $rc; +} # Display information from the daemon. # sub lsxcatd @@ -853,7 +967,7 @@ sub tabprune push @{$rsp{data}}, " tabprune [-V] -d <# of days>"; push @{$rsp{data}}, " tabprune [-h|--help]"; push @{$rsp{data}}, " tabprune [-v|--version]"; - push @{$rsp{data}}, " tables supported:eventlog,auditlog,isnm_perf,isnm_perf_sum"; + push @{$rsp{data}}, " tables supported:eventlog,auditlog"; push @{$rsp{data}}, " -d option only supported for eventlog,auditlog"; if ($exitcode) { $rsp{errorcode} = $exitcode; } $cb->(\%rsp); @@ -952,7 +1066,7 @@ sub tabprune if (($table eq "eventlog") || ($table eq "auditlog")) { $attrrecid="recid"; } else { - if ($table eq "isnm_perf") { # if ISNM + if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later $attrrecid="perfid"; } else { $attrrecid="period"; # isnm_perf_sum table From 4a91bb39ccdf569edc57555dd2dc3a2f2d93900f Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 1 Aug 2013 12:17:05 -0400 Subject: [PATCH 4/4] document tabdump -n --- xCAT-client/pods/man8/tabdump.8.pod | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/xCAT-client/pods/man8/tabdump.8.pod b/xCAT-client/pods/man8/tabdump.8.pod index bcac4eed1..63b39e26f 100644 --- a/xCAT-client/pods/man8/tabdump.8.pod +++ b/xCAT-client/pods/man8/tabdump.8.pod @@ -10,6 +10,8 @@ B [I] B [I<-f> I] [I
] +B [I<-n> I<# of records>] [I] + B [I<-w> I==I] [B<-w> I=~I] ...] [I
] B [I<-w> I==I] [B<-w> I=~I] ...] [I<-f> I] [I
] @@ -38,6 +40,15 @@ Display usage message. Show descriptions of the tables, instead of the contents of the tables. If a table name is also specified, descriptions of the columns (attributes) of the table will be displayed. Otherwise, a summary of each table will be displayed. +=item B<-n> + +Shows the most recent number of entries as supplied on the -n flag from the auditlog or eventlog table. + +=item B<-f> + +File name or path to file in which to dump the table. Without this the table is dumped +to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory. + =item B<-w> I<'attr==val'> B<-w> I<'attr=~val'> ... Use one or multiple -w flags to specify the selection string that can be used to select particular rows of the table. See examples. @@ -54,11 +65,6 @@ Operator descriptions: !~ Select nodes where the attribute value matches the SQL NOT LIKE value. -=item B<-f> - -File name or path to file in which to dump the table. Without this the table is dumped -to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory. - =back =head1 RETURN VALUE @@ -111,6 +117,12 @@ tabdump -w 'audittime>2011-04-18 11:30:00' auditlog =item * +To display the 10 most recent entries in the auditlog: + +tabdump -n 10 auditlog + +=item * + To see what tables exist in the xCAT database: B