2009-01-06 11:05:02 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::PPCrflash ;
use strict ;
use Getopt::Long ;
use xCAT::PPCcli qw( SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR ) ;
use xCAT::Usage ;
use xCAT::PPCinv ;
use xCAT::DSHCLI ;
2009-01-15 03:01:54 +00:00
use xCAT::Table ;
2012-08-09 03:48:50 +00:00
use xCAT::Utils ;
use xCAT::TableUtils ;
2009-01-06 11:05:02 +00:00
use Getopt::Long ;
use File::Spec ;
use POSIX qw( tmpnam ) ;
my $ packages_dir = ( ) ;
2011-02-14 05:10:24 +00:00
my $ activate = ( ) ;
my $ verbose = 0 ;
2009-01-06 11:05:02 +00:00
$ ::POWER_DEST_DIR = "/tmp" ;
my $ release_level ;
my $ active_level ;
my @ dirlist ;
#######################################
# This flag tracks the operation to be performed. If set, it means we need
# to commit a previously applied update or else recover from one.
#######################################
my $ housekeeping = undef ;
#####################################
#For -V|--verbose,put the $msg into @value
###################################
sub dpush {
2011-02-14 05:10:24 +00:00
my $ value = shift ;
my $ msg = shift ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
if ( $ verbose == 1 ) {
push ( @$ value , $ msg ) ;
}
2009-01-06 11:05:02 +00:00
}
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
2011-02-14 05:10:24 +00:00
my $ request = shift ;
my % opt = ( ) ;
my $ cmd = $ request - > { command } ;
my $ args = $ request - > { arg } ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:15:21 +00:00
#############################################
# Change CEC/Frame node into FSPs/BPAs
#############################################
2011-03-18 05:28:50 +00:00
#my @newnodes = ();
#my $nodes = $request->{node};
#foreach my $snode(@$nodes) {
# my $ntype = xCAT::DBobjUtils->getnodetype($snode);
# if ( $ntype =~ /^(cec|frame)$/) {
# my $children = xCAT::DBobjUtils->getchildren($snode);
# unless( $children ) {
# next;
# }
# foreach (@$children) {
# push @newnodes, $_;
# }
# } else {
# push @newnodes, $snode;
# }
#}
#$request->{node} = \@newnodes;
2011-02-14 05:15:21 +00:00
#############################################
2011-02-14 05:10:24 +00:00
# Responds with usage statement
#############################################
local * usage = sub {
my $ usage_string = xCAT::Usage - > getUsage ( $ cmd ) ;
return ( [ $ _ [ 0 ] , $ usage_string ] ) ;
} ;
#############################################
# Process command-line arguments
#############################################
if ( ! defined ( $ args ) ) {
return ( usage ( "No arguments specified" ) ) ;
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
#############################################
# Checks case in GetOptions, allows opts
# to be grouped (e.g. -vx), and terminates
# at the first unrecognized option.
#############################################
@ ARGV = @$ args ;
$ Getopt:: Long:: ignorecase = 0 ;
Getopt::Long:: Configure ( "bundling" ) ;
2012-06-18 08:29:59 +00:00
if ( ! GetOptions ( \ % opt , qw( h|help v|version V|verbose p=s d=s activate=s commit recover bpa_acdl ) ) ) {
2011-02-14 05:10:24 +00:00
return ( usage ( ) ) ;
}
####################################
# Option -v for version
####################################
if ( exists ( $ opt { v } ) ) {
2012-06-18 08:29:59 +00:00
if ( ! defined ( $ ::VERSION ) ) {
return ( [ xCAT::Usage - > getVersion ( $ cmd ) ] ) ;
}
return ( [ $ ::VERSION ] ) ;
2011-02-14 05:10:24 +00:00
}
2009-05-21 09:26:58 +00:00
if ( exists ( $ opt { h } ) || $ opt { help } ) {
2011-02-14 05:10:24 +00:00
return ( usage ( ) ) ;
2009-05-21 09:26:58 +00:00
}
2011-02-14 05:10:24 +00:00
#################################
#Option --activate not valid with --commit or --recover
#################################
2012-06-18 08:29:59 +00:00
if ( exists ( $ opt { bpa_acdl } ) && ( exists ( $ opt { activate } ) || exists ( $ opt { commit } ) ||
exists ( $ opt { recover } ) || exists ( $ opt { p } ) || exists ( $ opt { d } ) ) ) {
return ( usage ( "Option --bpa_acdl not valid with other options " ) ) ;
}
2011-02-14 05:10:24 +00:00
if ( exists ( $ opt { activate } ) && ( exists ( $ opt { commit } ) || exists ( $ opt { recover } ) ) ) {
return ( usage ( "Option --activate not valid with --commit or --recover " ) ) ;
}
#################################
#Option -p not valid with --commit or --recover
#################################
if ( exists ( $ opt { p } ) && ( exists ( $ opt { commit } ) || exists ( $ opt { recover } ) ) ) {
return ( usage ( "Option -p not valid with --commit or --recover " ) ) ;
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
#################################
#Option -p required
#################################
if ( exists ( $ opt { p } ) && ( ! exists ( $ opt { activate } ) ) ) {
return ( usage ( "Option -p must be used with --activate " ) ) ;
}
if ( exists ( $ opt { p } ) && ( $ opt { p } !~ /^\// ) ) { #relative path
$ opt { p } = xCAT::Utils - > full_path ( $ opt { p } , $ request - > { cwd } - > [ 0 ] ) ;
}
2011-08-10 07:00:18 +00:00
if ( exists ( $ opt { d } ) ) {
if ( ! exists ( $ opt { activate } ) ) {
return ( usage ( "Option -d must be used with --activate " ) ) ;
}
}
if ( exists ( $ opt { d } ) && ( $ opt { d } !~ /^\// ) ) { #relative path
$ opt { d } = xCAT::Utils - > full_path ( $ opt { d } , $ request - > { cwd } - > [ 0 ] ) ;
}
2011-02-14 05:10:24 +00:00
###############################
#--activate's value only can be concurrent and disruptive
################################
if ( exists ( $ opt { activate } ) ) {
2012-06-18 08:29:59 +00:00
if ( ( $ opt { activate } ne "deferred" ) && ( $ opt { activate } ne "disruptive" ) ) {
return ( usage ( "--activate's value can only be deferred or disruptive" ) ) ;
2009-01-06 11:05:02 +00:00
}
2011-08-10 07:00:18 +00:00
if ( ! exists ( $ opt { d } ) ) {
$ opt { d } = "/tmp" ;
}
2011-02-14 05:10:24 +00:00
}
2011-08-10 07:00:18 +00:00
2011-02-14 05:10:24 +00:00
####################################
# Check for "-" with no option
####################################
if ( grep ( /^-$/ , @ ARGV ) ) {
return ( usage ( "Missing option: -" ) ) ;
}
####################################
# Check for an extra argument
####################################
if ( defined ( $ ARGV [ 0 ] ) ) {
return ( usage ( "Invalid Argument: $ARGV[0]" ) ) ;
}
#check to see if we are housekeeping or updating
#
if ( defined ( $ opt { commit } ) ) {
print "commit flag\n" ;
$ housekeeping = "commit" ;
} elsif ( defined ( $ opt { recover } ) ) {
print "recover flag\n" ;
$ housekeeping = "recover" ;
2012-06-18 08:29:59 +00:00
} elsif ( defined ( $ opt { bpa_acdl } ) ) {
print "bpa_acdl flag\n" ;
$ housekeeping = "bpa_acdl" ;
2011-02-14 05:10:24 +00:00
} else {
print "no housekeeping - update mode\n" ;
$ housekeeping = undef ;
}
2010-01-18 06:14:05 +00:00
$ request - > { housekeeping } = $ housekeeping ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
#############################################
2009-07-14 09:15:29 +00:00
# Option -V for verbose output
############################################
if ( exists ( $ opt { V } ) ) {
2011-02-14 05:10:24 +00:00
$ verbose = 1 ;
2009-07-14 09:15:29 +00:00
}
2009-05-21 06:48:57 +00:00
2011-02-14 05:10:24 +00:00
####################
#suport for "rflash", copy the rpm and xml packages from user-spcefied-directory to /install/packages_fw
#####################
2012-06-18 08:29:59 +00:00
if ( ( ! exists ( $ opt { commit } ) ) && ( ! exists ( $ opt { recover } ) ) && ( ! exists ( $ opt { bpa_acdl } ) ) ) {
2009-07-14 09:15:29 +00:00
if ( preprocess_for_rflash ( $ request , \ % opt ) == - 1 ) {
2011-02-14 05:10:24 +00:00
return ( usage ( ) ) ;
2009-07-14 09:15:29 +00:00
}
2011-02-14 05:10:24 +00:00
}
2009-07-14 09:15:29 +00:00
2011-02-14 05:10:24 +00:00
if ( noderange_validate ( $ request ) == - 1 ) {
return ( usage ( ) ) ;
}
2011-11-29 05:16:54 +00:00
$ request - > { callback } - > ( { data = > [ "It may take considerable time to complete, depending on the number of systems being updated. In particular, power subsystem updates may take an hour or more if there are many attached managed systems. Please waiting. " ] } ) ;
2012-01-05 02:59:33 +00:00
if ( $ request - > { hwtype } =~ /^(fsp|bpa)$/ && $ opt { activate } =~ /^disruptive$/ ) {
2011-11-29 05:16:54 +00:00
$ request - > { callback } - > ( { data = > [ "You can find the log files in the /var/log/xcatd/dfm/rflash/." ] } ) ;
}
2009-06-11 07:21:58 +00:00
2011-02-14 05:10:24 +00:00
####################################
# No operands - add command name
####################################
$ request - > { method } = $ cmd ;
return ( \ % opt ) ;
2009-01-06 11:05:02 +00:00
}
2009-05-21 06:48:57 +00:00
##########################################################################
# Invokes the callback with the specified message
##########################################################################
sub send_msg {
my $ request = shift ;
my $ ecode = shift ;
my % output ;
#################################################
# Called from child process - send to parent
#################################################
if ( exists ( $ request - > { pipe } ) ) {
my $ out = $ request - > { pipe } ;
$ output { errorcode } = $ ecode ;
$ output { data } = \ @ _ ;
print $ out freeze ( [ \ % output ] ) ;
print $ out "\nENDOFFREEZE6sK4ci\n" ;
}
#################################################
# Called from parent - invoke callback directly
#################################################
elsif ( exists ( $ request - > { callback } ) ) {
my $ callback = $ request - > { callback } ;
$ output { errorcode } = $ ecode ;
$ output { data } = \ @ _ ;
$ callback - > ( \ % output ) ;
}
}
2009-07-14 09:15:29 +00:00
#####################################
#When run rflash with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR.
#####################################
sub noderange_validate {
my $ request = shift ;
2011-02-14 05:10:24 +00:00
#my $opt = shift;
2009-07-14 09:15:29 +00:00
my $ noderange = $ request - > { node } ;
#my $t = print_var($request, "request");
#print $t;
####################
## $f1 and $f2 are the flags for rflash, to check if there are BPAs and CECs at the same time.
##################
my $ f1 = 0 ;
my $ f2 = 0 ;
###########################################
# Group nodes
###########################################
2012-02-10 11:01:54 +00:00
my $ mytypehash = xCAT::DBobjUtils - > getnodetype ( $ noderange , "ppc" ) ;
2009-07-14 09:15:29 +00:00
foreach my $ node ( @$ noderange ) {
my $ type = undef ;
2011-06-07 09:04:28 +00:00
#my $sitetab = xCAT::Table->new( 'nodetype' );
#if ( defined( $sitetab )) {
# my ($ent) = $sitetab->getAttribs({ node=>$node},'nodetype');
# if ( defined($ent) ) {
# $type = $ent->{nodetype};
# }
#}
2012-02-10 11:01:54 +00:00
$ type = $$ mytypehash { $ node } ;
2009-07-14 09:15:29 +00:00
#print "type:$type\n";
2010-12-17 02:06:49 +00:00
if ( $ type =~ /(fsp|lpar|cec)/ ) {
2009-07-14 09:15:29 +00:00
$ f1 = 1 ;
} else {
$ f2 = 1 ;
my $ exargs = $ request - > { arg } ;
#my $t = print_var($exargs, "exargs");
#print $t;
2011-06-17 14:47:34 +00:00
#if ( grep(/commit/,@$exargs) != 0 || grep(/recover/,@$exargs) != 0) {
# send_msg( $request, 1, "When run \"rflash\" with the \"commit\" or \"recover\" operation, the noderange cannot be BPA and can only be CEC or LPAR.");
# send_msg( $request, 1, "And then, it will do the operation for both managed systems and power subsystems.");
# return -1;
# }
2009-07-14 09:15:29 +00:00
}
}
2009-05-21 06:48:57 +00:00
2009-07-14 09:15:29 +00:00
if ( $ f1 * $ f2 ) {
2011-02-14 05:10:24 +00:00
send_msg ( $ request , 1 , "The argument noderange of rflash can't be BPA and CEC(or LPAR) at the same time" ) ;
2009-07-14 09:15:29 +00:00
return - 1 ;
}
}
2009-05-21 06:48:57 +00:00
sub preprocess_for_rflash {
2011-02-14 05:10:24 +00:00
my $ request = shift ;
my $ opt = shift ;
2009-12-10 02:19:40 +00:00
my $ callback = $ request - > { callback } ;
2012-08-09 03:48:50 +00:00
my $ install_dir = xCAT::TableUtils - > getInstallDir ( ) ;
2011-02-14 05:10:24 +00:00
my $ packages_fw = "$install_dir/packages_fw" ;
my $ c = 0 ;
2009-05-21 06:48:57 +00:00
my $ packages_d ;
2011-02-14 05:10:24 +00:00
# foreach (@$exargs) {
# $c++;
# if($_ eq "-p") {
# $packages_d = $$exargs[$c];
# last;
# }
# }
2009-05-21 06:48:57 +00:00
$ packages_d = $$ opt { p } ;
2011-02-14 05:15:21 +00:00
if ( $ packages_d ne $ packages_fw ) {
$$ opt { p } = $ packages_fw ;
if ( ! - d $ packages_d ) {
#send_msg($request, 1, "The directory $packages_d doesn't exist!");
$ callback - > ( { data = > [ "The directory $packages_d doesn't exist!" ] } ) ;
$ request = ( ) ;
return - 1 ;
}
#print "opening directory and reading names\n";
opendir DIRHANDLE , $ packages_d ;
my @ dirlist = readdir DIRHANDLE ;
closedir DIRHANDLE ;
@ dirlist = File::Spec - > no_upwards ( @ dirlist ) ;
# Make sure we have some files to process
#
if ( ! scalar ( @ dirlist ) ) {
#send_msg($request, 1, "The directory $packages_d is empty !");
$ callback - > ( { data = > [ "The directory $packages_d is empty !" ] } ) ;
$ request = ( ) ;
return - 1 ;
}
#Find the rpm lic file
my @ rpmlist = grep /\.rpm$/ , @ dirlist ;
my @ xmllist = grep /\.xml$/ , @ dirlist ;
if ( @ rpmlist == 0 | @ xmllist == 0 ) {
#send_msg($request, 1, "There isn't any rpm and xml files in the directory $packages_d!");
$ callback - > ( { data = > [ "There isn't any rpm and xml files in the directory $packages_d!" ] } ) ;
$ request = ( ) ;
return - 1 ;
}
my $ rpm_list = join ( " " , @ rpmlist ) ;
my $ xml_list = join ( " " , @ xmllist ) ;
my $ cmd ;
if ( - d $ packages_fw ) {
2011-12-13 07:19:31 +00:00
$ cmd = "rm -rf $packages_fw/*" ;
2011-02-14 05:15:21 +00:00
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
if ( $ ::RUNCMD_RC != 0 )
{
#send_msg($request, 1, "Failed to remove the old packages in $packages_fw.");
$ callback - > ( { data = > [ "Failed to remove the old packages in $packages_fw." ] } ) ;
$ request = ( ) ;
return - 1 ;
}
}
2011-12-13 07:19:31 +00:00
$ cmd = "mkdir -p $packages_fw" ;
2011-02-14 05:15:21 +00:00
xCAT::Utils - > runcmd ( "$cmd" , 0 ) ;
if ( $ ::RUNCMD_RC != 0 )
{
#send_msg($request, 1, "$cmd failed.");
$ callback - > ( { data = > [ "$cmd failed." ] } ) ;
$ request = ( ) ;
return ;
}
$ cmd = "cp $packages_d/*.rpm $packages_d/*.xml $packages_fw" ;
xCAT::Utils - > runcmd ( $ cmd , 0 ) ;
if ( $ ::RUNCMD_RC != 0 )
{
#send_msg($request, 1, "$cmd failed.");
$ callback - > ( { data = > [ "$cmd failed." ] } ) ;
$ request = ( ) ;
return - 1 ;
}
#$req->{arg} = $exargs;
}
2009-05-21 06:48:57 +00:00
return 0 ;
}
2009-01-06 11:05:02 +00:00
sub print_var {
2011-02-14 05:10:24 +00:00
my $ j = shift ;
my $ msg = shift ;
my $ var = "+++++++++$msg start--++++\n" ;
if ( ref ( $ j ) eq "ARRAY" ) {
my $ t ;
foreach $ t ( @$ j ) {
if ( ref ( $ t ) eq "ARRAY" ) {
my $ t0 = join ( " " , @$ t ) ;
#if(ref($t0) eq "SCALAR") {
$ var = $ var . "\t$t0(array)\n" ;
#} else {
# &print_var($t0);
#}
} elsif ( ref ( $ t ) eq "HASH" ) {
my $ t12 ;
my $ t23 ;
while ( ( $ t12 , $ t23 ) = each ( %$ t ) ) {
$ var = $ var . "\t$t12 => \n" ;
#if(ref($t23) eq "SCALAR") {
$ var = $ var . "\t$t23(hash)\n" ;
#} else {
# &print_var($t23);
#}
2011-02-14 05:18:59 +00:00
}
2011-02-14 05:10:24 +00:00
} else {
$ var = $ var . "$t\n" ;
}
}
} elsif ( ref ( $ j ) eq "HASH" ) {
my $ t1 ;
my $ t2 ;
while ( ( $ t1 , $ t2 ) = each ( %$ j ) ) {
$ var = $ var . "$t1 =>" ;
if ( ref ( $ t2 ) eq "HASH" ) {
my $ t12 ;
my $ t23 ;
while ( ( $ t12 , $ t23 ) = each ( %$ t2 ) ) {
$ var = $ var . "\t$t12 => $t23\n" ;
2009-01-06 11:05:02 +00:00
}
2011-02-14 05:10:24 +00:00
} elsif ( ref ( $ t2 ) eq "ARRAY" ) {
my $ t = join ( " " , @$ t2 ) ;
$ var = $ var . "$t (array)\n" ;
} else {
$ var = $ var . "$t2\n" ;
}
}
} else {
$ var = $ var . "$j(scalar)\n" ;
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
$ var = $ var . "+++++++++++$msg end+++++++++++\n" ;
return $ var ;
2009-01-06 11:05:02 +00:00
}
#-------------------------------------------------------------------------#
# get_lic_filenames - construct and validate the lup filenames for each #
# each node #
#-------------------------------------------------------------------------#
#
sub get_lic_filenames {
2011-02-14 05:10:24 +00:00
my $ mtms = shift ;
my $ upgrade_required = 0 ;
my $ msg = undef ;
my $ filename ;
if ( ! - d $ packages_dir ) {
$ msg = "The directory $packages_dir doesn't exist!" ;
return ( "" , "" , "" , $ msg , - 1 ) ;
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
#print "opening directory and reading names\n";
opendir DIRHANDLE , $ packages_dir ;
@ dirlist = readdir DIRHANDLE ;
closedir DIRHANDLE ;
@ dirlist = File::Spec - > no_upwards ( @ dirlist ) ;
# Make sure we have some files to process
#
if ( ! scalar ( @ dirlist ) ) {
$ msg = "directory $packages_dir is empty" ;
return ( "" , "" , "" , $ msg , - 1 ) ;
}
$ release_level =~ /(\w{4})(\d{3})/ ;
my $ pns = $ 1 ;
my $ fff = $ 2 ;
#Find the latest version lic file
@ dirlist = grep /\.rpm$/ , @ dirlist ;
@ dirlist = grep /$1/ , @ dirlist ;
if ( ! scalar ( @ dirlist ) ) {
$ msg = "There isn't a package suitable for $mtms" ;
return ( "" , "" , "" , $ msg , - 1 ) ;
}
if ( scalar ( @ dirlist ) > 1 ) {
# Need to find the latest version package.
@ dirlist = reverse sort ( @ dirlist ) ;
my $ t = "\n" ;
foreach $ t ( @ dirlist ) {
$ msg = $ msg . "$t\t" ;
2009-01-06 11:05:02 +00:00
}
2011-02-14 05:10:24 +00:00
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
$ filename = File::Spec - > catfile ( $ packages_dir , $ dirlist [ 0 ] ) ;
$ dirlist [ 0 ] =~ /(\w{4})(\d{3})_(\w{3})_(\d{3}).rpm$/ ;
##############
#If the release levels are different, it will be upgrade_required.
#############
if ( $ fff ne $ 2 ) {
$ upgrade_required = 1 ;
} else {
if ( ( $ pns eq $ 1 ) && ( $ 4 <= $ active_level ) ) {
$ msg = $ msg . "Upgrade $mtms $activate!" ;
# if($activate ne "concurrent") {
# $msg = "Option --actviate's value should be disruptive";
# return ("", "","", $msg, -1);
# }
} else {
2012-06-18 08:29:59 +00:00
$ msg = $ msg . "Upgrade $mtms!" ;
if ( $ activate !~ /^(disruptive|deferred)$/ ) {
$ msg = "Option --activate's value shouldn't be $activate, and it must be disruptive or deferred" ;
2011-02-14 05:10:24 +00:00
return ( "" , "" , "" , $ msg , - 1 ) ;
}
}
}
#print "filename is $filename\n";
my $ xml_file_name = $ filename ;
$ xml_file_name =~ s/(.+\.)rpm/\1xml/ ;
#print "check_licdd_update: source xml file is $xml_file_name\n";
if ( ( - z $ filename ) || ( - z $ xml_file_name ) ) {
$ msg = "The package $filename or xml $xml_file_name is empty" ;
return ( "" , "" , "" , $ msg , - 1 ) ;
}
return ( $ filename , $ xml_file_name , $ upgrade_required , $ msg , 0 ) ;
2009-01-06 11:05:02 +00:00
}
2009-01-15 03:01:54 +00:00
sub get_one_mtms {
2011-02-14 05:10:24 +00:00
my $ exp = shift ;
my $ bpa = shift ;
my $ cmd = "lssyscfg -r cage -e $bpa" ;
my $ mtms ;
my $ msg ;
my $ values = xCAT::PPCcli:: send_cmd ( $ exp , $ cmd ) ;
my $ Rc = shift ( @$ values ) ;
#####################################
# Return error
#####################################
if ( $ Rc != SUCCESS ) {
$ msg = "ERROR: Failed to find a CEC managed by $bpa on the HMC" ;
return ( "" , $ msg ) ;
}
2009-03-12 07:28:21 +00:00
2011-02-14 05:10:24 +00:00
foreach ( @$ values ) {
if ( $ _ =~ /cage_num=(\w*),contents=sys,type_model_serial_num=(\w+)-(\w+)\*(\w+),loc_code=(\w+).(\w+).(\w+)/ ) {
$ mtms = "$2-$3*$4" ;
last ;
2009-03-12 07:28:21 +00:00
}
2011-02-14 05:10:24 +00:00
}
2009-01-15 03:01:54 +00:00
2011-02-14 05:10:24 +00:00
# print "the managed system is $mtms!\n";
return ( $ mtms , $ msg ) ;
2009-01-15 03:01:54 +00:00
}
2009-01-06 11:05:02 +00:00
##########################
#Performs Licensed Internal Code (LIC) update support for HMC-attached POWER5 and POWER6 Systems
###########################
sub rflash {
2009-06-11 07:21:58 +00:00
my $ request = shift ;
my $ hash = shift ;
my $ exp = shift ;
2009-09-29 11:41:58 +00:00
my $ subreq = $ request - > { subreq } ;
2009-06-11 07:21:58 +00:00
my $ hwtype = @$ exp [ 2 ] ;
my @ result ;
my $ timeout = $ request - > { ppctimeout } ;
2010-01-18 06:14:05 +00:00
my $ housekeeping = $ request - > { housekeeping } ;
2009-05-12 05:15:57 +00:00
2009-12-02 09:38:51 +00:00
$ packages_dir = $ request - > { opt } - > { p } ;
2011-02-14 05:10:24 +00:00
$ activate = $ request - > { opt } - > { activate } ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
my $ hmc ;
my $ mtms ;
my $ component ; # system or power
my $ h ;
my $ user ;
my $ tmp_file ; #the file handle of the stanza
my $ rpm_file ;
my $ xml_file ;
my @ rpm_files ;
my @ xml_files ;
my $ upgrade_required ;
my $ stanza = undef ;
my $ mtms_t ;
my @ value ;
2009-06-11 07:21:58 +00:00
my % infor ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
$ hmc = @$ exp [ 3 ] ;
dpush ( \ @ value , [ $ hmc , "In rflash()" ] ) ;
dpush ( \ @ value , [ $ hmc , print_var ( $ request , "request" ) ] ) ;
dpush ( \ @ value , [ $ hmc , print_var ( $ hash , "hash" ) ] ) ;
dpush ( \ @ value , [ $ hmc , print_var ( $ exp , "exp" ) ] ) ;
# print_var($t);
########################
# Now build a temporary file containing the stanzas to be run on the HMC
###################
my $ tmp_file = tmpnam ( ) ; # the file handle of the stanza
##############################
# Open the temp file
##########################
dpush ( \ @ value , [ $ hmc , "opening file $tmp_file" ] ) ;
unless ( open TMP , ">$tmp_file" ) {
push ( @ value , [ $ hmc , "cannot open $tmp_file, $!\n" ] ) ;
return ( \ @ value ) ;
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
while ( ( $ mtms , $ h ) = each ( %$ hash ) ) {
dpush ( \ @ value , [ $ hmc , "mtms:$mtms" ] ) ;
$ mtms_t = "$mtms_t $mtms" ;
2009-06-11 07:21:58 +00:00
my $ lflag = 0 ;
2011-02-14 05:10:24 +00:00
my $ managed_system = $ mtms ;
if ( defined ( $ housekeeping ) ) {
2009-06-11 07:21:58 +00:00
#$hmc_has_work = 1;
2011-02-14 05:10:24 +00:00
#$::work_flag = 1;
2009-06-11 07:21:58 +00:00
& dpush ( \ @ value , [ $ hmc , "$mtms:creating stanza for housekeeping operation\n" ] ) ;
$ stanza = "updlic::" . $ managed_system . "::" . $ housekeeping . "::::" ;
2011-02-14 05:10:24 +00:00
& dpush ( \ @ value , [ $ hmc , "$mtms:Writing $stanza to file\n" ] ) ;
#push(@result,[$hmc,"$mtms:$housekeeping successfully!"]);
2009-06-11 07:21:58 +00:00
$ infor { $ mtms } = [ $ housekeeping ] ;
print TMP "$stanza\n" ;
2011-02-14 05:10:24 +00:00
} else {
while ( my ( $ name , $ d ) = each ( %$ h ) ) {
2011-05-11 10:18:43 +00:00
if ( @$ d [ 4 ] !~ /^(fsp|bpa|lpar|cec|frame)$/ ) {
push @ value , [ $ name , "Information only available for LPAR/CEC/BPA/Frame" , RC_ERROR ] ;
2011-02-14 05:10:24 +00:00
next ;
}
###############
#If $name is a Lpar, the flag will be changed from "lpar" to "fsp"
#######################
2011-05-11 10:18:43 +00:00
if ( @$ d [ 4 ] =~ /^lpar$/ || @$ d [ 4 ] =~ /^cec$/ ) {
2011-02-14 05:10:24 +00:00
@$ d [ 4 ] = "fsp" ;
$ lflag = 1 ;
2011-05-11 10:18:43 +00:00
#push (@value, [$hmc,"$name is a Lpar on MTMS $mtms", 1]);
2011-02-14 05:10:24 +00:00
}
if ( @$ d [ 4 ] eq "fsp" ) {
$ component = "system" ;
} else {
$ component = "power" ;
}
dpush ( \ @ value , [ $ hmc , "$mtms:component:$component!" ] ) ;
my $ values = xCAT::PPCcli:: lslic ( $ exp , $ d , $ timeout ) ;
my $ Rc = shift ( @$ values ) ;
#####################################
# Return error
#####################################
if ( $ Rc != SUCCESS ) {
push @ value , [ $ name , @$ values [ 0 ] , $ Rc ] ;
2009-06-11 07:21:58 +00:00
next ;
2011-02-14 05:10:24 +00:00
}
if ( @$ values [ 0 ] =~ /ecnumber=(\w+)/ ) {
$ release_level = $ 1 ;
& dpush ( \ @ value , [ $ hmc , "$mtms :release level:$1" ] ) ;
}
if ( @$ values [ 0 ] =~ /activated_level=(\w+)/ ) {
$ active_level = $ 1 ;
& dpush ( \ @ value , [ $ hmc , "$mtms :activated level:$1" ] ) ;
}
my $ msg ;
my $ flag = 0 ;
( $ rpm_file , $ xml_file , $ upgrade_required , $ msg , $ flag ) = & get_lic_filenames ( $ mtms ) ;
if ( $ flag == - 1 ) {
push ( @ value , [ $ hmc , "$mtms: $msg" ] ) ;
push ( @ value , [ $ hmc , "Failed to upgrade the firmware of $mtms on $hmc" ] ) ;
return ( \ @ value ) ;
}
dpush ( \ @ value , [ $ hmc , $ msg ] ) ;
# If we get to this point, the HMC has to attempt an update on the
# managed system, so set the flag.
#
#$hmc_has_work = 1;
#::work_flag = 1;
# Collect the rpm and xml file names in a list so we can dcp then
# in one call.
#
if ( scalar ( grep /$rpm_file/ , @ rpm_files ) == 0 ) {
push @ rpm_files , $ rpm_file ;
push @ xml_files , $ xml_file ;
}
my ( $ volume , $ directories , $ file ) = File::Spec - > splitpath ( $ rpm_file ) ;
2009-06-11 07:21:58 +00:00
#push(@result,[$hmc, "Upgrade $mtms from release level:$release_level activated level:$active_level to $file successfully"]);
2011-02-14 05:10:24 +00:00
#If mtms is a bpa, we should change the managed_system to a cec whose parent is a bpa.
if ( $ component eq "power" ) {
( $ managed_system , $ msg ) = & get_one_mtms ( $ exp , $ managed_system ) ;
if ( $ managed_system eq "" ) {
push ( @ value , [ $ hmc , $ msg ] ) ;
return ( \ @ value ) ;
}
dpush ( \ @ value , [ $ hmc , $ msg ] ) ;
$ infor { $ managed_system } = [ "upgrade" , $ release_level , $ active_level , $ file , "power" , $ mtms ] ;
} else {
$ infor { $ managed_system } = [ "upgrade" , $ release_level , $ active_level , $ file ] ;
2009-06-12 10:12:37 +00:00
}
2009-06-11 07:21:58 +00:00
}
2011-02-14 05:10:24 +00:00
my $ rpm_dest = $ ::POWER_DEST_DIR . "/" . $ dirlist [ 0 ] ;
# The contents of the stanza file are slightly different depending
# on the operation being performed.
#
# $managed_system = "9125-F2A*0262652";
if ( $ upgrade_required ) {
$ stanza = "updlic::" . $ managed_system . "::upgrade::::$rpm_dest" ;
} else {
$ stanza = "updlic::" . $ managed_system . "::activate::" . $ component . "::" . $ rpm_dest ;
}
dpush ( \ @ value , [ $ hmc , "Writing $stanza to file" ] ) ;
print TMP "$stanza\n" ;
@ dirlist = ( ) ;
$ rpm_file = ( ) ;
$ xml_file = ( ) ;
}
}
# Close the file. dcp the stanza file, rpm update and xml file to the
# target HMC
#
close TMP ;
##################################
2009-09-25 07:27:04 +00:00
# Get userid/password
##################################
my $ cred = $ request - > { $ hmc } { cred } ;
2011-02-14 05:10:24 +00:00
$ user = @$ cred [ 0 ] ;
dpush ( \ @ value , [ $ hmc , "user: $user" ] ) ; ;
#$password = @$cred[1]
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
my $ rpm_file_list = join ( " " , @ rpm_files ) ;
my $ xml_file_list = join ( " " , @ xml_files ) ;
###############################
#Prepare for "xdcp"-----runDcp_api is removed.
##############################
2009-09-25 07:27:04 +00:00
my $ source = "$tmp_file $rpm_file_list $xml_file_list" ;
my $ target = "/tmp" ;
2011-02-14 05:10:24 +00:00
my $ current_userid = getpwuid ( $> ) ;
2009-09-25 07:27:04 +00:00
my $ res = xCAT::Utils - > runxcmd ( {
command = > [ 'xdcp' ] ,
node = > [ $ hmc ] ,
arg = > [ "-l" , $ user , $ source , $ target ] ,
2011-02-14 05:10:24 +00:00
env = > [ "DSH_FROM_USERID=$current_userid" , "DSH_TO_USERID=$user" ] ,
2009-09-25 07:27:04 +00:00
} ,
$ subreq , 0 , 1 ) ;
if ( $ ::RUNCMD_RC ) { # error from dcp
2011-02-14 05:10:24 +00:00
my $ rsp = { } ;
dpush ( \ @ value , [ $ hmc , "invoking xdcp" ] ) ;
$ rsp - > { data } - > [ 0 ] = "Error from xdcp. Return Code = $::RUNCMD_RC" ;
2009-09-25 07:27:04 +00:00
xCAT::MsgUtils - > message ( "E" , $ rsp , $ ::CALLBACK , 1 ) ;
2011-02-14 05:10:24 +00:00
push ( @ value , [ $ hmc , $ rsp - > { data } - > [ 0 ] ] ) ;
push ( @ value , [ $ hmc , "Failed to copy $tmp_file $rpm_file_list $xml_file_list to $hmc" ] ) ;
2009-09-27 01:24:21 +00:00
push ( @ value , [ $ hmc , "Please check whether the HMC $hmc is configured to allow remote ssh automatic connections" ] ) ;
2011-02-14 05:10:24 +00:00
push ( @ value , [ $ hmc , "Failed to upgrade the firmware of $mtms_t on $hmc" ] ) ;
return ( \ @ value ) ;
}
2009-01-15 03:01:54 +00:00
2011-02-14 05:10:24 +00:00
my $ r = ( ) ;
foreach $ r ( @$ res ) {
push ( @ value , [ $ r ] ) ;
}
push ( @ value , [ $ hmc , "copy files to $hmc completely" ] ) ;
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
###############################################
# Now that all the stanzas files have been built and copied to the HMCs,
# we can use a single dsh command to invoke them all.
################################################
2009-09-21 11:42:37 +00:00
# @res = xCAT::Utils->runcmd( $cmd, 0, 1);
# my @re1 = xCAT::Utils->runxcmd( {
# command => ['xdsh'],
# node => [$hmc],
# arg => [ "-l", $user , $cmd_hmc ]
# },
# , $subreq, 0, 1);
#
2011-02-14 05:10:24 +00:00
#$options{ 'user' } = $user;
#$options{ 'nodes' } = $hmc;
#$options{ 'exit-status' } = 1;
#$options{ 'stream' } = 1;
#$options{ 'command' } = "csmlicutil $tmp_file";
#$options{ 'command' } = "ls -al";
#@res = xCAT::DSHCLI->runDsh_api(\%options, 0);
#my $Rc = pop(@res);
#push(@value, [$Rc]);
# The above code isn't supported.
2009-09-21 11:42:37 +00:00
my $ cmd_hmc = "csmlicutil $tmp_file" ;
2011-05-11 10:18:43 +00:00
#my $cmd_hmc = "ls -al";
print "before runxcmd, current_userid = $current_userid; DSH_TO_USERID=$user \n" ;
2009-09-25 07:27:04 +00:00
my $ res = xCAT::Utils - > runxcmd ( {
command = > [ 'xdsh' ] ,
node = > [ $ hmc ] ,
arg = > [ "-l" , $ user , $ cmd_hmc ] ,
2011-02-14 05:10:24 +00:00
env = > [ "DSH_FROM_USERID=$current_userid" , "DSH_TO_USERID=$user" ] ,
2009-09-25 07:27:04 +00:00
} ,
$ subreq , 0 , 1 ) ;
if ( $ ::RUNCMD_RC ) { # error from dsh
2009-06-11 07:21:58 +00:00
my $ rsp = { } ;
2009-09-21 12:20:32 +00:00
$ rsp - > { data } - > [ 0 ] = "Error from xdsh. Return Code = $::RUNCMD_RC" ;
2009-06-11 07:21:58 +00:00
xCAT::MsgUtils - > message ( "S" , $ rsp , $ ::CALLBACK , 1 ) ;
2011-02-14 05:10:24 +00:00
dpush ( \ @ value , [ $ hmc , "failed to run xdsh" ] ) ;
push ( @ value , [ $ hmc , $ rsp - > { data } - > [ 0 ] ] ) ;
push ( @ value , [ $ hmc , "Failed to upgrade the firmware of $mtms_t on $hmc" ] ) ;
return ( \ @ value ) ;
2009-06-11 07:21:58 +00:00
}
2009-01-06 11:05:02 +00:00
2011-02-14 05:10:24 +00:00
my $ r = ( ) ;
foreach $ r ( @$ res ) {
push ( @ value , [ $ r ] ) ;
2009-06-11 07:21:58 +00:00
#hmc1: mtms : LIC_RC = 0 -- successful
#hmc1: mtms : LIC_RC = 8 -- failed
#hmc1: mtms : LIC_RC = 12 -- failed
if ( index ( $ r , "LIC_RC" ) == - 1 ) {
next ;
}
my @ tmp1 = split ( /:/ , $ r ) ;
$ tmp1 [ 1 ] =~ s/\s+//g ;
# LIC_RC = 0
# LIC_RC = 8
$ tmp1 [ 2 ] =~ /LIC_RC\s=\s(\d*)/ ;
if ( $ 1 != 0 ) { # failed
my $ tmp3 = $ infor { $ tmp1 [ 1 ] } ;
2009-06-12 10:12:37 +00:00
if ( $$ tmp3 [ 4 ] eq "power" ) {
$ tmp1 [ 1 ] = $$ tmp3 [ 5 ] ;
}
2009-06-11 07:21:58 +00:00
if ( $$ tmp3 [ 0 ] eq "upgrade" ) {
2011-02-14 05:10:24 +00:00
push ( @ result , [ $ hmc , "failed to $$tmp3[0] $tmp1[1] from release level:$$tmp3[1] activated level:$$tmp3[2] to $$tmp3[3]" ] ) ;
2009-06-11 07:21:58 +00:00
} else {
push ( @ result , [ $ hmc , "failed to $$tmp3[0] the firmware for $tmp1[1]" ] ) ;
}
} else { # successful
my $ tmp3 = $ infor { $ tmp1 [ 1 ] } ;
2009-06-12 10:12:37 +00:00
if ( $$ tmp3 [ 4 ] eq "power" ) {
$ tmp1 [ 1 ] = $$ tmp3 [ 5 ] ;
}
2009-06-11 07:21:58 +00:00
if ( $$ tmp3 [ 0 ] eq "upgrade" ) {
2011-02-14 05:10:24 +00:00
push ( @ result , [ $ hmc , "$$tmp3[0] $tmp1[1] from release level:$$tmp3[1] activated level:$$tmp3[2] to $$tmp3[3] successfully" ] ) ;
2009-06-11 07:21:58 +00:00
} else {
2011-02-14 05:10:24 +00:00
push ( @ result , [ $ hmc , "$$tmp3[0] the firmware for $tmp1[1] successfully" ] ) ;
2009-06-11 07:21:58 +00:00
}
2011-02-14 05:10:24 +00:00
}
}
push ( @ value , @ result ) ;
return ( \ @ value ) ;
2009-01-06 11:05:02 +00:00
}
1 ;