Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add video none #2037

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/Ravada/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2442,13 +2442,21 @@ sub _set_controller_filesystem($self, $number, $data) {
sub _set_controller_video($self, $number, $data={type => 'qxl'}) {
$data->{type} = 'qxl' if !exists $data->{type};
$data->{type} = lc(delete $data->{driver}) if exists $data->{driver};
my $pci_slot = $self->_new_pci_slot();

my $doc = XML::LibXML->load_xml(string => $self->xml_description_inactive);
my ($devices) = $doc->findnodes("/domain/devices");

if (exists $data->{primary} && $data->{primary} =~ /yes/) {
_remove_all_video_primary($devices);
}

if ($data->{type} eq 'none') {
_remove_all_video($devices);
} else {
_remove_all_video($devices,'type'=>'none');
}
my $pci_slot = $self->_new_pci_slot();

my $video = $devices->addNewChild(undef,'video');
my $model = $video->addNewChild(undef,'model');
for my $field (keys %$data) {
Expand All @@ -2473,6 +2481,19 @@ sub _remove_all_video_primary($devices) {
}
}

sub _remove_all_video($devices, $attribute=undef, $value=undef) {
confess "Error: attribute '$attribute' value search must be defined"
if defined $attribute && !defined $value;

for my $video ($devices->findnodes("video")) {
my ($model) = $video->findnodes('model');
next if defined $attribute
&& (!$model->getAttribute($attribute)
|| $model->getAttribute($attribute) ne $value);

$devices->removeChild($video);
}
}
sub _set_controller_network($self, $number, $data) {

my $driver = (delete $data->{driver} or 'virtio');
Expand Down Expand Up @@ -3659,7 +3680,7 @@ sub reload_config($self, $doc) {
$new_domain = $self->_vm->vm->define_domain($doc->toString);
};

die ''.$@ if $@;
die ''.$@."\n" if$@;

$self->domain($new_domain);

Expand Down
33 changes: 31 additions & 2 deletions t/request/30_hardware.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ sub test_add_hardware_request_drivers {
test_remove_almost_all_hardware($vm, $domain, $hardware);
for my $driver (@$options) {
$driver = lc($driver);
next if $hardware eq 'video' && $driver eq 'none';
diag("Testing new $hardware $driver remove=$remove");

my $info0 = $domain->info(user_admin);
Expand Down Expand Up @@ -208,6 +209,10 @@ sub _remove_other_video_primary($domain) {

sub test_add_hardware_request($vm, $domain, $hardware, $data={}) {

return if $hardware eq 'video'
&& exists $data->{type} && defined $data->{type}
&& $data->{type} eq 'none';

$domain = Ravada::Domain->open($domain->id);

confess if !ref($data) || ref($data) ne 'HASH';
Expand Down Expand Up @@ -501,6 +506,7 @@ sub _test_kvm_accel3d($domain,$value) {
}

sub test_add_video($domain) {
test_add_video_none($domain);
my $data = { type => 'virtio', heads => 1 };
test_video_vgamem($domain);
test_video_virtio_3d_change_type($domain);
Expand All @@ -509,6 +515,27 @@ sub test_add_video($domain) {
test_video_primary($domain);
}

sub test_add_video_none($domain) {
my %args = (
uid => user_admin->id
,name => 'video'
,id_domain => $domain->id
,data => {
type => 'none'
}
);
my $req = Ravada::Request->add_hardware(%args);
wait_request();
is($req->error,'');

$args{data}->{type} = 'cirrus';
$req = Ravada::Request->add_hardware(%args);
wait_request();
is($req->error,'');


}

sub test_add_cdrom($domain) {
my $n = 0;
for my $device ( $domain->list_volumes_info ) {
Expand Down Expand Up @@ -758,11 +785,14 @@ sub test_remove_hardware_by_index($vm, $hardware) {
my $items1 = [];
$items1 = $info_hw1->{$hardware};

my $index = 1;
$index = 0 if $items1 && scalar(@$items1)<=1;

Ravada::Request->remove_hardware(
uid => user_admin->id
,id_domain => $domain->id
,name => $hardware
,index => 1
,index => $index
);
wait_request();
my $info_hw2 = $domain->info(user_admin)->{hardware};
Expand Down Expand Up @@ -1728,7 +1758,6 @@ for my $vm_name (vm_names()) {
lock_hash(%controllers);

for my $hardware ( sort keys %controllers ) {
next if $hardware eq 'video';
my $name= new_domain_name();
my $domain_b = $BASE->clone(
name => $name
Expand Down
21 changes: 15 additions & 6 deletions templates/main/manage_machine_edit_video.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</select>
</div>
</div>
<div class="row">
<div class="row" ng-hide="item.type=='none'">
<div class="col-lg-2" align="right"><%=l 'primary' %></div>
<div class="col-lg-2">
<input type="checkbox" ng-model="item.primary"
Expand All @@ -23,7 +23,7 @@
<span class="info"><%=l 'Primary can not be unset, enable it in another video device' %></span>
</div>
</div>
<div class="row">
<div class="row" ng-hide="item.type=='none'">

<div class="col-lg-2" align="right"><%=l 'vram' %></div>
<div class="col-lg-1">
Expand All @@ -38,17 +38,26 @@

</div>

<div class="row">
<div class="row" ng-hide="item.type=='none'">
<div class="col-lg-2" align="right"><%=l 'heads' %></div>
<div class="col-lg-2">
<input type="text" size="2" ng-model="item.heads"/>
</div>
</div>

<div class="row">
<span class="info"
ng-show="item.type=='cirrus' && !item.primary">
<%=l "video type 'cirrus' is only valid as primary video device" %>
<div class="col-lg-8 alert alert-warning"
ng-show="((item.type=='cirrus' || item.type=='vga')
&& !item.primary )
|| item.type=='none'
">
<span ng-show="item.type=='cirrus' || item.type =='vga' && !item.primary">
<%=l "This video type is only valid as primary video device" %>
</span>

<span ng-show="item.type=='none'" >
<%=l "Setting video to 'none' removes all other video devices" %>
</span>
</div>
</div>
</div>
Loading