Changeset 772 in ProjectBuilder
- Timestamp:
- May 3, 2009, 7:52:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r769 r772 227 227 228 228 Snapshot a virtual environment for pb usage 229 230 =item B<test2vm> 231 232 Test a package in a virtual machine 233 234 =item B<test2ve> 235 236 Test a package in a virtual environment 229 237 230 238 =item B<newver> … … 432 440 pb_pkg2ssh(); 433 441 } elsif ($action =~ /^build2ve$/) { 434 pb_build2v("ve" );442 pb_build2v("ve","build"); 435 443 } elsif ($action =~ /^build2vm$/) { 436 pb_build2v("vm" );444 pb_build2v("vm","build"); 437 445 } elsif ($action =~ /^cms2ve$/) { 438 446 pb_cms2build(); 439 pb_build2v("ve" );447 pb_build2v("ve","build"); 440 448 } elsif ($action =~ /^cms2vm$/) { 441 449 pb_cms2build(); 442 pb_build2v("vm" );450 pb_build2v("vm","build"); 443 451 } elsif ($action =~ /^launchvm$/) { 444 452 pb_launchv("vm",$ENV{'PBV'},0); … … 456 464 pb_launchv("vm",$ENV{'PBV'},1); 457 465 } elsif ($action =~ /^setupve$/) { 458 pb_setup _v("ve");466 pb_setup2v("ve"); 459 467 } elsif ($action =~ /^setupvm$/) { 460 pb_setup _v("vm");468 pb_setup2v("vm"); 461 469 } elsif ($action =~ /^snapve$/) { 462 pb_snap _v("ve");470 pb_snap2v("ve"); 463 471 } 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"); 465 477 } elsif ($action =~ /^newproj$/) { 466 478 # Nothing to do - already done in pb_env_init … … 777 789 # Do we have additional script to run to prepare the environement for the project ? 778 790 # 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"; 783 796 } 784 797 } … … 827 840 } 828 841 842 sub 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 829 861 sub pb_build2pkg { 830 862 … … 1045 1077 my $tmout = "vmtmout"; 1046 1078 my $path = "vmpath"; 1047 if ( ($cmt eq "vm") || ($cmt eq "VMScript")) {1079 if ($cmt =~ /^VM/) { 1048 1080 $login = "vmlogin"; 1049 1081 $dir = "pbdefdir"; … … 1053 1085 $host = "vmhost"; 1054 1086 $port = "vmport"; 1055 } elsif ( ($cmt eq "ve")|| ($cmt eq "VEScript")) {1087 } elsif ($cmt =~ /^VE/) { 1056 1088 $login = "velogin"; 1057 1089 $dir = "pbdefdir"; … … 1093 1125 ($pbver,$pbtag) = split(/-/,$vertag); 1094 1126 1095 if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {1127 if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) { 1096 1128 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz"; 1097 1129 if ($cmd eq "") { … … 1108 1140 } 1109 1141 1110 if ( ($cmt eq "vm") || ($cmt eq "ve")) {1142 if ($cmt =~ /V[EM]build/) { 1111 1143 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript"; 1112 1144 } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) { 1113 1145 $src="$src $ENV{'PBDESTDIR'}/pbscript"; 1146 } elsif ($cmt =~ /V[EM]test/) { 1147 $src="$src $ENV{'PBDESTDIR'}/pbtest"; 1114 1148 } elsif ($cmt eq "Announce") { 1115 1149 $src="$src $ENV{'PBTMP'}/pbscript"; … … 1137 1171 1138 1172 my $mac; 1139 if ( ($cmt ne "ve") && ($cmt ne "VEScript")) {1173 if ($cmt !~ /^VE/) { 1140 1174 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}"; 1141 1175 # Overwrite account value if passed as parameter … … 1144 1178 } else { 1145 1179 # VE 1146 # Overwrite account value if passed as parameter (typically for setup _ve)1180 # Overwrite account value if passed as parameter (typically for setup2ve) 1147 1181 $mac = $sshlogin->{$ENV{'PBPROJ'}}; 1148 1182 $mac = $pbaccount if (defined $pbaccount); … … 1151 1185 my $tdir; 1152 1186 my $bdir; 1153 if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/) ) {1187 if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/) || ($cmt =~ /V[EM]test/)) { 1154 1188 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/src"; 1155 1189 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) { … … 1157 1191 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/src"; 1158 1192 } 1159 } elsif ( ($cmt eq "vm") || ($cmt eq "ve")) {1193 } elsif ($cmt =~ /V[EM]build/) { 1160 1194 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery"; 1161 1195 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build"; … … 1276 1310 # Useless for VE 1277 1311 my $nport; 1278 if ( ($cmt ne "ve") && ($cmt ne "VEScript")) {1312 if ($cmt !~ /^VE/) { 1279 1313 $nport = $sshport->{$ENV{'PBPROJ'}}; 1280 1314 $nport = "$pbport" if (defined $pbport); … … 1289 1323 # should use a hash instead... 1290 1324 my ($shcmd,$cpcmd,$cptarget,$cp2target); 1291 if ( ($cmt ne "ve") && ($cmt ne "VEScript")) {1325 if ($cmt !~ /^VE/) { 1292 1326 my $keyfile = pb_ssh_get(0); 1293 1327 $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac"; 1294 1328 $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport"; 1295 1329 $cptarget = "$mac:$tdir"; 1296 if ($cmt eq "vm") {1330 if ($cmt =~ /^VM/) { 1297 1331 $cp2target = "$mac:$bdir"; 1298 1332 } … … 1336 1370 1337 1371 # For VE we need to change the owner manually 1338 if ($cmt eq "ve") {1372 if ($cmt =~ /^VE/) { 1339 1373 pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac"); 1340 1374 } 1341 1375 1342 pb_system("$shcmd \"echo \'cd $tdir ; if [ - fpbscript ]; 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/) { 1344 1378 # Get back info on pkg produced, compute their name and get them from the VM 1345 1379 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target"); 1346 1380 # For VE we need to change the owner manually 1347 if ($cmt eq " ve") {1381 if ($cmt eq "VEbuild") { 1348 1382 pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID"); 1349 1383 } … … 1382 1416 } 1383 1417 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n"); 1384 if ((! $vmexist) && ( ($cmt eq "vm") || ($cmt eq "VMScript"))) {1418 if ((! $vmexist) && ($cmt =~ /^VM/)) { 1385 1419 # If in setupvm then takes a snapshot just before halting 1386 1420 if ($snapme != 0) { … … 1402 1436 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)"); 1403 1437 } 1404 if (( ($cmt eq "ve") || ($cmt eq "VEScript")) && ($snapme != 0)) {1438 if (($cmt =~ /^VE/) && ($snapme != 0)) { 1405 1439 ($odir,$over,$oarch) = split(/-/,$v); 1406 1440 my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch"; … … 1427 1461 1428 1462 if (not defined $vm1) { 1429 ($vm,$all) = pb_get _v($vtype);1463 ($vm,$all) = pb_get2v($vtype); 1430 1464 } else { 1431 1465 @$vm = ($vm1); … … 1673 1707 1674 1708 # Return string for date synchro 1675 sub pb_date _v {1709 sub pb_date2v { 1676 1710 1677 1711 my $vtype = shift; … … 1708 1742 1709 1743 my $vtype = shift; 1710 1711 my ($v,$all) = pb_get_v($vtype); 1744 my $action = shift || "build"; 1745 1746 my ($v,$all) = pb_get2v($vtype); 1712 1747 1713 1748 # Send tar files when we do a global generation 1714 pb_build2ssh() if ( $all == 1);1749 pb_build2ssh() if (($all == 1) && ($action eq "build")); 1715 1750 1716 1751 my ($vmexist,$vmpid) = (undef,undef); … … 1738 1773 print SCRIPT "# Setup the variables required for building\n"; 1739 1774 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 } 1743 1781 1744 1782 # VE needs a good /proc … … 1746 1784 print SCRIPT "sudo mount -t proc /proc /proc\n"; 1747 1785 } 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); 1758 1788 print SCRIPT "# Time sync\n"; 1759 1789 print SCRIPT "echo 'setting up date with '"; … … 1774 1804 } 1775 1805 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"; 1776 1813 1777 1814 # 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 1786 1833 if ($vtype eq "ve") { 1787 1834 print SCRIPT "sudo umount /proc\n"; … … 1789 1836 1790 1837 # 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"); 1794 1846 } 1795 1847 … … 1811 1863 # and launch the build through pbscript 1812 1864 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); 1814 1866 } 1815 1867 } … … 1925 1977 # or only some (if all we publish also tar files in addition to pkgs 1926 1978 # 1927 sub pb_get _v {1979 sub pb_get2v { 1928 1980 1929 1981 my $vtype = shift; … … 1953 2005 # pb will take your local public SSH key to access 1954 2006 # the pb account in the VM later on if needed 1955 sub pb_setup _v {2007 sub pb_setup2v { 1956 2008 1957 2009 my $vtype = shift; 1958 2010 1959 my ($vm,$all) = pb_get _v($vtype);2011 my ($vm,$all) = pb_get2v($vtype); 1960 2012 1961 2013 # Script generated … … 1964 2016 foreach my $v (@$vm) { 1965 2017 # Deal with date sync. 1966 my ($ntpline,$dateline) = pb_date _v($vtype,$v);2018 my ($ntpline,$dateline) = pb_date2v($vtype,$v); 1967 2019 1968 2020 # Name of the account to deal with for VM/VE … … 2252 2304 } 2253 2305 2254 # Function to create a snapshot named 'pb' for VMs /VEs2255 sub pb_snap _v {2306 # Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs 2307 sub pb_snap2v { 2256 2308 2257 2309 my $vtype = shift; 2258 2310 2259 my ($vm,$all) = pb_get _v($vtype);2311 my ($vm,$all) = pb_get2v($vtype); 2260 2312 2261 2313 # Script generated
Note:
See TracChangeset
for help on using the changeset viewer.