Skip to content

Commit

Permalink
Get default stack from the Stacks API (#3648)
Browse files Browse the repository at this point in the history
* Get default stack from the Stacks API

* Fix for stacks

* Fix typos and remove unreachable return statement
  • Loading branch information
nwmac authored and richard-cox committed Jun 13, 2019
1 parent 86c1b06 commit 4438b33
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/test-e2e/application/application-deploy-e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Application Deploy -', () => {
});

beforeAll(() => {
return cfHelper.fetchDefaultStack(e2e.secrets.getDefaultCFEndpoint()).then(stack => defaultStack = stack);
return cfHelper.fetchDefaultCFEndpointStack().then(stack => defaultStack = stack);
});

afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/test-e2e/application/application-view-e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Application View -', () => {
});

beforeAll(() => {
return cfHelper.fetchDefaultStack(e2e.secrets.getDefaultCFEndpoint()).then(stack => defaultStack = stack);
return cfHelper.fetchDefaultCFEndpointStack().then(stack => defaultStack = stack);
});

afterAll(() => {
Expand Down
45 changes: 33 additions & 12 deletions src/test-e2e/helpers/cf-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { e2e, E2ESetup } from '../e2e';
import { E2EConfigCloudFoundry } from '../e2e.types';
import { CFRequestHelpers } from './cf-request-helpers';

const stackPriority = {
cf: [ 'cflinuxfs3', 'cflinuxfs2' ],
suse: [ 'sle15', 'opensuse42' ]
};

export class CFHelpers {
static cachedDefaultCfGuid: string;
Expand Down Expand Up @@ -166,18 +170,35 @@ export class CFHelpers {
});
}

// Default Stack based on the CF Vendor
fetchDefaultStack(endpoint: E2EConfigCloudFoundry) {
const reqObj = this.cfRequestHelper.newRequest();
const options = {
url: endpoint.url + '/v2/info'
};
return reqObj(options).then((response) => {
const json = JSON.parse(response.body);
const isSUSE = json.description.indexOf('SUSE') === 0;
return isSUSE ? 'sle15' : 'cflinuxfs2';
}).catch((e) => {
return 'unknown';
// Get defult stack for the default CF
fetchDefaultCFEndpointStack() {
return this.fetchDefaultCfGuid(true).then(guid => {
return this.cfRequestHelper.sendCfGet(guid, '/stacks').then(json => {

const endpoint = this.cfRequestHelper.getDefaultCFEndpoint();
// Get the info for the Default CF
const reqObj = this.cfRequestHelper.newRequest();
const options = {
url: endpoint.url + '/v2/info'
};
return reqObj(options).then((response) => {
const infoJson = JSON.parse(response.body);
const isSUSE = infoJson.description.indexOf('SUSE') === 0;

const stackPriorities = isSUSE ? stackPriority.suse : stackPriority.cf;
const stacksAvailable = {};
json.resources.forEach(s => stacksAvailable[s.entity.name] = true);

for (const s of stackPriorities) {
if (stacksAvailable[s]) {
return s;
}
}
return stackPriorities[0];
}).catch((e) => {
return 'unknown';
});
});
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/test-e2e/helpers/cf-request-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class CFRequestHelpers extends RequestHelpers {
});
}

getDefaultCFEndpoint = () => {
return this.e2eHelper.secrets.getDefaultCFEndpoint();
}

getCfGuid = (cfName?: string): promise.Promise<string> =>
this.getCfInfo(cfName).then((endpoint: EndpointModel) => endpoint ? endpoint.guid : null)

Expand Down

0 comments on commit 4438b33

Please sign in to comment.