-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-134095 / 25.10 / Allow root disk size to be increased (#11532)
- Loading branch information
Showing
97 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...nce-details/instance-disks/increase-root-disk-size/increase-root-disk-size.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<h1 matDialogTitle> | ||
{{ 'Increase Root Disk Size' | translate }} | ||
</h1> | ||
|
||
<form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()"> | ||
<ix-input | ||
type="number" | ||
formControlName="size" | ||
[label]="'Root Disk Size (in GiB)' | translate" | ||
[required]="true" | ||
></ix-input> | ||
|
||
<ix-form-actions> | ||
<button | ||
mat-button | ||
type="button" | ||
ixTest="cancel" | ||
matDialogClose | ||
> | ||
{{ 'Cancel' | translate }} | ||
</button> | ||
|
||
<button | ||
mat-button | ||
color="primary" | ||
type="submit" | ||
ixTest="save" | ||
[disabled]="form.invalid" | ||
> | ||
{{ 'Save' | translate }} | ||
</button> | ||
</ix-form-actions> | ||
</form> |
4 changes: 4 additions & 0 deletions
4
...nce-details/instance-disks/increase-root-disk-size/increase-root-disk-size.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:host { | ||
display: block; | ||
width: 350px; | ||
} |
86 changes: 86 additions & 0 deletions
86
...-details/instance-disks/increase-root-disk-size/increase-root-disk-size.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { MatButtonHarness } from '@angular/material/button/testing'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { of } from 'rxjs'; | ||
import { GiB } from 'app/constants/bytes.constant'; | ||
import { fakeSuccessfulJob } from 'app/core/testing/utils/fake-job.utils'; | ||
import { mockApi, mockJob } from 'app/core/testing/utils/mock-api.utils'; | ||
import { VirtualizationInstance } from 'app/interfaces/virtualization.interface'; | ||
import { DialogService } from 'app/modules/dialog/dialog.service'; | ||
import { IxFormHarness } from 'app/modules/forms/ix-forms/testing/ix-form.harness'; | ||
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'; | ||
import { ApiService } from 'app/modules/websocket/api.service'; | ||
import { | ||
IncreaseRootDiskSizeComponent, | ||
} from 'app/pages/virtualization/components/all-instances/instance-details/instance-disks/increase-root-disk-size/increase-root-disk-size.component'; | ||
|
||
describe('IncreaseRootDiskSizeComponent', () => { | ||
let spectator: Spectator<IncreaseRootDiskSizeComponent>; | ||
let loader: HarnessLoader; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: IncreaseRootDiskSizeComponent, | ||
providers: [ | ||
mockApi([ | ||
mockJob('virt.instance.update', fakeSuccessfulJob()), | ||
]), | ||
mockProvider(SnackbarService), | ||
mockProvider(MatDialogRef), | ||
mockProvider(DialogService, { | ||
jobDialog: jest.fn(() => ({ | ||
afterClosed: () => of(true), | ||
})), | ||
}), | ||
{ | ||
provide: MAT_DIALOG_DATA, | ||
useValue: { | ||
id: 'test', | ||
root_disk_size: 2 * GiB, | ||
} as VirtualizationInstance, | ||
}, | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
}); | ||
|
||
it('shows current root disk size', async () => { | ||
const form = await loader.getHarness(IxFormHarness); | ||
|
||
expect(await form.getValues()).toEqual({ | ||
'Root Disk Size (in GiB)': '2', | ||
}); | ||
}); | ||
|
||
it('increases root disk size when new value is set', async () => { | ||
const form = await loader.getHarness(IxFormHarness); | ||
await form.fillForm({ | ||
'Root Disk Size (in GiB)': '4', | ||
}); | ||
|
||
const saveButton = await loader.getHarness(MatButtonHarness.with({ text: 'Save' })); | ||
await saveButton.click(); | ||
|
||
expect(spectator.inject(ApiService).job).toHaveBeenCalledWith('virt.instance.update', [ | ||
'test', | ||
{ root_disk_size: 4 }, | ||
]); | ||
expect(spectator.inject(DialogService).jobDialog).toHaveBeenCalled(); | ||
expect(spectator.inject(SnackbarService).success).toHaveBeenCalled(); | ||
expect(spectator.inject(MatDialogRef).close).toHaveBeenCalledWith(4); | ||
}); | ||
|
||
it('does not allow value that is smaller than previous root disk size', async () => { | ||
const form = await loader.getHarness(IxFormHarness); | ||
await form.fillForm({ | ||
'Root Disk Size (in GiB)': '1', | ||
}); | ||
|
||
const input = await form.getControl('Root Disk Size (in GiB)'); | ||
expect(await input.getErrorText()).toBe('Minimum value is 2'); | ||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
...tance-details/instance-disks/increase-root-disk-size/increase-root-disk-size.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
ChangeDetectionStrategy, Component, Inject, | ||
} from '@angular/core'; | ||
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
import { MatButton } from '@angular/material/button'; | ||
import { | ||
MAT_DIALOG_DATA, MatDialogClose, MatDialogRef, MatDialogTitle, | ||
} from '@angular/material/dialog'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { TranslateModule, TranslateService } from '@ngx-translate/core'; | ||
import { GiB } from 'app/constants/bytes.constant'; | ||
import { VirtualizationInstance } from 'app/interfaces/virtualization.interface'; | ||
import { DialogService } from 'app/modules/dialog/dialog.service'; | ||
import { FormActionsComponent } from 'app/modules/forms/ix-forms/components/form-actions/form-actions.component'; | ||
import { IxInputComponent } from 'app/modules/forms/ix-forms/components/ix-input/ix-input.component'; | ||
import { IxFormatterService } from 'app/modules/forms/ix-forms/services/ix-formatter.service'; | ||
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'; | ||
import { TestDirective } from 'app/modules/test-id/test.directive'; | ||
import { ApiService } from 'app/modules/websocket/api.service'; | ||
import { ErrorHandlerService } from 'app/services/error-handler.service'; | ||
|
||
@UntilDestroy() | ||
@Component({ | ||
selector: 'ix-increase-root-disk-size', | ||
templateUrl: './increase-root-disk-size.component.html', | ||
styleUrls: ['./increase-root-disk-size.component.scss'], | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [ | ||
IxInputComponent, | ||
MatButton, | ||
MatDialogClose, | ||
MatDialogTitle, | ||
ReactiveFormsModule, | ||
TestDirective, | ||
TranslateModule, | ||
FormActionsComponent, | ||
], | ||
}) | ||
export class IncreaseRootDiskSizeComponent { | ||
protected readonly form = this.formBuilder.group({ | ||
size: [0], | ||
}); | ||
|
||
constructor( | ||
@Inject(MAT_DIALOG_DATA) private instance: VirtualizationInstance, | ||
private formBuilder: NonNullableFormBuilder, | ||
private errorHandler: ErrorHandlerService, | ||
private dialogService: DialogService, | ||
private api: ApiService, | ||
private translate: TranslateService, | ||
private snackbar: SnackbarService, | ||
private dialogRef: MatDialogRef<IncreaseRootDiskSizeComponent>, | ||
protected formatter: IxFormatterService, | ||
) { | ||
this.form.setValue({ | ||
size: this.instance.root_disk_size / GiB, | ||
}); | ||
|
||
this.form.controls.size.addValidators(Validators.min(this.instance.root_disk_size / GiB)); | ||
} | ||
|
||
onSubmit(): void { | ||
this.dialogService.jobDialog( | ||
this.api.job('virt.instance.update', [this.instance.id, { root_disk_size: this.form.value.size }]), | ||
{ title: this.translate.instant('Increasing disk size') }, | ||
) | ||
.afterClosed() | ||
.pipe( | ||
this.errorHandler.catchError(), | ||
untilDestroyed(this), | ||
) | ||
.subscribe(() => { | ||
this.dialogRef.close(this.form.value.size); | ||
this.snackbar.success(this.translate.instant('Disk size increased')); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.