Unverified Commit 1b15f31f authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Refactor/warnings (#1689)

refactor: fixed some minor warnings

* refactor: allow size_limit in config
* refactor: ignore warning when no port defined
* fix(frontend): default swap and data only when no advanced
* refactor(frontend): hide node row
* test: new machine advanced options
* fix(download): do not try to download when no URL

closes #1684
parent 4c9b7b7b
......@@ -67,6 +67,7 @@ our %VALID_CONFIG = (
,field => undef
,server => undef
,port => undef
,size_limit => undef
}
,log => undef
);
......
......@@ -3655,7 +3655,8 @@ sub list_ports($self) {
while (my $data = $sth->fetchrow_hashref) {
lock_hash(%$data);
push @list,($data);
$clone_port{$data->{internal_port}}++;
$clone_port{$data->{internal_port}}++
if $data->{internal_port};
}
if ($self->is_known() && !$self->is_base && $self->id_base) {
......
......@@ -781,7 +781,7 @@ sub _check_downloading($self) {
my ($id_iso2,$downloading, $device, $has_cd) = $sth->fetchrow;
my $req_download = _search_request('download', id_iso => $id_iso2);
if ($has_cd && !$device && !$req_download) {
if ($has_cd && !$device && !$iso_file && !$req_download) {
$req_download = Ravada::Request->download(
id_iso => $id_iso2
,uid => Ravada::Utils::user_daemon->id
......
......@@ -2428,6 +2428,7 @@ sub admin {
}
}
if ($page eq 'machines') {
_count_nodes($c);
Ravada::Request->refresh_vms();
$c->stash(n_clones_hide => ($CONFIG_FRONT->{admin}->{hide_clones} or 10) );
$c->stash(autostart => ( $CONFIG_FRONT->{admin}->{autostart} or 0));
......@@ -2455,6 +2456,15 @@ sub admin {
$c->render( template => 'main/admin_'.$page);
};
sub _count_nodes($c) {
my $sth = $RAVADA->_dbh->prepare(
"SELECT count(*) FROM vms"
);
$sth->execute();
my ($n) = $sth->fetchrow;
$c->stash( _n_nodes => $n );
}
sub _search_id_iso($name) {
my $sth = $RAVADA->_dbh
->prepare("SELECT id FROM iso_images WHERE name=?");
......@@ -2521,7 +2531,7 @@ sub req_new_domain {
my $data = ($c->param('data') or 0);
$data *= 1024*1024*1024;
if (!$c->param('_advanced')) {
if (!$c->param('_advanced_options')) {
$swap = int(1024 * 1024 * 1024) if !$swap;
$data = int(1024 * 1024 * 1024) if !$data;
}
......
......@@ -124,6 +124,7 @@ sub test_form_new_machine() {
my $form = $dom->find('form')->grep( sub {$_->attr('name') eq $form_name});
ok($form->[0], "Expecting form name=$form_name") or return;
for my $name ('id_iso', 'name', 'iso_file', 'memory','disk'
, '_advanced_options'
, 'swap', 'data') {
my $inputs = $form->[0]->find("input")
->grep( sub { $_->attr('name') eq $name } );
......
......@@ -621,6 +621,84 @@ sub test_new_machine_empty($t, $vm_name) {
}
}
sub test_new_machine_default($t, $vm_name) {
my $name = new_domain_name();
my $iso_name = 'Alpine%64 bits';
my $id_iso = search_id_iso($iso_name);
$t->post_ok('/new_machine.html' => form => {
backend => $vm_name
,id_iso => $id_iso
,name => $name
,disk => 1
,ram => 1
,submit => 1
}
)->status_is(302);
wait_request();
my $domain = rvd_front->search_domain($name);
my $disks = $domain->info(user_admin)->{hardware}->{disk};
my ($swap ) = grep { $_->{file} =~ /SWAP/ } @$disks;
ok($swap,"Expecting a swap disk volume");
my ($data) = grep { $_->{file} =~ /DATA/ } @$disks;
ok($data,"Expecting a data disk volume");
my ($iso) = grep { $_->{file} =~ /iso$/ } @$disks;
ok($iso,"Expecting an ISO cdrom disk volume");
}
sub test_new_machine_advanced_options($t, $vm_name, $swap=undef ,$data=undef) {
my $name = new_domain_name();
my $iso_name = 'Alpine%64 bits';
my $id_iso = search_id_iso($iso_name);
my @args = (
backend => $vm_name
,id_iso => $id_iso
,name => $name
,disk => 1
,ram => 1
,submit => 1
,_advanced_options => 1
);
push @args,(swap => 1) if $swap;
push @args,(data => 1) if $data;
$t->post_ok('/new_machine.html' => form => {
@args
}
)->status_is(302);
wait_request();
my $domain = rvd_front->search_domain($name);
my $disks = $domain->info(user_admin)->{hardware}->{disk};
my ($d_swap ) = grep { $_->{file} =~ /SWAP/ } @$disks;
if ($swap) {
ok($d_swap,"Expecting swap disk volume");
} else {
ok(!$d_swap,"Expecting no swap disk volume");
}
my ($d_data) = grep { $_->{file} =~ /DATA/ } @$disks;
if ($data) {
ok($d_data,"Expecting data disk volume");
} else {
ok(!$d_data,"Expecting no data disk volume");
}
my ($iso) = grep { $_->{file} =~ /iso$/ } @$disks;
ok($iso,"Expecting an ISO cdrom disk volume") or warn Dumper($disks);
}
sub test_new_machine_change_iso($t, $vm_name) {
my $iso_name = 'Alpine%32 bits';
_download_iso($iso_name);
......@@ -740,6 +818,11 @@ for my $vm_name ( @{rvd_front->list_vm_types} ) {
test_new_machine($t);
if ($vm_name eq 'KVM') {
test_new_machine_default($t, $vm_name);
test_new_machine_advanced_options($t, $vm_name);
test_new_machine_advanced_options($t, $vm_name,1);
test_new_machine_advanced_options($t, $vm_name,0,1);
test_new_machine_advanced_options($t, $vm_name,1,1);
test_new_machine_change_iso($t, $vm_name);
test_new_machine_empty($t, $vm_name);
}
......
......@@ -125,7 +125,9 @@
<div style="float:right">
<%=l 'Status' %></div></th>
<th class="lgMachActions"><%=l 'Actions' %></th>
% if ($_n_nodes>1 ) {
<th class="lgMachNode"><%=l 'Node' %></th>
% }
</tr>
</thead>
<tbody>
......@@ -269,9 +271,12 @@
<div ng-show="machine.is_base && !machine.is_locked"
ng-cloak><span class="badge badge-pill badge-light"><%=l 'This Machine is a base' %></span></div>
</td>
% if ($_n_nodes>1 ) {
<td class="lgMachNode">
<span class="badge badge-info" title="<%=l 'Node'%>">{{machine.node}}</span>
</td>
% }
</tr>
</tbody>
</table>
......
......@@ -114,7 +114,7 @@
</label>
<div class="col-lg-9">
<input type="checkbox" ng-model="_advanced_options"
name="_advanced_options" value="0"/>
name="_advanced_options" value="1"/>
</div>
</div>
......
Supports Markdown
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