[pkg-kolab] r1426 - pkg-kolab_testsuite

Mathieu Parent sathieu at alioth.debian.org
Thu Nov 26 22:12:30 UTC 2009


Author: sathieu
Date: 2009-11-26 22:12:30 +0000 (Thu, 26 Nov 2009)
New Revision: 1426

Added:
   pkg-kolab_testsuite/testsuite.ini
Modified:
   pkg-kolab_testsuite/testsuite
Log:
- Configuration in testsuite.ini
- New option --platform
- New command: list-platforms


Modified: pkg-kolab_testsuite/testsuite
===================================================================
--- pkg-kolab_testsuite/testsuite	2009-11-26 21:10:45 UTC (rev 1425)
+++ pkg-kolab_testsuite/testsuite	2009-11-26 22:12:30 UTC (rev 1426)
@@ -40,6 +40,10 @@
 
 Extra step: Log in via ssh
 
+=item I<list-platforms>
+
+Extra step: List available platforms
+
 =back
 
 =head1 OPTIONS
@@ -54,6 +58,10 @@
 
 Prints the manual page and exits.
 
+=item B<--platform>=I<NAME>
+
+Set platform. See also command I<list-platforms>.
+
 =back
 
 =head1 COPYRIGHT AND AUTHORS
@@ -82,40 +90,17 @@
 
 use Getopt::Long;
 use Pod::Usage;
+use Config::IniFiles;
+use Data::Dumper;
 
 use Expect;
 use UUID;
 use Sys::Virt;
 
-my %config = (
-    # general
-    'verbose' => '',
-    'slave_count' => 1,
-    'storagepooldir' => '/var/tmp/pkg-kolab_testsuite',
-    'user' => $< , # $REAL_USER_ID
-    'group' => 'disk',
-    
-    # vm
-    'vmmemory' => "256Mb",
-    'vmsize' => "2Gb",
-    'vmswap' => "128Mb",
-    'vm_install_method' => 'debootstrap', # debootstrap
-    'vmdist' => 'sid',
-    
-    # virt
-    'virt_uri' => 'vbox:///session',
-    'virt_type' => 'vbox',
-    
-    # network
-    'bridge' => 'br0',
-    'dnsdomain' => 'local.tld',
-    
-    # kolab conf
-    'kolab_installation_method' => 'native', # native, openpkg (WIP)
-    'kolab_manager_password' => '12345',
-    'ca_passphrase' => '12345678',
-    
-);
+my $cfg = new Config::IniFiles
+    -file => 'testsuite.ini',
+    -default => 'default';
+my $platform = 'none'; 
 
 #disable buffer
 $| = 1;
@@ -126,11 +111,17 @@
 #=======================================================
 # General functions
 #-------------------------------------------------------
