[libvirt] [tck PATCH v3 0/2] new NetworkHelper function get_network_ip()

New for V3: added in the NetAddr::IP dependency to Build.PL, and added a prequel patch that removes all tabs from that file. Laine Stump (2): Remove tab characters from Build.PL new NetworkHelper function get_network_ip() Build.PL | 105 +++++++++++++++++++------------------ lib/Sys/Virt/TCK/NetworkHelpers.pm | 22 ++++++++ 2 files changed, 75 insertions(+), 52 deletions(-) -- 2.14.3

Signed-off-by: Laine Stump <laine@laine.org> --- Build.PL | 104 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/Build.PL b/Build.PL index 63785a5..9593021 100644 --- a/Build.PL +++ b/Build.PL @@ -27,11 +27,11 @@ sub process_pkgdata_files { my $wanted = sub { my $dir = $File::Find::dir; my $name = $File::Find::name; - if (-d) { - $tck_dirs{$name} = []; - } elsif (-f && /\.(t|sh|fwall|xml|dat)$/) { - push @{$tck_dirs{$dir}}, $name; - } + if (-d) { + $tck_dirs{$name} = []; + } elsif (-f && /\.(t|sh|fwall|xml|dat)$/) { + push @{$tck_dirs{$dir}}, $name; + } }; find($wanted, 'scripts'); @@ -40,19 +40,19 @@ sub process_pkgdata_files { File::Path::mkpath($tck_dir); foreach my $srcdir (keys %tck_dirs) { - next unless @{$tck_dirs{$srcdir}}; + next unless @{$tck_dirs{$srcdir}}; - my $dstdir = $srcdir; - $dstdir =~ s,scripts/,,; + my $dstdir = $srcdir; + $dstdir =~ s,scripts/,,; - $dstdir = File::Spec->catdir($self->blib, 'pkgdata', $dstdir); - File::Path::mkpath($dstdir); + $dstdir = File::Spec->catdir($self->blib, 'pkgdata', $dstdir); + File::Path::mkpath($dstdir); - foreach my $file (@{$tck_dirs{$srcdir}}) { - my $result = $self->copy_if_modified(from => $file, - to_dir => $dstdir, - flatten => 1); - } + foreach my $file (@{$tck_dirs{$srcdir}}) { + my $result = $self->copy_if_modified(from => $file, + to_dir => $dstdir, + flatten => 1); + } } } @@ -64,52 +64,52 @@ my $b = $class->new( dist_author => 'Daniel Berrange <dan@berrange.com>', dist_abstract => 'libvirt Technology Compatability Kit', requires => { - 'perl' => '5.8.0', - 'accessors' => 0, - 'App::Prove' => '3.11', - 'Config::Record' => '1.0.0', - 'Cwd' => 0, - 'Digest' => 0, - 'Digest::MD5' => 0, - 'File::Copy' => 0, - 'File::Path' => 0, - 'File::Slurp' => 0, - 'File::Spec::Functions' => 0, - 'LWP::UserAgent' => 0, - 'IO::String' => 0, - 'IO::Uncompress::Gunzip' => 0, - 'IO::Uncompress::Bunzip2' => 0, - 'TAP::Formatter::HTML' => 0, - 'TAP::Formatter::JUnit' => 0, - 'TAP::Harness' => 3.11, - 'TAP::Harness::Archive' => 0, - 'Test::Exception' => 0, - 'Test::Builder' => 0, - 'Test::More' => 0, - 'Sub::Uplevel' => 0, - 'Sys::Virt' => '0.2.0', - 'XML::Twig' => 0, - 'XML::Writer' => 0, - 'XML::XPath' => 0, + 'perl' => '5.8.0', + 'accessors' => 0, + 'App::Prove' => '3.11', + 'Config::Record' => '1.0.0', + 'Cwd' => 0, + 'Digest' => 0, + 'Digest::MD5' => 0, + 'File::Copy' => 0, + 'File::Path' => 0, + 'File::Slurp' => 0, + 'File::Spec::Functions' => 0, + 'LWP::UserAgent' => 0, + 'IO::String' => 0, + 'IO::Uncompress::Gunzip' => 0, + 'IO::Uncompress::Bunzip2' => 0, + 'TAP::Formatter::HTML' => 0, + 'TAP::Formatter::JUnit' => 0, + 'TAP::Harness' => 3.11, + 'TAP::Harness::Archive' => 0, + 'Test::Exception' => 0, + 'Test::Builder' => 0, + 'Test::More' => 0, + 'Sub::Uplevel' => 0, + 'Sys::Virt' => '0.2.0', + 'XML::Twig' => 0, + 'XML::Writer' => 0, + 'XML::XPath' => 0, }, build_requires => { - 'Test::Pod' => '0', - 'Test::Pod::Coverage' => '0', + 'Test::Pod' => '0', + 'Test::Pod::Coverage' => '0', }, script_files => [ - "bin/libvirt-tck", + "bin/libvirt-tck", ], create_makefile_pl => 'passthrough', meta_add => { - resources => { - license => "http://www.gnu.org/licenses/gpl.html", - homepage => "http://libvirt.org/", - repository => "http://libvirt.org/hg/libvirt-tck", - MailingList => "http://www.redhat.com/mailman/listinfo/libvir-list", - }, + resources => { + license => "http://www.gnu.org/licenses/gpl.html", + homepage => "http://libvirt.org/", + repository => "http://libvirt.org/hg/libvirt-tck", + MailingList => "http://www.redhat.com/mailman/listinfo/libvir-list", + }, }, conf_files => { - 'conf/default.cfg' => 'conf/default.cfg', + 'conf/default.cfg' => 'conf/default.cfg', }, PL_files => [ 'perl-Sys-Virt-TCK.spec.PL' ], ); -- 2.14.3

On Tue, Mar 06, 2018 at 09:17:51AM -0500, Laine Stump wrote:
Signed-off-by: Laine Stump <laine@laine.org> --- Build.PL | 104 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 52 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

This function gets the first IP address for the named virtual network. It is returned as a Net::IP object, so that we will have info about its netmask/prefix and can easily get it broadcast address and perform arithmetic on the address. Signed-off-by: Laine Stump <laine@laine.org> --- Build.PL | 1 + lib/Sys/Virt/TCK/NetworkHelpers.pm | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Build.PL b/Build.PL index 9593021..bf2d7a9 100644 --- a/Build.PL +++ b/Build.PL @@ -79,6 +79,7 @@ my $b = $class->new( 'IO::String' => 0, 'IO::Uncompress::Gunzip' => 0, 'IO::Uncompress::Bunzip2' => 0, + 'NetAddr::IP' => 0, 'TAP::Formatter::HTML' => 0, 'TAP::Formatter::JUnit' => 0, 'TAP::Harness' => 3.11, diff --git a/lib/Sys/Virt/TCK/NetworkHelpers.pm b/lib/Sys/Virt/TCK/NetworkHelpers.pm index 5f563e5..7bbce62 100644 --- a/lib/Sys/Virt/TCK/NetworkHelpers.pm +++ b/lib/Sys/Virt/TCK/NetworkHelpers.pm @@ -1,4 +1,5 @@ use Sys::Virt::TCK qw(xpath); +use NetAddr::IP qw(:lower); use strict; use utf8; @@ -9,6 +10,27 @@ sub get_first_macaddress { return $mac; } +sub get_network_ip { + my $conn = shift; + my $netname = shift; + diag "getting ip for network $netname"; + my $net = $conn->get_network_by_name($netname); + my $net_ip = xpath($net, "string(/network/ip[1]/\@address"); + my $net_mask = xpath($net, "string(/network/ip[1]/\@netmask"); + my $net_prefix = xpath($net, "string(/network/ip[1]/\@prefix"); + my $ip; + + if ($net_mask) { + $ip = NetAddr::IP->new($net_ip, $net_mask); + } elsif ($net_prefix) { + $ip = NetAddr::IP->new("$net_ip/$net_mask"); + } else { + $ip = NetAddr::IP->new("$net_ip"); + } + return $ip; +} + + sub get_ip_from_leases{ my $conn = shift; my $netname = shift; -- 2.14.3

On Tue, Mar 06, 2018 at 09:17:52AM -0500, Laine Stump wrote:
This function gets the first IP address for the named virtual network. It is returned as a Net::IP object, so that we will have info about its netmask/prefix and can easily get it broadcast address and perform arithmetic on the address.
Signed-off-by: Laine Stump <laine@laine.org> --- Build.PL | 1 + lib/Sys/Virt/TCK/NetworkHelpers.pm | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Laine Stump