summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Peck <bpeck@redhat.com>2013-02-11 14:13:37 -0500
committerBill Peck <bpeck@redhat.com>2013-02-11 14:13:37 -0500
commit30fd8b1983d0ea6b7fb8b286c5c7d89f30653332 (patch)
tree3756a3099ed17c3992db643326aa0aa639422886
parent25cefa443e4ed12c9b5cc43a4016cef28e241e61 (diff)
downloadtests-30fd8b1983d0ea6b7fb8b286c5c7d89f30653332.tar.gz
tests-30fd8b1983d0ea6b7fb8b286c5c7d89f30653332.tar.xz
tests-30fd8b1983d0ea6b7fb8b286c5c7d89f30653332.zip
make dell_upgrade script report pass/fail.
-rw-r--r--firmware/dell_upgrade/Makefile32
-rw-r--r--firmware/dell_upgrade/runtest.sh9
-rw-r--r--firmware/dell_upgrade/upgrade_dell146
3 files changed, 187 insertions, 0 deletions
diff --git a/firmware/dell_upgrade/Makefile b/firmware/dell_upgrade/Makefile
new file mode 100644
index 0000000..be8fa1e
--- /dev/null
+++ b/firmware/dell_upgrade/Makefile
@@ -0,0 +1,32 @@
+# Include Common Makefile
+include /usr/share/rhts/lib/rhts-make.include
+
+# The version of the test rpm that gets created / submitted.
+export TESTVERSION=1.0
+
+export TEST=/distribution/dell_upgrade
+
+.PHONY: build clean run
+
+# All files you want bundled into your rpm.
+FILES= $(METADATA) runtest.sh Makefile upgrade_dell
+
+build: $(METADATA)
+ chmod a+x ./runtest.sh ./upgrade_dell
+
+clean:
+ rm -f $(METADATA)
+
+run: build
+ ./runtest.sh
+
+$(METADATA):
+ touch $(METADATA)
+ @echo "Name: $(TEST)" >$(METADATA)
+ @echo "Description: configure and enable dnsmasq" >>$(METADATA)
+ @echo "Path: $(TEST_DIR)" >>$(METADATA)
+ @echo "TestTime: 60m" >>$(METADATA)
+ @echo "TestVersion: $(TESTVERSION)" >>$(METADATA)
+ @echo "License: GPLv3" >>$(METADATA)
+ @echo "Owner: Bill Peck <bpeck@redhat.com>" >>$(METADATA)
+ @echo "Requires: dmidecode" >>$(METADATA)
diff --git a/firmware/dell_upgrade/runtest.sh b/firmware/dell_upgrade/runtest.sh
new file mode 100644
index 0000000..8fb80e0
--- /dev/null
+++ b/firmware/dell_upgrade/runtest.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# Source the common test script helpers
+. /usr/bin/rhts_environment.sh
+
+./upgrade_dell && report_result $TEST PASS 0 || report_result $TEST FAIL 1
+
+exit 0
+
diff --git a/firmware/dell_upgrade/upgrade_dell b/firmware/dell_upgrade/upgrade_dell
new file mode 100644
index 0000000..e42607a
--- /dev/null
+++ b/firmware/dell_upgrade/upgrade_dell
@@ -0,0 +1,146 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use File::Temp qw(tempdir);
+BEGIN {
+ # Install needed RHEL packages if missing
+ my %rhelmodules = (
+ 'XML::Simple' => 'perl-XML-Simple',
+ );
+ for my $module (keys %rhelmodules) {
+ eval "use $module;";
+ if ($@) {
+ my $pkg = $rhelmodules{$module};
+ system("yum install -y $pkg");
+ eval "use $module;";
+ }
+ }
+}
+my $errorsto = 'pere@hungry.com';
+
+upgrade_dell();
+
+exit 0;
+
+sub run_firmware_script {
+ my ($opts, $script) = @_;
+ unless ($script) {
+ print STDERR "fail: missing script name\n";
+ exit 1
+ }
+ print STDERR "Running $script\n\n";
+
+ if (0 == system("sh $script $opts")) { # FIXME correct exit code handling
+ print STDERR "success: firmware script ran succcessfully\n";
+ } else {
+ print STDERR "fail: firmware script returned error\n";
+ exit 1;
+ }
+}
+
+sub run_firmware_scripts {
+ my ($opts, @dirs) = @_;
+ # Run firmware packages
+ for my $dir (@dirs) {
+ print STDERR "info: Running scripts in $dir\n";
+ opendir(my $dh, $dir) or die "Unable to open directory $dir: $!";
+ while (my $s = readdir $dh) {
+ next if $s =~ m/^\.\.?/;
+ run_firmware_script($opts, "$dir/$s");
+ }
+ closedir $dh;
+ }
+}
+
+sub download {
+ my $url = shift;
+ print STDERR "info: Downloading $url\n";
+ system("wget --quiet \"$url\"");
+}
+
+sub upgrade_dell {
+ my @dirs;
+ my $product = `dmidecode -s system-product-name`;
+ chomp $product;
+
+ if ($product =~ m/PowerEdge/) {
+
+ # on RHEL, these pacakges are needed by the firwmare upgrade scripts
+ system('yum install -y compat-libstdc++-33.i686 libstdc++.i686 libxml2.i686 procmail');
+
+ my $tmpdir = tempdir(
+ CLEANUP => 1
+ );
+ chdir($tmpdir);
+ fetch_dell_fw('catalog/Catalog.xml.gz');
+ system('gunzip Catalog.xml.gz');
+ my @paths = fetch_dell_fw_list('Catalog.xml');
+ # -q is quiet, disabling interactivity and reducing console output
+ my $fwopts = "-q";
+ if (@paths) {
+ for my $url (@paths) {
+ fetch_dell_fw($url);
+ }
+ run_firmware_scripts($fwopts, $tmpdir);
+ } else {
+ print STDERR "error: Unsupported Dell model '$product'.\n";
+ print STDERR "error: Please report to $errorsto.\n";
+ exit 1;
+ }
+ chdir('/');
+ } else {
+ print STDERR "error: Unsupported Dell model '$product'.\n";
+ print STDERR "error: Please report to $errorsto.\n";
+ exit 1;
+ }
+}
+
+sub fetch_dell_fw {
+ my $path = shift;
+ my $url = "ftp://ftp.us.dell.com/$path";
+ download($url);
+}
+
+# Using ftp://ftp.us.dell.com/catalog/Catalog.xml.gz, figure out which
+# firmware packages to download from Dell. Only work for Linux
+# machines and 11th generation Dell servers.
+sub fetch_dell_fw_list {
+ my $filename = shift;
+
+ my $product = `dmidecode -s system-product-name`;
+ chomp $product;
+ my ($mybrand, $mymodel) = split(/\s+/, $product);
+
+ print STDERR "Finding firmware bundles for $mybrand $mymodel\n";
+
+ my $xml = XMLin($filename);
+ my @paths;
+ for my $bundle (@{$xml->{SoftwareBundle}}) {
+ my $brand = $bundle->{TargetSystems}->{Brand}->{Display}->{content};
+ my $model = $bundle->{TargetSystems}->{Brand}->{Model}->{Display}->{content};
+ my $oscode;
+ if ("ARRAY" eq ref $bundle->{TargetOSes}->{OperatingSystem}) {
+ $oscode = $bundle->{TargetOSes}->{OperatingSystem}[0]->{osCode};
+ } else {
+ $oscode = $bundle->{TargetOSes}->{OperatingSystem}->{osCode};
+ }
+ if ($mybrand eq $brand && $mymodel eq $model && "LIN" eq $oscode)
+ {
+ @paths = map { $_->{path} } @{$bundle->{Contents}->{Package}};
+ }
+ }
+ for my $component (@{$xml->{SoftwareComponent}}) {
+ my $componenttype = $component->{ComponentType}->{value};
+
+ # Drop application packages, only firmware and BIOS
+ next if 'APAC' eq $componenttype;
+
+ my $cpath = $component->{path};
+ for my $path (@paths) {
+ if ($cpath =~ m%/$path$%) {
+ push(@paths, $cpath);
+ }
+ }
+ }
+ return @paths;
+}