+sub conf
+{
+    my $parameter = shift;
+    return $cfg->val($platform, $parameter); 
+}
+
 sub initial_check
 {
     my $groups = `groups`;
     die 'The current user should be in group "libvirt".' if not $groups =~ /(^| )libvirt($| )/;
-    if($config{'virt_type'} eq 'vbox') {
+    if(conf('virt_type') eq 'vbox') {
         die 'The current user should be in group "disk".' if not $groups =~ /(^| )disk($| )/;
     }
 }
@@ -140,11 +131,11 @@
 {
     my $hosts = "127.0.0.1 localhost\n";
 
-    for(my $domid = 0; $domid<=$config{'slave_count'}; $domid++) {
+    for(my $domid = 0; $domid<=conf('slave_count'); $domid++) {
         my $domname = "kolab_test_slave$domid";
         $domname = "kolab_test_master" if $domid == 0;
         my $domip = domain_ip($domid, $domname);
-        $hosts .= "$domip    $domname.".$config{'dnsdomain'}." $domname\n";
+        $hosts .= "$domip    $domname.".conf('dns_domain')." $domname\n";
         
     }
     return $hosts;
@@ -157,12 +148,12 @@
     my $command = shift || undef;
     if(defined($command)) {
         system('ssh',
-            '-i', $config{'storagepooldir'}.'/key',
+            '-i', conf('storage_pool_dir').'/key',
             "root\@$domip",
             $command);
     } else {
         system('ssh',
-            '-i', $config{'storagepooldir'}.'/key',
+            '-i', conf('storage_pool_dir').'/key',
             "root\@$domip");
     }
 }
@@ -225,7 +216,7 @@
     my $domip = domain_ip($domid, $domname);
     
     #$Expect::Log_Stdout = 0;
-    return Expect->spawn("ssh -i '".$config{'storagepooldir'}."/key' root\@$domip")
+    return Expect->spawn("ssh -i '".conf('storage_pool_dir')."/key' root\@$domip")
 }
 
 #=======================================================
@@ -236,14 +227,14 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $size = $config{'vmsize'};
-    my $memory = $config{'vmmemory'};
-    my $swap = $config{'vmswap'};
-    my $dist = $config{'vmdist'};
-    my $storagepooldir = $config{'storagepooldir'};
+    my $size = conf('vm_size');
+    my $memory = conf('vm_memory');
+    my $swap = conf('vm_swap');
+    my $dist = conf('vm_dist');
+    my $storagepooldir = conf('storage_pool_dir');
     
     print "* Bootstraping:\n";
-    if($config{'vm_install_method'} eq 'debootstrap') {
+    if(conf('vm_install_method') eq 'debootstrap') {
         system("sudo xen-create-image --hostname $domname ".
             "--ip ".domain_ip($domid, $domname)." ".
             "--dist $dist --install-method debootstrap ".
@@ -253,9 +244,9 @@
             "--force ".
             "--cache --output '$storagepooldir' --no-hosts ");
     } else {
-        die 'Unknow vm_install_method: '.$config{'vm_install_method'};
+        die 'Unknow vm_install_method: '.conf('vm_install_method');
     }
-    system("sudo chown -R ".$config{'user'}.":".$config{'group'}." '$storagepooldir'");
+    system("sudo chown -R ".conf('user').":".conf('group')." '$storagepooldir'");
 }
 
 #-------------------------------------------------------
@@ -264,7 +255,7 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $storagepooldir = $config{'storagepooldir'};
+    my $storagepooldir = conf('storage_pool_dir');
 
     print "* Preparing chroot";
     system("sudo mkdir -p '$storagepooldir/domains/$domname/disk'");
@@ -278,7 +269,7 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $storagepooldir = $config{'storagepooldir'};
+    my $storagepooldir = conf('storage_pool_dir');
     
     print "* Releasing chroot";
     system("sudo umount '$storagepooldir/domains/$domname/disk'");
@@ -292,7 +283,7 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $storagepooldir = $config{'storagepooldir'};
+    my $storagepooldir = conf('storage_pool_dir');
     my $CHROOT = "$storagepooldir/domains/$domname/disk";
     my $DEVICE = '/dev/loop0';
     
@@ -335,11 +326,11 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $storagepooldir = $config{'storagepooldir'};
+    my $storagepooldir = conf('storage_pool_dir');
     
     domain_pre_chroot($domid, $domname);
     
-    if($config{'virt_type'} eq 'vbox') {
+    if(conf('virt_type') eq 'vbox') {
         domain_make_bootable($domid, $domname);
     }
 
@@ -359,7 +350,7 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $storagepooldir = $config{'storagepooldir'};
+    my $storagepooldir = conf('storage_pool_dir');
     
     domain_pre_chroot($domid, $domname);
     
@@ -375,11 +366,11 @@
     my $domid = shift;
     my $domname = shift;
     
-    my $size = $config{'vmsize'};
-    my $memory = $config{'vmmemory'};
-    my $swap = $config{'vmswap'};
-    my $storagepooldir = $config{'storagepooldir'};
-    my $bridge = $config{'bridge'};
+    my $size = conf('vm_size');
+    my $memory = conf('vm_memory');
+    my $swap = conf('vm_swap');
+    my $storagepooldir = conf('storage_pool_dir');
+    my $bridge = conf('bridge');
 
     print "* Flushing MAC adress udev rule:\n";
     domain_pre_chroot($domid, $domname);
@@ -387,7 +378,7 @@
     domain_post_chroot($domid, $domname);
     
     print "* Preparing:\n";
-    if($config{'virt_type'} eq 'vbox') {
+    if(conf('virt_type') eq 'vbox') {
         #release
         system("VBoxManage unregistervm '$domname' --delete");
         system("VBoxManage closemedium disk '$storagepooldir/domains/$domname/disk.vmdk'");
@@ -433,11 +424,11 @@
     </devices>
     </domain>";
         $test_domains{$domid} = $vmm->define_domain($xml);
-    } elsif($config{'virt_type'} eq 'xen') {
+    } elsif(conf('virt_type') eq 'xen') {
         $test_domains{$domid} = $vmm->get_domain_by_name($domname);
         #TODO: test
     } else {
-        print "Unsupported virt_type: ".$config{'virt_type'}."\n";
+        print "Unsupported virt_type: ".conf('virt_type')."\n";
         exit 1;
     }
     print "* Starting:\n";
@@ -458,14 +449,14 @@
 EOF");
     # ====
     print "* Preparing packages:\n";
-    if($config{'kolab_installation_method'} eq 'native') {
+    if(conf('kolab_installation_method') eq 'native') {
         remote_command($domip, 'cat <<EOF > /etc/apt/sources.list.d/kolab.list
 #kolab
 deb http://pkg-kolab.alioth.debian.org/packages UNRELEASED/
 EOF');
         remote_command($domip, 'apt-get -qq update');
         print "* Following https://wiki.kolab.org/index.php/Debian_-_Administrators_-_Kolab_Installation\n";
-    } elsif($config{'kolab_installation_method'} eq 'openpkg') {
+    } elsif(conf('kolab_installation_method') eq 'openpkg') {
         print "* Following http://wiki.kolab.org/index.php/Kolab2_Installation_-_Source\n";
         print "* Download a snapshot\n";
         remote_command($domip, 'mkdir /tmp/kolabtemp');
@@ -475,14 +466,14 @@
         remote_command($domip, 'gpg --verify SHA1SUMS.sig');
         remote_command($domip, 'sha1sum -c SHA1SUMS');
     } else {
-        die 'Unknow kolab_installation_method: '.$config{'kolab_installation_method'};
+        die 'Unknow kolab_installation_method: '.conf('kolab_installation_method');
     }
     
     # ====
     print "* Installing:\n";
-    if($config{'kolab_installation_method'} eq 'native') {
+    if(conf('kolab_installation_method') eq 'native') {
         remote_command($domip, 'DEBIAN_FRONTEND=noninteractive apt-get -y --allow-unauthenticated install kolabd postfix slapd');
-    } elsif($config{'kolab_installation_method'} eq 'openpkg') {
+    } elsif(conf('kolab_installation_method') eq 'openpkg') {
         remote_command($domip, 'mkdir /kolab');
         print "* Prerequisites: bison, flex, gcc, make, libtool, automake and autoconf\n";
         remote_command($domip, 'DEBIAN_FRONTEND=noninteractive apt-get -y install bison flex gcc make libtool automake autoconf');
@@ -490,11 +481,11 @@
         print "* install-kolab.sh\n";
         remote_command($domip, 'cd /tmp/kolabtemp && sh install-kolab.sh 2>&1 | tee /root/kolab-install.log');
     } else {
-        die 'Unknow kolab_installation_method: '.$config{'kolab_installation_method'};
+        die 'Unknow kolab_installation_method: '.conf('kolab_installation_method');
     }
     
     # ====
-    if($config{'kolab_installation_method'} eq 'native') {
+    if(conf('kolab_installation_method') eq 'native') {
         print "* Stopping services:\n";
         remote_command($domip, '/etc/init.d/apache2 stop');
         remote_command($domip, '/etc/init.d/kolabd stop');
@@ -520,7 +511,7 @@
                     $fh->send("kolab_bootstrap -b\n");
                     $step++;
                     return exp_continue;
-                } elsif($step == 17 + $config{'slave_count'}) {
+                } elsif($step == 17 + conf('slave_count')) {
                     $fh->send("exit\n");
                     $step++;
                 } else {
@@ -542,7 +533,7 @@
             },
         ],
         [
-            qr'Please enter Hostname including Domain Name \(e.g. thishost.domain.tld\) \['.$domname.".".$config{'dnsdomain'}.'\]: $',
+            qr'Please enter Hostname including Domain Name \(e.g. thishost.domain.tld\) \['.$domname.".".conf('dns_domain').'\]: $',
             sub {
                 my $fh = shift;
                 $step++ if $step == 1; #Confirmation is skipped if "LDAP repository is empty"
@@ -575,7 +566,7 @@
         # >> common
         # << master only
         [
-            qr'Please enter your Maildomain - if you do not know your mail domain use the fqdn from above \['.$config{'dnsdomain'}.'\]: $',
+            qr'Please enter your Maildomain - if you do not know your mail domain use the fqdn from above \['.conf('dns_domain').'\]: $',
             sub {
                 my $fh = shift;
                 if( $step == 4 ) {
@@ -605,7 +596,7 @@
             sub {
                 my $fh = shift;
                 if( $step == 6 ) {
-                    $fh->send($config{'kolab_manager_password'}."\n");
+                    $fh->send(conf('kolab_manager_password')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -617,12 +608,12 @@
             qr'Enter fully qualified hostname of slave kolab server e.g. thishost.domain.tld \[empty when done\]: $',
             sub {
                 my $fh = shift;
-                if( ($step >= 7) and ($step < 7 + $config{'slave_count'})) {
-                    $fh->send("kolab_test_slave".($step-6).".".$config{'dnsdomain'}."\n");
+                if( ($step >= 7) and ($step < 7 + conf('slave_count'))) {
+                    $fh->send("kolab_test_slave".($step-6).".".conf('dns_domain')."\n");
                     $step++;
                     return exp_continue;
                 }
-                if($step == 7 + $config{'slave_count'}) {
+                if($step == 7 + conf('slave_count')) {
                     $fh->send("\n"); #empty when done
                     $step++;
                     return exp_continue;
@@ -635,7 +626,7 @@
             qr'Do you want to create CA and certificates \[y\] \(y/n\): $',
             sub {
                 my $fh = shift;
-                if( $step == 8 + $config{'slave_count'} ) {
+                if( $step == 8 + conf('slave_count') ) {
                     $fh->send("y\n");
                     $step++;
                     return exp_continue;
@@ -648,7 +639,7 @@
             qr'Enter organization name \[Kolab\]: $',
             sub {
                 my $fh = shift;
-                if( $step == 9 + $config{'slave_count'} ) {
+                if( $step == 9 + conf('slave_count') ) {
                     $fh->send("\n");
                     $step++;
                     return exp_continue;
@@ -661,7 +652,7 @@
             qr'Enter organizational unit \[Test-CA\]: $',
             sub {
                 my $fh = shift;
-                if( $step == 10 + $config{'slave_count'} ) {
+                if( $step == 10 + conf('slave_count') ) {
                     $fh->send("\n");
                     $step++;
                     return exp_continue;
@@ -674,7 +665,7 @@
             qr'CA certificate filename \(or enter to create\)\s$',
             sub {
                 my $fh = shift;
-                if( $step == 11 + $config{'slave_count'} ) {
+                if( $step == 11 + conf('slave_count') ) {
                     $fh->send("\n");
                     $step++;
                     return exp_continue;
@@ -687,8 +678,8 @@
             qr'^Enter PEM pass phrase:$'m,
             sub {
                 my $fh = shift;
-                if( $step == 12 + $config{'slave_count'} ) {
-                    $fh->send($config{'ca_passphrase'}."\n");
+                if( $step == 12 + conf('slave_count') ) {
+                    $fh->send(conf('ca_passphrase')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -700,8 +691,8 @@
             qr'^Verifying - Enter PEM pass phrase:$'m,
             sub {
                 my $fh = shift;
-                if( $step == 13 + $config{'slave_count'} ) {
-                    $fh->send($config{'ca_passphrase'}."\n");
+                if( $step == 13 + conf('slave_count') ) {
+                    $fh->send(conf('ca_passphrase')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -716,7 +707,7 @@
             sub {
                 my $fh = shift;
                 if( $step == 4 ) {
-                    $fh->send("ldaps://kolab_test_master.".$config{'dnsdomain'}."\n");
+                    $fh->send("ldaps://kolab_test_master.".conf('dns_domain')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -742,7 +733,7 @@
             sub {
                 my $fh = shift;
                 if( $step == 6 ) {
-                    $fh->send($config{'kolab_manager_password'}."\n");
+                    $fh->send(conf('kolab_manager_password')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -758,7 +749,7 @@
                 my $fh = shift;
                 if( $step == 7 ) {
                     $fh->send("y\n");
-                    $step = 14 + $config{'slave_count'};
+                    $step = 14 + conf('slave_count');
                     return exp_continue;
                 } else {
                     print "Step is $step (should be 7)\n";
@@ -773,8 +764,8 @@
             qr'Enter pass phrase for /etc/kolab/ca/private/cakey.pem:$',
             sub {
                 my $fh = shift;
-                if( $step == 14 + $config{'slave_count'} ) {
-                    $fh->send($config{'ca_passphrase'}."\n");
+                if( $step == 14 + conf('slave_count') ) {
+                    $fh->send(conf('ca_passphrase')."\n");
                     $step++;
                     return exp_continue;
                 } else {
@@ -786,7 +777,7 @@
             qr'Sign the certificate\? \[y/n\]:$',
             sub {
                 my $fh = shift;
-                if( $step == 15 + $config{'slave_count'} ) {
+                if( $step == 15 + conf('slave_count') ) {
                     $fh->send("y\n");
                     $step++;
                     return exp_continue;
@@ -799,7 +790,7 @@
             qr'1 out of 1 certificate requests certified, commit\? \[y/n\]$',
             sub {
                 my $fh = shift;
-                if( $step == 16 + $config{'slave_count'} ) {
+                if( $step == 16 + conf('slave_count') ) {
                     $fh->send("y\n");
                     $step++;
                     return exp_continue;
@@ -825,7 +816,7 @@
 
     # ====
     print "* Starting services:\n";
-    if($config{'kolab_installation_method'} eq 'native') {
+    if(conf('kolab_installation_method') eq 'native') {
         remote_command($domip, '/etc/init.d/amavis start #optionally');
         remote_command($domip, '/etc/init.d/slapd start');
         remote_command($domip, '/etc/init.d/saslauthd start');
@@ -833,12 +824,12 @@
         remote_command($domip, '/etc/init.d/kolab-cyrus start');
         remote_command($domip, '/etc/init.d/kolabd start');
         remote_command($domip, '/etc/init.d/apache2 start');
-    } elsif($config{'kolab_installation_method'} eq 'openpkg') {
+    } elsif(conf('kolab_installation_method') eq 'openpkg') {
         remote_command($domip, '/kolab/bin/openpkg rc all start');
     }
 
     # ====
-    if($config{'kolab_installation_method'} eq 'native') {
+    if(conf('kolab_installation_method') eq 'native') {
         print "* Installing PHP Unit:\n";
         remote_command($domip, 'apt-get -qy install phpunit');
     }
@@ -853,7 +844,7 @@
 
     # raising memory limit
     remote_command($domip, 'echo memory_limit = 64M > /etc/php5/conf.d/memory_limit.ini');
-    remote_command($domip, "testsaslauthd -u manager -p '".$config{'kolab_manager_password'}."'");
+    remote_command($domip, "testsaslauthd -u manager -p '".conf('kolab_manager_password')."'");
     test_tap($domid, $domname, 'phpunit --tap '.
         '/usr/share/php/tests/Kolab_Filter/Horde/Kolab/Filter/AllTests.php');
     test_tap($domid, $domname, 'phpunit --tap '.
@@ -874,8 +865,8 @@
 # Main
 #-------------------------------------------------------
 initial_check();
-$vmm = Sys::Virt->new(address => $config{'virt_uri'});
-system("mkdir -p '".$config{'storagepooldir'}."'");
+$vmm = Sys::Virt->new(address => conf('virt_uri'));
+system("mkdir -p '".conf('storage_pool_dir')."'");
 
 #-------------------------------------------------------
 my $o_help = 0;
@@ -883,7 +874,7 @@
 my $result = GetOptions(
     'help|?' => \$o_help,
     'man' => \$o_man,
-    'verbose!' => $config{'verbose'},
+    'platform=s' => \$platform,
     '<>' => \&process,
     ) or pod2usage(2);
 
@@ -896,12 +887,28 @@
 {
     my $action = shift;
     
+    #Platform:
+    if($action eq 'list-platforms') {
+        print join("\n", $cfg->Sections)."\n";
+        exit 0;
+    }
+    if($platform eq 'none') {
+        print "Missing option: --platform\n";
+        pod2usage(-exitstatus => 0, -verbose => 1);
+    }
+    if(!$cfg->SectionExists($platform)) {
+        print "Platform does'nt exists: $platform\n";
+        pod2usage(-exitstatus => 0, -verbose => 1);
+    }
+    
+    #SSH
     if ($action eq 'preboot_install') {
         #generate common ssh key
-        system("ssh-keygen -f '".$config{'storagepooldir'}."/key' -N ''");
+        system("ssh-keygen -f '".conf('storage_pool_dir')."/key' -N ''");
     }
     
-    for(my $domid = 0; $domid<=$config{'slave_count'}; $domid++) {
+    #Main loop
+    for(my $domid = 0; $domid<=conf('slave_count'); $domid++) {
         my $domname = "kolab_test_slave$domid";
         $domname = "kolab_test_master" if $domid == 0;
         print "Action $action for domain $domname:\n";

Added: pkg-kolab_testsuite/testsuite.ini
===================================================================
--- pkg-kolab_testsuite/testsuite.ini	                        (rev 0)
+++ pkg-kolab_testsuite/testsuite.ini	2009-11-26 22:12:30 UTC (rev 1426)
@@ -0,0 +1,37 @@
+[default]
+; general
+slave_count=1
+storage_pool_dir=/var/tmp/pkg-kolab_testsuite
+user=mathieu;$<  # $REAL_USER_ID
+group=disk
+
+; vm
+vm_memory=256Mb
+vm_size=2Gb
+vm_swap=128Mb
+vm_install_method=debootstrap; debootstrap
+vm_dist=sid
+
+; virt
+virt_uri=vbox:///session
+virt_type=vbox
+
+; network
+bridge=br0
+dns_domain=local.tld
+
+; kolab conf
+kolab_installation_method=native; native openpkg
+kolab_manager_password=12345
+ca_passphrase=12345678
+
+[debian-sid-native]
+vm_install_method=debootstrap
+vm_dist=sid
+kolab_installation_method=native
+
+[debian-sid-openpkg]
+vm_install_method=debootstrap
+vm_dist=sid
+kolab_installation_method=openpkg
+




More information about the pkg-kolab-devel mailing list