Commit 6ed38c46 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip: user may have been removed

parent 147a6ce1
......@@ -5022,12 +5022,13 @@ sub _enforce_limits_active($self, $request) {
}
for my $id_user(keys %domains) {
my $user = Ravada::Auth::SQL->search_by_id($id_user);
my %grants = $user->grants();
my %grants;
%grants = $user->grants() if $user;
my $start_limit = (defined($grants{'start_limit'}) && $grants{'start_limit'} > 0) ? $grants{'start_limit'} : $start_limit_default;
next if scalar @{$domains{$id_user}} <= $start_limit;
next if $user->is_admin;
next if $user->can_start_many;
next if $user && $user->is_admin;
next if $user && $user->can_start_many;
my @domains_user = sort { $a->start_time <=> $b->start_time
|| $a->id <=> $b->id }
......@@ -5048,7 +5049,7 @@ sub _enforce_limits_active($self, $request) {
);
return;
}
$user->send_message("Too many machines started. $active out of $start_limit. Stopping ".$domain->name);
$user->send_message("Too many machines started. $active out of $start_limit. Stopping ".$domain->name) if $user;
$active--;
if ($domain->can_hybernate && !$domain->is_volatile) {
$domain->hybernate($USER_DAEMON);
......
......@@ -1222,7 +1222,9 @@ sub _max_n_order_display($self) {
}
sub _normalize_display($self, $display, $json=1) {
confess Dumper($display) if exists $display->{port} && $display->{port} && !$display->{id_vm};
$display->{id_vm}=$self->_vm->id
if exists $display->{port} && $display->{port} && !$display->{id_vm};
my %valid_field = map { $_ => 1 }
qw(id id_domain port ip display listen_ip driver password is_builtin is_secondary
is_active n_order extra id_domain_port id_vm );
......
......@@ -1343,23 +1343,19 @@ sub test_enforce_limits($domain, $n_expected, $user=user_admin) {
delete_request('enforce_limits');
wait_request();
for my $n ( 1 .. 10 ) {
diag("$n enforce limits");
if (!$domain->is_active()) {
$domain->start(user =>$user, remote_ip => '1.2.3.4');
wait_request(skip => [], debug => 0 );
}
my $req;
for my $m ( 1 .. 10 ) {
diag("$n.$m create request enforce_limits");
my @list = rvd_back->list_domains(user => $user, active => 1);
warn Dumper([ map { $_->name } @list]);
return if scalar(@list)<=$n_expected ;
$req = Ravada::Request->enforce_limits(_force => 1);
last if $req;
sleep 1;
}
my @list = rvd_back->list_domains(user => $user, active => 1);
warn Dumper([ map { $_->name } @list]);
return if scalar(@list)<=$n_expected ;
wait_request( request => $req, debug => 0);
next if $req->status ne 'done';
......@@ -1370,7 +1366,6 @@ sub test_enforce_limits($domain, $n_expected, $user=user_admin) {
}
ok(!$req->error,"Expecting no error on ".$req->command." got ".($req->error or ''));
@list = rvd_back->list_domains(user => $user, active => 1);
warn Dumper([ map { $_->name } @list]);
return if scalar(@list)<=$n_expected ;
}
}
......@@ -1586,7 +1581,6 @@ sub test_display_drivers($vm, $remove) {
,name => 'display'
,data => { driver => $driver }
);
warn $req->id;
Ravada::Request->start_domain(uid => user_admin->id
,id_domain => $domain->id
);
......
......@@ -99,7 +99,7 @@ sub _set_clones_client_status($base) {
sub test_user_create($base, $n_start) {
$base->is_public(1);
my $user = create_user('kevin','carter');
my $user = create_user('kevin'.$base->type,'carter');
my @clones = $base->clones();
wait_request();
_remove_enforce_limits();
......
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