Skip to content
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
4 changes: 4 additions & 0 deletions app/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ const instanceActions = {
updateNic: ['stopped'],
// https://github.com/oxidecomputer/omicron/blob/6dd9802/nexus/src/app/instance.rs#L1520-L1522
serialConsole: ['running', 'rebooting', 'migrating', 'repairing'],

// https://github.com/oxidecomputer/omicron/blob/5e27bde/nexus/src/app/affinity.rs#L357 checks to see that there's no VMM
// TODO: determine whether the intent is only `stopped` or also `failed`
addToAntiAffinityGroup: ['stopped'],
} satisfies Record<string, InstanceState[]>

// setting .states is a cute way to make it ergonomic to call the test function
Expand Down
32 changes: 24 additions & 8 deletions app/pages/project/instances/AntiAffinityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as R from 'remeda'

import {
apiq,
instanceCan,
queryClient,
useApiMutation,
usePrefetchedQuery,
Expand Down Expand Up @@ -53,6 +54,12 @@ export const allAntiAffinityGroups = ({ project }: PP.Project) =>
query: { project, limit: ALL_ISH },
})

const instanceView = ({ project, instance }: PP.Instance) =>
apiq('instanceView', {
path: { instance },
query: { project },
})

const colHelper = createColumnHelper<AffinityGroup | AntiAffinityGroup>()
const staticCols = [
colHelper.accessor('description', Columns.description),
Expand All @@ -70,6 +77,7 @@ export function AntiAffinityCard() {
instanceAntiAffinityGroups(instanceSelector)
)
const { data: allGroups } = usePrefetchedQuery(allAntiAffinityGroups(instanceSelector))
const { data: instanceData } = usePrefetchedQuery(instanceView(instanceSelector))

const nonMemberGroups = useMemo(
() => R.differenceWith(allGroups.items, memberGroups.items, (a, b) => a.id === b.id),
Expand Down Expand Up @@ -143,19 +151,27 @@ export function AntiAffinityCard() {
getCoreRowModel: getCoreRowModel(),
})

const getDisabledReason = () => {
if (!instanceCan.addToAntiAffinityGroup(instanceData)) {
return 'This instance must be stopped to add it to a group'
}
if (allGroups.items.length === 0) {
return 'No groups found'
}
if (nonMemberGroups.length === 0) {
return 'Instance is already in all groups'
}
return undefined
}
const disabledReason = getDisabledReason()

return (
<CardBlock>
<CardBlock.Header title="Anti-affinity groups" titleId="anti-affinity-groups-label">
<Button
size="sm"
disabled={nonMemberGroups.length === 0}
disabledReason={
allGroups.items.length === 0
? 'No groups found'
: nonMemberGroups.length === 0
? 'Instance is already in all groups'
: undefined
}
disabled={!!disabledReason}
disabledReason={disabledReason}
onClick={() => setIsModalOpen(true)}
>
Add to group
Expand Down
15 changes: 13 additions & 2 deletions test/e2e/anti-affinity.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,19 @@ test('add and remove instance from group on instance settings', async ({ page })
// Ensure the group is not initially present
await expect(groupCell).toBeHidden()

// add instance to group
await page.getByRole('button', { name: 'Add to group' }).click()
// Make sure Add to group button is disabled
const addToGroupButton = page.getByRole('button', { name: 'Add to group' })
await expect(addToGroupButton).toBeDisabled()

// Stop the instance
await page.getByRole('button', { name: 'Stop' }).click()
const confirmStopModal = page.getByRole('dialog', { name: 'Confirm stop' })
await expect(confirmStopModal).toBeVisible()
await confirmStopModal.getByRole('button', { name: 'Confirm' }).click()
await expect(confirmStopModal).toBeHidden()

// Add instance to group
await addToGroupButton.click()
const modal = page.getByRole('dialog', { name: 'Add to anti-affinity group' })
await expect(modal).toBeVisible()
await modal.getByRole('combobox', { name: 'Anti-affinity group' }).click()
Expand Down
Loading