Commit 50fed357 authored by Fernando Verdugo's avatar Fernando Verdugo
Browse files

fix(renewMAC): renew MAC all nics

- testing 2 nics

Issue #1201
parent d390bf21
......@@ -1610,7 +1610,7 @@ sub _xml_modify_network {
my $self = shift;
my $doc = shift;
my $network = shift;
warn $network;
my ($type, $source );
if (ref($network) =~ /^Ravada/) {
($type, $source) = ($network->type , $network->source);
......@@ -1995,13 +1995,6 @@ sub _new_uuid {
sub _xml_modify_mac {
my $self = shift;
my $doc = shift or confess "Missing XML doc";
my ($if_mac) = $doc->findnodes('/domain/devices/interface/mac')
or exit;
my $mac = $if_mac->getAttribute('address');
my @macparts0 = split/:/,$mac;
my @old_macs;
for my $dom ($self->vm->list_all_domains) {
......@@ -2012,10 +2005,16 @@ sub _xml_modify_mac {
push @old_macs,($nic_mac);
}
}
warn $if_mac;
for my $if_mac ($doc->findnodes('/domain/devices/interface/mac') ) {
my $mac = $if_mac->getAttribute('address');
my @macparts0 = split/:/,$mac;
my $new_mac;
my @tried;
my $foundit;
for ( 1 .. 1000 ) {
for my $cont ( 1 .. 1000 ) {
my @macparts = @macparts0;
......@@ -2024,7 +2023,7 @@ warn $if_mac;
die "Missing num " if !defined $num;
$macparts[$pos] = $num;
$new_mac = lc(join(":",@macparts));
warn $new_mac;
warn $new_mac;
push @tried,($new_mac);
last if !grep /^$new_mac$/i,@old_macs && $self->_unique_mac($new_mac);
......@@ -2033,14 +2032,14 @@ warn $new_mac;
if ( $self->_unique_mac($new_mac) ) {
$if_mac->setAttribute(address => $new_mac);
return;
$foundit = 1;
last;
}
}
die "I can't find a new unique mac '$new_mac'\n".Dumper(\@tried);
die "I can't find a new unique mac '$new_mac'\n".Dumper(\@tried) if !$foundit;
}
}
=pod
sub xml_add_graphics_image {
......
......@@ -28,18 +28,19 @@ my $BACKEND = 'KVM';
################################################################
sub test_create_domain {
my $vm_name = shift;
my $vm = rvd_back->search_vm($vm_name);
ok($vm,"I can't find VM $vm_name") or return;
my $name = new_domain_name();
my $domain;
eval { $domain = $vm->create_domain(name => $name
$domain = $vm->create_domain(name => $name
, id_owner => $USER->id
, disk => 1024 * 1024
, arg_create_dom($vm_name))
};
, arg_create_dom($vm_name));
my $req = Ravada::Request->add_hardware(name => 'network', id_domain => $domain->id, uid => user_admin->id);
wait_request();
ok($domain,"No domain $name created with ".ref($vm)." ".($@ or '')) or return;
ok($domain->name
......@@ -58,7 +59,7 @@ sub test_req_prepare_base{
ok(!$domain0->is_base,"Domain $name should not be base");
my $req = Ravada::Request->prepare_base(id_domain => $domain0->id, uid => user_admin->id);
$RAVADA->_process_all_requests_dont_fork();
wait_request();
ok($req->status('done'),"Request should be done, it is".$req->status);
ok(!$req->error(),"Request error ".$req->error);
......@@ -76,15 +77,8 @@ sub test_add_nic {
my $vm_name = shift;
# diag("Testing add description $vm_name");
my $vm =rvd_back->search_vm($vm_name);
my $vm = rvd_back->search_vm($vm_name);
my $domain = test_create_domain($vm_name);
my $req = Ravada::Request->add_hardware(name => 'network',
, id_domain => $domain->id
, uid => $USER->id
);
wait_request();
is($req->error,"");
is($req->status,"done");
#Read xml
sub read_mac{
......@@ -94,7 +88,7 @@ sub test_add_nic {
my (@if_mac) = $xml->findnodes('/domain/devices/interface/mac');
for my $if_mac (@if_mac) {
my $mac = $if_mac->getAttribute('address');
warn $mac;
diag "\n$mac";
push @mac, $mac;
}
return(@mac);
......
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