[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 3/4] Add nested test case of installing L2 guest VM



From: "longtao.pang" <longtaox.pang@xxxxxxxxx>

This patch is used for installing L2 guest VM inside L1 guest VM.

---
 sg-run-job        |    2 +
 ts-debian-install |  166 +++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 132 insertions(+), 36 deletions(-)

diff --git a/sg-run-job b/sg-run-job
index a4c0de1..7c0c6ca 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -292,6 +292,8 @@ proc need-hosts/test-nested {} {return host}
 proc run-job/test-nested {} {
     run-ts . = ts-nested-L1-debian-install-part1
     run-ts . = ts-nested-L1-debian-install-part2
+    run-ts . = ts-debian-install + host + nested + amd64 + nested_L2
+    run-ts . = ts-guest-destroy + host nested
 }
 
 proc test-guest-migr {g} {
diff --git a/ts-debian-install b/ts-debian-install
index 58ea743..2ca54e8 100755
--- a/ts-debian-install
+++ b/ts-debian-install
@@ -22,41 +22,61 @@ use Osstest::TestSupport;
 
 tsreadconfig();
 
-our ($whhost,$gn) = @ARGV;
-$whhost ||= 'host';
-$gn ||= 'debian';
+our ($whhost,$gn,$arch,$nested_L2) = @ARGV;
+$nested_L2 ||= '';
 
-our $ho= selecthost($whhost);
+if($nested_L2 eq 'nested_L2') {
+    my $L1_IP = &get_VM_IP($r{'nested_ether'});
+    $whhost = "host=$L1_IP";
+    $gn ||= 'nested';
+    $arch ||= 'amd64';
+} else {
+    $whhost ||= 'host';
+    $gn ||= 'debian';  
+}
 
+our $ho= selecthost($whhost);
 our $ram_mb=    512;
 our $swap_mb=  1000;
 our $disk_mb= 10000;
-
 our $guesthost= "$gn.guest.osstest";
 our $gho;
+our $L2_MAC = select_ether($ho,"L2_ether");
 
 sub prep () {
     target_install_packages_norec($ho, qw(lvm2 xen-tools));
-
-    $gho= prepareguest($ho, $gn, $guesthost, 22,
-                       $swap_mb + $disk_mb + 2,
-                       40);
-    target_cmd_root($ho, "umount $gho->{Lvdev} ||:");
+    unless($nested_L2 eq 'nested_L2') {
+       $gho= prepareguest($ho, $gn, $guesthost, 22,
+                          $swap_mb + $disk_mb + 2,
+                          40);
+       target_cmd_root($ho, "umount $gho->{Lvdev} ||:");
+    }
 }
 
 sub ginstall () {
-    my $arch= $r{"$gho->{Guest}_arch"};
+    my $gsuite;
+    my $kernpath;
+    my $initrd;
+    my $kernver;
+    if($nested_L2 eq 'nested_L2'){
+        my $suite= "$c{DebianSuite}";
+        $gsuite= defined($suite) ? "--dist=$suite" : '';
+        $kernver ||= target_cmd_output_root($ho, 'uname -r');
+        $kernpath = "/boot/vmlinuz-$kernver";
+        $initrd ||= "/boot/initrd.img-$kernver";
+    } else {
+        my $arch= $r{"$gho->{Guest}_arch"};
+        $gsuite= guest_var($gho,'suite',$c{GuestDebianSuite});
+        $kernpath = guest_var($gho,'kernel_path',$r{xen_kernel_path});
+        $initrd = guest_var($gho,'initrd_path',$r{xen_initrd_path});
+        if (!$kernpath) {
+           $kernver= guest_var($gho,'kernel_ver',$r{xen_kernel_ver});
+            $kernver ||= target_cmd_output($ho, 'uname -r');
+           $kernpath = "/boot/vmlinuz-$kernver";
+           $initrd ||= "/boot/initrd.img-$kernver";
+        } 
+    } 
     my $archarg= defined($arch) ? "--arch $arch" : '';
-    my $gsuite= guest_var($gho,'suite',$c{GuestDebianSuite});
-
-    my $kernpath = guest_var($gho,'kernel_path',$r{xen_kernel_path});
-    my $initrd = guest_var($gho,'initrd_path',$r{xen_initrd_path});
-    if (!$kernpath) {
-       my $kernver= guest_var($gho,'kernel_ver',$r{xen_kernel_ver});
-       $kernver ||= target_cmd_output($ho, 'uname -r');
-       $kernpath = "/boot/vmlinuz-$kernver";
-       $initrd ||= "/boot/initrd.img-$kernver";
-    }
     if (!$initrd) {
        $initrd = $kernpath;
        $initrd =~ s,/vmlinuz-,/initrd.img-, or die "$initrd ?";
@@ -76,23 +96,97 @@ sub ginstall () {
             fi
 END
     }
-    target_cmd_root($ho, <<END, 2000);
-        xen-create-image \\
-            --dhcp --mac $gho->{Ether} \\
-            --memory ${ram_mb}Mb --swap ${swap_mb}Mb \\
-            --dist $gsuite \\
-            --mirror http://$c{DebianMirrorHost}/$c{DebianMirrorSubpath} \\
-            --hostname $gho->{Name} \\
-            --lvm $gho->{Vg} --force \\
-            --kernel $kernpath \\
-            --genpass 0 --password xenroot \\
-            $initrd_opt \\
-            $archarg
+    if($nested_L2 eq 'nested_L2') {
+        target_cmd_root($ho, <<END, 2000);
+            xen-create-image \\
+                --dhcp --mac=$L2_MAC \\
+                --size=${disk_mb}Mb --memory=${ram_mb}Mb --swap=${swap_mb}Mb \\
+                --mirror=http://$c{DebianMirrorHost}/$c{DebianMirrorSubpath} \\
+                --hostname $guesthost \\
+                --dir=/testnested \\
+                --kernel=$kernpath \\
+                --genpass 0 --password xenroot \\
+                $initrd_opt \\
+                $gsuite \\
+                $archarg
+END
+    } else {
+        target_cmd_root($ho, <<END, 2000);
+            xen-create-image \\
+                --dhcp --mac $gho->{Ether} \\
+                --memory ${ram_mb}Mb --swap ${swap_mb}Mb \\
+                --dist $gsuite \\
+                --mirror http://$c{DebianMirrorHost}/$c{DebianMirrorSubpath} \\
+                --hostname $gho->{Name} \\
+                --lvm $gho->{Vg} --force \\
+                --kernel $kernpath \\
+                --genpass 0 --password xenroot \\
+                $initrd_opt \\
+                $archarg
 END
-    my $cfg_xend= "/etc/xen/$gho->{Name}.cfg";
-    store_runvar("$gho->{Guest}_cfgpath", $cfg_xend);
-    store_runvar("$gho->{Guest}_swap_lv", "$gho->{Name}-swap");
+        my $cfg_xend= "/etc/xen/$gho->{Name}.cfg";
+        store_runvar("$gho->{Guest}_cfgpath", $cfg_xend);
+        store_runvar("$gho->{Guest}_swap_lv", "$gho->{Name}-swap");
+    }
+}
+
+sub start () {
+    my $cfg_xend= "/etc/xen/$guesthost.cfg";
+    my $cmd= toolstack()->{Command}." create ".$cfg_xend;
+    target_cmd_root($ho, $cmd, 30);
+    my $domains = target_cmd_output_root($ho, toolstack()->{Command}." list");
+    logm("guest state is\n$domains");
+}
+
+sub get_VM_IP {
+    my $IP;
+    my $leases;
+    my $dhcpf = $c{HostProp_DhcpWatchMethod};
+    my @meth = split /\s+/, $dhcpf;
+    if ($dhcpf =~ m,/,) {
+    $leases= new IO::File $meth[2], 'r';
+        if (!defined $leases) { return "open $meth[2]: $!"; }
+    } else {
+        $leases= new IO::Socket::INET(PeerAddr => $meth[2]);
+    }
+    while (<$leases>) {
+        my @lines = <$leases>;
+        my @newlines = reverse(@lines);
+        for(my $i=0;$i<@newlines;$i++) {
+            next if($newlines[$i] !~ /$_[0]/);
+            for($i;$i<@newlines;$i++) {
+                next if ($newlines[$i] !~ /^lease\s+(\d+\.\d+\.\d+\.\d+)\s*/);
+                $IP = $1;
+                return $IP;
+                }
+        last;
+        }
+    }
+}
+
+sub check_VM_up {
+    my ($g_ip) = @_;
+    my $ping_out = `ping -c 5 $g_ip 2>&1`;
+    if($ping_out =~ m/5 received/) {
+        logm("$guesthost is up and ping is OK!");
+    } else {
+        logm("Failed to boot up $guesthost");
+    }
+}
+
+sub stop_guest {
+    logm("shutdown L2 guest!");
+    target_cmd_root($ho,toolstack()->{Command}." shutdown -w ".$guesthost,100);
 }
 
 prep();
 ginstall();
+if($nested_L2 eq 'nested_L2') { 
+    start();
+    logm("waiting for 15's to boot up L2 guest!");
+    sleep(15);
+    my $L2_IP = get_VM_IP("$L2_MAC");
+    logm("L2 guest's IP is $L2_IP and try to ping it!");
+    check_VM_up($L2_IP);
+    stop_guest();
+}
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.