Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Support force delete ADC resource #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion app/waf/src/controllers/adc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,20 @@ export class AdcController extends BaseController {
})
async deleteById(
@param(Schema.pathParameter('adcId', 'ADC resource ID')) id: string,
@param(
Schema.queryParameter('force', 'Force delete ADC resource', 'boolean'),
)
force: boolean = false,
): Promise<void> {
let adc = await this.adcRepository.findById(id, undefined, {
tenantId: await this.tenantId,
});

if (force) {
await this.adcRepository.deleteById(id);
return;
}

if (adc.type === 'HW') {
if (!(await this.untrustAdc(adc)))
throw new HttpErrors.UnprocessableEntity('Fail to untrust device');
Expand Down Expand Up @@ -706,7 +715,7 @@ export class AdcController extends BaseController {
return userDataB64Encoded;
}

private async deleteOn(adc: Adc, addon: AddonReqValues): Promise<void> {
public async deleteOn(adc: Adc, addon: AddonReqValues): Promise<void> {
let reclaimFuncs: {[key: string]: Function} = {
license: async () => {
let doMgr = await OnboardingManager.instanlize(
Expand Down
9 changes: 9 additions & 0 deletions app/waf/src/controllers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ export class Schema {
return buildParameterSchema(name, 'path', true, 'string', '', desc);
}

static queryParameter(
name: string,
desc: string,
type: string,
format?: string,
): ParameterObject {
return buildParameterSchema(name, 'query', false, type, format || '', desc);
}

static createRequest(entity: typeof Entity, desc: string): object {
let props = buildProperties(entity);
return buildRequestSchema(
Expand Down
41 changes: 40 additions & 1 deletion app/waf/test/acceptance/adc.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ describe('AdcController test', () => {
});
});

it('post ' + prefix + '/adcs/{adcId}: delete done', async () => {
it('delete ' + prefix + '/adcs/{adcId}: delete done', async () => {
LetResponseWith({
bigip_get_mgmt_tm_sys_license: StubResponses.bigipNoLicense200,
});
Expand Down Expand Up @@ -2134,6 +2134,45 @@ describe('AdcController test', () => {
expect(resp.status).equal(404);
});

it('delete ' + prefix + '/adcs/{adcId}: force delete', async () => {
let adc = await givenAdcData(wafapp, {
type: 'VE',
status: 'ACTIVE',
});

let stub = sinon.stub(controller, 'deleteOn');

await client
.del(`${prefix}/adcs/${adc.id}?force=true`)
.set('X-Auth-Token', ExpectedData.userToken)
.set('tenant-id', ExpectedData.tenantId)
.expect(204);

await client
.get(`${prefix}/adcs/${adc.id}`)
.set('X-Auth-Token', ExpectedData.userToken)
.set('tenant-id', ExpectedData.tenantId)
.expect(404);

expect(!stub.called);
stub.restore();
});

it('delete ' + prefix + '/adcs/{adcId}: wrong force parameter', async () => {
let adc = await givenAdcData(wafapp, {
type: 'VE',
status: 'ACTIVE',
});

let resp = await client
.del(`${prefix}/adcs/${adc.id}?force=abc`)
.set('X-Auth-Token', ExpectedData.userToken)
.set('tenant-id', ExpectedData.tenantId)
.expect(400);

expect(resp.body.error.code).equal('INVALID_PARAMETER_VALUE');
});

//TODO: the timeout can only be tested through unit test?
//The following test case leads all tests fail.
// it(
Expand Down