X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=test%2Ftestclearcase.pl;h=545f3d047f4b6dd7cbaec7bb9af2aeb506cf181d;hb=64b1fd397779f5b896e23fcca190b3e42f244145;hp=42e315280c760afc9a1ddca5efa4e41fe75fb0d4;hpb=1140ca8d56832ae529db0f353112ac192cdf9432;p=clearscm.git diff --git a/test/testclearcase.pl b/test/testclearcase.pl index 42e3152..545f3d0 100755 --- a/test/testclearcase.pl +++ b/test/testclearcase.pl @@ -43,6 +43,17 @@ $Date: 2011/01/09 01:01:32 $ -[no]uc|m: Perform UCM Clearcase tests (Default: noucm) -[no]clean: Cleanup after yourself (Default: clean) +if -ucm is specified then the following additional parameters should be set: + + -username: Username to connect to Clearquest with (Can set CQ_USERNAME) + -password: Password to use to connect to Clearquest (CQ_PASSWORD) + -weburl: Web URL to use for enabling Clearcase -> Clearquest + connection (CQ_WEBURL - Do not specify the trailing + "/oslc") + -database: Clearquest database to enable (CQ_DATABASE) + -dbset: Clearquest DBSet (CQ_DBSET) + -provider: Name of provider (Default: CQPROV) + =head1 DESCRIPTION Clearcase smoke tests. Perform simple Clearcase operations to validate that @@ -58,7 +69,7 @@ use warnings; use Cwd; use FindBin; use Getopt::Long; -use Term::ANSIColor qw(:constants); +use Pod::Usage; use lib "$FindBin::Bin/../lib"; @@ -89,8 +100,6 @@ use Utils; # Globals my $VERSION = '2.1'; -my (@ucmobjs, $order); - my ( $test_vob, $test_view, @@ -106,7 +115,7 @@ my ( $test_intview, ); -my ($vbs, $vws, %default_opts, %opts); +my (%default_opts, %opts); my ($script) = ($FindBin::Script =~ /^(.*)\.pl/); @@ -122,14 +131,23 @@ sub LogOpts() { ); for (sort keys %opts) { + next if /help/ || /usage/ || /password/; + if (ref $opts{$_} eq 'ARRAY') { my $name = $_; - $log->msg("$name:\t$_") for (@{$opts{$_}}); + + for (@{$opts{$_}}) { + $log->msg("$name:\t$_") if $_; + } # for } else { - $log->msg("$_:\t$opts{$_}"); + if ($opts{$_}) { + $log->msg("$_:\t$opts{$_}"); + } else { + $log->msg("$_:\t"); + } # if } # if } # for - + return; } # LogOpts @@ -144,7 +162,7 @@ sub CreateVob($) { my ($status, @output) = $newvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs"); - $log->log($_) for (@output); + $log->log($_) for @output; return ($status, $newvob); } # CreateVob @@ -159,9 +177,7 @@ sub CreatePvob($) { #my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs", 'A test Pvob'); my ($status, @output) = $pvob->create($opts{vobhost}, "$opts{vobstore}/$vobname.vbs"); - $log->log($_) for (@output); - - push @ucmobjs, $pvob unless $status; + $log->log($_) for @output; return ($status, $pvob); } # CreatePvob @@ -173,14 +189,14 @@ sub MountVob($) { # Create mount directory my ($status, @output); - + ($status, @output) = Execute 'mkdir -p ' . $vob->tag . ' 2>&1' unless -d $vob->tag; - $log->log($_) for (@output); + $log->log($_) for @output; ($status, @output) = $vob->mount; - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # MountVob @@ -192,15 +208,29 @@ sub DestroyVob($) { ($status, @output) = $Clearcase::CC->execute('cd'); + $log->err('Unable to perform cd command', 1) if $status; + $log->msg('Unmounting vob ' . $vob->tag); ($status, @output) = $vob->umount; + if ($status) { + $log->err('Unable to unmount vob ' . $vob->tag); + } else { + $log->msg('Umounted vob ' . $vob->tag); + } # if + $log->msg('Removing vob ' . $vob->tag); ($status, @output) = $vob->remove; - $log->log($_) for (@output); + if ($status) { + $log->err("Failed to execute command " . + $Clearcase::CC->lastcmd . "\n" . + join "\t\n", @output); + } # if + + $log->log($_) for @output; return $status; } # DestroyVob @@ -214,7 +244,7 @@ sub CreateView($) { my ($status, @output) = $view->create($opts{viewhost}, "$opts{viewstore}/$tag.vws"); - $log->log($_) for (@output); + $log->log($_) for @output; return ($status, $view); } # CreateView @@ -226,11 +256,23 @@ sub SetView($) { my ($status, @output) = $view->set; - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # SetView +sub StopView($) { + my ($view) = @_; + + $log->msg('Stopping view ' . $view->tag); + + my ($status, @output) = $view->stop; + + $log->log($_) for @output; + + return $status; +} # StopView + sub DestroyView($) { my ($view) = @_; @@ -238,14 +280,14 @@ sub DestroyView($) { my ($status, @output) = $Clearcase::CC->execute('cd'); - $log->log($_) for (@output); + $log->log($_) for @output; chdir $ENV{HOME} or $log->err("Unable to chdir $ENV{HOME}", 1); ($status, @output) = $view->remove; - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # DestroyView @@ -267,7 +309,7 @@ sub CreateViewPrivateFiles(@) { close $file; } # for - + return; } # CreateViewPrivateFiles @@ -284,7 +326,7 @@ sub CheckOut($) { ($status, @output) = $newElement->checkout; - $log->log($_) for (@output); + $log->log($_) for @output; $log->err("Unable to check out $_", $status) if $status; } # for @@ -295,11 +337,11 @@ sub CheckOut($) { ($status, @output) = $newElement->checkout; - $log->log($_) for (@output); + $log->log($_) for @output; $log->err("Unable to check out $element", $status) if $status; } # if - + return; } # CheckOut @@ -316,7 +358,7 @@ sub CheckIn($) { ($status, @output) = $newElement->checkin; - $log->log($_) for (@output); + $log->log($_) for @output; $log->err("Unable to check in $_", $status) if $status; } # for @@ -327,11 +369,11 @@ sub CheckIn($) { ($status, @output) = $newElement->checkin; - $log->log($_) for (@output); + $log->log($_) for @output; $log->err("Unable to check in $element", $status) if $status; } # if - + return; } # CheckIn @@ -357,11 +399,11 @@ sub MakeElements(@) { my ($status, @output) = $newElement->mkelem; - $log->log($_) for (@output); + $log->log($_) for @output; $log->err("Unable to make $_ an element", $status) if $status; } # for - + return; } # MakeElements @@ -390,7 +432,7 @@ sub RunTests() { $log->msg("$script: Start Base Clearcase Tests"); $log->msg('Removing test files'); - unlink $_ for (@elements); + unlink $_ for @elements; $log->msg('Creating view private files'); @@ -443,31 +485,116 @@ sub Cleanup(;$$$) { } # Cleanup sub CleanupUCM() { - my $status = 0; + my ($rc, $status, @output); - # Need to remove UCM objects in the opposite order in which we created them - for (reverse @ucmobjs) { - my ($rc, @output); + $log->msg('Removing ' . $test_activity->name); - if (ref $_ eq 'Clearcase::UCM::Pvob') { - $log->msg('Removing Pvob ' . $_->tag); + ($rc, @output) = $test_activity->remove; - $status += DestroyVob $_; - } else { - $log->msg('Removing ' . ref ($_) . ' ' . $_->name); + $status += $rc; - ($rc, @output) = $_->remove; + $log->log($_) for @output; - $status += $rc; - } # if - } # for + # Need to remove baselines from streams first using rebase (Devstream) + $log->msg('Rebasing ' . $test_devstream->name . ' to remove baseline'); + + $status += RebaseStream( + $test_devstream, + ' -dbaseline ' . $test_baseline->name . '@' . $test_baseline->pvob->tag . + ' -view ' . $test_devview->name . ' -complete', + ); + + # Change intstream to not have a recommended baseline + $log->msg('Changing ' . $test_intstream->name . ' to remove recommended baseline'); + + ($rc, @output) = $test_intstream->nrecommended; + + $status += $rc; + + $log->log($_) for @output; + + $status += DestroyView($test_devview); + + $log->msg('Removing ' . $test_baseline->name); + + ($rc, @output) = $test_baseline->remove; + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Rebasing ' . $test_intstream->name . ' to remove INITIAL baseline'); + + $status += RebaseStream( + $test_intstream, + ' -dbaseline tc.component_INITIAL' . '@' . $test_intstream->pvob->tag . + ' -view ' . $test_intview->name . ' -complete', + ); + + $log->msg('Removing ' . $test_component->name . ' from ' . $test_project->name); + + ($rc, @output) = $test_project->change( + '-dmodcomp ' . $test_component->name . '@' . $test_project->pvob->tag + ); + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Removing ' . $test_component->name); + + ($rc, @output) = $test_component->remove; + + $status += $rc; + + $log->log($_) for @output; + + $status += DestroyView($test_intview); + + $log->msg('Removing '. $test_devstream->name); + + ($rc, @output) = $test_devstream->remove; + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Removing ' . $test_intstream->name); + + ($rc, @output) = $test_intstream->remove; + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Removing ' . $test_project->name); + + ($rc, @output) = $test_project->remove; + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Removing ' . $test_folder->name); + + ($rc, @output) = $test_folder->remove; + + $status += $rc; + + $log->log($_) for @output; + + $log->msg('Removing ' . $test_pvob->name); + + ($rc, @output) = DestroyVob($test_pvob); + + $log->log($_) for @output; return $status; } # CleanupUCM sub SetupTest($$) { my ($vob_tag, $view_tag) = @_; - + my ($status, @output); $log->msg('Setup test environment'); @@ -513,36 +640,88 @@ sub SetupTest($$) { ($status, @output) = $Clearcase::CC->execute("cd $dir"); - if ($status != 0) { - $log->log($_) for (@output); - } # if + $log->log($_) for @output; return $status; } # SetupTest +sub SetupAttributeTypes() { + my @CC_CMI_Types = qw(CONTEXT TASK PROVIDERS); + + my $status = SetView($test_intview); + + return $status if $status; + + for (@CC_CMI_Types) { + my $cmd = "mkattype -nc -vtype string CC_CMI_$_"; + + my ($rc, @output) = $Clearcase::CC->execute($cmd); + + $status += $rc; + + $log->log($_) for @output; + } # for + + return $status; +} # SetupAttributeTypes + +sub CRMRegister() { + my $cmd = "crmregister add -database $opts{database} -connection RDE " + . "-url $opts{weburl} -username $opts{username} " + . "-password $opts{password}"; + + my ($status, @output) = Execute $cmd; + + $log->log($_) for @output; + + return $status; +} # CRMRegister + +sub MakeCMProvider() { + my $cmd = 'mkcmprovider -vob ' . $test_pvob->tag + . '-type cmcq -version V1_0 -description ' + . '"RDE CMI CQ Provider" ' + . '-connection baseurl:' . $opts{weburl} . " $opts{provider}"; + + my ($status, @output) = $Clearcase::CC->execute($cmd); + + $log->log($_) for @output; + + return $status; +} # MakeCMProvider + sub SetupUCMTest() { my $status; - $log->msg("Creating UCM Pvob $Clearcase::VOBTAG_PREFIX/tc.pvob"); + $log->msg("Register RDE://$opts{username}\@$opts{database}"); + + $status = CRMRegister; + + $log->err("Unable to register RDE://$opts{username}\@$opts{database} - Check logfile", $status) + if $status; + + $log->msg("Creating UCM Pvob ${Clearcase::VOBTAG_PREFIX}tc.pvob"); + + ($status, $test_pvob) = CreatePvob("${Clearcase::VOBTAG_PREFIX}tc.pvob"); + + MountVob $test_pvob; - ($status, $test_pvob) = CreatePvob("$Clearcase::VOBTAG_PREFIX/tc.pvob"); - return $status; } # SetupUCMTest sub CreateUCMProject() { # Get the root folder to put this project into (may create folders later) - my $folder = Clearcase::UCM::Folder->new('tc.folder', $test_pvob); + $test_folder = Clearcase::UCM::Folder->new('tc.folder', $test_pvob); - $test_project = Clearcase::UCM::Project->new('tc.project', $folder, $test_pvob); + $test_project = Clearcase::UCM::Project->new('tc.project', $test_folder, $test_pvob); - $log->msg('Creating UCM Project tc.project'); + $test_project->remove if $test_project->exists; - my ($status, @output) = $test_project->create(); + $log->msg('Creating UCM Project tc.project'); - $log->log($_) for (@output); + my ($status, @output) = $test_project->create; - push @ucmobjs, $test_project unless $status; + $log->log($_) for @output; return $status; } # CreateUCMProject @@ -554,9 +733,7 @@ sub CreateUCMIntStream() { my ($status, @output) = $test_intstream->create($test_project, '-integration'); - $log->log($_) for (@output); - - push @ucmobjs, $test_intstream unless $status; + $log->log($_) for @output; return $status; } # CreateUCMIntStream @@ -568,12 +745,10 @@ sub CreateUCMDevStream() { my ($status, @output) = $test_devstream->create($test_project); - $log->log($_) for (@output); - - push @ucmobjs, $test_devstream unless $status; + $log->log($_) for @output; return $status; -} # CreateUCMIntStream +} # CreateUCMDevStream sub CreateUCMComponent() { $test_component = Clearcase::UCM::Component->new('tc.component', $test_pvob); @@ -584,9 +759,7 @@ sub CreateUCMComponent() { "$Clearcase::VIEWTAG_PREFIX/" . $test_intview->tag . $test_vob->tag ); - $log->log($_) for (@output); - - push @ucmobjs, $test_component unless $status; + $log->log($_) for @output; return $status; } # CreateUCMComponent @@ -597,7 +770,7 @@ sub AddModifiableComponent() { ' ' . $test_project->name . '@' . $test_pvob->tag ); - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # AddModifiableCOmponent @@ -612,9 +785,7 @@ sub CreateUCMIntView() { '-stream ' . $test_intstream->name . '@' . $test_pvob->tag ); - $log->log($_) for (@output); - - push @ucmobjs, $test_intview unless $status; + $log->log($_) for @output; $test_intview->start unless $status; @@ -631,9 +802,7 @@ sub CreateUCMDevView() { '-stream ' . $test_devstream->name . '@' . $test_pvob->tag ); - $log->log($_) for (@output); - - push @ucmobjs, $test_devview unless $status; + $log->log($_) for @output; $test_devview->start unless $status; @@ -647,9 +816,7 @@ sub CreateUCMBaseline() { my ($status, @output) = $test_baseline->create($test_intview, undef, '-identical'); - $log->log($_) for (@output); - - push @ucmobjs, $test_baseline unless $status; + $log->log($_) for @output; return $status; } # CreateUCMBaseline @@ -661,29 +828,27 @@ sub CreateUCMActivity() { my ($status, @output) = $test_activity->create($test_devstream, 'A UCM Test Activity'); - $log->log($_) for (@output); - - push @ucmobjs, $test_activity unless $status; + $log->log($_) for @output; return $status; } # CreateUCMActivity -sub RebaseStream($$;$) { - my ($stream, $baseline, $opts) = @_; +sub RebaseStream($$) { + my ($stream, $opts) = @_; - my ($status, @output) = $stream->rebase($baseline, $opts); + my ($status, @output) = $stream->rebase($opts); - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # RebaseStream -sub RecommendBaseline($) { - my ($baseline) = @_; +sub RecommendBaseline($$) { + my ($stream, $baseline) = @_; - my ($status, @output) = $test_intstream->recommend($baseline); + my ($status, @output) = $stream->recommend($baseline); - $log->log($_) for (@output); + $log->log($_) for @output; return $status; } # RecommentBaseline @@ -697,15 +862,17 @@ sub RunUCMTests() { $status += CreateUCMIntStream; $status += CreateUCMDevStream; $status += CreateUCMIntView; + $status += SetupAttributeTypes; $status += CreateUCMDevView; $status += CreateUCMComponent; $status += AddModifiableComponent; - $status += RebaseStream($test_intstream, 'tc.component_INITIAL', '-complete'); - $status += RecommendBaseline('tc.component_INITIAL'); + $status += RebaseStream($test_intstream, '-baseline tc.component_INITIAL -complete'); + $status += RecommendBaseline($test_intstream, 'tc.component_INITIAL'); $status += CreateUCMBaseline; - $status += RebaseStream($test_devstream, 'tc.baseline', '-complete'); + $status += RebaseStream($test_devstream, '-baseline tc.baseline -complete'); + $status += RecommendBaseline($test_devstream, 'tc.baseline'); $status += CreateUCMActivity; - + $log->msg("$script: End UCM Clearcase Tests"); return $status; @@ -716,8 +883,18 @@ my $startTime = time; my $conf_file = "$FindBin::Bin/$script.conf"; my $status = 0; -$opts{base} = 1; -$opts{clean} = 1; +$opts{help} = sub { pod2usage }; +$opts{usage} = sub { pod2usage (-verbose => 2)}; +$opts{base} = 1; +$opts{clean} = 1; +$opts{username} = $ENV{CQ_USERNAME}; +$opts{password} = $ENV{CQ_PASSWORD}; +$opts{weburl} = $ENV{CQ_WEBURL}; + +$opts{weburl} .= $opts{weburl} ? "/oslc" : undef; +$opts{database} = $ENV{CQ_DATABASE}; +$opts{dbset} = $ENV{CQ_DBSET}; +$opts{provider} = $ENV{CQ_PROVIDER} || 'CQPROV'; GetOptions( \%opts, @@ -728,7 +905,11 @@ GetOptions( 'base!', 'ucm!', 'clean!', -) or Usage; + 'username=s', + 'database=s', + 'dbset=s', + 'provider', +) || pod2usage; # Read the config file if (-f $conf_file) { @@ -742,6 +923,13 @@ for (keys %default_opts) { $opts{$_} = $default_opts{$_} if !$opts{$_}; } # for +# Check CQ parameters +if ($opts{ucm}) { + for ('username', 'password', 'weburl', 'database', 'dbset', 'provider') { + pod2usage "In UCM mode you must specify -$_" unless $opts{$_}; + } # for +} # if + $log->msg("$script: Start"); LogOpts; @@ -749,10 +937,12 @@ LogOpts; # Since we are creating private vobs (to avoid complications with having to # know and code the registry password when making public vobs), we'll simply # change $Clearcase::VOBTAG_PREFIX -$Clearcase::VOBTAG_PREFIX = $ENV{TMP} || '/tmp'; +if ($ARCHITECTURE !~ /win/i) { + $Clearcase::VOBTAG_PREFIX = $ENV{TMP} . '/' || '/tmp'; +} # if if ($opts{base}) { - $status = SetupTest "$Clearcase::VOBTAG_PREFIX/tc.vob", 'tc.view'; + $status = SetupTest "${Clearcase::VOBTAG_PREFIX}tc.vob", 'tc.view'; if ($status == 0) { $status += RunTests; @@ -761,7 +951,7 @@ if ($opts{base}) { } # if # Note if we are doing UCM tests then we need the view and vob here... - $status += Cleanup($test_view, $test_vob) if $opts{clean} and !$opts{ucm}; + $status += Cleanup($test_view, $test_vob) if $opts{clean} && !$opts{ucm}; if ($status != 0) { $log->err("$script: Failed (Base Clearcase)"); @@ -785,7 +975,7 @@ if ($opts{ucm}) { } # if if ($status != 0) { - $log->err("$script Failed (UCM Clearcase)"); + $log->err("$script: Failed (UCM Clearcase)"); } else { $log->msg("$script: Passed (UCM Clearcase)"); } # if @@ -817,11 +1007,9 @@ L L -L - =head2 ClearSCM Perl Modules -=begin man +=begin man Clearcase Clearcase::Element