Commit 059b4bc4 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

test(KVM): check for duplicated MACs in 2nd eth

issue #1294
parent 01e8d17f
...@@ -72,16 +72,8 @@ sub test_req_prepare_base{ ...@@ -72,16 +72,8 @@ sub test_req_prepare_base{
$domain->is_public(1); $domain->is_public(1);
} }
#Read xml
sub test_add_nic { sub read_mac{
my $vm_name = shift;
# diag("Testing add description $vm_name");
my $vm = rvd_back->search_vm($vm_name);
my $domain = test_create_domain($vm_name);
#Read xml
sub read_mac{
my $domain = shift; my $domain = shift;
my $xml = XML::LibXML->load_xml(string => $domain->get_xml_base()); my $xml = XML::LibXML->load_xml(string => $domain->get_xml_base());
my @mac; my @mac;
...@@ -91,7 +83,15 @@ sub test_add_nic { ...@@ -91,7 +83,15 @@ sub test_add_nic {
push @mac, $mac; push @mac, $mac;
} }
return(@mac); return(@mac);
} }
sub test_add_nic {
my $vm_name = shift;
# diag("Testing add description $vm_name");
my $vm = rvd_back->search_vm($vm_name);
my $domain = test_create_domain($vm_name);
my $domain_other = test_create_domain($vm_name);
#Prepare base #Prepare base
test_req_prepare_base($domain->name); test_req_prepare_base($domain->name);
...@@ -112,10 +112,15 @@ sub test_add_nic { ...@@ -112,10 +112,15 @@ sub test_add_nic {
my $domain_clon = $RAVADA->search_domain($name); my $domain_clon = $RAVADA->search_domain($name);
my @mac = read_mac($domain); my @mac = read_mac($domain);
my @mac_other = read_mac($domain_other);
my @mac2 = read_mac($domain_clon); my @mac2 = read_mac($domain_clon);
isnt($mac[0],$mac2[0], "1st MAC from 1st NIC cloned are the same"); isnt($mac[0],$mac2[0], "1st MAC from 1st NIC cloned are the same");
isnt($mac[1],$mac2[1], "2nd MAC from 2nd NIC cloned are the same"); isnt($mac[1],$mac2[1], "2nd MAC from 2nd NIC cloned are the same");
my %dupe_mac = ();
for my $mac (@mac, @mac_other, @mac2) {
ok(!$dupe_mac{$mac}++,"MAC $mac duplicated");
}
} }
......
...@@ -98,6 +98,7 @@ sub test_many_clones($base) { ...@@ -98,6 +98,7 @@ sub test_many_clones($base) {
}; };
test_re_expose($base) if $base->type eq 'Void'; test_re_expose($base) if $base->type eq 'Void';
test_different_mac($base, $base->clones) if $base->type ne 'Void';
for my $clone ( $base->clones ) { for my $clone ( $base->clones ) {
my $req = Ravada::Request->remove_domain( my $req = Ravada::Request->remove_domain(
name => $clone->{name} name => $clone->{name}
...@@ -106,6 +107,22 @@ sub test_many_clones($base) { ...@@ -106,6 +107,22 @@ sub test_many_clones($base) {
} }
} }
sub test_different_mac(@domain) {
my %found;
for my $domain (@domain) {
$domain = Ravada::Front::Domain->open($domain->{id})
if ref($domain) !~/^Ravada/;
my $xml = XML::LibXML->load_xml(string => $domain->_data_extra('xml'));
my (@if_mac) = $xml->findnodes('/domain/devices/interface/mac');
for my $if_mac (@if_mac) {
my $mac = $if_mac->getAttribute('address');
ok(!exists $found{$mac},"Error: MAC $mac from ".$domain->name
." also in domain : ".($found{$mac} or '')) or exit;
$found{$mac} = $domain->name;
}
}
}
sub test_re_expose($base) { sub test_re_expose($base) {
diag("Test re-expose"); diag("Test re-expose");
for my $clone ( $base->clones ) { for my $clone ( $base->clones ) {
...@@ -196,6 +213,9 @@ for my $vm_name ( vm_names() ) { ...@@ -196,6 +213,9 @@ for my $vm_name ( vm_names() ) {
ok($base) or next; ok($base) or next;
push @bases,($base->name); push @bases,($base->name);
mojo_request($t, "add_hardware", { id_domain => $base->id, name => 'network' });
wait_request(debug => 1, check_error => 1, background => 1, timeout => 120);
$t->get_ok("/machine/prepare/".$base->id.".json")->status_is(200); $t->get_ok("/machine/prepare/".$base->id.".json")->status_is(200);
_wait_request(debug => 0, background => 1); _wait_request(debug => 0, background => 1);
$base = rvd_front->search_domain($name); $base = rvd_front->search_domain($name);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment