Subversion Repositories DevTools

Rev

Rev 5198 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

require 5.008_002;
use strict;
use warnings;

use JatsEnv;
use JatsError;
use Pod::Usage;                             # required for help support
use Getopt::Long;
use JatsRmApi;

use DBI;
use Cwd;

#
#   The LWP is a part of the Active State Perl, but not the solaris perl
#   If the user has not read the installation doco that insists we use
#   ActiveState perl...
#
my $UserAgentAvailable = eval "require LWP::UserAgent";

#
#   Global data
#
my $VERSION      = "1.0.0";                 # Update this
my $opt_debug    = $ENV{'GBE_DEBUG'};        # Allow global debug
my $opt_verbose  = $ENV{'GBE_VERBOSE'};      # Allow global verbose
my $opt_help = 0;

#
#   Release Manager Connection Information
#   Deployment manager Connection information
#
my $RM_URL = $ENV{GBE_RM_URL};
my $DM_URL = $ENV{GBE_DM_URL};
my $RM_DB;
my $DM_DB;

#-------------------------------------------------------------------------------
# Function        : Mainline Entry Point
#
# Description     :
#
# Inputs          :
#
my $result = GetOptions (
        "help+"         => \$opt_help,              # flag, multiple use allowed
        "manual:3"      => \$opt_help,
        "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
);

#
#   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
#

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
pod2usage(-verbose => 1) if ($opt_help == 2 );
pod2usage(-verbose => 2) if ($opt_help > 2);

#
#   Configure the error reporting process now that we have the user options
#
ErrorConfig( 'name'    =>'RMTEST',
        'verbose' => $opt_verbose,
);


#
#   Open the connection and display some data
#
my $rtag_id = $ARGV[0];
Message("Getting RTAG ".$rtag_id);
$ENV{GBE_RM_LOCATION} = "jdbc:oracle:thin:\@auperaprm01:1521:RELEASEM";
$ENV{GBE_RM_USERNAME} = "RM_READONLY";
$ENV{GBE_RM_PASSWORD} = "RM_READONLY";
$ENV{GBE_RM_URL} = "http://bms:8002/ManagerSuite/Release_Manager";
$ENV{DBI_DRIVER} = "ODBC";
getOracleData();
#getDeployData();
#getHttpData();
Message "Test Complete\n";
exit;

sub getOracleData
{
        my $count = 0;
        my (@row);

        my $package;
        my $lastpackage = "";
        my $version;
        my $lastversion = "";
        my $testdescription;
        my $testduration;

        Message("Test Oracle Interface");

        #
        #   Connect to database
        #
        JatsRmApi::connectRM(\$RM_DB, $opt_verbose);

        # First get details from pv_id
        Message("Extract data");
        my $m_sqlstr = "select packages.pkg_name, package_versions.pkg_version, build_instances.timestamp, test_run.platform, test_run.test_name, test_run.test_outcome, test_run.time_taken, test_run.fail_message " .
        "from release_manager.packages " .
        "inner join release_manager.package_versions on packages.pkg_id = package_versions.pkg_id " .
        "inner join release_manager.release_content on package_versions.pv_id = release_content.pv_id " .
        "inner join release_manager.build_instances on package_versions.pv_id = build_instances.pv_id " .
        "inner join release_manager.test_run on build_instances.build_id = test_run.build_id " .
        "where release_content.rtag_id = $rtag_id " .
        "order by packages.pkg_name, package_versions.pkg_version desc";
        my $sth = $RM_DB->prepare($m_sqlstr);
        if ( defined($sth) )
        {
                Message("\$sth is defined");
                if ( $sth->execute( ) )
                {
                        if ( $sth->rows )
                        {
                                while ( @row = $sth->fetchrow_array )
                                {
                                        $count++;

                                        $package = $row[0];
                                        $version = $row[1];

                                        if ($package ne $lastpackage)
                                        {
                                                if ($lastversion ne "")
                                                {
                                                        print "##teamcity[testSuiteFinished name='$lastversion']\n";
                                                        $lastversion = "";
                                                }
                                                if ($lastpackage ne "")
                                                {
                                                        print "##teamcity[testSuiteFinished name='$lastpackage']\n";
                                                }
                                                $lastpackage = $package;
                                                print "##teamcity[testSuiteStarted name='$package']\n";
                                        }

                                        if ($version ne $lastversion)
                                        {
                                                if ($lastversion ne "")
                                                {
                                                        print "##teamcity[testSuiteFinished name='$lastversion']\n";
                                                }
                                                $lastversion = $version;
                                                print "##teamcity[testSuiteStarted name='$version']\n";
                                        }

                                        if ($row[3] eq "JAVA")
                                        {
                                                $row[4] =~ m/^.*\.([^\.]+)::(.*)$/;
                                                $testdescription = "name='$1.$2'";
                                        }
                                        else
                                        {
                                                $testdescription = "name='$row[4]'";
                                        }

                                        print "##teamcity[testStarted $testdescription]\n";
                                        if ($row[5] ne "PASS")
                                        {
                                                print "##teamcity[testFailed $testdescription]\n";
                                        }
                                        $testduration = $row[6];
                                        if (defined $testduration)
                                        {
                                                print "##teamcity[testFinished $testdescription duration='$testduration']\n";
                                        }
                                        else
                                        {
                                                print "##teamcity[testFinished $testdescription]\n";
                                        }

                                }
                        }
                        $sth->finish();
                        if ($lastversion ne "")
                        {
                                print "##teamcity[testSuiteFinished name='$lastversion']\n";
                        }
                        if ($lastpackage ne "")
                        {
                                print "##teamcity[testSuiteFinished name='$lastpackage']\n";
                        }
                }
                else
                {
                        Error("Execute failure", $sth->errstr);
                }
        }
        else
        {
                Error("Prepare failure" );
        }

        #
        #   Report the data extracted
        #
        Error("No data extracted from the database") unless ( $count );
        Message "Extracted $count records\n";

        #
        #   Close down the connection
        #
        disconnectRM(\$RM_DB);
}

