Commit c9aa4734 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Feature #902 start many (#907)

* Master is now release 0.3.1

* add indonesia translation (#875)

* add start_many machines option

* test(frontend): check two machines are started

issue #905

* wip(installer): fix problem adding grants

Merged duplicated code and fixed wrong grant description with
help from @gloriarodriguez

issue #902

* wip(test): removed unnecessary check

issue #902
parent 671c9b6f
......@@ -3,7 +3,7 @@ package Ravada;
use warnings;
use strict;
our $VERSION = '0.3.0-beta6';
our $VERSION = '0.4.0-alpha2';
use Carp qw(carp croak);
use Data::Dumper;
......@@ -875,12 +875,12 @@ sub _alias_grants($self) {
}
sub _add_grants($self) {
$self->_add_grant('shutdown', 1);
$self->_add_grant('screenshot', 1);
$self->_add_grant('shutdown', 1,"Can shutdown own virtual machines");
$self->_add_grant('screenshot', 1,"Can get a screenshot of own virtual machines");
$self->_add_grant('start_many',0,"Can have more than one machine started")
}
sub _add_grant($self, $grant, $allowed) {
sub _add_grant($self, $grant, $allowed, $description) {
my $sth = $CONNECTOR->dbh->prepare(
"SELECT id FROM grant_types WHERE name=?"
);
......@@ -892,7 +892,7 @@ sub _add_grant($self, $grant, $allowed) {
$sth = $CONNECTOR->dbh->prepare("INSERT INTO grant_types (name, description)"
." VALUES (?,?)");
$sth->execute($grant,"can shutdown any virtual machine owned by the user");
$sth->execute($grant, $description);
$sth->finish;
return if !$allowed;
......@@ -942,6 +942,7 @@ sub _enable_grants($self) {
,'screenshot'
,'shutdown', 'shutdown_all', 'shutdown_clone'
,'screenshot'
,'start_many'
);
$sth = $CONNECTOR->dbh->prepare("SELECT id,name FROM grant_types");
......
......@@ -248,6 +248,9 @@ msgstr "Tidak dapat menghapus dasar, mesin memiliki klon"
msgid "For spice redirection you'll need to install"
msgstr "Untuk pengalihan spice Anda harus memasang"
msgid "in your computer."
msgstr "di komputer Anda"
msgid "Search in your distro, e.g. in Debian/Ubuntu with"
msgstr "Cari di distribusi Anda, mis. di Debia /Ubuntu dengan"
......@@ -387,6 +390,12 @@ msgstr "Kata sandi tidak cocok"
msgid "Some of the password fields are empty"
msgstr "Beberapa kata sandi kosong"
msgid "Status"
msgstr "Status"
msgid "Actions"
msgstr "Aksi"
msgid "Machine locked by request"
msgstr "Mesin terkunci atas permintaan"
......@@ -414,6 +423,9 @@ msgstr "Untuk pengalihan Spice anda butuh untuk memasang"
msgid "in your computer."
msgstr "dikomputer anda"
msgid "Search in your distro, e.g. in Debian/Ubuntu with"
msgstr "Cari di distro anda, contoh di Debian/Ubuntu dengan"
msgid "You will need to install"
msgstr "Anda akan butuh untuk memasang"
......@@ -427,6 +439,16 @@ msgstr ""
"Perlu diketahui dalam Windows, pengalihan Spice adalah tidak otomatis"
"diperlukan untuk mengasosiasikan protokol dengan program."
msgid "To make this possible, download"
msgstr "Untuk memungkinkan, unduh "
msgid ""
"or copy the following lines in an ASCII file and save with extension .reg, "
"then execute the file."
msgstr ""
"atau salin baris ini dalam ASCII dan simpan dengan ekstensien .reg, "
"lalu eksekusi file ini."
msgid "A viewer is required to run the virtual machines."
msgstr "Penonton dibutuhkan untuk menjalankan mesin virtual."
......@@ -629,9 +651,18 @@ msgstr "mengubah status publik"
msgid "Changing Base State"
msgstr "Mengubah status basis"
msgid "action"
msgstr "aksi"
msgid "Grants"
msgstr "Hibah"
msgid "public"
msgstr "publik"
msgid "New Base"
msgstr "Basis Baru"
msgid "Version"
msgstr "Versi"
......@@ -653,6 +684,9 @@ msgstr "Kodenya adalah"
msgid "License"
msgstr "Lisensi"
msgid "Machine locked by"
msgstr "Mesin terkunci oleh"
msgid "This Machine is a base"
msgstr "Mesin ini adalah basis"
......
......@@ -487,10 +487,62 @@ sub test_domain_limit_noadmin {
is(scalar @list,1) or die Dumper(\@list);
is($list[0]->name, $domain2->name) if $list[0];
$domain2->remove($user);
$domain->remove($user);
$domain->remove(user_admin);
$domain2->remove(user_admin);
}
sub test_domain_limit_allowed {
my $vm_name = shift;
my $user = $USER;
user_admin->grant($user,'create_machine');
user_admin->grant($user,'start_many');
is($user->is_admin,0);
for my $domain ( rvd_back->list_domains()) {
$domain->shutdown_now(user_admin);
}
my $domain = create_domain($vm_name, $user);
ok($domain,"Expecting a new domain created") or exit;
$domain->shutdown_now($USER) if $domain->is_active;
is(rvd_back->list_domains(user => $user, active => 1),0
,Dumper(rvd_back->list_domains())) or exit;
$domain->start( $user);
is($domain->is_active,1);
ok($domain->start_time <= time,"Expecting start time <= ".time
." got ".time);
sleep 1;
is(rvd_back->list_domains(user => $user, active => 1),1);
my $domain2 = create_domain($vm_name, $user);
$domain2->shutdown_now( $user ) if $domain2->is_active;
is(rvd_back->list_domains(user => $user, active => 1),1);
$domain2->start( $user );
my $req = Ravada::Request->enforce_limits(timeout => 1);
rvd_back->_process_all_requests_dont_fork();
sleep 1;
rvd_back->_process_all_requests_dont_fork();
my @list = rvd_back->list_domains(user => $user, active => 1);
is(scalar @list,2) or die Dumper([ map { $_->name } @list]);
user_admin->revoke($user,'start_many');
$req = Ravada::Request->enforce_limits(timeout => 1);
rvd_back->_process_all_requests_dont_fork();
sleep 1;
rvd_back->_process_all_requests_dont_fork();
@list = rvd_back->list_domains(user => $user, active => 1);
is(scalar @list,1,"[$vm_name] expecting 1 active domain")
or die Dumper([ map { $_->name } @list]);
$domain->remove(user_admin);
$domain2->remove(user_admin);
}
sub test_domain_limit_already_requested {
my $vm_name = shift;
......@@ -584,6 +636,7 @@ for my $vm_name ('Void','KVM') {
test_spinned_off_base($vm_name);
test_domain_limit_admin($vm_name);
test_domain_limit_noadmin($vm_name);
test_domain_limit_allowed($vm_name);
$domain->remove( user_admin );
......
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