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

[Xen-devel] [PATCH 2/3] Add nested testcase of installing L2 guest VM.



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

Adding <ts-nested-L2-debian-install> which is used for installing L2
guest VM inside L1 guest VM.

---
 sg-run-job                  |    1 +
 ts-nested-L2-debian-install |  148 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100755 ts-nested-L2-debian-install

diff --git a/sg-run-job b/sg-run-job
index 0898113..b5f41f6 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -291,6 +291,7 @@ proc run-job/test-pair {} {
 proc need-hosts/test-nested {} {return host}
 proc run-job/test-nested {} {
     run-ts . = ts-nested-L1-debian-install
+    run-ts . = ts-nested-L2-debian-install
     run-ts . = ts-guest-destroy + host nested
 }
 
diff --git a/ts-nested-L2-debian-install b/ts-nested-L2-debian-install
new file mode 100755
index 0000000..dd68461
--- /dev/null
+++ b/ts-nested-L2-debian-install
@@ -0,0 +1,148 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2013 Citrix Inc.
+# Copyright (C) 2014 Intel Inc.
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict qw(vars);
+use DBI;
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our ($whhost,$gn,$arch) = @ARGV;
+
+my $L1_IP = &get_VM_IP($r{'nested_ether'});
+$whhost ||= "host=$L1_IP";
+$gn ||= 'nested';
+$arch ||= 'amd64';
+our $ho= selecthost($whhost);
+
+our $ram_mb=    512;
+our $swap_mb=  1000;
+our $disk_mb= 5000;
+our $guesthost= "$gn.guest.osstest";
+our $cfg_xend= "/etc/xen/$guesthost.cfg";
+my $L2_MAC = select_ether($ho,"L2_ether");
+
+sub prep () {
+    target_install_packages_norec($ho, qw(xen-tools));
+}
+
+sub ginstall () {
+    my $archarg= defined($arch) ? "--arch=$arch" : '';
+    my $suite= "$c{DebianSuite}";
+    my $gsuite= defined($suite) ? "--dist=$suite" : '';
+
+    my $kernver ||= target_cmd_output_root($ho, 'uname -r');
+    my $kernpath = "/boot/vmlinuz-$kernver";
+    my $initrd ||= "/boot/initrd.img-$kernver";
+    if (!$kernpath) {
+       die "$kernpath $?";
+    }
+    if (!$initrd) {
+       $initrd = $kernpath;
+       $initrd =~ s,/vmlinuz-,/initrd.img-, or die "$initrd ?";
+    }
+    my $initrd_opt = $initrd eq 'none' ? '' : "--initrd=$initrd";
+
+    if ($ho->{Suite} =~ m/lenny|squeeze|wheezy/) {
+        target_cmd_root($ho, <<END, 10);
+            set -e
+            # xen-create-image requires this to exists (see Debian bug #732456)
+            # even though it is otherwise quite happy on a pure xl system.
+            if [ ! -f /etc/xen/xend-config.sxp ] ; then
+                # xen-create-image checks for these and warns if they don't
+                # exist or are set to "dummy"
+                echo "(vif-script osstest)" >>/etc/xen/xend-config.sxp
+                echo "(network-script osstest)" >>/etc/xen/xend-config.sxp
+            fi
+END
+    }
+    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
+}
+
+
+sub start () {
+    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();
+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®.