"""
This test case is intended to check the existence of all hard coded config options used by
the dashboard.
-
If you include further hard coded options in the dashboard, feel free to add them to the
list.
"""
'osd_scrub_interval_randomize_ratio', # osd-pg-scrub
'osd_scrub_invalid_stats', # osd-pg-scrub
'osd_scrub_load_threshold', # osd-pg-scrub
- 'osd_scrub_max_preemptions' # osd-pg-scrub
+ 'osd_scrub_max_preemptions', # osd-pg-scrub
+ 'mon_allow_pool_delete' # pool-list
]
for config_option in hard_coded_options:
import { of } from 'rxjs';
import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
+import { ConfigurationService } from '../../../shared/api/configuration.service';
import { PoolService } from '../../../shared/api/pool.service';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
import { ExecutingTask } from '../../../shared/models/executing-task';
expect(component.columns.every((column) => Boolean(column.prop))).toBeTruthy();
});
+ describe('monAllowPoolDelete', () => {
+ let configurationService: ConfigurationService;
+
+ beforeEach(() => {
+ configurationService = TestBed.get(ConfigurationService);
+ });
+
+ it('should set value correctly if mon_allow_pool_delete flag is set to true', () => {
+ const configOption = {
+ name: 'mon_allow_pool_delete',
+ value: [
+ {
+ section: 'mon',
+ value: 'true'
+ }
+ ]
+ };
+ spyOn(configurationService, 'get').and.returnValue(of(configOption));
+ fixture = TestBed.createComponent(PoolListComponent);
+ component = fixture.componentInstance;
+ expect(component.monAllowPoolDelete).toBe(true);
+ });
+
+ it('should set value correctly if mon_allow_pool_delete flag is set to false', () => {
+ const configOption = {
+ name: 'mon_allow_pool_delete',
+ value: [
+ {
+ section: 'mon',
+ value: 'false'
+ }
+ ]
+ };
+ spyOn(configurationService, 'get').and.returnValue(of(configOption));
+ fixture = TestBed.createComponent(PoolListComponent);
+ component = fixture.componentInstance;
+ expect(component.monAllowPoolDelete).toBe(false);
+ });
+
+ it('should set value correctly if mon_allow_pool_delete flag is not set', () => {
+ const configOption = {
+ name: 'mon_allow_pool_delete'
+ };
+ spyOn(configurationService, 'get').and.returnValue(of(configOption));
+ fixture = TestBed.createComponent(PoolListComponent);
+ component = fixture.componentInstance;
+ expect(component.monAllowPoolDelete).toBe(false);
+ });
+ });
+
describe('pool deletion', () => {
let taskWrapper: TaskWrapperService;
expect(component.selectionCacheTiers).toEqual([]);
});
});
+
+ describe('getDisableDesc', () => {
+ it('should return message if mon_allow_pool_delete flag is set to false', () => {
+ component.monAllowPoolDelete = false;
+ expect(component.getDisableDesc()).toBe(
+ 'Pool deletion is disabled by the mon_allow_pool_delete configuration setting.'
+ );
+ });
+
+ it('should return undefined if mon_allow_pool_delete flag is set to true', () => {
+ component.monAllowPoolDelete = true;
+ expect(component.getDisableDesc()).toBeUndefined();
+ });
+ });
});
import * as _ from 'lodash';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
+import { ConfigurationService } from '../../../shared/api/configuration.service';
import { PoolService } from '../../../shared/api/pool.service';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
import { ActionLabelsI18n, URLVerbs } from '../../../shared/constants/app.constants';
tableActions: CdTableAction[];
viewCacheStatusList: any[];
selectionCacheTiers: any[] = [];
+ monAllowPoolDelete = false;
constructor(
private poolService: PoolService,
private pgCategoryService: PgCategoryService,
private dimlessPipe: DimlessPipe,
private urlBuilder: URLBuilderService,
+ private configurationService: ConfigurationService,
public actionLabels: ActionLabelsI18n
) {
this.permissions = this.authStorageService.getPermissions();
permission: 'delete',
icon: 'fa-trash-o',
click: () => this.deletePoolModal(),
- name: this.actionLabels.DELETE
+ name: this.actionLabels.DELETE,
+ disable: () => !this.selection.first() || !this.monAllowPoolDelete,
+ disableDesc: () => this.getDisableDesc()
}
];
+
+ this.configurationService.get('mon_allow_pool_delete').subscribe((data: any) => {
+ if (_.has(data, 'value')) {
+ const monSection = _.find(data.value, (v) => {
+ return v.section === 'mon';
+ }) || { value: false };
+ this.monAllowPoolDelete = monSection.value === 'true' ? true : false;
+ }
+ });
}
ngOnInit() {
const cacheTierIds = this.selection.hasSingleSelection ? this.selection.first()['tiers'] : [];
this.selectionCacheTiers = this.pools.filter((pool) => cacheTierIds.includes(pool.pool));
}
+
+ getDisableDesc(): string | undefined {
+ if (!this.monAllowPoolDelete) {
+ return this.i18n(
+ 'Pool deletion is disabled by the mon_allow_pool_delete configuration setting.'
+ );
+ }
+ }
}