File: 600-interfaces.t

package info (click to toggle)
libsys-virt-perl 11.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,088 kB
  • sloc: perl: 2,187; sh: 12; makefile: 3
file content (109 lines) | stat: -rw-r--r-- 2,572 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- perl -*-

use strict;
use warnings;

use Test::More tests => 25;

BEGIN {
        use_ok('Sys::Virt');
}


my $conn = Sys::Virt->new(uri => "test:///default");

isa_ok($conn, "Sys::Virt");


my $nid = $conn->num_of_interfaces();
is($nid, 1, "1 active interface");

my @ifacenames = $conn->list_interface_names($nid);
is_deeply(\@ifacenames, ["eth1"], "interface names");

my $iface = $conn->get_interface_by_name($ifacenames[0]);
isa_ok($iface, "Sys::Virt::Interface");

is($iface->get_name, "eth1", "name");

my @ifaces;
SKIP: {
    skip "Impl missing in test driver in libvirt 0.10.2", 2;

    @ifaces = $conn->list_all_interfaces();
    is(int(@ifaces), 1, "1 active interface");
    is($ifaces[0]->get_name, "2eth1", "interface name matches");
}

ok($iface->is_active(), "interface is active");

# Lookup again via MAC to verify we get the same
my $mac = $iface->get_mac();

my $iface2 = $conn->get_interface_by_mac($mac);
isa_ok($iface2, "Sys::Virt::Interface");
is($iface2->get_name, "eth1", "name");

@ifaces = $conn->list_interfaces();
is($#ifaces, 0, "one interface");
isa_ok($ifaces[0], "Sys::Virt::Interface");


my $nname = $conn->num_of_defined_networks();
is($nname, 0, "0 defined interfaces");

my $xml = "
<interface type='ethernet' name='eth2'>
  <start mode='onboot'/>
  <mac address='aa:bb:cc:ff:ee:ff'/>
  <mtu size='1492'/>
  <protocol family='ipv4'>
    <ip address='192.168.0.6' prefix='24'/>
    <route gateway='192.168.0.1'/>
  </protocol>
</interface>";

$iface = $conn->define_interface($xml);

$nname = $conn->num_of_defined_interfaces();
is($nname, 1, "1 defined interface");

my @names = $conn->list_defined_interface_names($nname);
is_deeply(\@names, ["eth2"], "names");

@ifaces = $conn->list_defined_interfaces();
is($#ifaces, 0, "1 defined interface");
isa_ok($ifaces[0], "Sys::Virt::Interface");

$iface = $conn->get_interface_by_name("eth2");
isa_ok($iface, "Sys::Virt::Interface");


$iface->create();

my $nids = $conn->num_of_interfaces();
is($nids, 2, "2 active interfaces");

my @ids = sort { $a cmp $b } $conn->list_interface_names($nids);
is_deeply(\@ids, ["eth1", "eth2"], "interface names");

$iface->destroy();


$nids = $conn->num_of_interfaces();
is($nids, 1, "1 active interfaces");

@ids = $conn->list_interface_names($nids);
is_deeply(\@ids, ["eth1"], "interface names");

$iface = $conn->get_interface_by_name("eth2");

$iface->undefine();


$nname = $conn->num_of_defined_interfaces();
is($nname, 0, "0 defined interface");

@names = $conn->list_defined_interface_names($nname);
is_deeply(\@names, [], "names");