Skip to content

Commit

Permalink
WIP - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Nov 20, 2023
1 parent f4576cd commit ed16531
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
12 changes: 7 additions & 5 deletions pkg/storaged/filesystem/filesystem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 <StorageUsageBar stats={stats} critical={0.95} block={block_name(block)} short={short} />;
else if (short)
return block.Size;
else if (short && !narrow)
return <StorageSize size={block.Size} />;
else
return fmt_size(block.Size);
};
Expand All @@ -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: <MountPointUsageBar key="size" mount_point={mount_point} block={backing_block} short />,
page_size: <MountPointUsageBar mount_point={mount_point} block={backing_block} short />,
has_warning: !!mismount_warning,
component: FilesystemCard,
props: { backing_block, content_block, fstab_config, mismount_warning },
Expand Down
19 changes: 10 additions & 9 deletions pkg/storaged/iscsi/create-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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) {
Expand Down Expand Up @@ -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" }
};
Expand All @@ -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),
Expand All @@ -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);
});
Expand All @@ -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: [
Expand All @@ -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)
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion pkg/storaged/lvm2/create-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 13 additions & 15 deletions pkg/storaged/nfs/nfs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
]
});
Expand Down
10 changes: 5 additions & 5 deletions pkg/storaged/overview/overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <StorageBarMenu label={_("Create storage device")} menuItems={menu_items} />;
Expand Down
2 changes: 1 addition & 1 deletion pkg/storaged/pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
Expand Down
3 changes: 2 additions & 1 deletion pkg/storaged/stratis/create-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/verify/check-metrics
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions test/verify/check-storage-lvm2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/verify/check-storage-multipath
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import storagelib
import testlib


@testlib.skipImage("No support for multipath", "debian-*", "ubuntu-*", "arch")
class TestStorageMultipath(storagelib.StorageCase):

Expand Down

0 comments on commit ed16531

Please sign in to comment.