Skip to content

Commit

Permalink
wip: test frontend list
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Feb 8, 2024
1 parent 153615f commit 00b4aba
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions t/device/10_templates.t
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,52 @@ sub _mangle_dom_hd_kvm($domain) {
$domain->reload_config($xml);
}

sub test_templates_change_devices($vm) {
return if $vm->type ne 'Void';
sub test_frontend_list($vm) {

my $path = "/var/tmp/$</ravada/dev";
my $hd1 = _mock_hd($vm , $path);
my $hd2 = _mock_hd($vm , $path);

my $domain = _create_domain_hd($vm, $hd1);
$domain->start(user_admin);

my $ws_args = {
channel => '/'.$vm->id
,login => user_admin->name
};
my $front_devices = Ravada::WebSocket::_list_host_devices(rvd_front(), $ws_args);

my ($dev_attached) = ($domain->list_host_devices_attached);

for my $fd ( @$front_devices ) {
for my $dev ( @{$fd->{devices}} ) {
if ($dev->{name} eq $dev_attached->{name}) {
ok($dev->{domain} , "Expecting domains listed in ".$dev->{name}) or next;
is($dev->{domain}->{id}, $domain->id,"Expecting ".$domain->name." attached in ".$dev->{name});
}
}
}
}

sub _mock_hd($vm, $path) {

my ($template, $name) = _mock_devices($vm , $path);

my $id_hd = $vm->add_host_device(template => $template->{name});
my $hd = Ravada::HostDevice->search_by_id($id_hd);

$hd->_data(list_command => "ls $path");
$hd->_data(list_filter => $name);

return $hd;
}

sub _mock_devices($vm, $path) {
my $templates = Ravada::HostDevice::Templates::list_templates($vm->type);
ok(@$templates);

my ($template) = grep { $_->{list_command} eq 'lsusb' } @$templates;

my $path = "/var/tmp/$</ravada/dev";
make_path($path) if !-e $path;

my $name = base_domain_name()." Mock_device ID";
Expand All @@ -610,6 +648,15 @@ sub test_templates_change_devices($vm) {
close $out;
}

return ($template, $name);
}

sub test_templates_change_devices($vm) {
return if $vm->type ne 'Void';

my $path = "/var/tmp/$</ravada/dev";
my ($template, $name) = _mock_devices($vm, $path);

$vm->add_host_device(template => $template->{name});
my ($hostdev) = $vm->list_host_devices();
$hostdev->_data(list_command => "ls $path");
Expand Down Expand Up @@ -833,6 +880,8 @@ for my $vm_name ( vm_names()) {

diag("Testing host devices in $vm_name");

test_frontend_list($vm);

test_templates_gone_usb_2($vm);
test_templates_gone_usb($vm);
test_templates_changed_usb($vm);
Expand Down

0 comments on commit 00b4aba

Please sign in to comment.