From 1197c0b678e45222e41183a538340ae1806b839c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 5 Jul 2022 17:34:32 +0200 Subject: [dnbd3/vmstore] Add selection for DNBD3 server, or NFS mode, show any errors --- .../vmstore/inc/vmstorebenchmark.inc.php | 16 ++++-- modules-available/vmstore/page.inc.php | 41 +++++++++++++-- .../vmstore/templates/benchmark-imgselect.html | 58 ++++++++++++++-------- .../vmstore/templates/benchmark-result.html | 24 +++++++-- 4 files changed, 106 insertions(+), 33 deletions(-) (limited to 'modules-available/vmstore') diff --git a/modules-available/vmstore/inc/vmstorebenchmark.inc.php b/modules-available/vmstore/inc/vmstorebenchmark.inc.php index 10c55431..3a696d04 100644 --- a/modules-available/vmstore/inc/vmstorebenchmark.inc.php +++ b/modules-available/vmstore/inc/vmstorebenchmark.inc.php @@ -25,12 +25,12 @@ class VmStoreBenchmark /** * @param array $machineUuids - * @param string $image - * @param bool $nfs + * @param string $image relative path/name of image + * @param string $serverOrMode IP address of DNBD3 server, OR 'auto' for all servers known to client, or 'nfs' for NFS * @param int $start timestamp when the clients should start * @return ?string taskId, or null on error */ - public static function start(string $id, array $machineUuids, string $image, bool $nfs, int &$start) + public static function start(string $id, array $machineUuids, string $image, string $serverOrMode, int &$start) { Module::isAvailable('rebootcontrol'); $clients = Database::queryAll('SELECT machineuuid, clientip FROM machine WHERE machineuuid IN (:uuids)', @@ -41,7 +41,13 @@ class VmStoreBenchmark // The more clients we have, the longer it takes to SSH into all of them. // As of 2022, RemoteExec processes 4 clients in parallel $start = ceil(count($clients) / 4 + 5 + time()); - $nfsOpt = $nfs ? '--nfs' : ''; + if ($serverOrMode === 'nfs') { + $modeOption = '--nfs'; + } elseif ($serverOrMode === 'auto') { + $modeOption = ''; + } else { + $modeOption = "--servers '$serverOrMode'"; + } // We fork off the benchmark into the background, and collect the results with another RemoteExec job // when we're done. This is because RemoteExec only does four concurrent SSH connections, so if we wanted to // do this the easy, synchronous way, we never could run more than four tests at the same time. @@ -49,7 +55,7 @@ class VmStoreBenchmark ( exec &> /dev/null < /dev/null setsid -image_speedcheck --start $start --console $nfsOpt --file "$image" > "/tmp/speedcheck-$id" +image_speedcheck --start $start --console $modeOption --file "$image" > "/tmp/speedcheck-$id" ) & COMMAND; $task = RebootControl::runScript($clients, $command); diff --git a/modules-available/vmstore/page.inc.php b/modules-available/vmstore/page.inc.php index 8813cde0..b490e749 100644 --- a/modules-available/vmstore/page.inc.php +++ b/modules-available/vmstore/page.inc.php @@ -91,6 +91,7 @@ class Page_VmStore extends Page if (!Module::isAvailable('rebootcontrol')) { ErrorHandler::traceError('rebootcontrol module not enabled'); } + Render::setTitle(Dictionary::translate('page-title-benchmark', true)); if (Request::post('action') === 'start') { $this->benchmarkActionStart(); } @@ -134,13 +135,23 @@ class Page_VmStore extends Page } Util::redirect('?do=vmstore&show=benchmark&action=result&id=' . $id); } - $nfs = !Dnbd3::isEnabled(); + $selectedServer = Request::post('server', 'auto', 'string'); + if ($selectedServer !== 'nfs' && !Dnbd3::isEnabled()) { + $selectedServer = 'nfs'; + } elseif ($selectedServer !== 'auto') { + $ip = Dnbd3::getServer($selectedServer); + if ($ip === false) { + Message::addError('invalid-dnbd3-server-id', $selectedServer); + return; + } + $selectedServer = $ip['clientip']; + } $data['image'] = Request::post('image', Request::REQUIRED, 'string'); // Save once first to minimize race window $data['task'] = 'inprogress'; Property::updateListEntry(VmStoreBenchmark::PROP_LIST_KEY, $id, json_encode($data), 30); $start = 0; - $data['task'] = VmStoreBenchmark::start($id, $data['machines'], $data['image'], $nfs, $start); + $data['task'] = VmStoreBenchmark::start($id, $data['machines'], $data['image'], $selectedServer, $start); if ($data['task'] === null) { $data['task'] = 'failed'; } else { @@ -176,7 +187,8 @@ class Page_VmStore extends Page if (!isset($images[$name])) { $images[$name] = [ 'users' => 0, - 'size' => Util::readableFileSize($img['size'], 1), + 'size' => $img['size'], + 'size_s' => Util::readableFileSize($img['size'], 1), 'name' => $name, 'id' => count($images) ]; @@ -184,8 +196,25 @@ class Page_VmStore extends Page $images[$name]['users'] += $img['users']; } } + $servers = []; + if (Dnbd3::isEnabled()) { + $servers[] = ['idx' => 'auto', + 'server' => Dictionary::translate('dnbd3-all-loadbalance', true)]; + foreach ($lookup as $ip => $idx) { + $servers[] = ['idx' => $idx, 'server' => $ip]; + } + } + if (!Dnbd3::isEnabled() || Dnbd3::hasNfsFallback()) { + $servers[] = ['idx' => 'nfs', 'server' => 'NFS']; + } + $servers[0]['checked'] = 'checked'; ArrayUtil::sortByColumn($images, 'users', SORT_NUMERIC | SORT_DESC); - Render::addTemplate('benchmark-imgselect', ['id' => $id, 'list' => array_values($images)]); + Module::isAvailable('js_stupidtable'); + Render::addTemplate('benchmark-imgselect', [ + 'id' => $id, + 'list' => array_values($images), + 'servers' => $servers, + ]); } private function benchmarkShowResult() @@ -265,6 +294,10 @@ EOF; 'values' => VmStoreBenchmark::parseBenchLine($mode[3]), ]; } + } else { + $client['stderr'] = substr($out['stderr'], 0, 4000) + . "\nStatus: {$out['state']}, ExitCode: {$out['exitCode']}'"; + $client['stdout'] = substr($out['stdout'], 0, 4000); } $m = Database::queryFirst('SELECT clientip, hostname FROM machine WHERE machineuuid = :uuid', ['uuid' => $uuid]); diff --git a/modules-available/vmstore/templates/benchmark-imgselect.html b/modules-available/vmstore/templates/benchmark-imgselect.html index 26ac898e..2ef61644 100644 --- a/modules-available/vmstore/templates/benchmark-imgselect.html +++ b/modules-available/vmstore/templates/benchmark-imgselect.html @@ -7,29 +7,45 @@ - - - - - - - - - - {{#list}} +
+
{{lang_image}}{{lang_users}}{{lang_size}}
+ - - - + + + - {{/list}} - -
-
- - -
-
{{users}}{{size}}{{lang_image}}{{lang_users}}{{lang_size}}
+ + + {{#list}} + + +
+ + +
+ + {{users}} + {{size_s}} + + {{/list}} + + + + +
+ +
+ {{lang_selectServerOrNfs}} +
+ {{#servers}} +
+ + +
+ {{/servers}} + +