Commit 4dfe8b9f authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip: refresh devices before domain start

parent c9f4a520
......@@ -196,12 +196,16 @@ sub _data($self, $field, $value=undef) {
|| $value !~ /^(ls|find)/);
$value = encode_json($value) if ref($value);
my $old_value = $self->_data($field);
return if defined $old_value && $old_value eq $value;
my $sth = $$CONNECTOR->dbh->prepare("UPDATE host_devices SET $field=?"
." WHERE id=? "
);
$sth->execute($value, $self->id);
$self->meta->get_attribute($field)->set_value($self, $value);
$self->_dettach_in_domains() if $field =~ /^list_/;
$self->_dettach_in_domains() if $field =~ /^(devices|list_)/;
return $value;
} else {
my $sth = $$CONNECTOR->dbh->prepare("SELECT * FROM host_devices"
......
......@@ -301,6 +301,56 @@ sub _count_locked() {
return $n;
}
sub test_templates_change_devices($vm) {
return if $vm->type ne 'Void';
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";
opendir my $dir,$path or die "$! $path";
while ( my $file = readdir $dir ) {
next if $file !~ /^$name/;
unlink "$path/$file" or die "$! $path/$file";
}
closedir $dir;
my $n_devices = 3;
for ( 1 .. $n_devices ) {
open my $out,">","$path/${name} $_:$_ Foo bar"
or die $!;
print $out "fff6f017-3417-4ad3-b05e-17ae3e1a461".int(rand(10));
close $out;
}
$vm->add_host_device(template => $template->{name});
my ($hostdev) = $vm->list_host_devices();
$hostdev->_data(list_command => "ls $path");
$hostdev->list_devices();
my $domain = _create_domain_hd($vm, $hostdev);
$domain->start(user_admin);
is(scalar($hostdev->list_domains_with_device()),1);
my ($dev_attached) = ($domain->list_host_devices_attached);
$domain->shutdown_now(user_admin);
my $file = "$path/".$dev_attached->{name};
unlink $file or die "$! $file";
warn $file;
$domain->start(user_admin);
my ($dev_attached2) = ($domain->list_host_devices_attached);
isnt($dev_attached2->{name}, $dev_attached->{name});
die $domain->name;
}
sub test_templates_change_filter($vm) {
my $templates = Ravada::HostDevice::Templates::list_templates($vm->type);
ok(@$templates);
......@@ -469,7 +519,7 @@ sub test_hd_remove($vm, $host_device) {
clean();
for my $vm_name ( vm_names()) {
for my $vm_name (reverse vm_names()) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......@@ -482,6 +532,7 @@ for my $vm_name ( vm_names()) {
diag("Testing host devices in $vm_name");
test_templates_change_devices($vm);
test_templates($vm);
test_templates_change_filter($vm);
......
Markdown is supported
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