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

Re: [Xen-devel] [OSSTEST PATCH 3/4] Add nested testcase of installing L2 guest VM




> -----Original Message-----
> From: Wei Liu [mailto:wei.liu2@xxxxxxxxxx]
> Sent: Thursday, December 11, 2014 7:44 PM
> To: Pang, LongtaoX
> Cc: xen-devel@xxxxxxxxxxxxx; Ian.Jackson@xxxxxxxxxxxxx;
> Ian.Campbell@xxxxxxxxxx; wei.liu2@xxxxxxxxxx; Hu, Robert; Zheng, Di
> Subject: Re: [OSSTEST PATCH 3/4] Add nested testcase of installing L2 guest VM
> 
> On Wed, Dec 10, 2014 at 04:07:39PM +0800, longtao.pang wrote:
> > 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 e513bd1..85f7b22 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-debian-hvm-install + host + nested + nested_L1
> >      run-ts . = ts-xen-install + host + nested + nested_build
> > +    run-ts . = ts-debian-install + host + nested + amd64 + nested_L2
> > +    run-ts . = ts-guest-destroy + host nested
> 
> It would also be possible to run ts-debian-hvm-install as L2. That would suite
> this test case better -- it's testing nested HVM.
> 
> There's no need to remove the PV test case though.

[Pang, LongtaoX] 
[Pang, LongtaoX] Thanks for checking. We used ts-debian-hvm-install for 
installing L1 HVM guest via ISO Image, 
because we will build XEN, XEN-Tools and dom0 kernel inside it, and then we 
will install L2 guest inside L1. 
But, L2 guest is just a native OS, so we think use ts-debian-install is enough 
for installing L2 and will make it easy to control.

> 
> >  }
> >
> >  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;
> > -
> 
> Stray blank line.
> 
> >  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";
> > +        }
> > +    }
> 
> To be honest, this looks convoluted. Special casing needs better explanation.

[Pang, LongtaoX] Thanks for checking, I will try to adjust it.

> 
> >      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
> 
> As far as I can tell, the only difference is a few variables.
> 
> You can set up variables in
> 
>   if ($nested_L2) {
>     var = foo;
>   } else {
>     var = bar;
>   }
>   target_cmd_root($ho,  var ... );
> 
> Just like you did in previous hunk. Please add in some comments where
> necessary.


[Pang, LongtaoX] Thanks for checking, I will try to modify this.

> 
> >  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"); }
> 
> I think we already have a guest start script?
> 
> This hunk is going to break easily if we're more flexible about the toolstack 
> (we
> already have a partially working libvirt test case).
>

[Pang, LongtaoX] Thanks for checking, I have tried to use ts-guest-start to 
start guest, but it maybe not suit for here, 
because some function and parameters in the script is not necessary here, If we 
use the script we will modify it again and may impact other test jobs. 
So I create a function here to start L2 guest.
 
> > +
> > +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");
> > +    }
> > +}
> > +
> 
> target_ping_check_{up,down} may be suitable?


[Pang, LongtaoX] Thanks for checking, I will try to modify this.

> 
> 
> Wei.
> 
> 
> > +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®.