Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint restore fixes #1149

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/ContainerCheckpointModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ const ContainerCheckpointModal = ({ containerWillCheckpoint, onAddNotification }
const [keep, setKeep] = useState(false);
const [leaveRunning, setLeaveRunning] = useState(false);
const [tcpEstablished, setTcpEstablished] = useState(false);
const [ignoreRootFS, setIgnoreRootFS] = useState(false);

const handleCheckpointContainer = () => {
setProgress(true);
client.postContainer(containerWillCheckpoint.isSystem, "checkpoint", containerWillCheckpoint.Id, {
keep,
leaveRunning,
tcpEstablished,
ignoreRootFS,
})
.catch(ex => {
const error = cockpit.format(_("Failed to checkpoint container $0"), containerWillCheckpoint.Names);
Expand Down Expand Up @@ -59,9 +57,6 @@ const ContainerCheckpointModal = ({ containerWillCheckpoint, onAddNotification }
<Checkbox label={_("Support preserving established TCP connections")}
id="checkpoint-dialog-tcpEstablished" name="tcpEstablished"
isChecked={tcpEstablished} onChange={setTcpEstablished} />
<Checkbox label={_("Do not include root file-system changes when exporting")}
id="checkpoint-dialog-ignoreRootFS" name="ignoreRootFS"
isChecked={ignoreRootFS} onChange={setIgnoreRootFS} />
</Form>
</Modal>
);
Expand Down
127 changes: 54 additions & 73 deletions src/ContainerRestoreModal.jsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,71 @@
import React from 'react';
import React, { useState } from 'react';
import { Button, Checkbox, Form, Modal } from '@patternfly/react-core';
import { DialogsContext } from "dialogs.jsx";
import { useDialogs } from "dialogs.jsx";
import cockpit from 'cockpit';

import * as client from './client.js';

const _ = cockpit.gettext;

class ContainerRestoreModal extends React.Component {
static contextType = DialogsContext;
const ContainerRestoreModal = ({ containerWillRestore, onAddNotification }) => {
const Dialogs = useDialogs();

constructor(props) {
super(props);
this.state = {
inProgress: false,
keep: false,
tcpEstablished: false,
ignoreRootFS: false,
ignoreStaticIP: false,
ignoreStaticMAC: false
};
this.handleChange = this.handleChange.bind(this);
}
const [inProgress, setInProgress] = useState(false);
const [keep, setKeep] = useState(false);
const [tcpEstablished, setTcpEstablished] = useState(false);
const [ignoreStaticIP, setIgnoreStaticIP] = useState(false);
const [ignoreStaticMAC, setIgnoreStaticMAC] = useState(false);

handleChange(checked, event) {
if (event.target.type === "checkbox")
this.setState({ [event.target.name]: event.target.checked });
}

handleRestoreContainer(args) {
const Dialogs = this.context;
const container = this.props.containerWillRestore;
this.setState({ inProgress: true });
client.postContainer(container.isSystem, "restore", container.Id, args)
const handleRestoreContainer = () => {
setInProgress(true);
client.postContainer(containerWillRestore.isSystem, "restore", containerWillRestore.Id, {
keep,
tcpEstablished,
ignoreStaticIP,
ignoreStaticMAC,
})
.catch(ex => {
const error = cockpit.format(_("Failed to restore container $0"), container.Names);
this.props.onAddNotification({ type: 'danger', error, errorDetail: ex.message });
this.setState({ inProgress: false });
const error = cockpit.format(_("Failed to restore container $0"), containerWillRestore.Names);
onAddNotification({ type: 'danger', error, errorDetail: ex.message });
setInProgress(false);
})
.finally(() => {
Dialogs.close();
});
}
};

render() {
const Dialogs = this.context;
return (
<Modal isOpen
showClose={false}
position="top" variant="medium"
title={cockpit.format(_("Restore container $0"), this.props.containerWillRestore.Names)}
footer={<>
<Button variant="primary" isDisabled={this.state.inProgress}
isLoading={this.state.inProgress}
onClick={() => {
this.handleRestoreContainer({
keep: this.state.keep,
leaveRunning: this.state.leaveRunning,
tcpEstablished: this.state.tcpEstablished,
ignoreRootFS: this.state.ignoreRootFS
});
}}>
{_("Restore")}
</Button>
<Button variant="link" isDisabled={this.state.inProgress}
onClick={Dialogs.close}>
{_("Cancel")}
</Button>
</>}
>
<Form isHorizontal>
<Checkbox label={_("Keep all temporary checkpoint files")} id="restore-dialog-keep" name="keep"
isChecked={this.state.keep} onChange={this.handleChange} />
<Checkbox label={_("Restore with established TCP connections")}
id="restore-dialog-tcpEstablished" name="tcpEstablished"
isChecked={this.state.tcpEstablished} onChange={this.handleChange} />
<Checkbox label={_("Ignore IP address if set statically")} id="restore-dialog-ignoreStaticIP"
name="ignoreStaticIP" isChecked={this.state.ignoreStaticIP}
onChange={this.handleChange} />
<Checkbox label={_("Ignore MAC address if set statically")} id="restore-dialog-ignoreStaticMAC"
name="ignoreStaticMAC" isChecked={this.state.ignoreStaticMAC}
onChange={this.handleChange} />
</Form>
</Modal>
);
}
}
return (
<Modal isOpen
showClose={false}
position="top" variant="medium"
title={cockpit.format(_("Restore container $0"), containerWillRestore.Names)}
footer={<>
<Button variant="primary" isDisabled={inProgress}
isLoading={inProgress}
onClick={handleRestoreContainer}>
{_("Restore")}
</Button>
<Button variant="link" isDisabled={inProgress}
onClick={Dialogs.close}>
{_("Cancel")}
</Button>
</>}
>
<Form isHorizontal>
<Checkbox label={_("Keep all temporary checkpoint files")} id="restore-dialog-keep" name="keep"
isChecked={keep} onChange={setKeep} />
<Checkbox label={_("Restore with established TCP connections")}
id="restore-dialog-tcpEstablished" name="tcpEstablished"
isChecked={tcpEstablished} onChange={setTcpEstablished} />
<Checkbox label={_("Ignore IP address if set statically")} id="restore-dialog-ignoreStaticIP"
name="ignoreStaticIP" isChecked={ignoreStaticIP}
onChange={setIgnoreStaticIP} />
<Checkbox label={_("Ignore MAC address if set statically")} id="restore-dialog-ignoreStaticMAC"
name="ignoreStaticMAC" isChecked={ignoreStaticMAC}
onChange={setIgnoreStaticMAC} />
</Form>
</Modal>
);
};

export default ContainerRestoreModal;
2 changes: 0 additions & 2 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,6 @@ class TestApplication(testlib.MachineCase):
self.performContainerAction("busybox:latest", "Checkpoint")
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-keep', True)
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-tcpEstablished', True)
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-ignoreRootFS', True)
b.click('.pf-c-modal-box button:contains(Checkpoint)')
b.wait_not_present('.modal_dialog')

Expand Down Expand Up @@ -1175,7 +1174,6 @@ class TestApplication(testlib.MachineCase):
self.performContainerAction("swamped-crate", "Checkpoint")
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-keep', True)
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-tcpEstablished', True)
b.set_checked('.pf-c-modal-box input#checkpoint-dialog-ignoreRootFS', True)
b.click('.pf-c-modal-box button:contains(Checkpoint)')

with b.wait_timeout(300):
Expand Down