[PATCH tck 3/6] Add ability to setup NIC when creating guest XML

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

 



Enhance the 'generic_domain' method to allow it to setup
guest NICs, defaulting to the default network, but also
allowing use of vepa to a host NIC.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 conf/default.cfg                  |  6 ++++++
 lib/Sys/Virt/TCK.pm               | 39 ++++++++++++++++++++++++++++++++-------
 lib/Sys/Virt/TCK/DomainBuilder.pm | 13 +++++++------
 3 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/conf/default.cfg b/conf/default.cfg
index 0da118c..209e40d 100644
--- a/conf/default.cfg
+++ b/conf/default.cfg
@@ -178,3 +178,9 @@ host_block_devices = (
 #  }
 # Can list more than on block device if many are available
 )
+
+# List of host NIC devices that the test suite can screw
+# around with for testing purposes
+host_network_devices = (
+#   eth0
+)
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index 9981c0f..f8fa75d 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -851,6 +851,7 @@ sub generic_domain {
     my $name = exists $params{name} ? $params{name} : "tck";
     my $ostype = exists $params{ostype} ? $params{ostype} : "hvm";
     my $fullos = exists $params{fullos} ? $params{fullos} : 0;
+    my $netmode = exists $params{netmode} ? $params{netmode} : undef;
 
     my $caps = Sys::Virt::TCK::Capabilities->new(xml => $self->conn->get_capabilities);
 
@@ -859,18 +860,35 @@ sub generic_domain {
     $container = $self->best_container_domain($caps)
 	unless $ostype && $ostype ne "exe";
 
+    my $b;
     if ($container) {
 	die "Full provisioned OS not supported with containers yet" if $fullos;
 
-	return $self->generic_container_domain(name => $name,
-					       caps => $caps,
-					       domain => $container);
-    } else {
-	return $self->generic_machine_domain(name => $name,
+	$b = $self->generic_container_domain(name => $name,
 					     caps => $caps,
-					     ostype => $ostype,
-					     fullos => $fullos);
+					     domain => $container);
+    } else {
+	$b = $self->generic_machine_domain(name => $name,
+					   caps => $caps,
+					   ostype => $ostype,
+					   fullos => $fullos);
+    }
+    if ($netmode) {
+	if ($netmode eq "vepa") {
+	    $b->interface(type => "direct",
+			  source => "default",
+			  mac => "52:54:00:11:11:11",
+			  dev => $self->get_host_network_device(),
+			  mode => "vepa",
+			  virtualport => "802.1Qbg");
+	} else {
+	    $b->interface(type => "network",
+			  source => "default",
+			  mac => "52:54:00:11:11:11",
+			  filterref => "clean-traffic");
+	}
     }
+    return $b;
 }
 
 sub generic_pool {
@@ -1132,4 +1150,11 @@ sub get_host_block_device {
     return $match ? $device : undef;
 }
 
+sub get_host_network_device {
+    my $self = shift;
+    my $devindex = @_ ? shift : 0;
+
+    return $self->config("host_network_devices/[$devindex]", undef);
+}
+
 1;
diff --git a/lib/Sys/Virt/TCK/DomainBuilder.pm b/lib/Sys/Virt/TCK/DomainBuilder.pm
index 5308dc9..7a20008 100644
--- a/lib/Sys/Virt/TCK/DomainBuilder.pm
+++ b/lib/Sys/Virt/TCK/DomainBuilder.pm
@@ -277,7 +277,6 @@ sub interface {
 
     die "type parameter is required" unless $params{type};
     die "source parameter is required" unless $params{source};
-    die "model parameter is required" unless $params{model};
 
     push @{$self->{interfaces}}, \%params;
 
@@ -430,7 +429,7 @@ sub as_xml {
 	$w->emptyTag("mac",
 		     address =>  $interface->{mac});
 
-	if( $interface->{dev}) {
+	if ($interface->{dev}) {
 	    $w->emptyTag("source",
 			 dev => $interface->{dev},
 			 mode => $interface->{mode});
@@ -438,7 +437,7 @@ sub as_xml {
 	    $w->emptyTag("source",
 			 network => $interface->{source});
 	}
-	if( $interface->{virtualport}) {
+	if ($interface->{virtualport}) {
 	    $w->startTag("virtualport",
 			 type => $interface->{virtualport});
 	    $w->emptyTag("parameters",
@@ -448,9 +447,11 @@ sub as_xml {
 			 instanceid => '40000000-0000-0000-0000-000000000000');
 	    $w->endTag("virtualport");
 	}
-	$w->emptyTag("model",
-		     type => $interface->{model});
-	if( $interface->{filterref}) {
+	if ($interface->{model}) {
+	    $w->emptyTag("model",
+			 type => $interface->{model});
+	}
+	if ($interface->{filterref}) {
 	    $w->emptyTag("filterref",
 			 filter => $interface->{filterref});
 	}
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]