#-------------------------------------------------------------------------------
# Function        : getDeployData
#
# Description     : Ensure we can communicate with the Deployment database
#
# Inputs          : None
#
# Returns         :
#
sub getDeployData
{
        connectDM ( \$DM_DB, $opt_verbose );
        disconnectDM(\$DM_DB);
}

#-------------------------------------------------------------------------------
# Function        : getHttpData
#
# Description     : Test the Http interface to release manager
#
# Inputs          :
#
# Returns         :
#
sub getHttpData
{
        Message("Test HTTP Interface");

        unless ( $UserAgentAvailable )
        {
                Warning ("The perl installation does not contain the LWP module",
                        "The test to extract data from Release Manager will be skipped",
                        "The deployment scripts will not run properly");
                return 0;
        }

        my $user_agent = LWP::UserAgent->new( timeout => 30 );
        if ( $RM_URL )
        {
                Verbose("RM URL: $RM_URL");
                my $response = $user_agent->head( $RM_URL );
                Verbose ("Http Message: " . $response->status_line);
                if ( $response->is_success )
                {
                        Message("Retrieved Release Manager Data");
                }
                else
                {
                        Error("Unable to retrieve Release Manager Data", "Status: " . $response->status_line);
                }
        }
        else
        {
                Warning("Release Manager URL not defined: GBE_RM_URL");
        }

        if ( $DM_URL )
        {
                Verbose("DM URL: $DM_URL");
                my $response = $user_agent->head( $DM_URL );
                Verbose ("Http Message: " . $response->status_line);
                if ( $response->is_success )
                {
                        Message("Retrieved Deployment Manager Data");
                }
                else
                {
                        Error("Unable to retrieve Deployment Manager Data", "Status: " . $response->status_line);
                }
        }
        else
        {
                Warning("Deployment Manager URL not defined: GBE_DM_URL");
        }

        return 1;
}

#-------------------------------------------------------------------------------
#   Documentation
#

=pod

=head1 NAME

test_rmconnection - Test the connection to the Release Manager Database

=head1 SYNOPSIS

jats etool test_rmconnection [options]

 Options:
        -help              - Brief help message
        -help -help        - Detailed help message
        -man               - Full documentation
        -verbose           - Display additional information

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-help -help>

Print a detailed help message with an explanation for each option.

=item B<-man>

Prints the manual page and exits.

=item B<-verbose>

Prints additional information on the progress of the program.

=back

=head1 DESCRIPTION

This program is provided to test the connection between the users computer and
the Release Manager Database. It does this by querying the database in the
same manner as many of the deployments scripts.

=head1 EXAMPLE

jats etool test_rmconnection

=cut