Skip to content

Commit

Permalink
WIP: cockpit storage integration
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed Nov 30, 2023
1 parent 3d3c095 commit f01f3f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/components/storage/InstallationDestination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export const InstallationDestination = ({
: _("No usable disks detected")
)}
{rescanDisksButton}
{!isBootIso && <ModifyStorage idPrefix={idPrefix} onCritFail={onCritFail} onRescan={onClickRescan} />}
<ModifyStorage idPrefix={idPrefix} onCritFail={onCritFail} onRescan={onClickRescan} />
</Flex>
</FormGroup>
</>
Expand Down
41 changes: 23 additions & 18 deletions src/components/storage/ModifyStorage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ import { WrenchIcon, ExternalLinkAltIcon } from "@patternfly/react-icons";
const _ = cockpit.gettext;
const N_ = cockpit.noop;

const startBlivetGUI = (onStart, onStarted, errorHandler) => {
console.log("Spawning blivet-gui.");
// We don't have an event informing that blivet-gui started so just wait a bit.
const timeoutId = window.setTimeout(onStarted, 3000);
cockpit.spawn(["blivet-gui", "--keep-above", "--auto-dev-updates"], { err: "message" })
.then(() => {
console.log("blivet-gui exited.");
// If the blivet-gui exits earlier cancel the delay
window.clearTimeout(timeoutId);
return onStarted();
})
.catch((error) => { window.clearTimeout(timeoutId); errorHandler(error) });
let cockpit_window = null;

const startCockpitStorage = (onStart, onStarted, errorHandler) => {
window.localStorage.setItem("cockpit_anaconda",
JSON.stringify({
mount_point_prefix: "/mnt/sysimage",
ignore_devices: ["/dev/sr0", "/dev/loop0"]
}));
cockpit_window = window.open("/cockpit/@localhost/storage/index.html", "storage-tab");
onStart();
onStarted();
};

const stopCockpitStorage = () => {
if (cockpit_window) {
cockpit_window.close();
cockpit_window = null;
}
};

const StorageModifiedModal = ({ onClose, onRescan }) => {
Expand All @@ -55,7 +60,7 @@ const StorageModifiedModal = ({ onClose, onRescan }) => {
footer={
<>
<Button
onClick={() => { onClose(); onRescan() }}
onClick={() => { stopCockpitStorage(); onClose(); onRescan() }}
variant="primary"
id="storage-modified-modal-rescan-btn"
key="rescan"
Expand All @@ -64,7 +69,7 @@ const StorageModifiedModal = ({ onClose, onRescan }) => {
</Button>
<Button
variant="secondary"
onClick={() => onClose()}
onClick={() => { stopCockpitStorage(); onClose() }}
id="storage-modified-modal-ignore-btn"
key="ignore"
>
Expand Down Expand Up @@ -92,7 +97,7 @@ const ModifyStorageModal = ({ onClose, onToolStarted, errorHandler }) => {
footer={
<>
<Button
onClick={() => startBlivetGUI(
onClick={() => startCockpitStorage(
onStart,
onStarted,
errorHandler
Expand All @@ -103,7 +108,7 @@ const ModifyStorageModal = ({ onClose, onToolStarted, errorHandler }) => {
isDisabled={toolIsStarting}
variant="primary"
>
{_("Launch Blivet-gui storage editor")}
{_("Launch storage editor")}
</Button>
<Button
variant="link"
Expand All @@ -118,10 +123,10 @@ const ModifyStorageModal = ({ onClose, onToolStarted, errorHandler }) => {
}>
<TextContent>
<Text component={TextVariants.p}>
{_("Blivet-gui is an advanced storage editor that lets you resize, delete, and create partitions. It can set up LVM and much more.")}
{_("The storage editor lets you resize, delete, and create partitions. It can set up LVM and much more.")}
</Text>
<Text component={TextVariants.p}>
{_("Changes made in Blivet-gui will directly affect your storage.")}
{_("Changes made in the storage editor will directly affect your storage.")}
</Text>
</TextContent>
</Modal>
Expand Down
2 changes: 2 additions & 0 deletions src/components/storage/MountPointMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
import "./MountPointMapping.scss";

const _ = cockpit.gettext;
const cmpm = JSON.parse(window.localStorage.getItem("cockpit_mount_points"));

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable cmpm.

/* Filter out the partitioning requests array to contain only:
* - rows with required mount points
Expand Down Expand Up @@ -637,6 +638,7 @@ export const MountPointMapping = ({

return (
<>
<p>Cockpit says: {window.localStorage.getItem("cockpit_mount_points")}</p>
{showLuksUnlock &&
(
<EncryptedDevices
Expand Down
1 change: 1 addition & 0 deletions test/build-rpms
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ missing_packages = "cockpit-ws cockpit-bridge cockpit-storaged firefox dbus-glib

from machine.machine_core import machine_virtual # NOQA: imported through parent.py

TEST_SCENARIO="cockpit-pr-19352"

def build_rpms(srpm, image, verbose, quick):
subprocess.check_call([os.path.join(BOTS_DIR, "image-download"), image])
Expand Down

0 comments on commit f01f3f3

Please sign in to comment.