From: "longtao.pang" Subject: [PATCH 2/3] Add nested testcase of installing L2 guest VM. Date: Mon, 20 Oct 2014 09:04:12 +0800 Message-ID: <1413767053-22872-3-git-send-email-longtaox.pang@intel.com> References: <1413767053-22872-1-git-send-email-longtaox.pang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xg1OY-0000Nh-Fk for xen-devel@lists.xenproject.org; Mon, 20 Oct 2014 01:04:22 +0000 In-Reply-To: <1413767053-22872-1-git-send-email-longtaox.pang@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian.Jackson@eu.citrix.com Cc: robert.hu@intel.com, longtaox.pang@intel.com, wei.liu2@citrix.com, Ian.Campbell@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org From: "longtao.pang" Adding 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 . + +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, <>/etc/xen/xend-config.sxp + echo "(network-script osstest)" >>/etc/xen/xend-config.sxp + fi +END + } + target_cmd_root($ho, <{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