-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinstance-disks.e2e.ts
More file actions
309 lines (235 loc) · 10.5 KB
/
instance-disks.e2e.ts
File metadata and controls
309 lines (235 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import {
clickRowAction,
expect,
expectNoToast,
expectNotVisible,
expectRowVisible,
expectToast,
expectVisible,
stopInstance,
test,
} from './utils'
test('Disk detail side modal', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
await page.getByRole('button', { name: 'disk-1' }).click()
const modal = page.getByRole('dialog', { name: 'Disk details' })
await expect(modal).toBeVisible()
await expect(modal.getByText('disk-1')).toBeVisible()
await expect(modal.getByText('2 GiB')).toBeVisible()
})
test('Disabled actions', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
const bootDiskRow = page.getByRole('row', { name: 'disk-1', exact: false })
await expect(bootDiskRow).toBeVisible()
// Both buttons disabled, also test fancy tooltip
await bootDiskRow.getByRole('button', { name: 'Row actions' }).click()
const detachButton = page.getByRole('menuitem', { name: 'Detach' })
const unsetButton = page.getByRole('menuitem', { name: 'Unset' })
await expect(unsetButton).toBeDisabled()
await page.getByRole('menuitem', { name: 'Unset' }).hover()
await expect(
page.getByText('Instance must be stopped before boot disk can be changed')
).toBeVisible()
await expect(detachButton).toBeDisabled()
await detachButton.hover()
await expect(
page.getByText('Boot disk must be unset before it can be detached')
).toBeVisible()
await page.keyboard.press('Escape') // close menu
const otherDiskRow = page.getByRole('row', { name: 'disk-2', exact: false })
await expect(otherDiskRow).toBeVisible()
await otherDiskRow.getByRole('button', { name: 'Row actions' }).click()
const setButton = page.getByRole('menuitem', { name: 'Set as boot disk' })
await expect(setButton).toBeDisabled()
await setButton.hover()
await expect(
page.getByText('Instance must be stopped before boot disk can be changed')
).toBeVisible()
await expect(detachButton).toBeDisabled()
await detachButton.hover()
await expect(
page.getByText('Instance must be stopped before disk can be detached')
).toBeVisible()
await page.keyboard.press('Escape') // close menu
// confirm they become enabled when the instance is stopped
await stopInstance(page)
await bootDiskRow.getByRole('button', { name: 'Row actions' }).click()
await expect(unsetButton).toBeEnabled()
await expect(detachButton).toBeDisabled() // detach is always disabled on boot disk
await otherDiskRow.getByRole('button', { name: 'Row actions' }).click()
await expect(setButton).toBeEnabled()
await expect(detachButton).toBeEnabled()
})
test('Attach disk', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
// Have to stop instance to edit disks
await stopInstance(page)
// Attach existing disk form
await page.click('role=button[name="Attach existing disk"]')
// Disk is required
await expectNotVisible(page, ['text="Disk name is required"'])
await page.getByRole('button', { name: 'Attach disk' }).click()
await expectVisible(page, ['role=dialog >> text="Disk name is required"'])
await page.getByRole('combobox', { name: 'Disk name' }).click()
// disk-1 is already attached, so should not be visible in the list
await expectNotVisible(page, ['role=option[name="disk-1"]'])
await expectVisible(page, ['role=option[name="disk-3"]', 'role=option[name="disk-4"]'])
await page.click('role=option[name="disk-3"]')
await page.click('role=button[name="Attach disk"]')
await expectVisible(page, ['role=cell[name="disk-3"]'])
})
test('Create disk', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
const row = page.getByRole('cell', { name: 'created-disk' })
await expect(row).toBeHidden()
// Have to stop instance to edit disks
await stopInstance(page)
// New disk form
const createForm = page.getByRole('dialog', { name: 'Create disk' })
await expect(createForm).toBeHidden()
await page.getByRole('button', { name: 'Create disk' }).click()
await expect(createForm).toBeVisible()
await createForm.getByRole('textbox', { name: 'Name' }).fill('created-disk')
await expect(createForm.getByRole('textbox', { name: 'Description' })).toBeVisible()
await page.getByRole('radio', { name: 'Snapshot' }).click()
await page.getByRole('button', { name: 'Source snapshot' }).click()
await page.getByRole('option', { name: 'snapshot-heavy' }).click()
await createForm.getByRole('button', { name: 'Create disk' }).click()
const otherDisksTable = page.getByRole('table', { name: 'Additional disks' })
await expectRowVisible(otherDisksTable, { Disk: 'created-disk', size: '20 GiB' })
})
test('Detach disk', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
// Have to stop instance to edit disks
await stopInstance(page)
const successMsg = page.getByText('Disk disk-2 detached').first()
const row = page.getByRole('row', { name: 'disk-2' })
await expect(row).toBeVisible()
await expect(successMsg).toBeHidden()
await clickRowAction(page, 'disk-2', 'Detach')
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(successMsg).toBeVisible()
await expect(row).toBeHidden() // disk row goes away
})
test('Snapshot disk', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
// we don't know the full name of the disk, but this will work to find the toast
const toastMessage = /Snapshot disk-1-[a-z0-9]{6} created/
await expectNoToast(page, toastMessage)
await clickRowAction(page, 'disk-1', 'Snapshot')
await expectToast(page, toastMessage) // we see the toast!
// now go see the snapshot on the snapshots page
await page.getByRole('link', { name: 'Snapshots' }).click()
await page.getByRole('button', { name: 'next' }).click()
const table = page.getByRole('table')
await expectRowVisible(table, {
name: expect.stringMatching(/^disk-1-/),
disk: 'disk-1',
})
})
test('Attach disk error clears when modal closes', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
await stopInstance(page)
// Attach disks until we hit the limit
const disksToAttach = [
'disk-3',
'disk-4',
'disk-5',
'disk-6',
'disk-7',
'disk-8',
'disk-9',
'disk-10',
'local-disk',
'read-only-disk',
]
const attachModal = page.getByRole('dialog', { name: 'Attach disk' })
// Attach all available disks quickly to reach the 12 disk limit
for (const diskName of disksToAttach) {
await page.getByRole('button', { name: 'Attach existing disk' }).click()
await page.getByRole('combobox', { name: 'Disk name' }).click()
await page.getByRole('option', { name: diskName }).click()
await page.getByRole('button', { name: 'Attach disk' }).click()
await expect(attachModal).toBeHidden()
}
// Now try to attach one more and get an error
await page.getByRole('button', { name: 'Attach existing disk' }).click()
await expect(attachModal).toBeVisible()
await page.getByRole('combobox', { name: 'Disk name' }).click()
await page.getByRole('option', { name: 'disk-snapshot-error' }).click()
await page.getByRole('button', { name: 'Attach disk' }).click()
// Should see error about max disks
await expect(
page.getByText('Cannot attach more than 12 disks to an instance')
).toBeVisible()
// Close the modal - this is the key part of the bug test
await page.keyboard.press('Escape')
await expect(attachModal).toBeHidden()
// Detach one disk to make room
await clickRowAction(page, 'disk-10', 'Detach')
await page.getByRole('button', { name: 'Confirm' }).click()
// Try to attach again - error should be cleared (this was the bug)
await page.getByRole('button', { name: 'Attach existing disk' }).click()
await expect(attachModal).toBeVisible()
// The error should NOT be visible anymore
await expect(
page.getByText('Cannot attach more than 12 disks to an instance')
).toBeHidden()
// Should be able to successfully attach now
await page.getByRole('combobox', { name: 'Disk name' }).click()
await page.getByRole('option', { name: 'disk-snapshot-error' }).click()
await page.getByRole('button', { name: 'Attach disk' }).click()
await expect(attachModal).toBeHidden()
})
test('Change boot disk', async ({ page }) => {
await page.goto('/projects/mock-project/instances/db1')
// assert disk-1 is boot disk, disk-2 also there
const bootDiskTable = page.getByRole('table', { name: 'Boot disk' })
const otherDisksTable = page.getByRole('table', { name: 'Additional disks' })
const confirm = page.getByRole('button', { name: 'Confirm' })
const noBootDisk = page.getByText('No boot disk set')
const noOtherDisks = page.getByText('No other disks')
const disk1 = { Disk: 'disk-1', size: '2 GiB' }
const disk2 = { Disk: 'disk-2', size: '4 GiB' }
await expectRowVisible(bootDiskTable, disk1)
await expectRowVisible(otherDisksTable, disk2)
await stopInstance(page)
// Set disk-2 as boot disk
await clickRowAction(page, 'disk-2', 'Set as boot disk')
await confirm.click()
await expectRowVisible(bootDiskTable, disk2)
await expectRowVisible(otherDisksTable, disk1)
// Unset boot disk
await expect(noBootDisk).toBeHidden()
await clickRowAction(page, 'disk-2', 'Unset as boot disk')
await confirm.click()
await expect(noBootDisk).toBeVisible()
await expectRowVisible(otherDisksTable, disk1)
await expectRowVisible(otherDisksTable, disk2)
await expect(page.getByText('Setting a boot disk is recommended')).toBeVisible()
// detach disk so there's only one
await clickRowAction(page, 'disk-2', 'Detach')
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(page.getByText('Instance will boot from disk-1')).toBeVisible()
// set disk-1 back as boot disk
await clickRowAction(page, 'disk-1', 'Set as boot disk')
await confirm.click()
await expect(noBootDisk).toBeHidden()
await expect(noOtherDisks).toBeVisible()
// Remove disk-1 altogether, no disks left
await clickRowAction(page, 'disk-1', 'Unset as boot disk')
await confirm.click()
await expectRowVisible(otherDisksTable, disk1)
await clickRowAction(page, 'disk-1', 'Detach')
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(noBootDisk).toBeVisible()
await expect(noOtherDisks).toBeVisible()
await expect(page.getByText('Attach a disk to be able to set a boot disk')).toBeVisible()
})