Skip to content

Commit

Permalink
fix(volume) ensure volume snapshot editing is stable (was failing fre…
Browse files Browse the repository at this point in the history
…quently in firefox e2e tests

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Feb 26, 2024
1 parent cc03dbd commit d78b5ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/pages/instances/EditInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { useEventQueue } from "context/eventQueue";
import { hasDiskError, hasNetworkError } from "util/instanceValidation";
import FormFooterLayout from "components/forms/FormFooterLayout";
import { useToastNotification } from "context/toastNotificationProvider";
import { instanceLinkFromOperation } from "util/instances";
import { instanceLinkFromName } from "util/instances";

export interface InstanceEditDetailsFormValues {
name: string;
Expand Down Expand Up @@ -113,11 +113,11 @@ const EditInstance: FC<Props> = ({ instance }) => {
instancePayload.etag = instance.etag;

void updateInstance(instancePayload, project).then((operation) => {
const instanceLink = instanceLinkFromOperation({
operation,
const instanceName = values.name;
const instanceLink = instanceLinkFromName({
instanceName,
project,
});
if (!instanceLink) return;
eventQueue.set(
operation.metadata.id,
() => {
Expand Down
66 changes: 25 additions & 41 deletions src/pages/storage/forms/EditVolumeSnapshotForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,33 @@ const EditVolumeSnapshotForm: FC<Props> = ({ volume, snapshot, close }) => {
close();
};

const update = (expiresAt: string | null, newName?: string) => {
// NOTE: volume snapshot update api call is synchronous, so can't use events api
void updateVolumeSnapshot({
const updateExpirationTime = async (expiresAt: string | null) => {
await updateVolumeSnapshot({
volume,
snapshot: { ...snapshot, name: newName || snapshot.name },
snapshot,
expiresAt,
})
.then(() => {
notifyUpdateSuccess(newName || snapshot.name);
})
.catch((error: Error) => {
notify.failure("Snapshot update failed", error);
formik.setSubmitting(false);
});
}).catch((error: Error) => {
notify.failure("Snapshot update failed", error);
formik.setSubmitting(false);
});
};

const rename = (newName: string, expiresAt?: string | null) => {
void renameVolumeSnapshot({
volume,
snapshot,
newName,
}).then((operation) =>
eventQueue.set(
operation.metadata.id,
() => {
if (expiresAt) {
update(expiresAt || null, newName);
} else {
notifyUpdateSuccess(newName);
}
},
(msg) => {
const rename = (newName: string): Promise<void> => {
return new Promise((resolve) => {
void renameVolumeSnapshot({
volume,
snapshot,
newName,
}).then((operation) =>
eventQueue.set(operation.metadata.id, resolve, (msg) => {
toastNotify.failure(
`Snapshot ${snapshot.name} rename failed`,
new Error(msg),
);
formik.setSubmitting(false);
},
),
);
}),
);
});
};

const [expiryDate, expiryTime] = !snapshot.expires_at
Expand All @@ -100,24 +87,21 @@ const EditVolumeSnapshotForm: FC<Props> = ({ volume, snapshot, close }) => {
controllerState,
snapshot.name,
),
onSubmit: (values) => {
onSubmit: async (values) => {
notify.clear();
const newName = values.name;
const expiresAt =
values.expirationDate && values.expirationTime
? stringToIsoTime(
getExpiresAt(values.expirationDate, values.expirationTime),
)
: null;
const shouldRename = newName !== snapshot.name;
const shouldUpdate = expiresAt !== snapshot.expires_at;
if (shouldRename && shouldUpdate) {
rename(newName, expiresAt);
} else if (shouldRename) {
rename(newName);
} else {
update(expiresAt);
if (expiresAt !== snapshot.expires_at) {
await updateExpirationTime(expiresAt);
}
if (values.name !== snapshot.name) {
await rename(values.name);
}
notifyUpdateSuccess(values.name);
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/types/storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ export interface UploadState {
export interface LxdVolumeSnapshot {
name: string;
created_at: string;
expires_at: string;
expires_at?: string;
description?: string;
}

0 comments on commit d78b5ff

Please sign in to comment.