From 74769080c8158b7e11f27fd96b1d624ffb3e9738 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Wed, 24 May 2017 22:49:14 -0400 Subject: [PATCH 1/3] Based on the OpenBMC Sensor API, complete the development code for the supported options based on the possible values that are currently allowed to be returned. As more data is added, the code should be able to handle the printing of the data automatically --- .../references/man1/rvitals.1.rst | 17 ++++++++- perl-xCAT/xCAT/Usage.pm | 4 +- xCAT-client/pods/man1/rvitals.1.pod | 12 +++++- xCAT-server/lib/xcat/plugins/openbmc.pm | 37 ++++++++++++++++--- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/rvitals.1.rst b/docs/source/guides/admin-guides/references/man1/rvitals.1.rst index e6929cdfc..ca8af6688 100644 --- a/docs/source/guides/admin-guides/references/man1/rvitals.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rvitals.1.rst @@ -56,20 +56,27 @@ BMC specific: \ **rvitals**\ \ *noderange*\ {\ **temp | voltage | wattage | fanspeed | power | leds | all**\ } -OpenPOWER server specific: +OpenPOWER (IPMI) specific: ========================== \ **rvitals**\ \ *noderange*\ [\ **temp | voltage | wattage | fanspeed | power | leds | all**\ ] +OpenPOWER (OpenBMC) specific: +============================= + + +\ **rvitals**\ \ *noderange*\ [\ **temp | voltage | wattage | fanspeed | power | length | all**\ ] + + ******************* \ **Description**\ ******************* -\ **rvitals**\ retrieves hardware vital information from the on-board Service +\ **rvitals**\ Retrieves hardware vital information from the on-board Service Processor for a single or range of nodes and groups. @@ -133,6 +140,12 @@ Processor for a single or range of nodes and groups. +\ **length**\ + + Retrieves length related attributes. + + + \ **power**\ Retrieves power status. diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index 30ba4b701..200f59037 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -81,8 +81,10 @@ my %usage = ( rvitals noderange {temp|wattage|fanspeed|leds|summary|all} BMC specific: rvitals noderange {temp|voltage|wattage|fanspeed|power|leds|all} - OpenPOWER server specific: + OpenPOWER (IPMI) specific: rvitals noderange [temp|voltage|wattage|fanspeed|power|leds|all] + OpenPOWER (OpenBMC) specific: + rvitals noderange [temp|voltage|wattage|fanspeed|power|length|all] MIC specific: rvitals noderange {thermal|all}", "reventlog" => diff --git a/xCAT-client/pods/man1/rvitals.1.pod b/xCAT-client/pods/man1/rvitals.1.pod index 32ff2fb81..52bacd35e 100644 --- a/xCAT-client/pods/man1/rvitals.1.pod +++ b/xCAT-client/pods/man1/rvitals.1.pod @@ -26,13 +26,17 @@ B I {B|B|B|B|B|B I {B|B|B|B|B|B|B} -=head2 OpenPOWER server specific: +=head2 OpenPOWER (IPMI) specific: B I [B|B|B|B|B|B|B] +=head2 OpenPOWER (OpenBMC) specific: + +B I [B|B|B|B|B|B|B] + =head1 B -B retrieves hardware vital information from the on-board Service +B Retrieves hardware vital information from the on-board Service Processor for a single or range of nodes and groups. =head1 B @@ -75,6 +79,10 @@ Retrieves rack environmentals. Retrieves LEDs status. +=item B + +Retrieves length related attributes. + =item B Retrieves power status. diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index d67cf7ca1..6e8273947 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -458,7 +458,7 @@ sub parse_args { } elsif ($command eq "rvitals") { $check = unsupported($callback); if (ref($check) eq "ARRAY") { return $check; } $subcommand = "all" if (!defined($ARGV[0])); - unless ($subcommand =~ /^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^leds$|^all$/) { + unless ($subcommand =~ /^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^length$|^all$/) { return ([ 1, "Unsupported command: $command $subcommand" ]); } } else { @@ -1216,17 +1216,42 @@ sub rvitals_response { foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; - print Dumper(%content) . "\n"; - # $key_url is "/xyz/openbmc_project/sensors/xxx/yyy - # For now display xxx/yyy as a label - my ($junk, $label) = split("/sensors/", $key_url); + # - # Calculate the value based on the scale + # Skip over attributes that are not asked to be printed + # + if ($grep_string =~ "temp") { + unless ( $content{Unit} =~ "DegreesC") { next; } + } + if ($grep_string =~ "voltage") { + unless ( $content{Unit} =~ "Volts") { next; } + } + if ($grep_string =~ "wattage") { + unless ( $content{Unit} =~ "Watts") { next; } + } + if ($grep_string =~ "fanspeed") { + unless ( $content{Unit} =~ "RPMS") { next; } + } + if ($grep_string =~ "power") { + unless ( $content{Unit} =~ "Amperes" || $content{Unit} =~ "Joules" || $content{Unit} =~ "Watts" ) { next; } + } + if ($grep_string =~ "length") { + unless ( $content{Unit} =~ "Meters" ) { next; } + } + # + # $key_url is in the format: "/xyz/openbmc_project/sensors/xxx/yyy + # For now display xxx/yyy as a label + # + my ($junk, $label) = split("/sensors/", $key_url); + + # + # Calculate the adjusted value based on the scale attribute # my $calc_value = $content{Value}; if ( $content{Scale} != 0 ) { $calc_value = ($content{Value} * (10 ** $content{Scale})); } + $sensor_value = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; xCAT::SvrUtils::sendmsg("$sensor_value", $callback, $node); } From 5413376a58f3c5e964b463306008792f5971f895 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Fri, 26 May 2017 11:09:16 -0400 Subject: [PATCH 2/3] Sort the output of rvitals to arrange the types of sensor data together. Removing the node out of the label in order to allow the sort to happen on just the keywords For debug, just print the json instead of splitting to multiple lines --- xCAT-server/lib/xcat/plugins/openbmc.pm | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 6e8273947..c827e4528 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1209,10 +1209,10 @@ sub rvitals_response { my $grep_string = $status_info{RVITALS_RESPONSE}{argv}; my $src; my $content_info; - my $sensor_value; + my @sorted_output; print "$node: DEBUG Processing command: rvitals $grep_string \n"; - print Dumper(%{$response_info->{data}}) . "\n"; + print Dumper(%{$response_info->{data}}); foreach my $key_url (keys %{$response_info->{data}}) { my %content = %{ ${ $response_info->{data} }{$key_url} }; @@ -1238,11 +1238,12 @@ sub rvitals_response { if ($grep_string =~ "length") { unless ( $content{Unit} =~ "Meters" ) { next; } } - # - # $key_url is in the format: "/xyz/openbmc_project/sensors/xxx/yyy - # For now display xxx/yyy as a label - # - my ($junk, $label) = split("/sensors/", $key_url); + + my $label = (split(/\//, $key_url))[ -1 ]; + + # replace underscore with space, uppercase the first letter + $label =~ s/_/ /g; + $label =~ s/\b(\w)/\U$1/g; # # Calculate the adjusted value based on the scale attribute @@ -1252,8 +1253,15 @@ sub rvitals_response { $calc_value = ($content{Value} * (10 ** $content{Scale})); } - $sensor_value = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; - xCAT::SvrUtils::sendmsg("$sensor_value", $callback, $node); + $content_info = $label . ": " . $calc_value . " " . $sensor_units{ $content{Unit} }; + push (@sorted_output, $content_info); #Save output in array + } + # If sorted array has any contents, sort it and print it + if (scalar @sorted_output > 0) { + # Sort the output, alpha, then numeric + my @sorted_output = grep {s/(^|\D)0+(\d)/$1$2/g,1} sort + grep {s/(\d+)/sprintf"%06.6d",$1/ge,1} @sorted_output; + xCAT::SvrUtils::sendmsg("$_", $callback, $node) foreach (@sorted_output); } if ($next_status{ $node_info{$node}{cur_status} }) { From b8894ed38b7113da759e8bb9494ed4dab2c5e46e Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 30 May 2017 14:28:15 -0400 Subject: [PATCH 3/3] Following changes based on review comments * Modified to display altitude instead of length * Print an output message if there is no values returned from the BMC --- .../guides/admin-guides/references/man1/rvitals.1.rst | 6 +++--- perl-xCAT/xCAT/FSPvitals.pm | 1 - perl-xCAT/xCAT/Usage.pm | 2 +- xCAT-client/pods/man1/rvitals.1.pod | 6 +++--- xCAT-server/lib/xcat/plugins/openbmc.pm | 8 ++++++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/rvitals.1.rst b/docs/source/guides/admin-guides/references/man1/rvitals.1.rst index ca8af6688..c6a84c704 100644 --- a/docs/source/guides/admin-guides/references/man1/rvitals.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rvitals.1.rst @@ -67,7 +67,7 @@ OpenPOWER (OpenBMC) specific: ============================= -\ **rvitals**\ \ *noderange*\ [\ **temp | voltage | wattage | fanspeed | power | length | all**\ ] +\ **rvitals**\ \ *noderange*\ [\ **temp | voltage | wattage | fanspeed | power | altitude | all**\ ] @@ -140,9 +140,9 @@ Processor for a single or range of nodes and groups. -\ **length**\ +\ **altitude**\ - Retrieves length related attributes. + Retrieves altitude related attributes. diff --git a/perl-xCAT/xCAT/FSPvitals.pm b/perl-xCAT/xCAT/FSPvitals.pm index 3f31bf31c..11915abd7 100644 --- a/perl-xCAT/xCAT/FSPvitals.pm +++ b/perl-xCAT/xCAT/FSPvitals.pm @@ -375,7 +375,6 @@ sub rackenv { push @result, [ $name, $td, $Rc ]; if (!exists($request->{verbose})) { - #if( $td =~ /^Rack altitude in meters/ ) { if ($td =~ /^BPA-B total output in watts/) { last; } diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index 200f59037..742f7a9a1 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -84,7 +84,7 @@ my %usage = ( OpenPOWER (IPMI) specific: rvitals noderange [temp|voltage|wattage|fanspeed|power|leds|all] OpenPOWER (OpenBMC) specific: - rvitals noderange [temp|voltage|wattage|fanspeed|power|length|all] + rvitals noderange [temp|voltage|wattage|fanspeed|power|altitude|all] MIC specific: rvitals noderange {thermal|all}", "reventlog" => diff --git a/xCAT-client/pods/man1/rvitals.1.pod b/xCAT-client/pods/man1/rvitals.1.pod index 52bacd35e..bb7fec138 100644 --- a/xCAT-client/pods/man1/rvitals.1.pod +++ b/xCAT-client/pods/man1/rvitals.1.pod @@ -32,7 +32,7 @@ B I [B|B|B|B|B|B I [B|B|B|B|B|B|B] +B I [B|B|B|B|B|B|B] =head1 B @@ -79,9 +79,9 @@ Retrieves rack environmentals. Retrieves LEDs status. -=item B +=item B -Retrieves length related attributes. +Retrieves altitude related attributes. =item B diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index c827e4528..e896e9046 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -37,6 +37,8 @@ $::POWER_STATE_POWERING_ON="powering-on"; $::POWER_STATE_QUIESCED="quiesced"; $::POWER_STATE_RESET="reset"; +$::NO_ATTRIBUTES_RETURNED="No attributes returned from the BMC."; + sub unsupported { my $callback = shift; if (defined($::OPENBMC_DEVEL) && ($::OPENBMC_DEVEL eq "YES")) { @@ -458,7 +460,7 @@ sub parse_args { } elsif ($command eq "rvitals") { $check = unsupported($callback); if (ref($check) eq "ARRAY") { return $check; } $subcommand = "all" if (!defined($ARGV[0])); - unless ($subcommand =~ /^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^length$|^all$/) { + unless ($subcommand =~ /^temp$|^voltage$|^wattage$|^fanspeed$|^power$|^altitude$|^all$/) { return ([ 1, "Unsupported command: $command $subcommand" ]); } } else { @@ -1235,7 +1237,7 @@ sub rvitals_response { if ($grep_string =~ "power") { unless ( $content{Unit} =~ "Amperes" || $content{Unit} =~ "Joules" || $content{Unit} =~ "Watts" ) { next; } } - if ($grep_string =~ "length") { + if ($grep_string =~ "altitude") { unless ( $content{Unit} =~ "Meters" ) { next; } } @@ -1262,6 +1264,8 @@ sub rvitals_response { my @sorted_output = grep {s/(^|\D)0+(\d)/$1$2/g,1} sort grep {s/(\d+)/sprintf"%06.6d",$1/ge,1} @sorted_output; xCAT::SvrUtils::sendmsg("$_", $callback, $node) foreach (@sorted_output); + } else { + xCAT::SvrUtils::sendmsg("$::NO_ATTRIBUTES_RETURNED", $callback, $node); } if ($next_status{ $node_info{$node}{cur_status} }) {