Skip to content

Commit

Permalink
chore(integ): configure tests to run in pipeline (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
horsmand authored Nov 17, 2020
1 parent 49e22bf commit dcd3c11
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 119 deletions.
4 changes: 2 additions & 2 deletions integ/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ tsconfig.json
# Exclude eslint config
.eslintrc.js

# Exclude jest config
jest.config.js
# We want to pack the jest config because the running of the integration tests rely on it
!jest.config.js

# Exclude nyc
.nyc_output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [[ ! "${SKIP_TEST_CHECK}" = "true" ]]; then

# Load utility functions
source "../common/scripts/bash/deploy-utils.sh"

if [[ $OPTION != '--destroy-only' ]]; then
deploy_component_stacks $COMPONENT_NAME
execute_component_test $COMPONENT_NAME
Expand Down
20 changes: 19 additions & 1 deletion integ/components/deadline/common/scripts/bash/deploy-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# This hook function is meant to be run before any interactions with AWS (such as a cdk deploy or destroy)
function run_aws_interaction_hook() {
# Invoke hook function if it is exported and name is defined in PRE_AWS_INTERACTION_HOOK variable
if [ ! -z "${PRE_AWS_INTERACTION_HOOK+x}" ] && [ "$(type -t $PRE_AWS_INTERACTION_HOOK)" == "function" ]
then
$PRE_AWS_INTERACTION_HOOK
fi
}

function deploy_component_stacks () {
COMPONENT_NAME=$1

run_aws_interaction_hook

echo "Running $COMPONENT_NAME end-to-end test..."

echo "Deploying test app for $COMPONENT_NAME test suite"
npx cdk deploy "*" --require-approval=never
echo "Test app $COMPONENT_NAME deployed."

return 0
}

function execute_component_test () {
COMPONENT_NAME=$1

run_aws_interaction_hook

echo "Running test suite $COMPONENT_NAME..."
yarn run test "$COMPONENT_NAME.test" --json --outputFile="./.e2etemp/$COMPONENT_NAME.json"
echo "Test suite $COMPONENT_NAME complete."
Expand All @@ -25,6 +40,9 @@ function execute_component_test () {

function destroy_component_stacks () {
COMPONENT_NAME=$1

run_aws_interaction_hook

echo "Destroying test app $COMPONENT_NAME..."
npx cdk destroy "*" -f
rm -f "./cdk.context.json"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { App, Stack } from '@aws-cdk/core';
import {
Stage,
ThinkboxDockerRecipes,
} from 'aws-rfdk/deadline';

import { RenderStruct } from '../../../../lib/render-struct';
import { DatabaseType, StorageStruct } from '../../../../lib/storage-struct';
import { WorkerStruct } from '../../../../lib/worker-struct';
import { WorkerFleetTestingTier } from '../lib/workerFleetHttp-testing-tier';

const app = new App();
const env = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};

// Get unique tag for this integration test from environment variable
const integStackTag = process.env.INTEG_STACK_TAG!.toString();

// Worker fleets with their own repository and render queue will be created for each permutation of OS and protocol
const oss = ['Linux','Windows'];

let structs: Array<WorkerStruct> = [];
oss.forEach( (os, index) => {
const testId = 'WF' + (index + 1).toString();
// Create component stack for structs
const componentTier = new Stack(app, 'RFDKInteg-' + testId + '-ComponentTier' + integStackTag, {env});

const stagePath = process.env.DEADLINE_STAGING_PATH!.toString();
// Stage docker recipes, which include image used for the render queue instance and the repo
// installer (in `recipes.version`)
const recipes = new ThinkboxDockerRecipes(componentTier, 'DockerRecipes', {
stage: Stage.fromDirectory(stagePath),
});

// Create StorageStruct with repository
const storage = new StorageStruct(componentTier, 'StorageStruct' + testId, {
integStackTag,
databaseType: DatabaseType.DocDB,
version: recipes.version,
});
// Create render queue with HTTP protocol
const render = new RenderStruct(componentTier, 'RenderStruct' + testId, {
integStackTag,
repository: storage.repo,
protocol: 'http',
recipes,
});
// Create worker struct containing three nodes using either Linux or Windows
structs.push(new WorkerStruct(componentTier, 'WorkerStruct' + testId, {
integStackTag,
renderStruct: render,
os,
}));
});

new WorkerFleetTestingTier(app, 'RFDKInteg-WF-TestingTier' + integStackTag, {env, integStackTag, structs});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": "npx ts-node bin/deadline_03_workerFleet.ts",
"app": "npx ts-node bin/deadline_03_workerFleetHttp.ts",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as path from 'path';
import { Port } from '@aws-cdk/aws-ec2';
import { Construct } from '@aws-cdk/core';
import { IWorkerFleet } from 'aws-rfdk/deadline';
import { TestingTier, TestingTierProps } from '../../../../lib/testing-tier';
import { WorkerStruct } from '../../../../lib/worker-struct';

/**
* Interface for WorkerFleetTestingTier properties
*/
export interface WorkerFleetTestingTierProps extends TestingTierProps {
/**
* Array of WorkerStructs representing different test cases
*/
readonly structs: Array<WorkerStruct>;
}

/**
* Testing Tier for the Deadline WorkerFleet HTTP integration test
*
* Creates a test bastion and configures it to connect to one or more Deadline WorkerInstanceFleet constructs for testing.
*
* Resources Deployed
* ------------------------
* - A BastionLinuxHost instance
*
* Security Considerations
* ------------------------
* - The bastion instance created by this test is configured to access farm resources on their default ports
* Test scripts stored on the bastion are used to submit Deadline jobs to farm workers and request information about the workers.
*/
export class WorkerFleetTestingTier extends TestingTier {
constructor(scope: Construct, id: string, props: WorkerFleetTestingTierProps) {
super(scope, id, props);

const structs = props.structs;
structs.forEach( workerStruct => {

const testSuiteId = 'WF' + (structs.indexOf(workerStruct) + 1).toString();

const renderQueue = workerStruct.renderQueue;
this.configureRenderQueue(testSuiteId, renderQueue);

const workerFleet = workerStruct.workerFleet;
this.configureWorkerFleet(workerFleet);
});

this.configureBastionUserData({
testingScriptPath: path.join(__dirname, '../scripts/bastion/testing'),
});
this.installDeadlineClient();
}

/**
* Configures each worker to allow access from the bastion
*
* @param workerFleet Array of worker instances to connect to the test Bastion
*/
public configureWorkerFleet(workerFleet: Array<IWorkerFleet>) {
workerFleet.forEach( worker => {
this.testInstance.connections.allowTo(worker, Port.tcp(22));
});
}

}
Loading

0 comments on commit dcd3c11

Please sign in to comment.