Commit bb341bda authored by Eric Cano's avatar Eric Cano
Browse files

bug #72215: Remove the TAPEGATEWAYREQUEST table from the schema, and drop the...

bug #72215: Remove the TAPEGATEWAYREQUEST table from the schema, and drop the triggers that populate it.

In test_gateway_wipe_reinstall_migrate.pl fixed synthax and other minor issues. Now re-creates a working stager from scratch.
parent addd5689
......@@ -38,13 +38,15 @@ use DBD::Oracle qw(:ora_types);
# castor/cern.ch/dev/m/murrayc3/simpleTest_Sat_Aug_7.txt
my $DEV_FILE_NS_FILEID=5000043410;
my $adminList = 1028; # gid=1028(c3)
my $adminList = ':1028'; # gid=1028(c3)
my $originalDbSchema = "stager_oracle_create.sql";
my $originalDropSchema = "drop_oracle_schema.sql";
my $stageGid = 1474; # gid=1474(st)
my $stageUid = 14029; # uid=14029(stage)
my $checkout_location = '/var/scratch/canoc3/test_gateway_r21263';
my $dbDir = 'castor/db';
my $tstDir = 'test/tapegateway_release_tests';
# Forward declarations
sub open_db();
......@@ -56,22 +58,30 @@ sub main();
sub printUsage();
sub parseCommandLine ();
sub parseCommandLine ();
sub daemonIsRunning ();
sub getOrastagerconfigParam ( $ );
sub daemonIsRunning ( $ );
sub killDaemonWithTimeout ( $$ );
sub genBackupFileName ();
sub createBackupCopy ();
sub restoreFileFromBackupCopy ();
sub connectToStagerDb ();
sub sub getNbTapeCopiesInStagerDb ();
sub insertCastorFile ();
sub deleteCastorFile ();
sub setFileClassNbCopies ();
sub overrideCheckPermission ();
sub insertTapeCopy ();
sub insertTapeCopies();
sub deleteTapeCopy ();
sub deleteAllStreamsTapeCopiesAndCastorFiles ();
sub executeSQLPlusScript ( $$$$ );
sub genBackupFileName ( $ );
sub createBackupCopy ( $ );
sub restoreFileFromBackupCopy ( $$ );
sub connectToStagerDb ( $$$ );
sub getNbTapeCopiesInStagerDb ( $ );
sub insertCastorFile ( $$$$$$$$$$ );
sub deleteCastorFile ( $$ );
sub setFileClassNbCopies ( $$$ );
sub overrideCheckPermission ( $ );
sub insertTapeCopy ( $$$ );
sub insertTapeCopies( $$$$ );
sub deleteTapeCopy ( $$ );
sub deleteAllStreamsTapeCopiesAndCastorFiles ( $ );
sub executeSQLPlusScript ( $$$$$ );
sub wipeAndRecreateDefaultLxcastodev03 ();
sub migrateToNewTapeGatewaySchema ();
sub stopAndSwitchToTapeGatewayd ( $ );
sub stopAndSwitchToRtcpclientd ( $ );
sub startDemons ();
sub goodDaySingleAndDualCopyTest ();
# Hook for main. (not anymore)
# main();
......@@ -114,13 +124,19 @@ sub open_db()
sub check_leftovers ( $ )
{
my $dbh = shift;
my $sth = $dbh -> prepare("SELECT count (*) from (
my $sth = $dbh -> prepare ("SELECT count (*) FROM TABS");
$sth -> execute();
my @row = $sth->fetchrow_array();
if ($row[0] == 0) {
return 0;
}
$sth = $dbh -> prepare("SELECT count (*) from (
SELECT dc.id from diskcopy dc where
dc.status NOT IN ( 0 )
UNION ALL
SELECT tc.id from tapecopy tc)");
$sth -> execute ();
my @row = $sth->fetchrow_array();
@row = $sth->fetchrow_array();
return $row[0];
}
......@@ -168,7 +184,8 @@ sub nullize_arrays_undefs ( $ )
####################################################################################################
# Prints the usage message for this script
sub printUsage {
sub printUsage ()
{
print("Usage: test.py mighunterdExecutable\n");
print("Note: This script mjust be ran as root\n");
}
......@@ -179,7 +196,8 @@ sub printUsage {
# fails to parse the command-line arguments.
#
# @return The path to the executable of the mighunter daemon.
sub parseCommandLine {
sub parseCommandLine ()
{
my $expectedNbCmdLineArgs = 1;
my $actualNbCmdLineArgs = @ARGV;
if($expectedNbCmdLineArgs != $actualNbCmdLineArgs) {
......@@ -202,7 +220,8 @@ sub parseCommandLine {
#
# @param paramName The name of the parameter whose value is to be retrieved.
# @return The value of the parameter.
sub getOrastagerconfigParam {
sub getOrastagerconfigParam ( $ )
{
my $paramName = $_[0];
open(CONFIG, "</etc/castor/ORASTAGERCONFIG")
......@@ -277,7 +296,8 @@ sub killDaemonWithTimeout ( $$ )
#
# @param originalFilename The full path-name of the original file.
# @return The full path-name of the back-up copy.
sub genBackupFileName {
sub genBackupFileName ( $ )
{
my $originalFilename = $_[0];
my $uuid = `uuidgen`;
......@@ -296,7 +316,8 @@ sub genBackupFileName {
#
# @param originalFilename The full path-name of the original file.
# @return The full path-name of the back-up copy.
sub createBackupCopy {
sub createBackupCopy ( $ )
{
my $originalFilename = $_[0];
my $backupFilename = &genBackupFileName($originalFilename);
......@@ -311,7 +332,8 @@ sub createBackupCopy {
#
# @param originalFilename The full path-name of the original file.
# @param backupFilename The full path-name of the back-up copy.
sub restoreFileFromBackupCopy {
sub restoreFileFromBackupCopy ( $$ )
{
my $originalFilename = $_[0];
my $backupFilename = $_[1];
......@@ -328,7 +350,8 @@ sub restoreFileFromBackupCopy {
#
# This subroutine does not set any of the attributes of the
# database-connection.
sub connectToStagerDb {
sub connectToStagerDb ( $$$ )
{
my $user = &getOrastagerconfigParam("user");
my $passwd = &getOrastagerconfigParam("passwd");
my $dbName = &getOrastagerconfigParam("dbName");
......@@ -343,7 +366,8 @@ sub connectToStagerDb {
#
# @param dbh The handle to the stager-database.
# @return The number of tape-copies in the stager database.
sub getNbTapeCopiesInStagerDb {
sub getNbTapeCopiesInStagerDb ( $ )
{
my $dbh = $_[0];
my $stmt = "SELECT COUNT(*) FROM TapeCopy";
......@@ -368,7 +392,8 @@ sub getNbTapeCopiesInStagerDb {
# @param svcClassName
# @param fileClassName
# @return The database ID of the newly inserted CastorFile.
sub insertCastorFile {
sub insertCastorFile ( $$$$$$$$$$ )
{
my $dbh = $_[0];
my $nsHost = $_[1];
my $fileId = $_[2];
......@@ -431,7 +456,8 @@ sub insertCastorFile {
#
# @param dbh The handle to the stager-database.
# @param castorFileId The castor database ID.
sub deleteCastorFile {
sub deleteCastorFile ( $$ )
{
my $dbh = $_[0];
my $castorFileId = $_[1];
......@@ -454,7 +480,8 @@ sub deleteCastorFile {
# @param dbh The handle to the stager-database.
# @param fileClassName The name of the file-class.
# @param nbCopies The new number of tape-copies.
sub setFileClassNbCopies {
sub setFileClassNbCopies ( $$$ )
{
my $dbh = $_[0];
my $fileClassName = $_[1];
my $nbCopies = $_[2];
......@@ -477,7 +504,8 @@ sub setFileClassNbCopies {
# Override checkPermission
#
# @param dbh The handle to the stager-database.
sub overrideCheckPermission {
sub overrideCheckPermission ( $ )
{
my $dbh = $_[0];
my $stmt = "
......@@ -501,7 +529,8 @@ sub overrideCheckPermission {
# @param castorFileId The database ID of the associated castor-file.
# @param status The initial status of the tape-copy.
# @return The database ID of the newly inserted tape-copy.
sub insertTapeCopy {
sub insertTapeCopy ( $$$ )
{
my $dbh = $_[0];
my $castorFileId = $_[1];
my $status = $_[2];
......@@ -538,7 +567,8 @@ sub insertTapeCopy {
# @param castorFileId The database ID of the associated castor-file.
# @param status The initial status of the tape-copies.
# @param nbTapeCopies The number of rows to insert into the TapeCopy table.
sub insertTapeCopies {
sub insertTapeCopies ( $$$$ )
{
my $dbh = $_[0];
my $castorFileId = $_[1];
my $status = $_[2];
......@@ -576,7 +606,8 @@ sub insertTapeCopies {
#
# @param dbh The handle to the stager-database.
# @param tapeCopyId The castor database ID.
sub deleteTapeCopy {
sub deleteTapeCopy ( $$ )
{
my $dbh = $_[0];
my $tapeCopyId = $_[1];
......@@ -600,7 +631,8 @@ sub deleteTapeCopy {
# TO BE USED WITH CAUTION.
#
# @param dbh The handle to the stager-database.
sub deleteAllStreamsTapeCopiesAndCastorFiles {
sub deleteAllStreamsTapeCopiesAndCastorFiles ( $ )
{
my $dbh = $_[0];
my $stmt = "
......@@ -620,23 +652,23 @@ sub deleteAllStreamsTapeCopiesAndCastorFiles {
}
# Creates and calls an external script that calls sqlplus with the script name as a parameter
sub executeSQLPlusScript ( $$$$ )
sub executeSQLPlusScript ( $$$$$ )
{
my ( $u, $p , $db, $f, $title ) = ( shift, shift, shift, shift, shift );
if ( ! -e $f ) die "ABORT: $f: file not found.";
my $tmpDropSchema = `mktemp`; # This creates and empty 0600 file.
chomp $tmpDropSchema;
`echo "WHENEVER SQLERROR EXIT FAILURE;" > $tmpDropSchema`;
`echo "CONNECT $u/$p\@$db" >> $tmpDropSchema`;
`echo >> $tmpDropSchema`;
`cat $f >> $tmpDropSchema`;
`echo >> $tmpDropSchema`;
`echo "EXIT;" >> $tmpDropSchema`;
unlink $tmpDropSchema;
print ("$t\n");
my $result = `'sqlplus' /NOLOG \@$tmpDropSchema`;
if ( ! -e $f ) { die "ABORT: $f: file not found."; }
my $tmpScript = `mktemp`; # This creates and empty 0600 file.
chomp $tmpScript;
`echo "WHENEVER SQLERROR EXIT FAILURE;" > $tmpScript`;
`echo "CONNECT $u/$p\@$db" >> $tmpScript`;
`echo >> $tmpScript`;
`cat $f >> $tmpScript`;
`echo >> $tmpScript`;
`echo "EXIT;" >> $tmpScript`;
print ("$title\n");
my $result = `'sqlplus' /NOLOG \@$tmpScript`;
unlink $tmpScript;
print("\n");
print("$t RESULT\n");
print("$title RESULT\n");
print("===================\n");
print($result);
}
......@@ -676,27 +708,34 @@ sub wipeAndRecreateDefaultLxcastodev03 ()
$dbh->disconnect();
die ("Found leftovers in the stager's DB. Stopping here.");
}
my $originalDropSchemaFullpath=$checkout_location.'/'.$dbDir.'/'.$originalDropSchema;
my $originalDbSchemaFullpath=$checkout_location.'/'.$dbDir.'/'.$originalDbSchema;
die "ABORT: $originalDropSchema does not exist\n"
if ! -e $originalDropSchema;
if ! -e $originalDropSchemaFullpath;
die "ABORT: $originalDbSchema does not exist\n"
if ! -e $originalDbSchema;
if ! -e $originalDbSchemaFullpath;
my $dbUser = &getOrastagerconfigParam("user");
my $dbPasswd = &getOrastagerconfigParam("passwd");
my $dbName = &getOrastagerconfigParam("dbName");
executeSQLPlusScript ( $dbUser, $dbPasswd, $dbName, $originalDropSchema, "Dropping schema");
executeSQLPlusScript ( $dbUser, $dbPasswd, $dbName,
$originalDropSchemaFullpath,
"Dropping schema");
my $hacked_creation= `mktemp`;
`cat $originalDbSchema > $hacked_creation`;
chomp $hacked_creation;
`cat $originalDbSchemaFullpath > $hacked_creation`;
`sed -i s/^ACCEPT/--ACCEPT/ $hacked_creation`;
`sed -i s/^PROMPT/--PROMPT/ $hacked_creation`;
`sed -i s/^UNDEF/--UNDEF/ $hacked_creation`;
`sed -i s/\\&stageGid/$stageGid/g $hacked_creation`;
`sed -i s/\\&stageUid/$stageUid/g $hacked_creation`;
`sed -i s/\\&adminList/$adminList/g $hacked_creation`;
executeSQLPlusScript ( $dbUser, $dbPasswd, $dbName, $hacked_creation, "Re-creating schema");
executeSQLPlusScript ( $dbUser, $dbPasswd, $dbName,
$hacked_creation, "Re-creating schema");
unlink $hacked_creation;
# Restart the demons
......@@ -720,7 +759,7 @@ sub wipeAndRecreateDefaultLxcastodev03 ()
print($rmGetNodesResult);
# Fill database with the standard set-up for a dev-box
`nslistclass | grep NAME | awk '{print \$2}' | xargs -i enterFileClass --Name {} --GetFromCns`
`nslistclass | grep NAME | awk '{print \$2}' | xargs -i enterFileClass --Name {} --GetFromCns`;
`enterSvcClass --Name default --DiskPools default --DefaultFileSize 10485760 --FailJobsWhenNoSpace yes --NbDrives 1 --TapePool stager_dev04 --MigratorPolicy defaultMigrationPolicy --StreamPolicy streamPolicyAlwaysReturning1`;
`enterSvcClass --Name dev --DiskPools extra --DefaultFileSize 10485760 --FailJobsWhenNoSpace yes`;
......@@ -761,8 +800,9 @@ sub migrateToNewTapeGatewaySchema ()
my $dbUser = &getOrastagerconfigParam("user");
my $dbPasswd = &getOrastagerconfigParam("passwd");
my $dbName = &getOrastagerconfigParam("dbName");
print (executeSQLPlusScript ($dbUser, $dbPasswd, $dbName,
$checkout_location.'/test/tapegateway_release_tests/'.$i));
print(executeSQLPlusScript ($dbUser, $dbPasswd, $dbName,
$checkout_location.'/test/tapegateway_release_tests/'.$i,
"Executing $i"));
}
}
......@@ -776,8 +816,7 @@ sub stopAndSwitchToTapeGatewayd ( $ )
if (killDaemonWithTimeout ($i, 5)) {
die "Failed to stop a daemon. Call an exorcist.";
}
}
}
$dbh->do("UPDATE castorconfig SET value='tapegatewayd' WHERE class='tape' AND key='interfaceDaemon'");
$dbh->commit();
}
......@@ -802,7 +841,14 @@ sub stopAndSwitchToRtcpclientd ( $ )
sub startDemons ()
{
# Simply start all of them, demons not needed will jsut not start.
for ('tapegatewayd' 'stagerd' 'rtcpclientd' 'rmmasterd' 'rhd' 'rechandlerd' 'mighunterd' 'jobmanagerd') {
for ('jobmanagerd',
'mighunterd',
'rechandlerd',
'rhd',
'rmmasterd',
'rtcpclientd',
'stagerd',
'tapegatewayd') {
if (/tapegatewayd/) {
`( cd $checkout_location; LD_LIBRARY_PATH=\`find ./ -name "*.so*" \
| perl -p -e \'s|[^/]*\$|\n|\' | sort | uniq | tr \"\n\" \":\" \
......@@ -825,11 +871,11 @@ sub goodDaySingleAndDualCopyTest ()
# MAIN PROGRAM STARTS HERE
################################################################################
wipeAndRecreateDefaultLxcastodev03();
END {
`rm $tmpDropSchema` if(defined($tmpDropSchema));
`rm $tmpDbSchema` if(defined($tmpDbSchema));
$dbh->disconnect() if(defined($dbh));
}
#END {
# `rm $tmpDropSchema` if(defined($tmpDropSchema));
# `rm $tmpDbSchema` if(defined($tmpDbSchema));
# $dbh->disconnect() if(defined($dbh));
#}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment