Changeset 772 in ProjectBuilder


Ignore:
Timestamp:
May 3, 2009, 7:52:41 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • Adds new features test2vm and test2ve (will require 0.9.7 in VM/VE to really work)
  • standardize call with name 2v everywhere it's appropriate
  • New send2target targets based on VEtest, VEbuild, VEScript and same for VM. Makes tests consistent
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r769 r772  
    227227
    228228Snapshot a virtual environment for pb usage
     229
     230=item B<test2vm>
     231
     232Test a package in a virtual machine
     233
     234=item B<test2ve>
     235
     236Test a package in a virtual environment
    229237
    230238=item B<newver>
     
    432440    pb_pkg2ssh();
    433441} elsif ($action =~ /^build2ve$/) {
    434     pb_build2v("ve");
     442    pb_build2v("ve","build");
    435443} elsif ($action =~ /^build2vm$/) {
    436     pb_build2v("vm");
     444    pb_build2v("vm","build");
    437445} elsif ($action =~ /^cms2ve$/) {
    438446    pb_cms2build();
    439     pb_build2v("ve");
     447    pb_build2v("ve","build");
    440448} elsif ($action =~ /^cms2vm$/) {
    441449    pb_cms2build();
    442     pb_build2v("vm");
     450    pb_build2v("vm","build");
    443451} elsif ($action =~ /^launchvm$/) {
    444452    pb_launchv("vm",$ENV{'PBV'},0);
     
    456464    pb_launchv("vm",$ENV{'PBV'},1);
    457465} elsif ($action =~ /^setupve$/) {
    458     pb_setup_v("ve");
     466    pb_setup2v("ve");
    459467} elsif ($action =~ /^setupvm$/) {
    460     pb_setup_v("vm");
     468    pb_setup2v("vm");
    461469} elsif ($action =~ /^snapve$/) {
    462     pb_snap_v("ve");
     470    pb_snap2v("ve");
    463471} elsif ($action =~ /^snapvm$/) {
    464     pb_snap_v("vm");
     472    pb_snap2v("vm");
     473} elsif ($action =~ /^test2ve$/) {
     474    pb_build2v("ve","test");
     475} elsif ($action =~ /^test2vm$/) {
     476    pb_build2v("vm","test");
    465477} elsif ($action =~ /^newproj$/) {
    466478    # Nothing to do - already done in pb_env_init
     
    777789        # Do we have additional script to run to prepare the environement for the project ?
    778790        # Then include it in the pbconf delivery
    779         foreach my $pbvf ("pbvebuild.pre","pbvmbuild.pre","pbvebuild.post","pbvmbuild.post") {
    780             if (-x "$ENV{'PBROOTDIR'}/$pbvf") {
    781                 pb_filter_file("$ENV{'PBROOTDIR'}/$pbvf",$ptr,"$ENV{'PBDESTDIR'}/$pbvf",\%pb);
    782                 chmod 0755,"$ENV{'PBDESTDIR'}/$pbvf";
     791        foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
     792            if (-x "$pbvf") {
     793                my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
     794                pb_filter_file("$pbvf",$ptr,$target,\%pb);
     795                chmod 0755,"$target";
    783796            }
    784797        }
     
    827840}
    828841
     842sub pb_test2pkg {
     843    # Get the running distro to test on
     844    my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch) = pb_distro_init();
     845    pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch))."\n");
     846
     847    # Get list of packages to test
     848    # Get content saved in cms2build
     849    my $ptr = pb_get_pkg();
     850    @pkgs = @$ptr;
     851
     852    # Additional potential repo
     853    pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
     854    foreach my $pbpkg (@pkgs) {
     855        # We need to install the package to test, and deps brought with it
     856        pb_distro_installdeps(undef,$dtype,$pbupd,$pbpkg);
     857        pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
     858    }
     859}
     860
    829861sub pb_build2pkg {
    830862
     
    10451077    my $tmout = "vmtmout";
    10461078    my $path = "vmpath";
    1047     if (($cmt eq "vm") || ($cmt eq "VMScript")) {
     1079    if ($cmt =~ /^VM/) {
    10481080        $login = "vmlogin";
    10491081        $dir = "pbdefdir";
     
    10531085        $host = "vmhost";
    10541086        $port = "vmport";
    1055     } elsif (($cmt eq "ve")|| ($cmt eq "VEScript")) {
     1087    } elsif ($cmt =~ /^VE/) {
    10561088        $login = "velogin";
    10571089        $dir = "pbdefdir";
     
    10931125            ($pbver,$pbtag) = split(/-/,$vertag);
    10941126
    1095             if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
     1127            if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) {
    10961128                $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
    10971129                if ($cmd eq "") {
     
    11081140    }
    11091141
    1110     if (($cmt eq "vm") || ($cmt eq "ve")) {
     1142    if ($cmt =~ /V[EM]build/) {
    11111143        $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
    11121144    } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
    11131145        $src="$src $ENV{'PBDESTDIR'}/pbscript";
     1146    } elsif ($cmt =~ /V[EM]test/) {
     1147        $src="$src $ENV{'PBDESTDIR'}/pbtest";
    11141148    } elsif ($cmt eq "Announce") {
    11151149        $src="$src $ENV{'PBTMP'}/pbscript";
     
    11371171
    11381172    my $mac;
    1139     if (($cmt ne "ve") && ($cmt ne "VEScript")) {
     1173    if ($cmt !~ /^VE/) {
    11401174        $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
    11411175        # Overwrite account value if passed as parameter
     
    11441178    } else {
    11451179        # VE
    1146         # Overwrite account value if passed as parameter (typically for setup_ve)
     1180        # Overwrite account value if passed as parameter (typically for setup2ve)
    11471181        $mac = $sshlogin->{$ENV{'PBPROJ'}};
    11481182        $mac = $pbaccount if (defined $pbaccount);
     
    11511185    my $tdir;
    11521186    my $bdir;
    1153     if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
     1187    if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/) || ($cmt =~ /V[EM]test/)) {
    11541188        $tdir = $sshdir->{$ENV{'PBPROJ'}}."/src";
    11551189        if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
     
    11571191            $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/src";
    11581192        }
    1159     } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
     1193    } elsif ($cmt =~ /V[EM]build/) {
    11601194        $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
    11611195        $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
     
    12761310    # Useless for VE
    12771311    my $nport;
    1278     if (($cmt ne "ve") && ($cmt ne "VEScript")) {
     1312    if ($cmt !~ /^VE/) {
    12791313        $nport = $sshport->{$ENV{'PBPROJ'}};
    12801314        $nport = "$pbport" if (defined $pbport);
     
    12891323    # should use a hash instead...
    12901324    my ($shcmd,$cpcmd,$cptarget,$cp2target);
    1291     if (($cmt ne "ve") && ($cmt ne "VEScript")) {
     1325    if ($cmt !~ /^VE/) {
    12921326        my $keyfile = pb_ssh_get(0);
    12931327        $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
    12941328        $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
    12951329        $cptarget = "$mac:$tdir";
    1296         if ($cmt eq "vm") {
     1330        if ($cmt =~ /^VM/) {
    12971331            $cp2target = "$mac:$bdir";
    12981332        }
     
    13361370
    13371371    # For VE we need to change the owner manually
    1338     if ($cmt eq "ve") {
     1372    if ($cmt =~ /^VE/) {
    13391373        pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
    13401374    }
    13411375
    1342     pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
    1343     if (($cmt eq "vm") || ($cmt eq "ve")) {
     1376    pb_system("$shcmd \"echo \'cd $tdir ; if [ -x pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
     1377    if ($cmt =~ /^V[EM]build/) {
    13441378        # Get back info on pkg produced, compute their name and get them from the VM
    13451379        pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
    13461380        # For VE we need to change the owner manually
    1347         if ($cmt eq "ve") {
     1381        if ($cmt eq "VEbuild") {
    13481382            pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
    13491383        }
     
    13821416    }
    13831417    pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
    1384     if ((! $vmexist) && (($cmt eq "vm") || ($cmt eq "VMScript"))) {
     1418    if ((! $vmexist) && ($cmt =~ /^VM/)) {
    13851419        # If in setupvm then takes a snapshot just before halting
    13861420        if ($snapme != 0) {
     
    14021436        pb_system("$shcmd \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
    14031437    }
    1404     if ((($cmt eq "ve") || ($cmt eq "VEScript")) && ($snapme != 0)) {
     1438    if (($cmt =~ /^VE/) && ($snapme != 0)) {
    14051439        ($odir,$over,$oarch) = split(/-/,$v);
    14061440        my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch";
     
    14271461
    14281462    if (not defined $vm1) {
    1429         ($vm,$all) = pb_get_v($vtype);
     1463        ($vm,$all) = pb_get2v($vtype);
    14301464    } else {
    14311465        @$vm = ($vm1);
     
    16731707
    16741708# Return string for date synchro
    1675 sub pb_date_v {
     1709sub pb_date2v {
    16761710
    16771711my $vtype = shift;
     
    17081742
    17091743my $vtype = shift;
    1710 
    1711 my ($v,$all) = pb_get_v($vtype);
     1744my $action = shift || "build";
     1745
     1746my ($v,$all) = pb_get2v($vtype);
    17121747
    17131748# Send tar files when we do a global generation
    1714 pb_build2ssh() if ($all == 1);
     1749pb_build2ssh() if (($all == 1) && ($action eq "build"));
    17151750
    17161751my ($vmexist,$vmpid) = (undef,undef);
     
    17381773    print SCRIPT "# Setup the variables required for building\n";
    17391774    print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
    1740     print SCRIPT "# Preparation for pb\n";
    1741     print SCRIPT "mv .pbrc \$HOME\n";
    1742     print SCRIPT "cd ..\n";
     1775
     1776    if ($action eq "build") {
     1777        print SCRIPT "# Preparation for pb\n";
     1778        print SCRIPT "mv .pbrc \$HOME\n";
     1779        print SCRIPT "cd ..\n";
     1780    }
    17431781
    17441782    # VE needs a good /proc
     
    17461784        print SCRIPT "sudo mount -t proc /proc /proc\n";
    17471785    }
    1748    
    1749     # Get list of packages to build and get some ENV vars as well
    1750     my $ptr = pb_get_pkg();
    1751     @pkgs = @$ptr;
    1752     my $p = join(' ',@pkgs) if (@pkgs);
    1753     print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
    1754     print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
    1755     print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
    1756 
    1757     my ($ntpline,$dateline) = pb_date_v($vtype,$v);
     1786
     1787    my ($ntpline,$dateline) = pb_date2v($vtype,$v);
    17581788    print SCRIPT "# Time sync\n";
    17591789    print SCRIPT "echo 'setting up date with '";
     
    17741804    }
    17751805
     1806    # Get list of packages to build/test and get some ENV vars as well
     1807    my $ptr = pb_get_pkg();
     1808    @pkgs = @$ptr;
     1809    my $p = join(' ',@pkgs) if (@pkgs);
     1810    print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
     1811    print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
     1812    print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
    17761813
    17771814    # We may need to do some other tasks before building. Read a script here to finish setup
    1778     if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."build.pre") {
    1779         print SCRIPT "# Special pre-build instructions to be launched\n";
    1780         print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."build.pre");
    1781     }
    1782 
    1783     print SCRIPT "# Build\n";
    1784     print SCRIPT "echo Building packages on $vtype...\n";
    1785     print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} build2pkg $p\n";
     1815    if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
     1816        print SCRIPT "# Special pre-instructions to be launched\n";
     1817        print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
     1818    }
     1819
     1820    if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
     1821        print SCRIPT "# Special pre-$action instructions to be launched\n";
     1822        print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
     1823    }
     1824
     1825    print SCRIPT "# $action\n";
     1826    print SCRIPT "echo $action"."ing packages on $vtype...\n";
     1827
     1828    if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
     1829            die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
     1830    }
     1831    print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
     1832
    17861833    if ($vtype eq "ve") {
    17871834        print SCRIPT "sudo umount /proc\n";
     
    17891836
    17901837    # We may need to do some other tasks after building. Read a script here to exit properly
    1791     if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."build.post") {
    1792         print SCRIPT "# Special post-build instructions to be launched\n";
    1793         print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."build.post");
     1838    if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
     1839        print SCRIPT "# Special post-$action instructions to be launched\n";
     1840        print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
     1841    }
     1842
     1843    if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
     1844        print SCRIPT "# Special post-instructions to be launched\n";
     1845        print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
    17941846    }
    17951847
     
    18111863    # and launch the build through pbscript
    18121864    pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
    1813     pb_send2target($vtype,"$v",$vmexist,$vmpid);
     1865    pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
    18141866}
    18151867}
     
    19251977# or only some (if all we publish also tar files in addition to pkgs
    19261978#
    1927 sub pb_get_v {
     1979sub pb_get2v {
    19281980
    19291981my $vtype = shift;
     
    19532005# pb will take your local public SSH key to access
    19542006# the pb account in the VM later on if needed
    1955 sub pb_setup_v {
     2007sub pb_setup2v {
    19562008
    19572009my $vtype = shift;
    19582010
    1959 my ($vm,$all) = pb_get_v($vtype);
     2011my ($vm,$all) = pb_get2v($vtype);
    19602012
    19612013# Script generated
     
    19642016foreach my $v (@$vm) {
    19652017    # Deal with date sync.
    1966     my ($ntpline,$dateline) = pb_date_v($vtype,$v);
     2018    my ($ntpline,$dateline) = pb_date2v($vtype,$v);
    19672019
    19682020    # Name of the account to deal with for VM/VE
     
    22522304}
    22532305
    2254 # Function to create a snapshot named 'pb' for VMs/VEs
    2255 sub pb_snap_v {
     2306# Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
     2307sub pb_snap2v {
    22562308
    22572309my $vtype = shift;
    22582310
    2259 my ($vm,$all) = pb_get_v($vtype);
     2311my ($vm,$all) = pb_get2v($vtype);
    22602312
    22612313# Script generated
Note: See TracChangeset for help on using the changeset viewer.