From ed16531437cab31b924dfa32a4aae3be276fb506 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Mon, 20 Nov 2023 15:50:27 +0200 Subject: [PATCH] WIP - fixes --- pkg/storaged/filesystem/filesystem.jsx | 12 ++++++----- pkg/storaged/iscsi/create-dialog.jsx | 19 ++++++++--------- pkg/storaged/lvm2/create-dialog.jsx | 3 ++- pkg/storaged/nfs/nfs.jsx | 28 ++++++++++++-------------- pkg/storaged/overview/overview.jsx | 10 ++++----- pkg/storaged/pages.jsx | 2 +- pkg/storaged/stratis/create-dialog.jsx | 3 ++- test/verify/check-metrics | 2 +- test/verify/check-storage-lvm2 | 4 ++-- test/verify/check-storage-multipath | 1 + 10 files changed, 44 insertions(+), 40 deletions(-) diff --git a/pkg/storaged/filesystem/filesystem.jsx b/pkg/storaged/filesystem/filesystem.jsx index e839d6ebea73..19ae01041a61 100644 --- a/pkg/storaged/filesystem/filesystem.jsx +++ b/pkg/storaged/filesystem/filesystem.jsx @@ -32,8 +32,8 @@ import { import { dialog_open, TextInput, } from "../dialog.jsx"; -import { StorageLink, StorageUsageBar } from "../storage-controls.jsx"; -import { StorageCard, new_card } from "../pages.jsx"; +import { StorageLink, StorageUsageBar, StorageSize } from "../storage-controls.jsx"; +import { StorageCard, new_card, useIsNarrow } from "../pages.jsx"; import { format_dialog } from "../block/format-dialog.jsx"; import { is_mounted, MountPoint } from "./utils.jsx"; @@ -68,11 +68,13 @@ const _ = cockpit.gettext; const MountPointUsageBar = ({ mount_point, block, short }) => { useEvent(client.fsys_sizes, "changed"); + const narrow = useIsNarrow(); + const stats = client.fsys_sizes.data[mount_point]; if (stats) return ; - else if (short) - return block.Size; + else if (short && !narrow) + return ; else return fmt_size(block.Size); }; @@ -94,7 +96,7 @@ export function make_filesystem_card(next, backing_block, content_block, fstab_c title: content_block ? cockpit.format(_("$0 filesystem"), content_block.IdType) : _("Filesystem"), location: mp_text, next, - page_size: , + page_size: , has_warning: !!mismount_warning, component: FilesystemCard, props: { backing_block, content_block, fstab_config, mismount_warning }, diff --git a/pkg/storaged/iscsi/create-dialog.jsx b/pkg/storaged/iscsi/create-dialog.jsx index 7f3a6ab50dd0..519f6f87e51c 100644 --- a/pkg/storaged/iscsi/create-dialog.jsx +++ b/pkg/storaged/iscsi/create-dialog.jsx @@ -18,12 +18,13 @@ */ import cockpit from "cockpit"; +import client from "../client.js"; import { dialog_open, TextInput, PassInput, SelectRow } from "../dialog.jsx"; const _ = cockpit.gettext; -export function iscsi_discover(client) { +export function iscsi_discover() { dialog_open({ Title: _("Add iSCSI portal"), Fields: [ @@ -50,7 +51,7 @@ export function iscsi_discover(client) { .then(function (results) { if (!cancelled) { resolve(); - iscsi_add(client, vals, results[0]); + iscsi_add(vals, results[0]); } }) .catch(function (error) { @@ -84,7 +85,7 @@ export function iscsi_discover(client) { }); } -function iscsi_login(client, target, cred_vals) { +function iscsi_login(target, cred_vals) { const options = { 'node.startup': { t: 's', v: "automatic" } }; @@ -102,7 +103,7 @@ function iscsi_login(client, target, cred_vals) { ]); } -function iscsi_add(client, discover_vals, nodes) { +function iscsi_add(discover_vals, nodes) { dialog_open({ Title: cockpit.format(_("Available targets on $0"), discover_vals.address), @@ -118,10 +119,10 @@ function iscsi_add(client, discover_vals, nodes) { Action: { Title: _("Add"), action: function (vals) { - return iscsi_login(client, vals.target, discover_vals) + return iscsi_login(vals.target, discover_vals) .catch(err => { if (err.message.indexOf("authorization") != -1) - iscsi_add_with_creds(client, discover_vals, vals); + iscsi_add_with_creds(discover_vals, vals); else return Promise.reject(err); }); @@ -130,7 +131,7 @@ function iscsi_add(client, discover_vals, nodes) { }); } -function iscsi_add_with_creds(client, discover_vals, login_vals) { +function iscsi_add_with_creds(discover_vals, login_vals) { dialog_open({ Title: _("Authentication required"), Fields: [ @@ -142,7 +143,7 @@ function iscsi_add_with_creds(client, discover_vals, login_vals) { Action: { Title: _("Add"), action: function (vals) { - return iscsi_login(client, login_vals.target, vals) + return iscsi_login(login_vals.target, vals) .catch(err => { // HACK - https://github.com/storaged-project/udisks/issues/26 if (err.message.indexOf("authorization") != -1) @@ -157,7 +158,7 @@ function iscsi_add_with_creds(client, discover_vals, login_vals) { }); } -export function iscsi_change_name(client) { +export function iscsi_change_name() { return client.manager_iscsi.call('GetInitiatorName') .then(function (results) { const name = results[0]; diff --git a/pkg/storaged/lvm2/create-dialog.jsx b/pkg/storaged/lvm2/create-dialog.jsx index 05305b4163a3..cd19a36e6b1c 100644 --- a/pkg/storaged/lvm2/create-dialog.jsx +++ b/pkg/storaged/lvm2/create-dialog.jsx @@ -18,13 +18,14 @@ */ import cockpit from "cockpit"; +import client from "../client.js"; import { dialog_open, TextInput, SelectSpaces } from "../dialog.jsx"; import { validate_lvm2_name, get_available_spaces, prepare_available_spaces } from "../utils.js"; const _ = cockpit.gettext; -export function create_vgroup(client) { +export function create_vgroup() { function find_vgroup(name) { for (const p in client.vgroups) { if (client.vgroups[p].Name == name) diff --git a/pkg/storaged/nfs/nfs.jsx b/pkg/storaged/nfs/nfs.jsx index abc79ce59c5c..6fa91fc74413 100644 --- a/pkg/storaged/nfs/nfs.jsx +++ b/pkg/storaged/nfs/nfs.jsx @@ -37,7 +37,7 @@ import { parse_options, unparse_options, extract_option } from "../utils.js"; const _ = cockpit.gettext; -function nfs_busy_dialog(client, dialog_title, entry, error, action_title, action) { +function nfs_busy_dialog(dialog_title, entry, error, action_title, action) { function show(users) { if (users.length === 0) { dialog_open({ @@ -82,7 +82,7 @@ function get_exported_directories(server) { }); } -export function nfs_fstab_dialog(client, entry, card) { +export function nfs_fstab_dialog(entry, card) { const mount_options = entry ? entry.fields[3] : "defaults"; const split_options = parse_options(mount_options == "defaults" ? "" : mount_options); const opt_auto = !extract_option(split_options, "noauto"); @@ -224,20 +224,19 @@ function checked(error_title, promise) { }); } -function mount(client, entry) { +function mount(entry) { checked("Could not mount the filesystem", client.nfs.mount_entry(entry)); } -function unmount(client, entry, card) { +function unmount(entry, card) { client.nfs.unmount_entry(entry) .then(function () { if (!entry.fstab) navigate_away_from_card(card); }) .catch(function (error) { - nfs_busy_dialog(client, - _("Unable to unmount filesystem"), + nfs_busy_dialog(_("Unable to unmount filesystem"), entry, error, _("Stop and unmount"), function (users) { @@ -250,18 +249,17 @@ function unmount(client, entry, card) { }); } -function edit(client, entry, card) { - nfs_fstab_dialog(client, entry, card); +function edit(entry, card) { + nfs_fstab_dialog(entry, card); } -function remove(client, entry, card) { +function remove(entry, card) { client.nfs.remove_entry(entry) .then(function () { navigate_away_from_card(card); }) .catch(function (error) { - nfs_busy_dialog(client, - _("Unable to remove mount"), + nfs_busy_dialog(_("Unable to remove mount"), entry, error, _("Stop and remove"), function (users) { @@ -299,13 +297,13 @@ export function make_nfs_page(parent, entry) { props: { entry }, actions: [ (entry.mounted - ? { title: _("Unmount"), action: () => unmount(client, entry, nfs_card) } - : { title: _("Mount"), action: () => mount(client, entry) }), + ? { title: _("Unmount"), action: () => unmount(entry, nfs_card) } + : { title: _("Mount"), action: () => mount(entry) }), (entry.fstab - ? { title: _("Edit"), action: () => edit(client, entry, nfs_card) } + ? { title: _("Edit"), action: () => edit(entry, nfs_card) } : null), (entry.fstab - ? { title: _("Remove"), action: () => remove(client, entry, nfs_card), danger: true } + ? { title: _("Remove"), action: () => remove(entry, nfs_card), danger: true } : null), ] }); diff --git a/pkg/storaged/overview/overview.jsx b/pkg/storaged/overview/overview.jsx index fdc9a9a71dd1..0c44134109eb 100644 --- a/pkg/storaged/overview/overview.jsx +++ b/pkg/storaged/overview/overview.jsx @@ -140,11 +140,11 @@ const OverviewCard = ({ card, plot_state }) => { const menu_items = [ menu_item(null, _("Create MDRAID device"), () => create_mdraid()), - menu_item(lvm2_feature, _("Create LVM2 volume group"), () => create_vgroup(client)), - menu_item(stratis_feature, _("Create Stratis pool"), () => create_stratis_pool(client)), - menu_item(nfs_feature, _("New NFS mount"), () => nfs_fstab_dialog(client, null, null)), - menu_item(iscsi_feature, _("Change iSCSI initiater name"), () => iscsi_change_name(client)), - menu_item(iscsi_feature, _("Add iSCSI portal"), () => iscsi_discover(client)), + menu_item(lvm2_feature, _("Create LVM2 volume group"), () => create_vgroup()), + menu_item(stratis_feature, _("Create Stratis pool"), () => create_stratis_pool()), + menu_item(nfs_feature, _("New NFS mount"), () => nfs_fstab_dialog(null, null)), + menu_item(iscsi_feature, _("Change iSCSI initiater name"), () => iscsi_change_name()), + menu_item(iscsi_feature, _("Add iSCSI portal"), () => iscsi_discover()), ].filter(item => item !== null); const actions = ; diff --git a/pkg/storaged/pages.jsx b/pkg/storaged/pages.jsx index 38231c494b79..928c208b5e36 100644 --- a/pkg/storaged/pages.jsx +++ b/pkg/storaged/pages.jsx @@ -320,7 +320,7 @@ function page_block_summary(page) { let narrow_query = null; -const useIsNarrow = (onChange) => { +export const useIsNarrow = (onChange) => { if (!narrow_query) { const val = window.getComputedStyle(window.document.body).getPropertyValue("--pf-v5-global--breakpoint--md"); narrow_query = window.matchMedia(`(max-width: ${val})`); diff --git a/pkg/storaged/stratis/create-dialog.jsx b/pkg/storaged/stratis/create-dialog.jsx index e87d17e915d8..7f6be6109ec7 100644 --- a/pkg/storaged/stratis/create-dialog.jsx +++ b/pkg/storaged/stratis/create-dialog.jsx @@ -18,6 +18,7 @@ */ import cockpit from "cockpit"; +import client from "../client.js"; import { dialog_open, TextInput, CheckBoxes, PassInput, SelectSpaces } from "../dialog.jsx"; import { decode_filename, get_available_spaces, prepare_available_spaces } from "../utils.js"; @@ -27,7 +28,7 @@ import { validate_url, get_tang_adv } from "../crypto/tang.jsx"; const _ = cockpit.gettext; -export function create_stratis_pool(client) { +export function create_stratis_pool() { function find_pool(name) { for (const p in client.stratis_pools) { if (client.stratis_pools[p].Name == name) diff --git a/test/verify/check-metrics b/test/verify/check-metrics index 5520219b53bb..6e1d7f246b44 100755 --- a/test/verify/check-metrics +++ b/test/verify/check-metrics @@ -1213,7 +1213,7 @@ BEGIN {{ b.enter_page("/storage") # weird -- storage page does not show transient mount points, only permanent ones; so check for the device dev = m.execute("findmnt --noheadings -o SOURCE /var/cockpittest").strip() - b.wait_in_text("#mounts", dev) + b.wait_in_text('[data-test-card-title="Storage"]', dev) b.go("/metrics") b.enter_page("/metrics") diff --git a/test/verify/check-storage-lvm2 b/test/verify/check-storage-lvm2 index 3fc7dde85224..ce84916651a0 100755 --- a/test/verify/check-storage-lvm2 +++ b/test/verify/check-storage-lvm2 @@ -304,14 +304,14 @@ class TestStorageLvm2(storagelib.StorageCase): b.click(self.card_row("Storage", name="vgroup0")) # Check the we are really using a partition on disk1 now - b.wait_in_text(self.card_row_col("LVM2 physical volumes", 1, 2), f"Partition - Linux scsi_debug (8000)") + b.wait_in_text(self.card_row_col("LVM2 physical volumes", 1, 2), "Partition - Linux scsi_debug (8000)") # Add the unused space of disk2 self.dialog_with_retry(trigger=lambda: b.click(self.card_button("LVM2 physical volumes", "Add physical volume")), expect=lambda: self.dialog_is_present( 'disks', "unpartitioned space on " + disk2), values={"disks": {disk2: True}}) - b.wait_in_text(self.card_row_col("LVM2 physical volumes", 1, 2), f"Partition - Block device") + b.wait_in_text(self.card_row_col("LVM2 physical volumes", 1, 2), "Partition - Block device") def testSnapshots(self): m = self.machine diff --git a/test/verify/check-storage-multipath b/test/verify/check-storage-multipath index d095a2917156..9546625dccaa 100755 --- a/test/verify/check-storage-multipath +++ b/test/verify/check-storage-multipath @@ -20,6 +20,7 @@ import storagelib import testlib + @testlib.skipImage("No support for multipath", "debian-*", "ubuntu-*", "arch") class TestStorageMultipath(storagelib.StorageCase):