Skip to content

Commit

Permalink
wip: set cpu in inactive config
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Aug 31, 2023
1 parent e5db1fe commit d464ff2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/Ravada/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3246,12 +3246,13 @@ sub _change_hardware_cpu($self, $index, $data) {
if !$data->{cpu}->{'model'}->{'#text'};

delete $data->{cpu}->{model}->{'$$hashKey'};

my $doc = XML::LibXML->load_xml(string => $self->xml_description);
my @flags = (Sys::Virt::Domain::XML_INACTIVE);
my $doc = XML::LibXML->load_xml( string => $self->domain->get_xml_description( @flags ));
my $count = 0;
my $changed = 0;

my ($n_vcpu) = $doc->findnodes('/domain/vcpu/text()');
my ($cpu0) = $doc->findnodes('/domain/cpu');

$self->_fix_vcpu_from_topology($data);

Expand Down Expand Up @@ -3622,6 +3623,9 @@ sub reload_config($self, $doc) {
$self->_validate_xml($doc) if $self->_vm->vm->get_major_version >= 4;
my $new_domain = $self->_vm->vm->define_domain($doc->toString);
$self->domain($new_domain);

$self->_data_extra('xml', $doc->toString) if $self->is_known

}

sub _save_xml_tmp($self,$doc) {
Expand Down
19 changes: 11 additions & 8 deletions t/request/33_hw_cpu.t
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ sub test_current_max($vm) {
wait_request();
is($domain->needs_restart,0);

my $domain3 = Ravada::Front::Domain->open($domain->id);
my $info3 = $domain3->info(user_admin);

# change current cpu to 2
my $req2 = Ravada::Request->change_hardware(
hardware => 'cpu'
Expand All @@ -320,13 +323,13 @@ sub test_current_max($vm) {
'#text' => $max_cpu,
,'current' => 2
},
'cpu'=> $info0->{hardware}->{cpu}->[0]->{cpu}
'cpu'=> $info3->{hardware}->{cpu}->[0]->{cpu}
},
);
wait_request( debug => 0 );
wait_request( debug => 1 );

my $domain22 = Ravada::Domain->open($domain->id);
is($domain22->needs_restart,0) or exit;
is($domain22->needs_restart,0, $domain22->name) or exit;
my $info22 = $domain22->info(user_admin);
is($info22->{hardware}->{cpu}->[0]->{vcpu}->{'current'},2)
or die $domain->name;
Expand Down Expand Up @@ -354,12 +357,12 @@ sub test_current_max($vm) {
);
wait_request(debug => 0);

my $domain3 = Ravada::Front::Domain->open($domain->id);
is($domain3->needs_restart,1) or exit;
my $domain4 = Ravada::Front::Domain->open($domain->id);
is($domain4->needs_restart,1) or exit;

my $info3 = $domain3->info(user_admin);
is($info3->{hardware}->{cpu}->[0]->{vcpu}->{current},2) or die $domain3->name;
is($info3->{hardware}->{cpu}->[0]->{vcpu}->{'#text'}, $max_cpu+1) or die $domain3->name;
my $info4 = $domain3->info(user_admin);
is($info4->{hardware}->{cpu}->[0]->{vcpu}->{current},2) or die $domain4->name;
is($info4->{hardware}->{cpu}->[0]->{vcpu}->{'#text'}, $max_cpu+1) or die $domain3->name;

$domain->remove(user_admin);
}
Expand Down

0 comments on commit d464ff2

Please sign in to comment.