Skip to content

Commit

Permalink
Avoid removing VMs from an archived/archiving plans.
Browse files Browse the repository at this point in the history
Reference: https://issues.redhat.com/browse/MTV-1713

Avoid removing VMs from an archived/archiving plans.
If a plan's status is either archiving or archived, block the option to
remove VMs for that plan.

Signed-off-by: Sharon Gratch <[email protected]>
  • Loading branch information
sgratch committed Nov 27, 2024
1 parent 0047638 commit a9e19b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"Delete Provider": "Delete Provider",
"Delete StorageMap": "Delete StorageMap",
"Delete virtual machines from migration plan": "Delete virtual machines from migration plan",
"Deleting virtual machines from an archived migration plan is not allowed.": "Deleting virtual machines from an archived migration plan is not allowed.",
"Description": "Description",
"Details": "Details",
"Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.": "Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,11 @@ export const isPlanEditable = (plan: V1beta1Plan) => {
);
};

export const isPlanArchived = (plan: V1beta1Plan) => {
const planStatus = getPlanPhase({ obj: plan });

return planStatus === 'Archiving' || planStatus === 'Archived';
};

const getConditions = (obj: V1beta1Plan) =>
obj?.status?.conditions?.filter((c) => c.status === 'True').map((c) => c.type);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
StandardPageWithSelectionProps,
} from 'src/components/page/StandardPageWithSelection';
import { usePlanMigration } from 'src/modules/Plans/hooks/usePlanMigration';
import { isPlanExecuting } from 'src/modules/Plans/utils';
import { isPlanArchived, isPlanExecuting } from 'src/modules/Plans/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import { loadUserSettings, ResourceFieldFactory } from '@kubev2v/common';
Expand Down Expand Up @@ -244,10 +244,11 @@ export const MigrationVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) =>
}));

const isExecuting = isPlanExecuting(plan);
const isArchived = isPlanArchived(plan);

// If plan executing allow to cancel vms, o/w remove from plan
// If plan executing and not archived (happens when archiving a running plan), allow to cancel vms, o/w remove from plan
let actions: PageGlobalActions;
if (isExecuting) {
if (isExecuting && !isArchived) {
actions = [
({ selectedIds }) => (
<MigrationVMsCancelButton selectedIds={selectedIds || []} migration={lastMigration} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactNode, useCallback, useState } from 'react';
import { isPlanArchived } from 'src/modules/Plans/utils';
import { useToggle } from 'src/modules/Providers/hooks';
import { AlertMessageForModals, useModal } from 'src/modules/Providers/modals';
import { useForkliftTranslation } from 'src/utils/i18n';
Expand All @@ -23,6 +24,15 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
const vms = (plan?.spec?.vms || []).filter((vm) => !selected.includes(vm.id)) || [];

React.useEffect(() => {
if (isPlanArchived(plan)) {
setAlertMessage(
<AlertMessageForModals
title={t('Error')}
message={t('Deleting virtual machines from an archived migration plan is not allowed.')}
/>,
);
return;
}
if (vms.length < 1) {
setAlertMessage(
<AlertMessageForModals
Expand All @@ -33,7 +43,7 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
/>,
);
}
}, [vms]);
}, [vms, plan]);

const handleSave = useCallback(async () => {
toggleIsLoading();
Expand Down Expand Up @@ -63,7 +73,7 @@ export const PlanVMsDeleteModal: React.FC<PlanVMsDeleteModalProps> = ({ plan, se
key="confirm"
onClick={handleSave}
variant="danger"
isDisabled={vms.length < 1}
isDisabled={vms.length < 1 || isPlanArchived(plan)}
isLoading={isLoading}
>
{t('Delete')}
Expand Down

0 comments on commit a9e19b6

Please sign in to comment.