Subversion Repositories DevTools

Rev

Rev 5201 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5195 jmattner 1
require 5.008_002;
2
use strict;
3
use warnings;
4
 
5
use JatsEnv;
6
use JatsError;
7
use Pod::Usage;                             # required for help support
8
use Getopt::Long;
9
use JatsRmApi;
10
 
11
use DBI;
12
use Cwd;
13
 
14
#
15
#   The LWP is a part of the Active State Perl, but not the solaris perl
16
#   If the user has not read the installation doco that insists we use
17
#   ActiveState perl...
18
#
19
my $UserAgentAvailable = eval "require LWP::UserAgent";
20
 
21
#
22
#   Global data
23
#
24
my $VERSION      = "1.0.0";                 # Update this
25
my $opt_debug    = $ENV{'GBE_DEBUG'};        # Allow global debug
26
my $opt_verbose  = $ENV{'GBE_VERBOSE'};      # Allow global verbose
27
my $opt_help = 0;
28
 
29
#
30
#   Release Manager Connection Information
31
#   Deployment manager Connection information
32
#
33
my $RM_URL = $ENV{GBE_RM_URL};
34
my $DM_URL = $ENV{GBE_DM_URL};
35
my $RM_DB;
36
my $DM_DB;
37
 
38
#-------------------------------------------------------------------------------
39
# Function        : Mainline Entry Point
40
#
41
# Description     :
42
#
43
# Inputs          :
44
#
45
my $result = GetOptions (
46
	"help+"         => \$opt_help,              # flag, multiple use allowed
47
	"manual:3"      => \$opt_help,
48
	"verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
49
);
50
 
51
#
52
#   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
53
#
54
 
55
#
56
#   Process help and manual options
57
#
58
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
59
pod2usage(-verbose => 1) if ($opt_help == 2 );
60
pod2usage(-verbose => 2) if ($opt_help > 2);
61
 
62
#
63
#   Configure the error reporting process now that we have the user options
64
#
65
ErrorConfig( 'name'    =>'RMTEST',
66
	'verbose' => $opt_verbose,
67
);
68
 
69
 
70
#
71
#   Open the connection and display some data
72
#
73
my $rtag_id = $ARGV[0];
74
Message("Getting RTAG ".$rtag_id);
75
$ENV{GBE_RM_LOCATION} = "jdbc:oracle:thin:\@auperaprm01:1521:RELEASEM";
76
$ENV{GBE_RM_USERNAME} = "RM_READONLY";
77
$ENV{GBE_RM_PASSWORD} = "RM_READONLY";
78
$ENV{GBE_RM_URL} = "http://bms:8002/ManagerSuite/Release_Manager";
79
$ENV{DBI_DRIVER} = "ODBC";
80
getOracleData();
81
#getDeployData();
82
#getHttpData();
83
Message "Test Complete\n";
84
exit;
85
 
