Commit e4b9d1e7 authored by Fernando Verdugo's avatar Fernando Verdugo
Browse files

fix(volatile): not allow to create base

issue #1592
parent 11cb588c
......@@ -817,6 +817,7 @@ Prepares the virtual machine as a base:
sub prepare_base($self, $with_cd) {
my @base_img;
for my $volume ($self->list_volumes_info()) {
next if !$volume->file;
my $base_file = $volume->base_filename;
next if !$base_file || $base_file =~ /\.iso$/;
confess "Error: file '$base_file' already exists in ".$self->_vm->name
......@@ -860,6 +861,9 @@ sub _pre_prepare_base($self, $user, $request = undef ) {
# TODO: if disk is not base and disks have not been modified, do not generate them
# again, just re-attach them
# $self->_check_disk_modified(
die "Error: domain ".$self->name." is volatile and it can't be prepared as a base.\n"
if $self->is_volatile();
confess "ERROR: domain ".$self->name." is already a base" if $self->is_base();
$self->_check_has_clones();
......@@ -891,6 +895,8 @@ sub _check_free_space_prepare_base($self) {
$pool_base = $self->_vm->base_storage_pool() if $self->_vm->base_storage_pool();
for my $volume ($self->list_volumes_info(device => 'disk')) {;
next if !$volume->file;
die "Error: volume ".$volume->file." is missing.\n" if !$self->_vm->file_exists($volume->file);
$self->_vm->_check_free_disk($volume->capacity * 2, $pool_base);
}
};
......
......@@ -1812,6 +1812,46 @@ sub test_removed_leftover($vm) {
Test::Ravada::_check_leftovers();
}
sub test_prepare_base_disk_missing($vm) {
my $domain = create_domain($vm);
$domain->add_volume();
my @volumes = $domain->list_volumes();
my ($one, $two) = @volumes;
unlink $two;
eval {
$domain->prepare_base(user_admin);
};
like($@,qr/volume.*issing/) or die $domain->name;
$domain->remove_base(user_admin) if $domain->is_base;
open my $out,">",$two or die "$! $two";
print $out "Error\n";
close $two;
$domain->prepare_base(user_admin);
$domain->remove(user_admin);
}
sub test_prepare_base_volatile($vm) {
my $domain = create_domain($vm);
$domain->volatile_clones(1);
$domain->prepare_base(user_admin);
my $clone = $domain->clone(name => new_domain_name, user => user_admin);
is($clone->is_volatile(), 1);
eval { $clone->prepare_base(user_admin) };
like($@,qr/Error.*is volatile/);
$clone->remove(user_admin);
$domain->remove(user_admin);
}
#######################################################################33
for my $db ( 'mysql', 'sqlite' ) {
......@@ -1866,6 +1906,9 @@ for my $vm_name ( vm_names() ) {
}
flush_rules() if !$<;
test_prepare_base_disk_missing($vm);
test_prepare_base_volatile($vm);
test_change_display_settings($vm);
test_display_drivers($vm,0);
test_display_drivers($vm,1); #remove after testing display type
......
......@@ -179,7 +179,7 @@
ng-show="can_remove_base(machine)"
ng-click="open_modal('mb_',machine)"/>
<input type="checkbox"
ng-show="can_prepare_base(machine)"
ng-show="!machine.is_volatile && can_prepare_base(machine)"
ng-click="open_modal('mb_',machine)"
title ="<%=l 'Prepare base' %>" ng-cloak="1"/>
<div class="modal fade" tabindex="-1" role="dialog" id="mb_{{machine.id}}">
......
......@@ -23,7 +23,7 @@
% if ($domain->drivers && $USER->can_change_settings($domain->id) && $has_graphics_spice) {
<a class="nav-link" id="v-pills-graphics-tab" ng-click="refresh_machine()" href="#v-pills-graphics" data-toggle="pill" role="tab" aria-controls="v-pills-graphics" aria-selected="false"><%=l 'Graphics' %></a>
% }
% if ($USER->is_admin) {
% if ($USER->is_admin && !$domain->is_volatile) {
<a class="nav-link" id="v-pills-base-tab" href="#v-pills-base" data-toggle="pill" role="tab" aria-controls="v-pills-base" aria-selected="false">Base</a>
% }
% if ($USER->is_admin || $USER->can_clone_all ){
......
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