86
sub getOracleData
87
{
88
	my $count = 0;
89
	my (@row);
90
 
5198 jmattner 91
	my $package;
92
	my $lastpackage = "";
93
	my $version;
94
	my $lastversion = "";
5201 jmattner 95
	my $testdescription;
96
	my $testduration;
5198 jmattner 97
 
5195 jmattner 98
	Message("Test Oracle Interface");
99
 
100
	#
101
	#   Connect to database
102
	#
103
	JatsRmApi::connectRM(\$RM_DB, $opt_verbose);
104
 
105
	# First get details from pv_id
106
	Message("Extract data");
5201 jmattner 107
	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 " .
5195 jmattner 108
	"from release_manager.packages " .
109
	"inner join release_manager.package_versions on packages.pkg_id = package_versions.pkg_id " .
5201 jmattner 110
	"inner join release_manager.release_content on package_versions.pv_id = release_content.pv_id " .
5195 jmattner 111
	"inner join release_manager.build_instances on package_versions.pv_id = build_instances.pv_id " .
112
	"inner join release_manager.test_run on build_instances.build_id = test_run.build_id " .
5201 jmattner 113
	"where release_content.rtag_id = $rtag_id " .
5198 jmattner 114
	"order by packages.pkg_name, package_versions.pkg_version desc";
5195 jmattner 115
	my $sth = $RM_DB->prepare($m_sqlstr);
116
	if ( defined($sth) )
117
	{
118
		Message("\$sth is defined");
119
		if ( $sth->execute( ) )
120
		{
121
			if ( $sth->rows )
122
			{
123
				while ( @row = $sth->fetchrow_array )
124
				{
125
					$count++;
5198 jmattner 126
 
127
					$package = $row[0];
128
					$version = $row[1];
129
 
130
					if ($package ne $lastpackage)
131
					{
132
						if ($lastversion ne "")
133
						{
134
							print "##teamcity[testSuiteFinished name='$lastversion']\n";
135
							$lastversion = "";
136
						}
137
						if ($lastpackage ne "")
138
						{
139
							print "##teamcity[testSuiteFinished name='$lastpackage']\n";
140
						}
141
						$lastpackage = $package;
142
						print "##teamcity[testSuiteStarted name='$package']\n";
143
					}
144
 
145
					if ($version ne $lastversion)
146
					{
147
						if ($lastversion ne "")
148
						{
149
							print "##teamcity[testSuiteFinished name='$lastversion']\n";
150
						}
151
						$lastversion = $version;
152
						print "##teamcity[testSuiteStarted name='$version']\n";
153
					}
154
 
5201 jmattner 155
					if ($row[3] eq "JAVA")
5198 jmattner 156
					{
5201 jmattner 157
						$row[4] =~ m/^.*\.([^\.]+)::(.*)$/;
158
						$testdescription = "name='$1.$2'";
5198 jmattner 159
					}
5201 jmattner 160
					else
161
					{
5484 alewis 162
						$row[4] =~ s/([|\[\]'])/|$1/g;
5201 jmattner 163
						$testdescription = "name='$row[4]'";
164
					}
5198 jmattner 165
 
5201 jmattner 166
					print "##teamcity[testStarted $testdescription]\n";
167
					if ($row[5] ne "PASS")
168
					{
169
						print "##teamcity[testFailed $testdescription]\n";
170
					}
171
					$testduration = $row[6];
172
					if (defined $testduration)
173
					{
174
						print "##teamcity[testFinished $testdescription duration='$testduration']\n";
175
					}
176
					else
177
					{
178
						print "##teamcity[testFinished $testdescription]\n";
179
					}
180
 
5195 jmattner 181
				}
182
			}
183
			$sth->finish();
5198 jmattner 184
			if ($lastversion ne "")
185
			{
186
				print "##teamcity[testSuiteFinished name='$lastversion']\n";
187
			}
188
			if ($lastpackage ne "")
189
			{
190
				print "##teamcity[testSuiteFinished name='$lastpackage']\n";
191
			}
5195 jmattner 192
		}
193
		else
194
		{
195
			Error("Execute failure", $sth->errstr);
196
		}
197
	}
198
	else
199
	{
200
		Error("Prepare failure" );
201
	}
202
 
203
	#
204
	#   Report the data extracted
205
	#
206
	Error("No data extracted from the database") unless ( $count );
207
	Message "Extracted $count records\n";
208
 
209
	#
210
	#   Close down the connection
211
	#
212
	disconnectRM(\$RM_DB);
213
}
214
 
215
#-------------------------------------------------------------------------------
216
# Function        : getDeployData
217
#
218
# Description     : Ensure we can communicate with the Deployment database
219
#
220
# Inputs          : None
221
#
222
# Returns         :
223
#
224
sub getDeployData
225
{
226
	connectDM ( \$DM_DB, $opt_verbose );
227
	disconnectDM(\$DM_DB);
228
}
229
 
230
#-------------------------------------------------------------------------------
231
# Function        : getHttpData
232
#
233
# Description     : Test the Http interface to release manager
234
#
235
# Inputs          :
236
#
237
# Returns         :
238
#
239
sub getHttpData
240
{
241
	Message("Test HTTP Interface");
242
 
243
	unless ( $UserAgentAvailable )
244
	{
245
		Warning ("The perl installation does not contain the LWP module",
246
			"The test to extract data from Release Manager will be skipped",
247
			"The deployment scripts will not run properly");
248
		return 0;
249
	}
250
 
251
	my $user_agent = LWP::UserAgent->new( timeout => 30 );
252
	if ( $RM_URL )
253
	{
254
		Verbose("RM URL: $RM_URL");
255
		my $response = $user_agent->head( $RM_URL );
256
		Verbose ("Http Message: " . $response->status_line);
257
		if ( $response->is_success )
258
		{
259
			Message("Retrieved Release Manager Data");
260
		}
261
		else
262
		{
263
			Error("Unable to retrieve Release Manager Data", "Status: " . $response->status_line);
264
		}
265
	}
266
	else
267
	{
268
		Warning("Release Manager URL not defined: GBE_RM_URL");
269
	}
270
 
271
	if ( $DM_URL )
272
	{
273
		Verbose("DM URL: $DM_URL");
274
		my $response = $user_agent->head( $DM_URL );
275
		Verbose ("Http Message: " . $response->status_line);
276
		if ( $response->is_success )
277
		{
278
			Message("Retrieved Deployment Manager Data");
279
		}
280
		else
281
		{
282
			Error("Unable to retrieve Deployment Manager Data", "Status: " . $response->status_line);
283
		}
284
	}
285
	else
286
	{
287
		Warning("Deployment Manager URL not defined: GBE_DM_URL");
288
	}
289
 
290
	return 1;
291
}
292
 
293
#-------------------------------------------------------------------------------
294
#   Documentation
295
#
296
 
297
=pod
298
 
299
=head1 NAME
300
 
301
test_rmconnection - Test the connection to the Release Manager Database
302
 
303
=head1 SYNOPSIS
304
 
305
jats etool test_rmconnection [options]
306
 
307
 Options:
308
	-help              - Brief help message
309
	-help -help        - Detailed help message
310
	-man               - Full documentation
311
	-verbose           - Display additional information
312
 
313
=head1 OPTIONS
314
 
315
=over 8
316
 
317
=item B<-help>
318
 
319
Print a brief help message and exits.
320
 
321
=item B<-help -help>
322
 
323
Print a detailed help message with an explanation for each option.
324
 
325
=item B<-man>
326
 
327
Prints the manual page and exits.
328
 
329
=item B<-verbose>
330
 
331
Prints additional information on the progress of the program.
332
 
333
=back
334
 
335
=head1 DESCRIPTION
336
 
337
This program is provided to test the connection between the users computer and
338
the Release Manager Database. It does this by querying the database in the
339
same manner as many of the deployments scripts.
340
 
341
=head1 EXAMPLE
342
 
343
jats etool test_rmconnection
344
 
345
=cut
346
 
347