From 67b453d07ef0cccf5471cc7256ab6aee1d143764 Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Sun, 30 Aug 2020 20:49:29 +0000 Subject: [PATCH 01/15] fix(deadline): adding version check for staging deadline Adding minimum supported deadline version check while staging deadline installers. Now we fail fast if the provided version is not supported by RFDK. --- packages/aws-rfdk/lib/core/lib/index.ts | 1 + packages/aws-rfdk/lib/core/lib/utils.ts | 31 ++++++++++ packages/aws-rfdk/lib/core/test/utils.test.ts | 62 +++++++++++++++++++ packages/aws-rfdk/lib/deadline/lib/stage.ts | 9 +++ .../aws-rfdk/lib/deadline/test/stage.test.ts | 60 ++++++++++++++---- .../test/thinkbox-docker-recipes.test.ts | 4 +- 6 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 packages/aws-rfdk/lib/core/lib/utils.ts create mode 100644 packages/aws-rfdk/lib/core/test/utils.test.ts diff --git a/packages/aws-rfdk/lib/core/lib/index.ts b/packages/aws-rfdk/lib/core/lib/index.ts index 31b7b1430..8d50d5107 100644 --- a/packages/aws-rfdk/lib/core/lib/index.ts +++ b/packages/aws-rfdk/lib/core/lib/index.ts @@ -19,4 +19,5 @@ export * from './mountable-filesystem'; export { RFDK_VERSION } from './runtime-info'; export * from './script-assets'; export * from './staticip-server'; +export * from './utils'; export * from './x509-certificate'; diff --git a/packages/aws-rfdk/lib/core/lib/utils.ts b/packages/aws-rfdk/lib/core/lib/utils.ts new file mode 100644 index 000000000..cd10d393c --- /dev/null +++ b/packages/aws-rfdk/lib/core/lib/utils.ts @@ -0,0 +1,31 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +export class Utils { + /** + * This method compares two version strings + * + * @param versionFirst + * @param versionSecond + * + * @returns negative value if first version is smaller than second version; + * 0 if the versions matches, positive value if first version is smaller + * than second version. + */ + public static versionCompare(versionFirst: string, versionSecond: string): number { + const regExStripZero = /(\.0+)+$/; + const versionArrayFirst = versionFirst.replace(regExStripZero, '').split('.'); + const versionArraySecond = versionSecond.replace(regExStripZero, '').split('.'); + const l = Math.min(versionArrayFirst.length, versionArraySecond.length); + + for (let i = 0; i < l; i++) { + let diff = parseInt(versionArrayFirst[i], 10) - parseInt(versionArraySecond[i], 10); + if (diff) { + return diff; + } + } + return versionArrayFirst.length - versionArraySecond.length; + } +} \ No newline at end of file diff --git a/packages/aws-rfdk/lib/core/test/utils.test.ts b/packages/aws-rfdk/lib/core/test/utils.test.ts new file mode 100644 index 000000000..d0c22727c --- /dev/null +++ b/packages/aws-rfdk/lib/core/test/utils.test.ts @@ -0,0 +1,62 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Utils } from '../lib'; + +describe('Utils', () => { + describe('.versionCompare', () => { + test.each<[string, { firstVersion: string, secondVersion: string, expectedValue: number }]>([ + [ + 'equal version', + { + firstVersion: '1', + secondVersion: '1', + expectedValue: 0, + }, + ], [ + 'equal version', + { + firstVersion: '1', + secondVersion: '1.0', + expectedValue: 0, + }, + ], [ + 'equal version', + { + firstVersion: '1.0', + secondVersion: '1.0.0', + expectedValue: 0, + }, + ], [ + 'less than', + { + firstVersion: '1', + secondVersion: '2', + expectedValue: -1, + }, + ], [ + 'less than', + { + firstVersion: '1.2', + secondVersion: '2', + expectedValue: -1, + }, + ], [ + 'greater than', + { + firstVersion: '2.0.1', + secondVersion: '2.0', + expectedValue: 2, + }, + ], + ])('%s', (_name, testcase) => { + const { firstVersion, secondVersion, expectedValue } = testcase; + // WHEN + const result = Utils.versionCompare(firstVersion, secondVersion); + + expect(result).toEqual(expectedValue); + }); + }); +}); diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index f78283424..51d4fff5a 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -9,6 +9,7 @@ import * as path from 'path'; import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets'; import { Construct } from '@aws-cdk/core'; +import { Utils } from '../../core'; import { VersionQuery } from './version'; /** @@ -99,6 +100,8 @@ export interface StageProps { * requires to deploy Deadline. It should contain a manifest file, the Deadline * installers, and any supporting files required for building the Deadline * container. + * + * Note: Current version of RFDK supports Deadline v10.1.9 and later. */ export class Stage { /** @@ -154,6 +157,12 @@ export class Stage { throw new TypeError(`Expected a string "version" but got: ${typeof version}`); } + // Do minimum supported deadline version check + const minimumSupportedVersion = '10.1.9'; + if (Utils.versionCompare(version, minimumSupportedVersion) < 0) { + throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion})`); + } + return true; } diff --git a/packages/aws-rfdk/lib/deadline/test/stage.test.ts b/packages/aws-rfdk/lib/deadline/test/stage.test.ts index b1937e4cb..00697f917 100644 --- a/packages/aws-rfdk/lib/deadline/test/stage.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/stage.test.ts @@ -41,7 +41,7 @@ describe('Stage', () => { // GIVEN const manifest: Manifest = { schema: 1, - version: '1.2.3.4', + version: '10.1.9.2', recipes: {}, }; @@ -77,10 +77,34 @@ describe('Stage', () => { }); }); + describe('.fromDirectory', () => { + test('not supported version failure', () => { + // GIVEN + const manifest: Manifest = { + schema: 1, + version: '10.1.8.0', + recipes: {}, + }; + + // WHEN + const readFileSync = jest.spyOn(fs, 'readFileSync'); + readFileSync.mockReturnValue(JSON.stringify(manifest)); + + // THEN + expect(() => { + require('../lib').Stage.fromDirectory(STAGE_PATH) // eslint-disable-line + }).toThrow('Staged Deadline Version (10.1.8.0) is less than the minimum supported version (10.1.9)'); + + readFileSync.mockRestore(); + jest.resetModules(); + }); + + }); + test('has manifest', () => { const manifest: Manifest = { schema: 1, - version: '1.2.3.4', + version: '10.1.9.2', recipes: { a: { title: 'a-title', @@ -131,7 +155,7 @@ describe('Stage', () => { 'missing schema', { manifest: { - version: '1.2.3.4', + version: '10.1.9.2', recipes: {}, }, expectedError: /Manifest contains no "schema" key/, @@ -141,7 +165,7 @@ describe('Stage', () => { 'wrong schema type', { manifest: { schema: 'a', - version: '1.2.3.4', + version: '10.1.9.2', recipes: {}, }, expectedError: /Expected a numeric "schema" but got:/, @@ -156,6 +180,16 @@ describe('Stage', () => { expectedError: /Manifest contains no "version" key/, }, ], + [ + 'version not supported', { + manifest: { + schema: 1, + version: '10.1', + recipes: {}, + }, + expectedError: 'Staged Deadline Version (10.1) is less than the minimum supported version (10.1.9)', + }, + ], ])('%s', (_name, testcase) => { const { manifest, expectedError } = testcase; // WHEN @@ -225,7 +259,7 @@ describe('Stage', () => { recipeName: recipe, }, schema: 1, - version: '1.2.3.4', + version: '10.1.9.2', }; // WHEN @@ -287,7 +321,7 @@ describe('Stage', () => { const stage = new ReloadedStageWithPublicConstructor({ path: STAGE_PATH, manifest: { - version: '1.2.3.4', + version: '10.1.9.2', schema: 1, recipes: { [recipeName]: recipe, @@ -316,7 +350,7 @@ describe('Stage', () => { // GIVEN const manifest: Manifest = { schema: 1, - version: '1.2.3.4', + version: '10.1.9.2', recipes: {}, }; const invalidRecipeName = 'this-recipe-does-not-exist'; @@ -342,7 +376,7 @@ describe('Stage', () => { const stack = new Stack(app, 'Stack'); const manifest: Manifest = { schema: 1, - version: '1.2.3.4', + version: '10.1.9.2', recipes: {}, }; const stage = new StageWithPulicConstructor({ @@ -355,15 +389,15 @@ describe('Stage', () => { const linuxFullVersionString = version.linuxFullVersionString(); // THEN - expect(version.majorVersion).toEqual(1); - expect(version.minorVersion).toEqual(2); - expect(version.releaseVersion).toEqual(3); + expect(version.majorVersion).toEqual(10); + expect(version.minorVersion).toEqual(1); + expect(version.releaseVersion).toEqual(9); expect(version.linuxInstallers).toBeDefined(); - expect(version.linuxInstallers?.patchVersion).toEqual(4); + expect(version.linuxInstallers?.patchVersion).toEqual(2); expect(linuxFullVersionString).toBeDefined(); - expect(linuxFullVersionString).toEqual('1.2.3.4'); + expect(linuxFullVersionString).toEqual('10.1.9.2'); }); }); }); diff --git a/packages/aws-rfdk/lib/deadline/test/thinkbox-docker-recipes.test.ts b/packages/aws-rfdk/lib/deadline/test/thinkbox-docker-recipes.test.ts index b7df57068..590053bbd 100644 --- a/packages/aws-rfdk/lib/deadline/test/thinkbox-docker-recipes.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/thinkbox-docker-recipes.test.ts @@ -52,8 +52,8 @@ describe('ThinkboxDockerRecipes', () => { const MAJOR_VERSION = 10; const MINOR_VERSION = 1; - const RELEASE_VERSION = 8; - const PATCH_VERSION = 5; + const RELEASE_VERSION = 9; + const PATCH_VERSION = 2; const FULL_VERSION_STRING = `${MAJOR_VERSION}.${MINOR_VERSION}.${RELEASE_VERSION}.${PATCH_VERSION}`; beforeEach(() => { From e8d4e45dfc2026d3f5cd266ad9625fa4511404a8 Mon Sep 17 00:00:00 2001 From: Daniel Neilson <53624638+ddneilson@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:51:21 -0500 Subject: [PATCH 02/15] fix(examples): Minor fixes to Python example app REAME --- .../python/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/deadline/All-In-AWS-Infrastructure-Basic/python/README.md b/examples/deadline/All-In-AWS-Infrastructure-Basic/python/README.md index e587cc582..01b4726cc 100644 --- a/examples/deadline/All-In-AWS-Infrastructure-Basic/python/README.md +++ b/examples/deadline/All-In-AWS-Infrastructure-Basic/python/README.md @@ -16,7 +16,7 @@ These instructions assume that your working directory is `examples/deadline/All- ```bash pip install -r requirements.txt ``` -2. Change the value in the `deadline_client_linux_ami_map` variable in `bin/config.py` to include the region + AMI ID mapping of your EC2 AMI(s) with Deadline Worker. +2. Change the value in the `deadline_client_linux_ami_map` variable in `package/config.py` to include the region + AMI ID mapping of your EC2 AMI(s) with Deadline Worker. ```python # For example, in the us-west-2 region self.deadline_client_linux_ami_map: Mapping[str, str] = {'us-west-2': ' --secret-binary fileb:// ``` -4. The output from the previous step will contain the secret's ARN. Change the value of the `ubl_certificate_secret_arn` variable in `bin/config.py` to the secret's ARN: +4. The output from the previous step will contain the secret's ARN. Change the value of the `ubl_certificate_secret_arn` variable in `package/config.py` to the secret's ARN: ```python self.ubl_certificate_secret_arn: str = '' ``` -5. Choose your UBL limits and change the value of the `ubl_licenses` variable in `bin/config.py` accordingly: +5. Choose your UBL limits and change the value of the `ubl_licenses` variable in `package/config.py` accordingly: ```python self.ubl_licenses: List[UsageBasedLicense] = [ (e.g. UsageBasedLicense.forMaya(10))] ``` @@ -43,20 +43,20 @@ self.ubl_licenses: List[UsageBasedLicense] = [ (e.g. UsageBased ```bash aws ec2 create-key-pair --key-name ``` -7. Change the value of the `key_pair_name` variable in `bin/config.py` to your value for `` in the previous step:

**Note:** Save the value of the "KeyMaterial" field as a file in a secure location. This is your private key that you can use to SSH into the render farm. +7. Change the value of the `key_pair_name` variable in `package/config.py` to your value for `` in the previous step:

**Note:** Save the value of the "KeyMaterial" field as a file in a secure location. This is your private key that you can use to SSH into the render farm. ```python self.key_pair_name: Optional[str] = '' ``` -8. Choose the type of database you would like to deploy and change the value of the `deploy_mongo_db` variable in `bin/config.py` accordingly: +8. Choose the type of database you would like to deploy and change the value of the `deploy_mongo_db` variable in `package/config.py` accordingly: ```python # True = MongoDB, False = Amazon DocumentDB self.deploy_mongo_db: bool = False ``` -9. If you set `deploy_mongo_db` to `True`, then you must accept the [SSPL license](https://www.mongodb.com/licensing/server-side-public-license) to successfully deploy MongoDB. To do so, change the value of `accept_sspl_license` in `bin/config.py`: +9. If you set `deploy_mongo_db` to `True`, then you must accept the [SSPL license](https://www.mongodb.com/licensing/server-side-public-license) to successfully deploy MongoDB. To do so, change the value of `accept_sspl_license` in `package/config.py`: ```python self.accept_sspl_license: MongoDbSsplLicenseAcceptance = MongoDbSsplLicenseAcceptance.USER_REJECTS_SSPL ``` -10. Modify the `deadline_ver` field in the `config` block of `package.json` as desired, then stage the Docker recipes for `RenderQueue` and `UBLLicensing`: +10. Stage the Docker recipes for `RenderQueue` and `UBLLicensing`: ```bash # Set this value to the version of RFDK your application targets RFDK_VERSION= From 2347ed34e47e2d865c6a77723bcdf90a2e48750d Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Sun, 30 Aug 2020 20:49:29 +0000 Subject: [PATCH 03/15] fix(deadline): adding version check for staging deadline Adding minimum supported deadline version check while staging deadline installers. Now we fail fast if the provided version is not supported by RFDK. --- packages/aws-rfdk/lib/core/lib/utils.ts | 10 ++++---- packages/aws-rfdk/lib/deadline/lib/stage.ts | 24 +++++++++++++++++++ .../aws-rfdk/lib/deadline/test/stage.test.ts | 10 ++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/aws-rfdk/lib/core/lib/utils.ts b/packages/aws-rfdk/lib/core/lib/utils.ts index cd10d393c..e7325e0f5 100644 --- a/packages/aws-rfdk/lib/core/lib/utils.ts +++ b/packages/aws-rfdk/lib/core/lib/utils.ts @@ -11,21 +11,21 @@ export class Utils { * @param versionSecond * * @returns negative value if first version is smaller than second version; - * 0 if the versions matches, positive value if first version is smaller + * 0 if the versions matches, positive value if first version is greater * than second version. */ public static versionCompare(versionFirst: string, versionSecond: string): number { const regExStripZero = /(\.0+)+$/; const versionArrayFirst = versionFirst.replace(regExStripZero, '').split('.'); const versionArraySecond = versionSecond.replace(regExStripZero, '').split('.'); - const l = Math.min(versionArrayFirst.length, versionArraySecond.length); + const minLen = Math.min(versionArrayFirst.length, versionArraySecond.length); - for (let i = 0; i < l; i++) { - let diff = parseInt(versionArrayFirst[i], 10) - parseInt(versionArraySecond[i], 10); + for (let i = 0; i < minLen; i++) { + const diff = parseInt(versionArrayFirst[i], 10) - parseInt(versionArraySecond[i], 10); if (diff) { return diff; } } return versionArrayFirst.length - versionArraySecond.length; } -} \ No newline at end of file +} diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index 51d4fff5a..1bdf36132 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -155,6 +155,14 @@ export class Stage { throw new Error('Manifest contains no "version" key'); } else if (typeof version !== 'string') { throw new TypeError(`Expected a string "version" but got: ${typeof version}`); + } else if (!Stage.validateVersionFormat(version)) { + throw new Error(`Invalid version format - ${version}`); + } + + // Do minimum supported deadline version check + const minimumSupportedVersion = '10.1.9'; + if (Utils.versionCompare(version, minimumSupportedVersion) < 0) { + throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion})`); } // Do minimum supported deadline version check @@ -166,6 +174,22 @@ export class Stage { return true; } + private static validateVersionFormat(version: string): boolean { + /** + * Regex: ^\d+(?:\.\d+){3}$ + * Matches a sequence of '.' separated numbers with exactly 4 digits. + * - ^ asserts position at start of a line. + * - \d+ Matches one or more digits. + * - (?:\.\d+) Matches a dot and the following one or more digits. + * - * Matches previous pattern zero or more times. + * - $ asserts position at the end of a line + */ + if (version.match(/^\d+(?:\.\d+)*$/g)) { + return true; + } + return false; + } + /** * The path to the stage directory */ diff --git a/packages/aws-rfdk/lib/deadline/test/stage.test.ts b/packages/aws-rfdk/lib/deadline/test/stage.test.ts index 00697f917..a37fc4b85 100644 --- a/packages/aws-rfdk/lib/deadline/test/stage.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/stage.test.ts @@ -180,6 +180,16 @@ describe('Stage', () => { expectedError: /Manifest contains no "version" key/, }, ], + [ + 'incorrect version format', { + manifest: { + schema: 1, + version: '10.1.', + recipes: {}, + }, + expectedError: /Invalid version format/, + }, + ], [ 'version not supported', { manifest: { From c14f5c55d5d776978ce5d52ce060c2e05dc1258a Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Tue, 1 Sep 2020 18:20:44 +0000 Subject: [PATCH 04/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/stage.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index 1bdf36132..9a4433999 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -165,12 +165,6 @@ export class Stage { throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion})`); } - // Do minimum supported deadline version check - const minimumSupportedVersion = '10.1.9'; - if (Utils.versionCompare(version, minimumSupportedVersion) < 0) { - throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion})`); - } - return true; } From 10c4342fe26f04c6c023d6808ecbb9e08a661656 Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Tue, 1 Sep 2020 20:53:04 +0000 Subject: [PATCH 05/15] moving method to Utils class --- packages/aws-rfdk/lib/core/lib/utils.ts | 23 ++++++++++++++ packages/aws-rfdk/lib/core/test/utils.test.ts | 30 +++++++++++++++++++ packages/aws-rfdk/lib/deadline/lib/stage.ts | 18 +---------- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/packages/aws-rfdk/lib/core/lib/utils.ts b/packages/aws-rfdk/lib/core/lib/utils.ts index e7325e0f5..495d8a5f6 100644 --- a/packages/aws-rfdk/lib/core/lib/utils.ts +++ b/packages/aws-rfdk/lib/core/lib/utils.ts @@ -28,4 +28,27 @@ export class Utils { } return versionArrayFirst.length - versionArraySecond.length; } + + /** + * This method validates the given string for a sequence '.' separated numbers. + * + * @param version the string to be validated. + * + * @returns true if the format is correct, else false. + */ + public static validateVersionFormat(version: string): boolean { + /** + * Regex: ^\d+(?:\.\d+){3}$ + * Matches a sequence of '.' separated numbers with exactly 4 digits. + * - ^ asserts position at start of a line. + * - \d+ Matches one or more digits. + * - (?:\.\d+) Matches a dot and the following one or more digits. + * - * Matches previous pattern zero or more times. + * - $ asserts position at the end of a line + */ + if (version.match(/^\d+(?:\.\d+)*$/g)) { + return true; + } + return false; + } } diff --git a/packages/aws-rfdk/lib/core/test/utils.test.ts b/packages/aws-rfdk/lib/core/test/utils.test.ts index d0c22727c..ce893f2d8 100644 --- a/packages/aws-rfdk/lib/core/test/utils.test.ts +++ b/packages/aws-rfdk/lib/core/test/utils.test.ts @@ -59,4 +59,34 @@ describe('Utils', () => { expect(result).toEqual(expectedValue); }); }); + + describe('.validateVersionFormat', () => { + test.each<[string, { version: string, expectedValue: boolean }]>([ + [ + 'ending with .', + { + version: '10.1.9.', + expectedValue: false, + }, + ], [ + 'empty string', + { + version: '', + expectedValue: false, + }, + ], [ + 'correct version', + { + version: '10.1.9.2', + expectedValue: true, + }, + ], + ])('%s', (_name, testcase) => { + const { version, expectedValue } = testcase; + // WHEN + const result = Utils.validateVersionFormat(version); + + expect(result).toEqual(expectedValue); + }); + }); }); diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index 9a4433999..e6a7fe620 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -155,7 +155,7 @@ export class Stage { throw new Error('Manifest contains no "version" key'); } else if (typeof version !== 'string') { throw new TypeError(`Expected a string "version" but got: ${typeof version}`); - } else if (!Stage.validateVersionFormat(version)) { + } else if (!Utils.validateVersionFormat(version)) { throw new Error(`Invalid version format - ${version}`); } @@ -168,22 +168,6 @@ export class Stage { return true; } - private static validateVersionFormat(version: string): boolean { - /** - * Regex: ^\d+(?:\.\d+){3}$ - * Matches a sequence of '.' separated numbers with exactly 4 digits. - * - ^ asserts position at start of a line. - * - \d+ Matches one or more digits. - * - (?:\.\d+) Matches a dot and the following one or more digits. - * - * Matches previous pattern zero or more times. - * - $ asserts position at the end of a line - */ - if (version.match(/^\d+(?:\.\d+)*$/g)) { - return true; - } - return false; - } - /** * The path to the stage directory */ From d3a685cbc3dd5031065410bf4f0ab504fcd237dd Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Fri, 4 Sep 2020 19:49:20 +0000 Subject: [PATCH 06/15] review feedback --- packages/aws-rfdk/lib/core/lib/index.ts | 1 - packages/aws-rfdk/lib/core/lib/utils.ts | 54 ----------- packages/aws-rfdk/lib/core/test/utils.test.ts | 92 ------------------ packages/aws-rfdk/lib/deadline/lib/stage.ts | 16 +-- packages/aws-rfdk/lib/deadline/lib/version.ts | 97 ++++++++++++++++--- .../aws-rfdk/lib/deadline/test/stage.test.ts | 6 +- .../lib/deadline/test/version.test.ts | 95 +++++++++++++++++- 7 files changed, 188 insertions(+), 173 deletions(-) delete mode 100644 packages/aws-rfdk/lib/core/lib/utils.ts delete mode 100644 packages/aws-rfdk/lib/core/test/utils.test.ts diff --git a/packages/aws-rfdk/lib/core/lib/index.ts b/packages/aws-rfdk/lib/core/lib/index.ts index 8d50d5107..31b7b1430 100644 --- a/packages/aws-rfdk/lib/core/lib/index.ts +++ b/packages/aws-rfdk/lib/core/lib/index.ts @@ -19,5 +19,4 @@ export * from './mountable-filesystem'; export { RFDK_VERSION } from './runtime-info'; export * from './script-assets'; export * from './staticip-server'; -export * from './utils'; export * from './x509-certificate'; diff --git a/packages/aws-rfdk/lib/core/lib/utils.ts b/packages/aws-rfdk/lib/core/lib/utils.ts deleted file mode 100644 index 495d8a5f6..000000000 --- a/packages/aws-rfdk/lib/core/lib/utils.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -export class Utils { - /** - * This method compares two version strings - * - * @param versionFirst - * @param versionSecond - * - * @returns negative value if first version is smaller than second version; - * 0 if the versions matches, positive value if first version is greater - * than second version. - */ - public static versionCompare(versionFirst: string, versionSecond: string): number { - const regExStripZero = /(\.0+)+$/; - const versionArrayFirst = versionFirst.replace(regExStripZero, '').split('.'); - const versionArraySecond = versionSecond.replace(regExStripZero, '').split('.'); - const minLen = Math.min(versionArrayFirst.length, versionArraySecond.length); - - for (let i = 0; i < minLen; i++) { - const diff = parseInt(versionArrayFirst[i], 10) - parseInt(versionArraySecond[i], 10); - if (diff) { - return diff; - } - } - return versionArrayFirst.length - versionArraySecond.length; - } - - /** - * This method validates the given string for a sequence '.' separated numbers. - * - * @param version the string to be validated. - * - * @returns true if the format is correct, else false. - */ - public static validateVersionFormat(version: string): boolean { - /** - * Regex: ^\d+(?:\.\d+){3}$ - * Matches a sequence of '.' separated numbers with exactly 4 digits. - * - ^ asserts position at start of a line. - * - \d+ Matches one or more digits. - * - (?:\.\d+) Matches a dot and the following one or more digits. - * - * Matches previous pattern zero or more times. - * - $ asserts position at the end of a line - */ - if (version.match(/^\d+(?:\.\d+)*$/g)) { - return true; - } - return false; - } -} diff --git a/packages/aws-rfdk/lib/core/test/utils.test.ts b/packages/aws-rfdk/lib/core/test/utils.test.ts deleted file mode 100644 index ce893f2d8..000000000 --- a/packages/aws-rfdk/lib/core/test/utils.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -import { Utils } from '../lib'; - -describe('Utils', () => { - describe('.versionCompare', () => { - test.each<[string, { firstVersion: string, secondVersion: string, expectedValue: number }]>([ - [ - 'equal version', - { - firstVersion: '1', - secondVersion: '1', - expectedValue: 0, - }, - ], [ - 'equal version', - { - firstVersion: '1', - secondVersion: '1.0', - expectedValue: 0, - }, - ], [ - 'equal version', - { - firstVersion: '1.0', - secondVersion: '1.0.0', - expectedValue: 0, - }, - ], [ - 'less than', - { - firstVersion: '1', - secondVersion: '2', - expectedValue: -1, - }, - ], [ - 'less than', - { - firstVersion: '1.2', - secondVersion: '2', - expectedValue: -1, - }, - ], [ - 'greater than', - { - firstVersion: '2.0.1', - secondVersion: '2.0', - expectedValue: 2, - }, - ], - ])('%s', (_name, testcase) => { - const { firstVersion, secondVersion, expectedValue } = testcase; - // WHEN - const result = Utils.versionCompare(firstVersion, secondVersion); - - expect(result).toEqual(expectedValue); - }); - }); - - describe('.validateVersionFormat', () => { - test.each<[string, { version: string, expectedValue: boolean }]>([ - [ - 'ending with .', - { - version: '10.1.9.', - expectedValue: false, - }, - ], [ - 'empty string', - { - version: '', - expectedValue: false, - }, - ], [ - 'correct version', - { - version: '10.1.9.2', - expectedValue: true, - }, - ], - ])('%s', (_name, testcase) => { - const { version, expectedValue } = testcase; - // WHEN - const result = Utils.validateVersionFormat(version); - - expect(result).toEqual(expectedValue); - }); - }); -}); diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index e6a7fe620..7dd462f3e 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -9,8 +9,10 @@ import * as path from 'path'; import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets'; import { Construct } from '@aws-cdk/core'; -import { Utils } from '../../core'; -import { VersionQuery } from './version'; +import { + Version, + VersionQuery, +} from './version'; /** * Build arguments to supply to a Docker image build @@ -101,7 +103,7 @@ export interface StageProps { * installers, and any supporting files required for building the Deadline * container. * - * Note: Current version of RFDK supports Deadline v10.1.9 and later. + * Note: Current version of RFDK supports Deadline v10.1.9.2 and later. */ export class Stage { /** @@ -155,14 +157,12 @@ export class Stage { throw new Error('Manifest contains no "version" key'); } else if (typeof version !== 'string') { throw new TypeError(`Expected a string "version" but got: ${typeof version}`); - } else if (!Utils.validateVersionFormat(version)) { - throw new Error(`Invalid version format - ${version}`); } // Do minimum supported deadline version check - const minimumSupportedVersion = '10.1.9'; - if (Utils.versionCompare(version, minimumSupportedVersion) < 0) { - throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion})`); + const minimumSupportedVersion = new Version([10, 1, 9, 2]); + if (minimumSupportedVersion.isGreaterThan(Version.parse(version))) { + throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion.toString()})`); } return true; diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index 0b0a80aa2..5a1b517dc 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -72,6 +72,85 @@ abstract class VersionQueryBase extends Construct implements IVersion { } } +/** + * This class is reposonsible to do basic operations on version format. + */ +export class Version { + + /** + * This method parses the input string and returns the version object. + * + * @param version version string to parse + */ + public static parse(version: string): Version { + if (!Version.validateVersionFormat(version)) { + throw new TypeError(`Invalid version format. Expected format 'a.b.c.d', found '${version}'`); + } + + return new Version(version.split('.').map(x => parseInt(x))); + } + + /** + * This method validates the given string for a sequence '.' separated numbers. + * + * @param version the string to be validated. + * + * @returns true if the format is correct, else false. + */ + private static validateVersionFormat(version: string): boolean { + /** + * Regex: ^\d+(?:\.\d+){3}$ + * Matches a sequence of '.' separated numbers with exactly 4 digits. + * - ^ asserts position at start of a line. + * - \d+ Matches one or more digits. + * - (?:\.\d+) Matches a dot and the following one or more digits. + * - {3} Matches previous pattern exactly 3 times. + * - $ asserts position at the end of a line + */ + if (version.match(/^\d+(?:\.\d+){3}$/g)) { + return true; + } + return false; + } + + /** + * Numeric components of version. + */ + public readonly components: number[]; + + constructor(components: number[]) { + this.components = components; + } + + /** + * This method compares two version strings + * + * @param version + * + * @returns true if this version is greater than the provided version; + * false if this version is less than or equal to the provided verison. + */ + public isGreaterThan(version: Version): boolean { + if (this.components.length != version.components.length) { + throw new TypeError('Component count in both the versions should be same.'); + } + + for (let i = 0; i < this.components.length; i++) { + if (this.components[i] != version.components[i]) { + return this.components[i] > version.components[i]; + } + } + return false; + } + + /** + * The method returns the version components in dot separated string format. + */ + public toString(): string { + return this.components.join('.'); + } +} + /** * This class encapsulates information about a particular version of Thinkbox's Deadline software. * Information such as the version number, and where to get installers for that version from Amazon S3. @@ -100,16 +179,13 @@ export class VersionQuery extends VersionQueryBase { * @param versionstr The input version string */ public static parseVersionString(versionstr: string): IPatchVersion { - const match = VersionQuery.RE_FULL_VERSION.exec(versionstr); - if (!match) { - throw new Error(`"${versionstr}" is not a valid version`); - } + const version = Version.parse(versionstr); return { - majorVersion: parseInt(match.groups!.major, 10), - minorVersion: parseInt(match.groups!.minor, 10), - releaseVersion: parseInt(match.groups!.release, 10), - patchVersion: parseInt(match.groups!.patch, 10), + majorVersion: version.components[0], + minorVersion: version.components[1], + releaseVersion: version.components[2], + patchVersion: version.components[3], }; } @@ -191,11 +267,6 @@ export class VersionQuery extends VersionQueryBase { return VersionQuery.exact(scope, id, VersionQuery.parseVersionString(versionString)); } - /** - * Regular expression for matching a Deadline release version number - */ - private static readonly RE_FULL_VERSION = /^(?\d+)\.(?\d+)\.(?\d+)\.(?\d+)$/; - /** * @inheritdoc */ diff --git a/packages/aws-rfdk/lib/deadline/test/stage.test.ts b/packages/aws-rfdk/lib/deadline/test/stage.test.ts index a37fc4b85..ff7818cfc 100644 --- a/packages/aws-rfdk/lib/deadline/test/stage.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/stage.test.ts @@ -93,7 +93,7 @@ describe('Stage', () => { // THEN expect(() => { require('../lib').Stage.fromDirectory(STAGE_PATH) // eslint-disable-line - }).toThrow('Staged Deadline Version (10.1.8.0) is less than the minimum supported version (10.1.9)'); + }).toThrow('Staged Deadline Version (10.1.8.0) is less than the minimum supported version (10.1.9.2)'); readFileSync.mockRestore(); jest.resetModules(); @@ -194,10 +194,10 @@ describe('Stage', () => { 'version not supported', { manifest: { schema: 1, - version: '10.1', + version: '10.1.0.0', recipes: {}, }, - expectedError: 'Staged Deadline Version (10.1) is less than the minimum supported version (10.1.9)', + expectedError: 'Staged Deadline Version (10.1.0.0) is less than the minimum supported version (10.1.9.2)', }, ], ])('%s', (_name, testcase) => { diff --git a/packages/aws-rfdk/lib/deadline/test/version.test.ts b/packages/aws-rfdk/lib/deadline/test/version.test.ts index 6253a86b1..24e47e7cd 100644 --- a/packages/aws-rfdk/lib/deadline/test/version.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/version.test.ts @@ -13,11 +13,102 @@ import { } from '@aws-cdk/core'; import { IVersion, + Version, VersionQuery, } from '../lib'; let stack: Stack; +describe('Version', () => { + describe('.isGreaterThan', () => { + test.each<[string, { firstVersion: string, secondVersion: string, expectedValue: boolean }]>([ + [ + 'equal version', + { + firstVersion: '1.1.1.1', + secondVersion: '1.1.1.1', + expectedValue: false, + }, + ], [ + 'less than', + { + firstVersion: '10.0.9.2', + secondVersion: '10.1.9.2', + expectedValue: false, + }, + ], [ + 'less than', + { + firstVersion: '1.1.1.1', + secondVersion: '1.1.1.2', + expectedValue: false, + }, + ], [ + 'greater than', + { + firstVersion: '2.0.0.1', + secondVersion: '2.0.0.0', + expectedValue: true, + }, + ], + ])('%s', (_name, testcase) => { + const { firstVersion, secondVersion, expectedValue } = testcase; + + // WHEN + const lhs = Version.parse(firstVersion); + const result = lhs.isGreaterThan(Version.parse(secondVersion)); + + expect(result).toEqual(expectedValue); + }); + }); + + describe('.isGreaterThan constructor', () => { + + // WHEN + const lhs = new Version([10, 1, 9, 2]); + const result = lhs.isGreaterThan(Version.parse('10.0.9.2')); + + expect(result).toEqual(true); + + }); + + describe('.parse', () => { + test.each<[string, { version: string, expectedValue: boolean }]>([ + [ + 'ending with .', + { + version: '10.1.9.', + expectedValue: false, + }, + ], [ + 'empty string', + { + version: '', + expectedValue: false, + }, + ], [ + 'correct version', + { + version: '10.1.9.2', + expectedValue: true, + }, + ], + ])('%s', (_name, testcase) => { + const { version, expectedValue } = testcase; + // WHEN + let result = false; + try { + Version.parse(version); + result = true; + } catch (error) { + } finally { + } + + expect(result).toEqual(expectedValue); + }); + }); +}); + describe('VersionQuery', () => { beforeEach(() => { stack = new Stack(undefined, undefined); @@ -41,7 +132,7 @@ describe('VersionQuery', () => { test('throws not implemented error for valid version string', () => { // WHEN - expect( () => { + expect(() => { new VersionQuery(stack, 'version', { version: '1.2', }); @@ -151,7 +242,7 @@ describe('VersionQuery', () => { } // THEN - expect(when).toThrowError(new RegExp(`^"${versionStr}" is not a valid version$`)); + expect(when).toThrowError(new RegExp(`^Invalid version format. Expected format 'a.b.c.d', found '${versionStr}'$`)); }); }); }); From e50473db6d7f6c1c05b3280c1fd6d2e9bd18d2c0 Mon Sep 17 00:00:00 2001 From: David Horsman <56004724+horsmand@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:36:13 -0500 Subject: [PATCH 07/15] chore(repo): auto approve Dependabot PR's (#113) - Adds support for using the auto approve GitHub action to automatically approve PR's from Dependabot - Adds support for using Dependabot to update the version of any GitHub actions we are using --- .github/dependabot.yml | 4 ++++ .github/workflows/auto-approve.yml | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .github/workflows/auto-approve.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8af86612d..29aea89ed 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,3 +18,7 @@ updates: - dependency-name: "@aws-cdk/*" commit-message: prefix: "chore(deps):" + - package-ecosystem: "github-actions" + directory: "/" # Location of .github/workflows + schedule: + interval: "daily" diff --git a/.github/workflows/auto-approve.yml b/.github/workflows/auto-approve.yml new file mode 100644 index 000000000..4ffe15b0b --- /dev/null +++ b/.github/workflows/auto-approve.yml @@ -0,0 +1,15 @@ +# Automatically approve PRs made by Dependabot + +name: Auto Approve Dependabot PR's + +on: + pull_request + +jobs: + auto-approve: + runs-on: ubuntu-latest + steps: + - uses: hmarr/auto-approve-action@v2.0.0 + if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" From f12f3c749250a6f13eff1b0211f23d5d601274b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:40:09 -0500 Subject: [PATCH 08/15] chore(deps): bump typescript from 3.9.7 to 4.0.2 (#107) Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.9.7 to 4.0.2. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v3.9.7...v4.0.2) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- lambda-layers/package.json | 2 +- lambda-layers/yarn.lock | 26 +++++++++++++------------- package.json | 2 +- tools/cdk-build-tools/package.json | 2 +- tools/pkglint/package.json | 2 +- yarn.lock | 16 +++++----------- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/lambda-layers/package.json b/lambda-layers/package.json index 001840e48..d88472b6f 100644 --- a/lambda-layers/package.json +++ b/lambda-layers/package.json @@ -30,7 +30,7 @@ "maturity": "stable", "devDependencies": { "@types/node": "^14.6.1", - "typescript": "~3.9.7" + "typescript": "~4.0.2" }, "dependencies": { "aws-sdk": "^2.741.0" diff --git a/lambda-layers/yarn.lock b/lambda-layers/yarn.lock index 0e8f5d89a..8da5127f5 100644 --- a/lambda-layers/yarn.lock +++ b/lambda-layers/yarn.lock @@ -2,15 +2,15 @@ # yarn lockfile v1 -"@types/node@^14.0.12": - version "14.6.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.6.0.tgz#7d4411bf5157339337d7cff864d9ff45f177b499" - integrity sha512-mikldZQitV94akrc4sCcSjtJfsTKt4p+e/s0AGscVA6XArQ9kFclP+ZiYUMnq987rc6QlYxXv/EivqlfSLxpKA== - -aws-sdk@^2.693.0: - version "2.740.0" - resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.740.0.tgz#3ed1a9ad27d7f3e4fd289266f6e6d63d34dfd5ff" - integrity sha512-cSedIe7g5/S5o23jHvm9+vWhcYysmuKrmbML1Z0pO9KxlqOA9s4Z5f6Il7ZmvAktfmrxu1SyQu4YEoP5DL4/zw== +"@types/node@^14.6.1": + version "14.6.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.6.1.tgz#fdf6f6c6c73d3d8eee9c98a9a0485bc524b048d7" + integrity sha512-HnYlg/BRF8uC1FyKRFZwRaCPTPYKa+6I8QiUZFLredaGOou481cgFS4wKRFyKvQtX8xudqkSdBczJHIYSQYKrQ== + +aws-sdk@^2.741.0: + version "2.742.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.742.0.tgz#02373d324ca8201cd3fc8c1b82eff8b48b593f4c" + integrity sha512-zntDB0BpMn/y+B4RQvXuqY8DmJDYPkeFjZ6BbZ6vdNrsdB5TRz8p53ats4D3mLG068RB4M4AmVioFnU69nDXyQ== dependencies: buffer "4.9.2" events "1.1.1" @@ -76,10 +76,10 @@ sax@>=0.6.0: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== -typescript@~3.9.6: - version "3.9.7" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" - integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== +typescript@~4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2" + integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ== url@0.10.3: version "0.10.3" diff --git a/package.json b/package.json index 496d79fa7..5ffe70c5b 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "nyc": "^15.1.0", "standard-version": "^9.0.0", "ts-jest": "^26.2.0", - "typescript": "~3.9.7" + "typescript": "~4.0.2" }, "workspaces": { "packages": [ diff --git a/tools/cdk-build-tools/package.json b/tools/cdk-build-tools/package.json index 268393800..8861e8da2 100644 --- a/tools/cdk-build-tools/package.json +++ b/tools/cdk-build-tools/package.json @@ -56,7 +56,7 @@ "nodeunit": "^0.11.3", "nyc": "^15.1.0", "ts-jest": "^26.2.0", - "typescript": "~3.9.7", + "typescript": "~4.0.2", "yargs": "^15.4.1" }, "keywords": [ diff --git a/tools/pkglint/package.json b/tools/pkglint/package.json index d0daf8359..3fc413a4e 100644 --- a/tools/pkglint/package.json +++ b/tools/pkglint/package.json @@ -38,7 +38,7 @@ "@types/fs-extra": "^9.0.1", "@types/semver": "^7.3.3", "@types/yargs": "^15.0.5", - "typescript": "~3.9.7" + "typescript": "~4.0.2" }, "dependencies": { "case": "^1.6.3", diff --git a/yarn.lock b/yarn.lock index ac36c76d1..17ba990d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9931,17 +9931,6 @@ ts-node@^8.0.2: source-map-support "^0.5.17" yn "3.1.1" -ts-node@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3" - integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg== - dependencies: - arg "^4.1.0" - diff "^4.0.1" - make-error "^1.1.1" - source-map-support "^0.5.17" - yn "3.1.1" - tsame@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/tsame/-/tsame-2.0.1.tgz#70410ddbefcd29c61e2d68549b3347b0444d613f" @@ -10047,6 +10036,11 @@ typescript@^3.3.3, typescript@~3.9.7: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== +typescript@~4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2" + integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ== + uglify-js@^3.1.4: version "3.10.2" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.10.2.tgz#8cfa1209fd04199cc8a7f9930ddedb30b0f1912d" From 4353614dfb7749c7a9bb0731cd915723371c9c86 Mon Sep 17 00:00:00 2001 From: Claire P <68925298+aws-painec@users.noreply.github.com> Date: Fri, 4 Sep 2020 10:11:24 -0700 Subject: [PATCH 09/15] chore(integ): rewrite end-to-end test to simplify deploymen * chore(integ): rewrite end-to-end test to simplify deployment, use fallback values, eliminate output file * chore(integ): breaks up end-to-end scripts for test components into deploy, test, and teardown stages, use common functions instead of redundant scripts; add fallback to cleanup stacks on test failure * chore(integ): add summary output of test execution with deployment times * chore(integ): all tests now assumed to run unless override variable is set * chore(integ): break end-to-end test into different component scripts * chore(integ): combinede e2e scripts for test components into one component_e2e.sh script Co-authored-by: Claire Paine Co-authored-by: Claire Paine --- integ/.gitignore | 4 + integ/README.md | 51 +++++----- .../common/preflight/preflight.test.ts | 20 ---- .../common/scripts/bash/component_e2e.sh | 32 ++++++ .../common/scripts/bash/deploy-utils.sh | 35 +++++++ .../bin/deadline_01_repository.ts} | 0 .../cdk.json | 2 +- .../lib/testing-tier.ts | 0 .../bastion/testing/DL-read-docdb-response.sh | 0 .../testing/DL-read-repository-settings.sh | 0 .../test/deadline_01_repository.test.ts} | 0 .../bin/deadline_02_renderQueue.ts} | 0 .../cdk.json | 2 +- .../lib/testing-tier.ts | 0 .../testing/RQ-fetch-repository-file.sh | 0 .../bastion/testing/RQ-query-endpoint.sh | 0 .../scripts/bastion/testing/RQ-submit-job.sh | 0 .../testing/RQ-test-deadlinecommand.sh | 0 .../test/deadline_02_renderQueue.test.ts} | 0 .../bin/deadline_03_workerFleet.ts} | 0 .../cdk.json | 2 +- .../lib/testing-tier.ts | 0 .../bastion/testing/WF-report-worker-sets.sh | 0 .../bastion/testing/WF-report-workers.sh | 0 .../bastion/testing/WF-submit-jobs-to-sets.sh | 0 .../test/deadline_03_workerFleet.test.ts} | 0 .../renderQueue/scripts/bash/deploy-stacks.sh | 10 -- .../scripts/bash/destroy-stacks.sh | 10 -- .../deadline/renderQueue/scripts/bash/e2e.sh | 23 ----- .../repository/scripts/bash/deploy-stacks.sh | 12 --- .../repository/scripts/bash/destroy-stacks.sh | 12 --- .../deadline/repository/scripts/bash/e2e.sh | 23 ----- .../test/preflight/preflight.test.ts | 19 ---- .../workerFleet/scripts/bash/deploy-stacks.sh | 10 -- .../scripts/bash/destroy-stacks.sh | 10 -- .../deadline/workerFleet/scripts/bash/e2e.sh | 23 ----- .../test/preflight/preflight.test.ts | 23 ----- integ/scripts/bash/cleanup.sh | 16 +-- integ/scripts/bash/deploy-all.sh | 24 ++--- integ/scripts/bash/deploy-infrastructure.sh | 17 ++++ integ/scripts/bash/fetch-worker-amis.sh | 18 ++++ integ/scripts/bash/report-test-results.sh | 65 ++++++++++++ integ/scripts/bash/rfdk-integ-e2e.sh | 98 +++++++++++++------ integ/scripts/bash/set-test-variables.sh | 28 ++++++ integ/scripts/bash/stage-deadline.sh | 14 +++ integ/scripts/bash/tear-down.sh | 22 ++--- integ/scripts/bash/teardown-infrastructure.sh | 12 +++ integ/test-config.sh | 25 +++-- 48 files changed, 372 insertions(+), 290 deletions(-) delete mode 100644 integ/components/deadline/common/preflight/preflight.test.ts create mode 100755 integ/components/deadline/common/scripts/bash/component_e2e.sh create mode 100755 integ/components/deadline/common/scripts/bash/deploy-utils.sh rename integ/components/deadline/{repository/bin/deadline-repository.ts => deadline_01_repository/bin/deadline_01_repository.ts} (100%) rename integ/components/deadline/{repository => deadline_01_repository}/cdk.json (68%) rename integ/components/deadline/{repository => deadline_01_repository}/lib/testing-tier.ts (100%) rename integ/components/deadline/{repository => deadline_01_repository}/scripts/bastion/testing/DL-read-docdb-response.sh (100%) rename integ/components/deadline/{repository => deadline_01_repository}/scripts/bastion/testing/DL-read-repository-settings.sh (100%) rename integ/components/deadline/{repository/test/deadline-repository.test.ts => deadline_01_repository/test/deadline_01_repository.test.ts} (100%) rename integ/components/deadline/{renderQueue/bin/deadline-renderQueue.ts => deadline_02_renderQueue/bin/deadline_02_renderQueue.ts} (100%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/cdk.json (68%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/lib/testing-tier.ts (100%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/scripts/bastion/testing/RQ-fetch-repository-file.sh (100%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/scripts/bastion/testing/RQ-query-endpoint.sh (100%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/scripts/bastion/testing/RQ-submit-job.sh (100%) rename integ/components/deadline/{renderQueue => deadline_02_renderQueue}/scripts/bastion/testing/RQ-test-deadlinecommand.sh (100%) rename integ/components/deadline/{renderQueue/test/deadline-renderQueue.test.ts => deadline_02_renderQueue/test/deadline_02_renderQueue.test.ts} (100%) rename integ/components/deadline/{workerFleet/bin/deadline-workerFleet.ts => deadline_03_workerFleet/bin/deadline_03_workerFleet.ts} (100%) rename integ/components/deadline/{workerFleet => deadline_03_workerFleet}/cdk.json (68%) rename integ/components/deadline/{workerFleet => deadline_03_workerFleet}/lib/testing-tier.ts (100%) rename integ/components/deadline/{workerFleet => deadline_03_workerFleet}/scripts/bastion/testing/WF-report-worker-sets.sh (100%) rename integ/components/deadline/{workerFleet => deadline_03_workerFleet}/scripts/bastion/testing/WF-report-workers.sh (100%) rename integ/components/deadline/{workerFleet => deadline_03_workerFleet}/scripts/bastion/testing/WF-submit-jobs-to-sets.sh (100%) rename integ/components/deadline/{workerFleet/test/deadline-workerFleet.test.ts => deadline_03_workerFleet/test/deadline_03_workerFleet.test.ts} (100%) delete mode 100755 integ/components/deadline/renderQueue/scripts/bash/deploy-stacks.sh delete mode 100755 integ/components/deadline/renderQueue/scripts/bash/destroy-stacks.sh delete mode 100755 integ/components/deadline/renderQueue/scripts/bash/e2e.sh delete mode 100755 integ/components/deadline/repository/scripts/bash/deploy-stacks.sh delete mode 100755 integ/components/deadline/repository/scripts/bash/destroy-stacks.sh delete mode 100755 integ/components/deadline/repository/scripts/bash/e2e.sh delete mode 100644 integ/components/deadline/repository/test/preflight/preflight.test.ts delete mode 100755 integ/components/deadline/workerFleet/scripts/bash/deploy-stacks.sh delete mode 100755 integ/components/deadline/workerFleet/scripts/bash/destroy-stacks.sh delete mode 100755 integ/components/deadline/workerFleet/scripts/bash/e2e.sh delete mode 100644 integ/components/deadline/workerFleet/test/preflight/preflight.test.ts create mode 100755 integ/scripts/bash/deploy-infrastructure.sh create mode 100755 integ/scripts/bash/fetch-worker-amis.sh create mode 100755 integ/scripts/bash/report-test-results.sh create mode 100755 integ/scripts/bash/set-test-variables.sh create mode 100755 integ/scripts/bash/stage-deadline.sh create mode 100755 integ/scripts/bash/teardown-infrastructure.sh diff --git a/integ/.gitignore b/integ/.gitignore index e03f9a457..73e78aba7 100644 --- a/integ/.gitignore +++ b/integ/.gitignore @@ -11,6 +11,10 @@ yarn-error.log **/cdk.context.json test-output/ +# Deadline staging +stage/ +.e2etemp/ + # Include eslint config !.eslintrc.js diff --git a/integ/README.md b/integ/README.md index 5593e96d1..3a7745548 100644 --- a/integ/README.md +++ b/integ/README.md @@ -6,9 +6,9 @@ To run all test suites: 1. Configure AWS credentials (tests will use the default AWS profile, so either set up a default profile in .aws/credentials or use temporary credentials). -1. If your AWS profile has a different default region fromw here the test app will be deployed, set the AWS_REGION variable to the desired region. +1. Set the environment variable CDK_DEFAULT_REGION to the region the test should be deployed in -1. Configure test-config.sh. This script sets environment variables which are necessary for the tests. Currently this includes: +1. Configure test-config.sh. This script configures which test modules will run and overrides certain default values. Currently these include: * Options required for all Deadline test components: * DEADLINE_VERSION - version of the Deadline repository installer used for the test * DEADLINE_STAGING_PATH - Complete path to local staging folder for Deadline assets (see `packages/aws-rfdk/docs/DockerImageRecipes.md` for more information) @@ -20,30 +20,31 @@ To run all test suites: 1. Execute `yarn run e2e` from the `integ` directory. This will handle deploying the necessary stacks, run the appropriate tests on them, and then tear them down. -1. Test output is stored in the `test-output` folder, stamped with the same ID tag attached to the stacks created during the test. - # Example Output: ```bash -PASS components/deadline/repository/test/deadline-repository.test.ts (13.218 s) - DocDB tests - ✓ DL-1-1: Deadline DB is initialized (3 ms) - ✓ DL-2-1: Deadline DB is initialized - EFS tests - ✓ DL-1-2: EFS is initialized (1 ms) - ✓ DL-2-2: EFS is initialized - ✓ DL-1-3: repository.ini version matches Deadline installer (1 ms) - ✓ DL-2-3: repository.ini version matches Deadline installer - CloudWatch LogGroup tests - ✓ DL-1-4: Verify CloudWatch LogGroup contains two LogStreams - ✓ DL-2-4: Verify CloudWatch LogGroup contains two LogStreams - ✓ DL-1-5: Verify cloud-init-output LogStream (1622 ms) - ✓ DL-2-5: Verify cloud-init-output LogStream (1608 ms) - ✓ DL-1-6: Verify DeadlineRepositoryInstallationLogs LogStream (510 ms) - ✓ DL-2-6: Verify DeadlineRepositoryInstallationLogs LogStream (672 ms) - -Test Suites: 1 passed, 1 total -Tests: 12 passed, 12 total -Snapshots: 0 total -Time: 13.803 s, estimated 19 s +Pretest setup runtime: 0m 8s +Infrastructure stack deploy runtime: 0m 9s +Infrastructure stack cleanup runtime: 1m 46s +Results for test component deadline_01_repository: + -Tests ran: 21 + -Tests passed: 21 + -Tests failed: 0 + -Deploy runtime: 0m 34s + -Test suite runtime: 0m 30s + -Cleanup runtime: 9m 0s +Results for test component deadline_02_renderQueue: + -Tests ran: 8 + -Tests passed: 8 + -Tests failed: 0 + -Deploy runtime: 23m 41s + -Test suite runtime: 0m 55s + -Cleanup runtime: 16m 2s +Results for test component deadline_03_workerFleet: + -Tests ran: 16 + -Tests passed: 16 + -Tests failed: 0 + -Deploy runtime: 49m 44s + -Test suite runtime: 3m 3s + -Cleanup runtime: 55m 34s ``` diff --git a/integ/components/deadline/common/preflight/preflight.test.ts b/integ/components/deadline/common/preflight/preflight.test.ts deleted file mode 100644 index c0f5efba6..000000000 --- a/integ/components/deadline/common/preflight/preflight.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -const AWS_REGION = process.env.AWS_REGION?.toString(); -const DEADLINE_VERSION = process.env.DEADLINE_VERSION?.toString(); -const DEADLINE_STAGING_PATH = process.env.DEADLINE_STAGING_PATH?.toString(); - -test('AWS_REGION is set', () => { - expect(AWS_REGION).toBeTruthy(); -}); - -test('DEADLINE_VERSION is set', () => { - expect(DEADLINE_VERSION).toBeTruthy(); -}); - -test('DEADLINE_STAGING_PATH is set', () => { - expect(DEADLINE_STAGING_PATH).toBeTruthy(); -}); diff --git a/integ/components/deadline/common/scripts/bash/component_e2e.sh b/integ/components/deadline/common/scripts/bash/component_e2e.sh new file mode 100755 index 000000000..0feb4a6ff --- /dev/null +++ b/integ/components/deadline/common/scripts/bash/component_e2e.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +COMPONENT_NAME=${1:-undefined} +OPTION=${2:-undefined} + +if [[ $(basename $(pwd)) != $COMPONENT_NAME ]]; then + echo "ERROR: Script must be run from top directory of test component" + exit 1 +fi + +SKIP_TEST_CHECK=\$SKIP_${COMPONENT_NAME}_TEST +SKIP_TEST_CHECK=$(eval "echo $SKIP_TEST_CHECK" 2> /dev/null) || SKIP_TEST_CHECK=false +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 + fi + if [[ $OPTION != '--deploy-and-test-only' ]]; then + destroy_component_stacks $COMPONENT_NAME + fi +fi + +exit 0 diff --git a/integ/components/deadline/common/scripts/bash/deploy-utils.sh b/integ/components/deadline/common/scripts/bash/deploy-utils.sh new file mode 100755 index 000000000..a7af54264 --- /dev/null +++ b/integ/components/deadline/common/scripts/bash/deploy-utils.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +function deploy_component_stacks () { + COMPONENT_NAME=$1 + 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 + echo "Running test suite $COMPONENT_NAME..." + yarn run test "$COMPONENT_NAME.test" --json --outputFile="./.e2etemp/$COMPONENT_NAME.json" + echo "Test suite $COMPONENT_NAME complete." + + return 0 +} + +function destroy_component_stacks () { + COMPONENT_NAME=$1 + echo "Destroying test app $COMPONENT_NAME..." + npx cdk destroy "*" -f + rm -f "./cdk.context.json" + rm -rf "./cdk.out" + echo "Test app $COMPONENT_NAME destroyed." + + return 0 +} diff --git a/integ/components/deadline/repository/bin/deadline-repository.ts b/integ/components/deadline/deadline_01_repository/bin/deadline_01_repository.ts similarity index 100% rename from integ/components/deadline/repository/bin/deadline-repository.ts rename to integ/components/deadline/deadline_01_repository/bin/deadline_01_repository.ts diff --git a/integ/components/deadline/repository/cdk.json b/integ/components/deadline/deadline_01_repository/cdk.json similarity index 68% rename from integ/components/deadline/repository/cdk.json rename to integ/components/deadline/deadline_01_repository/cdk.json index ea162f8e1..e9e6fd71e 100644 --- a/integ/components/deadline/repository/cdk.json +++ b/integ/components/deadline/deadline_01_repository/cdk.json @@ -1,5 +1,5 @@ { - "app": "npx ts-node bin/deadline-repository.ts", + "app": "npx ts-node bin/deadline_01_repository.ts", "context": { "@aws-cdk/core:enableStackNameDuplicates": "true", "aws-cdk:enableDiffNoFail": "true" diff --git a/integ/components/deadline/repository/lib/testing-tier.ts b/integ/components/deadline/deadline_01_repository/lib/testing-tier.ts similarity index 100% rename from integ/components/deadline/repository/lib/testing-tier.ts rename to integ/components/deadline/deadline_01_repository/lib/testing-tier.ts diff --git a/integ/components/deadline/repository/scripts/bastion/testing/DL-read-docdb-response.sh b/integ/components/deadline/deadline_01_repository/scripts/bastion/testing/DL-read-docdb-response.sh similarity index 100% rename from integ/components/deadline/repository/scripts/bastion/testing/DL-read-docdb-response.sh rename to integ/components/deadline/deadline_01_repository/scripts/bastion/testing/DL-read-docdb-response.sh diff --git a/integ/components/deadline/repository/scripts/bastion/testing/DL-read-repository-settings.sh b/integ/components/deadline/deadline_01_repository/scripts/bastion/testing/DL-read-repository-settings.sh similarity index 100% rename from integ/components/deadline/repository/scripts/bastion/testing/DL-read-repository-settings.sh rename to integ/components/deadline/deadline_01_repository/scripts/bastion/testing/DL-read-repository-settings.sh diff --git a/integ/components/deadline/repository/test/deadline-repository.test.ts b/integ/components/deadline/deadline_01_repository/test/deadline_01_repository.test.ts similarity index 100% rename from integ/components/deadline/repository/test/deadline-repository.test.ts rename to integ/components/deadline/deadline_01_repository/test/deadline_01_repository.test.ts diff --git a/integ/components/deadline/renderQueue/bin/deadline-renderQueue.ts b/integ/components/deadline/deadline_02_renderQueue/bin/deadline_02_renderQueue.ts similarity index 100% rename from integ/components/deadline/renderQueue/bin/deadline-renderQueue.ts rename to integ/components/deadline/deadline_02_renderQueue/bin/deadline_02_renderQueue.ts diff --git a/integ/components/deadline/renderQueue/cdk.json b/integ/components/deadline/deadline_02_renderQueue/cdk.json similarity index 68% rename from integ/components/deadline/renderQueue/cdk.json rename to integ/components/deadline/deadline_02_renderQueue/cdk.json index b227ebd52..0d889e791 100644 --- a/integ/components/deadline/renderQueue/cdk.json +++ b/integ/components/deadline/deadline_02_renderQueue/cdk.json @@ -1,5 +1,5 @@ { - "app": "npx ts-node bin/deadline-renderQueue.ts", + "app": "npx ts-node bin/deadline_02_renderQueue.ts", "context": { "@aws-cdk/core:enableStackNameDuplicates": "true", "aws-cdk:enableDiffNoFail": "true" diff --git a/integ/components/deadline/renderQueue/lib/testing-tier.ts b/integ/components/deadline/deadline_02_renderQueue/lib/testing-tier.ts similarity index 100% rename from integ/components/deadline/renderQueue/lib/testing-tier.ts rename to integ/components/deadline/deadline_02_renderQueue/lib/testing-tier.ts diff --git a/integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-fetch-repository-file.sh b/integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-fetch-repository-file.sh similarity index 100% rename from integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-fetch-repository-file.sh rename to integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-fetch-repository-file.sh diff --git a/integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-query-endpoint.sh b/integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-query-endpoint.sh similarity index 100% rename from integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-query-endpoint.sh rename to integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-query-endpoint.sh diff --git a/integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-submit-job.sh b/integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-submit-job.sh similarity index 100% rename from integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-submit-job.sh rename to integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-submit-job.sh diff --git a/integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-test-deadlinecommand.sh b/integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-test-deadlinecommand.sh similarity index 100% rename from integ/components/deadline/renderQueue/scripts/bastion/testing/RQ-test-deadlinecommand.sh rename to integ/components/deadline/deadline_02_renderQueue/scripts/bastion/testing/RQ-test-deadlinecommand.sh diff --git a/integ/components/deadline/renderQueue/test/deadline-renderQueue.test.ts b/integ/components/deadline/deadline_02_renderQueue/test/deadline_02_renderQueue.test.ts similarity index 100% rename from integ/components/deadline/renderQueue/test/deadline-renderQueue.test.ts rename to integ/components/deadline/deadline_02_renderQueue/test/deadline_02_renderQueue.test.ts diff --git a/integ/components/deadline/workerFleet/bin/deadline-workerFleet.ts b/integ/components/deadline/deadline_03_workerFleet/bin/deadline_03_workerFleet.ts similarity index 100% rename from integ/components/deadline/workerFleet/bin/deadline-workerFleet.ts rename to integ/components/deadline/deadline_03_workerFleet/bin/deadline_03_workerFleet.ts diff --git a/integ/components/deadline/workerFleet/cdk.json b/integ/components/deadline/deadline_03_workerFleet/cdk.json similarity index 68% rename from integ/components/deadline/workerFleet/cdk.json rename to integ/components/deadline/deadline_03_workerFleet/cdk.json index 19e41fa30..40d32f0ee 100644 --- a/integ/components/deadline/workerFleet/cdk.json +++ b/integ/components/deadline/deadline_03_workerFleet/cdk.json @@ -1,5 +1,5 @@ { - "app": "npx ts-node bin/deadline-workerFleet.ts", + "app": "npx ts-node bin/deadline_03_workerFleet.ts", "context": { "@aws-cdk/core:enableStackNameDuplicates": "true", "aws-cdk:enableDiffNoFail": "true" diff --git a/integ/components/deadline/workerFleet/lib/testing-tier.ts b/integ/components/deadline/deadline_03_workerFleet/lib/testing-tier.ts similarity index 100% rename from integ/components/deadline/workerFleet/lib/testing-tier.ts rename to integ/components/deadline/deadline_03_workerFleet/lib/testing-tier.ts diff --git a/integ/components/deadline/workerFleet/scripts/bastion/testing/WF-report-worker-sets.sh b/integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-report-worker-sets.sh similarity index 100% rename from integ/components/deadline/workerFleet/scripts/bastion/testing/WF-report-worker-sets.sh rename to integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-report-worker-sets.sh diff --git a/integ/components/deadline/workerFleet/scripts/bastion/testing/WF-report-workers.sh b/integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-report-workers.sh similarity index 100% rename from integ/components/deadline/workerFleet/scripts/bastion/testing/WF-report-workers.sh rename to integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-report-workers.sh diff --git a/integ/components/deadline/workerFleet/scripts/bastion/testing/WF-submit-jobs-to-sets.sh b/integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-submit-jobs-to-sets.sh similarity index 100% rename from integ/components/deadline/workerFleet/scripts/bastion/testing/WF-submit-jobs-to-sets.sh rename to integ/components/deadline/deadline_03_workerFleet/scripts/bastion/testing/WF-submit-jobs-to-sets.sh diff --git a/integ/components/deadline/workerFleet/test/deadline-workerFleet.test.ts b/integ/components/deadline/deadline_03_workerFleet/test/deadline_03_workerFleet.test.ts similarity index 100% rename from integ/components/deadline/workerFleet/test/deadline-workerFleet.test.ts rename to integ/components/deadline/deadline_03_workerFleet/test/deadline_03_workerFleet.test.ts diff --git a/integ/components/deadline/renderQueue/scripts/bash/deploy-stacks.sh b/integ/components/deadline/renderQueue/scripts/bash/deploy-stacks.sh deleted file mode 100755 index fff918f17..000000000 --- a/integ/components/deadline/renderQueue/scripts/bash/deploy-stacks.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_RENDERQ_TEST_SUITE = true ]; then - npx cdk deploy "*" --require-approval=never -fi diff --git a/integ/components/deadline/renderQueue/scripts/bash/destroy-stacks.sh b/integ/components/deadline/renderQueue/scripts/bash/destroy-stacks.sh deleted file mode 100755 index 20c72cbbd..000000000 --- a/integ/components/deadline/renderQueue/scripts/bash/destroy-stacks.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_RENDERQ_TEST_SUITE = true ]; then - npx cdk destroy "*" -f -fi diff --git a/integ/components/deadline/renderQueue/scripts/bash/e2e.sh b/integ/components/deadline/renderQueue/scripts/bash/e2e.sh deleted file mode 100755 index 4b271f83f..000000000 --- a/integ/components/deadline/renderQueue/scripts/bash/e2e.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_RENDERQ_TEST_SUITE == true ]; then - - echo "Running Deadline RenderQueue end-to-end test..." >> "$OUTPUT_FILE" - - # Deploy a test app using the first configuration, run all jest tests, then tear the app down - echo "Deploying test app for Deadline Renderqueue test suite" >> "$OUTPUT_FILE" - npx cdk deploy "*" --require-approval=never - echo "Test app deployed. Running test suite..." >> "$OUTPUT_FILE" - npm run test deadline-renderQueue >> "$OUTPUT_FILE" 2>&1 - echo "Test suite complete. Destroying test app..." >> "$OUTPUT_FILE" - npx cdk destroy "*" -f - rm -f "./cdk.context.json" - rm -rf "./cdk.out" - echo "Test app destroyed." >> "$OUTPUT_FILE" - echo "Deadline RenderQueue tests complete." >> "$OUTPUT_FILE" -fi diff --git a/integ/components/deadline/repository/scripts/bash/deploy-stacks.sh b/integ/components/deadline/repository/scripts/bash/deploy-stacks.sh deleted file mode 100755 index 0c8edb349..000000000 --- a/integ/components/deadline/repository/scripts/bash/deploy-stacks.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ ${EXECUTE_DEADLINE_REPOSITORY_TEST_SUITE} = true ]; then - - npx cdk deploy "*" --require-approval=never - -fi diff --git a/integ/components/deadline/repository/scripts/bash/destroy-stacks.sh b/integ/components/deadline/repository/scripts/bash/destroy-stacks.sh deleted file mode 100755 index b780b2cd4..000000000 --- a/integ/components/deadline/repository/scripts/bash/destroy-stacks.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ ${EXECUTE_DEADLINE_REPOSITORY_TEST_SUITE} = true ]; then - - npx cdk destroy "*" -f - -fi diff --git a/integ/components/deadline/repository/scripts/bash/e2e.sh b/integ/components/deadline/repository/scripts/bash/e2e.sh deleted file mode 100755 index 72824f0fb..000000000 --- a/integ/components/deadline/repository/scripts/bash/e2e.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_REPOSITORY_TEST_SUITE = true ]; then - - echo "Running Deadline Repository end-to-end test..." >> "$OUTPUT_FILE" - - # Deploy a test app using the first configuration, run all jest tests, then tear the app down - echo "Deploying test app for Deadline Repository test suite" >> "$OUTPUT_FILE" - npx cdk deploy "*" --require-approval=never - echo "Test app deployed. Running test suite..." >> "$OUTPUT_FILE" - npm run test deadline-repository >> "$OUTPUT_FILE" 2>&1 - echo "Test suite complete. Destroying test app..." >> "$OUTPUT_FILE" - npx cdk destroy "*" -f - rm -f "./cdk.context.json" - rm -rf "./cdk.out" - echo "Test app destroyed." >> "$OUTPUT_FILE" - echo "Deadline Repository tests complete." >> "$OUTPUT_FILE" -fi diff --git a/integ/components/deadline/repository/test/preflight/preflight.test.ts b/integ/components/deadline/repository/test/preflight/preflight.test.ts deleted file mode 100644 index b7578a209..000000000 --- a/integ/components/deadline/repository/test/preflight/preflight.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -var USER_ACCEPTS_SSPL_FOR_RFDK_TESTS = process.env.USER_ACCEPTS_SSPL_FOR_RFDK_TESTS?.toString(); - -var runTests = process.env.EXECUTE_DEADLINE_REPOSITORY_TEST_SUITE?.toString(); - -if( runTests === 'true' ){ - test('USER_ACCEPTS_SSPL_FOR_RFDK_TESTS is set to true', () => { - expect(USER_ACCEPTS_SSPL_FOR_RFDK_TESTS).toBe('true'); - }); -} -else { - test('Skipping test suite; preflight not run', () =>{ - expect(1).toEqual(1); - }); -} diff --git a/integ/components/deadline/workerFleet/scripts/bash/deploy-stacks.sh b/integ/components/deadline/workerFleet/scripts/bash/deploy-stacks.sh deleted file mode 100755 index ad2e79021..000000000 --- a/integ/components/deadline/workerFleet/scripts/bash/deploy-stacks.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_WORKER_TEST_SUITE = true ]; then - npx cdk deploy "*" --require-approval=never -fi diff --git a/integ/components/deadline/workerFleet/scripts/bash/destroy-stacks.sh b/integ/components/deadline/workerFleet/scripts/bash/destroy-stacks.sh deleted file mode 100755 index bb76f2d9d..000000000 --- a/integ/components/deadline/workerFleet/scripts/bash/destroy-stacks.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_WORKER_TEST_SUITE = true ]; then - npx cdk destroy "*" -f -fi diff --git a/integ/components/deadline/workerFleet/scripts/bash/e2e.sh b/integ/components/deadline/workerFleet/scripts/bash/e2e.sh deleted file mode 100755 index 2e74d007d..000000000 --- a/integ/components/deadline/workerFleet/scripts/bash/e2e.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -euo pipefail - -if [ $EXECUTE_DEADLINE_WORKER_TEST_SUITE == true ]; then - - echo "Running Deadline Worker end-to-end test..." >> "$OUTPUT_FILE" - - # Deploy a test app using the first configuration, run all jest tests, then tear the app down - echo "Deploying test app for Deadline Worker test suite" >> "$OUTPUT_FILE" - npx cdk deploy "*" --require-approval=never - echo "Test app deployed. Running test suite..." >> "$OUTPUT_FILE" - npm run test deadline-workerFleet >> "$OUTPUT_FILE" 2>&1 - echo "Test suite complete. Destroying test app..." >> "$OUTPUT_FILE" - npx cdk destroy "*" -f - rm -f "./cdk.context.json" - rm -rf "./cdk.out" - echo "Test app destroyed." >> "$OUTPUT_FILE" - echo "Deadline Worker tests complete." >> "$OUTPUT_FILE" -fi diff --git a/integ/components/deadline/workerFleet/test/preflight/preflight.test.ts b/integ/components/deadline/workerFleet/test/preflight/preflight.test.ts deleted file mode 100644 index 5a5de5d02..000000000 --- a/integ/components/deadline/workerFleet/test/preflight/preflight.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -var LINUX_DEADLINE_AMI_ID = process.env.LINUX_DEADLINE_AMI_ID?.toString(); -var WINDOWS_DEADLINE_AMI_ID = process.env.WINDOWS_DEADLINE_AMI_ID?.toString(); - -var runTests = process.env.EXECUTE_DEADLINE_WORKER_TEST_SUITE?.toString(); - -if( runTests === 'true' ){ - test('LINUX_DEADLINE_AMI_ID is set', () => { - expect(LINUX_DEADLINE_AMI_ID).toBeTruthy(); - }); - test('WINDOWS_DEADLINE_AMI_ID is set', () => { - expect(WINDOWS_DEADLINE_AMI_ID).toBeTruthy(); - }); -} -else { - test('Skipping test suite; preflight not run', () =>{ - expect(1).toEqual(1); - }); -} diff --git a/integ/scripts/bash/cleanup.sh b/integ/scripts/bash/cleanup.sh index 2a07204da..f01e0d198 100755 --- a/integ/scripts/bash/cleanup.sh +++ b/integ/scripts/bash/cleanup.sh @@ -10,12 +10,14 @@ set -euo pipefail shopt -s globstar -root="$(pwd)" +INTEG_ROOT="$(pwd)" -for component in **/cdk.json; do - component_root="$(dirname "$component")" - rm -f "${component_root}/cdk.context.json" - rm -rf "${component_root}/cdk.out" - done +for COMPONENT in **/cdk.json; do + COMPONENT_ROOT="$(dirname "$COMPONENT")" + rm -f "${COMPONENT_ROOT}/cdk.context.json" + rm -rf "${COMPONENT_ROOT}/cdk.out" +done -rm -rf "${root}/node_modules" +rm -rf "$INTEG_ROOT/node_modules" +rm -rf "$INTEG_ROOT/stage" +rm -rf "$INTEG_ROOT/.e2etemp" diff --git a/integ/scripts/bash/deploy-all.sh b/integ/scripts/bash/deploy-all.sh index dc4e814b6..ea0d8b486 100755 --- a/integ/scripts/bash/deploy-all.sh +++ b/integ/scripts/bash/deploy-all.sh @@ -8,29 +8,29 @@ set -euo pipefail shopt -s globstar -root="$(pwd)" -infrastructure="${root}/components/_infrastructure" -source "${root}/test-config.sh" +INTEG_ROOT="$(pwd)" +INFRASTRUCTURE_APP="$INTEG_ROOT/components/_infrastructure" +source "$INTEG_ROOT/test-config.sh" if [ -z ${INTEG_STACK_TAG+x} ]; then # Create a unique tag to add to stack names and some resources export INTEG_STACK_TAG="$(date +%s%N)" fi -# Run preflight checks to make sure necessary variables, etc. are set -jest --passWithNoTests --silent "preflight" - # Deploy the infrastructure app, a cdk app containing only a VPC to be supplied to the following tests -cd "$infrastructure" +cd "$INFRASTRUCTURE_APP" npx cdk deploy "*" --require-approval=never -cd "$root" +cd "$INTEG_ROOT" -for component in **/cdk.json; do - component_root="$(dirname "$component")" +for COMPONENT in **/cdk.json; do + COMPONENT_ROOT="$(dirname "$COMPONENT")" + COMPONENT_NAME=$(basename "$COMPONENT_ROOT") # Use a pattern match to exclude the infrastructure app from the results - if [[ "$(basename "$component_root")" != _* ]]; then + if [[ "$(basename "$COMPONENT_ROOT")" != _* ]]; then # Excecute the e2e test in the component's scripts directory - cd "${root}/${component_root}" && "./scripts/bash/deploy-stacks.sh" + cd "$INTEG_STACK_TAG/$COMPONENT_ROOT" && ../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" --deploy-and-test-only fi done + +exit 0 diff --git a/integ/scripts/bash/deploy-infrastructure.sh b/integ/scripts/bash/deploy-infrastructure.sh new file mode 100755 index 000000000..4282c40ea --- /dev/null +++ b/integ/scripts/bash/deploy-infrastructure.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail +shopt -s globstar + +# Deploy the infrastructure app, a cdk app containing only a VPC to be supplied to the following tests +INFRASTRUCTURE_APP="$INTEG_ROOT/components/_infrastructure" +cd "$INFRASTRUCTURE_APP" +echo "Deploying RFDK-integ infrastructure..." +npx cdk deploy "*" --require-approval=never || yarn run tear-down +echo "RFDK-integ infrastructure deployed." +cd "$INTEG_ROOT" + +exit 0 diff --git a/integ/scripts/bash/fetch-worker-amis.sh b/integ/scripts/bash/fetch-worker-amis.sh new file mode 100755 index 000000000..e7f7aaef9 --- /dev/null +++ b/integ/scripts/bash/fetch-worker-amis.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +# Only pull AMI ids if one of these variables is not already set +if [ -z ${LINUX_DEADLINE_AMI_ID+x} ] || [ -z ${WINDOWS_DEADLINE_AMI_ID+x} ]; then + DEADLINE_RELEASE=$(sed 's/\(.*\..*\..*\)\..*/\1/' <<< $DEADLINE_VERSION) + curl https://awsportal.s3.amazonaws.com/$DEADLINE_RELEASE/Release/amis.json --silent -o "$INTEG_TEMP_DIR/amis.json" + if [ -z ${LINUX_DEADLINE_AMI_ID+x} ]; then + export LINUX_DEADLINE_AMI_ID=$(node -e $'const json = require(\'./.e2etemp/amis.json\'); console.log(json[process.argv[1]].worker["ami-id"])' "$AWS_REGION") + fi + if [ -z ${WINDOWS_DEADLINE_AMI_ID+x} ]; then + export WINDOWS_DEADLINE_AMI_ID=$(node -e $'const json = require(\'./.e2etemp/amis.json\'); console.log(json[process.argv[1]].windowsWorker["ami-id"])' "$AWS_REGION") + fi +fi diff --git a/integ/scripts/bash/report-test-results.sh b/integ/scripts/bash/report-test-results.sh new file mode 100755 index 000000000..e18fbc2ee --- /dev/null +++ b/integ/scripts/bash/report-test-results.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail +shopt -s globstar + +PRETEST_TIME=$(( $PRETEST_FINISH_TIME - $TEST_START_TIME )) +echo "Pretest setup runtime: $((($PRETEST_TIME / 60) % 60))m $(($PRETEST_TIME % 60))s" + +INFRASTRUCTURE_DEPLOY_TIME=$(( $INFRASTRUCTURE_DEPLOY_FINISH_TIME - $PRETEST_FINISH_TIME )) +echo "Infrastructure stack deploy runtime: $((($INFRASTRUCTURE_DEPLOY_TIME / 60) % 60))m $(($INFRASTRUCTURE_DEPLOY_TIME % 60))s" + +INFRASTRUCTURE_DESTROY_TIME=$(( $INFRASTRUCTURE_DESTROY_FINISH_TIME - $INFRASTRUCTURE_DESTROY_START_TIME )) +echo "Infrastructure stack cleanup runtime: $((($INFRASTRUCTURE_DESTROY_TIME / 60) % 60))m $(($INFRASTRUCTURE_DESTROY_TIME % 60))s" + +# Function pulls test results from test output file and calculates time spent on each stage of the test +report_results () { + COMPONENT_NAME=$1 + + if [ $(ls "$INTEG_TEMP_DIR/$COMPONENT_NAME.json" 2> /dev/null) ]; then + # Get test numbers from jest output + TESTS_RAN=$(node -e $'const json = require(process.argv[1]); console.log(json.numTotalTests)' "$INTEG_TEMP_DIR/$COMPONENT_NAME.json") + TESTS_PASSED=$(node -e $'const json = require(process.argv[1]); console.log(json.numPassedTests)' "$INTEG_TEMP_DIR/$COMPONENT_NAME.json") + TESTS_FAILED=$(node -e $'const json = require(process.argv[1]); console.log(json.numFailedTests)' "$INTEG_TEMP_DIR/$COMPONENT_NAME.json") + + DEPLOY_START_TIME=${COMPONENT_NAME}_START_TIME + DEPLOY_FINISH_TIME=$(node -e $'const json = require(process.argv[1]); console.log(json.startTime)' "$INTEG_TEMP_DIR/$COMPONENT_NAME.json") + DEPLOY_FINISH_TIME="${DEPLOY_FINISH_TIME:0:10}" + DESTROY_START_TIME=$(node -e $'const json = require(process.argv[1]); console.log(json.testResults[0].endTime)' "$INTEG_TEMP_DIR/$COMPONENT_NAME.json") + DESTROY_START_TIME="${DESTROY_START_TIME:0:10}" + DESTROY_FINISH_TIME=${COMPONENT_NAME}_FINISH_TIME + + # Calculate seconds from when deploy began to when test began + DEPLOY_TIME=$(( $DEPLOY_FINISH_TIME - $DEPLOY_START_TIME )) + # Calculate seconds from when deploy ended to when teardown began + TEST_TIME=$(( $DESTROY_START_TIME - $DEPLOY_FINISH_TIME )) + # Calculate seconds from when test ended to when teardown finished + DESTROY_TIME=$(( $DESTROY_FINISH_TIME - $DESTROY_START_TIME )) + + echo "Results for test component $COMPONENT_NAME: " + echo " -Tests ran:" $TESTS_RAN + echo " -Tests passed:" $TESTS_PASSED + echo " -Tests failed:" $TESTS_FAILED + echo " -Deploy runtime: $((($DEPLOY_TIME / 60) % 60))m $(($DEPLOY_TIME % 60))s" + echo " -Test suite runtime: $((($TEST_TIME / 60) % 60))m $(($TEST_TIME % 60))s" + echo " -Cleanup runtime: $((($DESTROY_TIME / 60) % 60))m $(($DESTROY_TIME % 60))s" + + fi +} + +# Report test results for each test component +for COMPONENT in **/cdk.json; do + COMPONENT_ROOT="$(dirname "$COMPONENT")" + COMPONENT_NAME=$(basename "$COMPONENT_ROOT") + # Use a pattern match to exclude the infrastructure app from the results + if [[ "$COMPONENT_NAME" != _* ]]; then + report_results $COMPONENT_NAME + + fi + export ${COMPONENT_NAME}_FINISH_TIME=$SECONDS +done + +exit 0 diff --git a/integ/scripts/bash/rfdk-integ-e2e.sh b/integ/scripts/bash/rfdk-integ-e2e.sh index 6976dff4f..80d904222 100755 --- a/integ/scripts/bash/rfdk-integ-e2e.sh +++ b/integ/scripts/bash/rfdk-integ-e2e.sh @@ -6,60 +6,102 @@ # Script to run end to end test for configured RFDK components # Configuration information for each test is drawn from integ/test-config.sh # Script handles stack deployment, execution of the necessary tests, and teardown -# set -euo pipefail shopt -s globstar -root="$(pwd)" -infrastructure="${root}/components/_infrastructure" +#Mark test start time +export TEST_START_TIME="$(date +%s)" +SECONDS=$TEST_START_TIME -echo "Loading config..." -source "${root}/test-config.sh" +export INTEG_ROOT="$(pwd)" +BASH_SCRIPTS="$INTEG_ROOT/scripts/bash" + +# Load environment variables from config file +if [ ! "${SKIP_TEST_CONFIG-}" = true ]; then + # Load variables from config file + echo "Loading config..." + source "$INTEG_ROOT/test-config.sh" +fi + +# Set variables from script +source $BASH_SCRIPTS/set-test-variables.sh + +# Make sure SSPL license has been accepted if running repository test +if [ ! "${SKIP_deadline_01_repository_TEST-}" = true ]; then + if [ $USER_ACCEPTS_SSPL_FOR_RFDK_TESTS != true ]; then + echo "Error: SSPL license has not been accepted for repository test; test will not run. See README.md for details" + exit 1 + fi +fi + +# Create temp directory +export INTEG_TEMP_DIR="$INTEG_ROOT/.e2etemp" +mkdir -p $INTEG_TEMP_DIR + +# Stage deadline from script +$BASH_SCRIPTS/stage-deadline.sh + +# If executing worker fleet tests, find Deadline AMIs based on supplied version +if [ ! "${SKIP_deadline_03_repository_TEST-}" = true ]; then + source $BASH_SCRIPTS/fetch-worker-amis.sh +fi # Create a unique tag to add to stack names and some resources if [ -z ${INTEG_STACK_TAG+x} ]; then - # Create a unique tag to add to stack names and some resources export INTEG_STACK_TAG="$(date +%s%N)" fi -# Set location of output file -mkdir -p "test-output" -export OUTPUT_FILE="${root}/test-output/output-${INTEG_STACK_TAG}.txt" - -echo "Starting RFDK-integ end-to-end tests" > "$OUTPUT_FILE" +# Mark pretest finish time +export PRETEST_FINISH_TIME=$SECONDS -# Run preflight checks to make sure necessary variables, etc. are set -jest --passWithNoTests --silent "preflight" +echo "Starting RFDK-integ end-to-end tests" -cd "$infrastructure" +# Define cleanup function for deployment failure +cleanup_on_failure () { + yarn run tear-down + exit 1 +} # Deploy the infrastructure app, a cdk app containing only a VPC to be supplied to the following tests -echo "Deploying RFDK-integ infrastructure..." >> "$OUTPUT_FILE" -npx cdk deploy "*" --require-approval=never -echo "RFDK-integ infrastructure deployed." >> "$OUTPUT_FILE" -cd "$root" +$BASH_SCRIPTS/deploy-infrastructure.sh || cleanup_on_failure + +# Mark infrastructure deploy finish time +export INFRASTRUCTURE_DEPLOY_FINISH_TIME=$SECONDS # Pull the top level directory for each cdk app in the components directory -for component in **/cdk.json; do - component_root="$(dirname "$component")" +for COMPONENT in **/cdk.json; do + COMPONENT_ROOT="$(dirname "$COMPONENT")" + COMPONENT_NAME=$(basename "$COMPONENT_ROOT") # Use a pattern match to exclude the infrastructure app from the results - if [[ "$(basename "$component_root")" != _* ]]; then + export ${COMPONENT_NAME}_START_TIME=$SECONDS + if [[ "$COMPONENT_NAME" != _* ]]; then # Excecute the e2e test in the component's scripts directory - cd "${root}/${component_root}" && "./scripts/bash/e2e.sh" + cd "$INTEG_ROOT/$COMPONENT_ROOT" && ../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" || cleanup_on_failure fi + export ${COMPONENT_NAME}_FINISH_TIME=$SECONDS done +# Mark infrastructure destroy start time +export INFRASTRUCTURE_DESTROY_START_TIME=$SECONDS + # Destroy the infrastructure stack on completion -echo "Test suites completed. Destroying infrastructure stack..." >> "$OUTPUT_FILE" -cd "$infrastructure" -npx cdk destroy "*" -f +cd $INTEG_ROOT +$BASH_SCRIPTS/teardown-infrastructure.sh || cleanup_on_failure -echo "Infrastructure stack destroyed." >> "$OUTPUT_FILE" -cd "$root" +# Mark infrastructure destroy finish time +export INFRASTRUCTURE_DESTROY_FINISH_TIME=$SECONDS + +cd "$INTEG_ROOT" + +echo "Complete!" + +# Report results +$BASH_SCRIPTS/report-test-results.sh echo "Cleaning up folders..." yarn run clean -echo "Complete!" >> "$OUTPUT_FILE" +echo "Exiting..." + exit 0 diff --git a/integ/scripts/bash/set-test-variables.sh b/integ/scripts/bash/set-test-variables.sh new file mode 100755 index 000000000..38799f641 --- /dev/null +++ b/integ/scripts/bash/set-test-variables.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +echo "Setting test variables..." + +# Get region from CDK_DEFAULT_REGION; assume us-west-2 if it's not set +if [ -z ${CDK_DEFAULT_REGION+x} ]; then + export AWS_REGION="us-west-2" +else + export AWS_REGION=$CDK_DEFAULT_REGION +fi + +# Set staging path to default if not overridden +if [ -z ${DEADLINE_STAGING_PATH+x} ]; then + export DEADLINE_STAGING_PATH="$INTEG_ROOT/stage" +elif [ $(ls "$DEADLINE_STAGING_PATH/manifest.json" 2> /dev/null) ]; then + #If path is set, extract the Deadline version to use for Deadline installations on the farm. This will override any other Deadline version provided. + export DEADLINE_VERSION=$(node -e $'const json = require(process.argv[1] + \'/manifest.json\'); console.log(json.version)' "$DEADLINE_STAGING_PATH") +fi + +# Set Deadline version to default if not overridden +if [ -z ${DEADLINE_VERSION+x} ]; then + export DEADLINE_VERSION="10.1.9.2" +fi diff --git a/integ/scripts/bash/stage-deadline.sh b/integ/scripts/bash/stage-deadline.sh new file mode 100755 index 000000000..b24c61370 --- /dev/null +++ b/integ/scripts/bash/stage-deadline.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +# Check if Deadline assets are staged at configured path +if [ ! $(ls "$DEADLINE_STAGING_PATH/manifest.json" 2> /dev/null) ]; then + # Stage Deadline assets + npx ../packages/aws-rfdk/bin/stage-deadline --deadlineInstallerURI "s3://thinkbox-installers/Deadline/$DEADLINE_VERSION/Linux/DeadlineClient-$DEADLINE_VERSION-linux-x64-installer.run" --dockerRecipesURI "s3://thinkbox-installers/DeadlineDocker/$DEADLINE_VERSION/DeadlineDocker-$DEADLINE_VERSION.tar.gz" --output "$DEADLINE_STAGING_PATH" +fi + +exit 0 diff --git a/integ/scripts/bash/tear-down.sh b/integ/scripts/bash/tear-down.sh index 413466082..3e9d34964 100755 --- a/integ/scripts/bash/tear-down.sh +++ b/integ/scripts/bash/tear-down.sh @@ -10,28 +10,26 @@ set -euo pipefail shopt -s globstar -root="$(pwd)" -infrastructure="${root}/components/_infrastructure" -source test-config.sh +INTEG_ROOT="$(pwd)" +INFRASTRUCTURE_APP="$INTEG_ROOT/components/_infrastructure" if [ -z ${INTEG_STACK_TAG+x} ]; then echo "INTEG_STACK_TAG must be set, exiting..." exit 1 fi -for component in **/cdk.json; do - component_root="$(dirname "$component")" +for COMPONENT in **/cdk.json; do + COMPONENT_ROOT="$(dirname "$COMPONENT")" + COMPONENT_NAME=$(basename "$COMPONENT_ROOT") # Use a pattern match to exclude the infrastructure app from the results - if [[ "$(basename "$component_root")" != _* ]]; then + if [[ "$(basename "$COMPONENT_ROOT")" != _* ]]; then # Excecute the e2e test in the component's scripts directory - cd "${root}/${component_root}" && "./scripts/bash/destroy-stacks.sh" + cd "$INTEG_ROOT/$COMPONENT_ROOT" && ../common/scripts/bash/component_e2e.sh "$COMPONENT_NAME" --destroy-only fi done -if [ -z ${SAVE_INFRASTRUCTURE+x} ]; then - cd "$infrastructure" && npx cdk destroy "*" -f -fi +cd "$INFRASTRUCTURE_APP" && npx cdk destroy "*" -f -cd "$root" +cd "$INTEG_ROOT" && yarn run clean -yarn run clean +exit 0 diff --git a/integ/scripts/bash/teardown-infrastructure.sh b/integ/scripts/bash/teardown-infrastructure.sh new file mode 100755 index 000000000..c6c43342a --- /dev/null +++ b/integ/scripts/bash/teardown-infrastructure.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +echo "Test suites completed. Destroying infrastructure stack..." +INFRASTRUCTURE_APP="$INTEG_ROOT/components/_infrastructure" +cd "$INFRASTRUCTURE_APP" +npx cdk destroy "*" -f +echo "Infrastructure stack destroyed." + +exit 0 diff --git a/integ/test-config.sh b/integ/test-config.sh index 3a9b77506..b3b2774ce 100755 --- a/integ/test-config.sh +++ b/integ/test-config.sh @@ -3,16 +3,25 @@ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -# Options for Deadline test suite -export EXECUTE_DEADLINE_REPOSITORY_TEST_SUITE=true -export EXECUTE_DEADLINE_RENDERQ_TEST_SUITE=true -export EXECUTE_DEADLINE_WORKER_TEST_SUITE=true -export DEADLINE_STAGING_PATH +# Accept SSPL license to install MongoDB +# - If not set to `true` here, the Repository test component will fail immediately on execution +export USER_ACCEPTS_SSPL_FOR_RFDK_TESTS=false + +# Version of Deadline to install on farm resources. +# - If not set here, will default to 10.1.9.2 export DEADLINE_VERSION -# Options for Deadline Repository test component -export USER_ACCEPTS_SSPL_FOR_RFDK_TESTS=false +# Qualified path to staged Deadline assets. +# - If not set here, assets will stage automatically to `aws-rfdk/integ/stage` +# - If set here, the version found in `manifest.json` at this path will override any value supplied for DEADLINE_VERSION +export DEADLINE_STAGING_PATH -# Options for Deadline WorkerFleet test component +# EC2 AMIs to use for Deadline workers +# - If not set here, the appropriate basic worker AMI for the version of Deadline and region will be pulled from the public directory export LINUX_DEADLINE_AMI_ID export WINDOWS_DEADLINE_AMI_ID + +# Configure test suites to include in end-to-end test +export SKIP_deadline_01_repository_TEST +export SKIP_deadline_02_renderQueue_TEST +export SKIP_deadline_03_workerFleet_TEST From fb6c6ed5ae8ea546a448f229dbf5983068b5c6ca Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Tue, 8 Sep 2020 21:46:35 +0000 Subject: [PATCH 10/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/version.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index 5a1b517dc..2eb63abaa 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -107,7 +107,7 @@ export class Version { * - {3} Matches previous pattern exactly 3 times. * - $ asserts position at the end of a line */ - if (version.match(/^\d+(?:\.\d+){3}$/g)) { + if (version.match(/^\d+(?:\.\d+){3}$/)) { return true; } return false; From 424b51c66d8f0e4e9120d43bd197fea65190539d Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Wed, 9 Sep 2020 16:33:42 +0000 Subject: [PATCH 11/15] adding isLessThan method --- packages/aws-rfdk/lib/deadline/lib/stage.ts | 3 +- packages/aws-rfdk/lib/deadline/lib/version.ts | 21 ++++++++ .../lib/deadline/test/version.test.ts | 51 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index 7dd462f3e..2a0b53669 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -161,7 +161,8 @@ export class Stage { // Do minimum supported deadline version check const minimumSupportedVersion = new Version([10, 1, 9, 2]); - if (minimumSupportedVersion.isGreaterThan(Version.parse(version))) { + const stagedVersion = Version.parse(version); + if (stagedVersion.isLessThan(minimumSupportedVersion)) { throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion.toString()})`); } diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index 2eb63abaa..a28a01391 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -143,6 +143,27 @@ export class Version { return false; } + /** + * This method compares two version strings + * + * @param version + * + * @returns true if this version is less than the provided version; + * false if this version is greater than or equal to the provided verison. + */ + public isLessThan(version: Version): boolean { + if (this.components.length != version.components.length) { + throw new TypeError('Component count in both the versions should be same.'); + } + + for (let i = 0; i < this.components.length; i++) { + if (this.components[i] != version.components[i]) { + return this.components[i] < version.components[i]; + } + } + return false; + } + /** * The method returns the version components in dot separated string format. */ diff --git a/packages/aws-rfdk/lib/deadline/test/version.test.ts b/packages/aws-rfdk/lib/deadline/test/version.test.ts index 24e47e7cd..7b08ce9f0 100644 --- a/packages/aws-rfdk/lib/deadline/test/version.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/version.test.ts @@ -72,6 +72,57 @@ describe('Version', () => { }); + describe('.isLessThan', () => { + test.each<[string, { firstVersion: string, secondVersion: string, expectedValue: boolean }]>([ + [ + 'equal version', + { + firstVersion: '1.1.1.1', + secondVersion: '1.1.1.1', + expectedValue: false, + }, + ], [ + 'greater minor version', + { + firstVersion: '10.1.9.2', + secondVersion: '10.0.9.2', + expectedValue: false, + }, + ], [ + 'greater patch version', + { + firstVersion: '1.1.1.2', + secondVersion: '1.1.1.1', + expectedValue: false, + }, + ], [ + 'less than', + { + firstVersion: '2.0.0.0', + secondVersion: '2.0.0.1', + expectedValue: true, + }, + ], + ])('%s', (_name, testcase) => { + const { firstVersion, secondVersion, expectedValue } = testcase; + + // WHEN + const lhs = Version.parse(firstVersion); + const result = lhs.isLessThan(Version.parse(secondVersion)); + + expect(result).toEqual(expectedValue); + }); + }); + + describe('.isLessThan constructor', () => { + + // WHEN + const lhs = new Version([10, 0, 9, 2]); + const result = lhs.isLessThan(Version.parse('10.1.9.2')); + + expect(result).toEqual(true); + }); + describe('.parse', () => { test.each<[string, { version: string, expectedValue: boolean }]>([ [ From 22b5652dd6daf06fc1cab4b991725dedc7df0c1f Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Tue, 15 Sep 2020 15:01:15 +0000 Subject: [PATCH 12/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/stage.ts | 5 +- packages/aws-rfdk/lib/deadline/lib/version.ts | 69 ++++++++++++------ .../aws-rfdk/lib/deadline/lib/worker-fleet.ts | 2 + .../scripts/powershell/configureWorker.ps1 | 4 +- .../lib/deadline/test/version.test.ts | 70 +++++++++++++++---- .../lib/deadline/test/worker-fleet.test.ts | 5 +- 6 files changed, 111 insertions(+), 44 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/stage.ts b/packages/aws-rfdk/lib/deadline/lib/stage.ts index 2a0b53669..cc8e6529a 100644 --- a/packages/aws-rfdk/lib/deadline/lib/stage.ts +++ b/packages/aws-rfdk/lib/deadline/lib/stage.ts @@ -160,10 +160,9 @@ export class Stage { } // Do minimum supported deadline version check - const minimumSupportedVersion = new Version([10, 1, 9, 2]); const stagedVersion = Version.parse(version); - if (stagedVersion.isLessThan(minimumSupportedVersion)) { - throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${minimumSupportedVersion.toString()})`); + if (stagedVersion.isLessThan(Version.MINIMUM_SUPPORTED_DEADLINE_VERSION)) { + throw new TypeError(`Staged Deadline Version (${version}) is less than the minimum supported version (${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()})`); } return true; diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index a28a01391..01f1d7beb 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -75,7 +75,12 @@ abstract class VersionQueryBase extends Construct implements IVersion { /** * This class is reposonsible to do basic operations on version format. */ -export class Version { +export class Version implements IPatchVersion { + + /** + * This variable holds the value for minimum supported deadline version. + */ + public static readonly MINIMUM_SUPPORTED_DEADLINE_VERSION = new Version([10, 1, 9, 2]); /** * This method parses the input string and returns the version object. @@ -116,9 +121,47 @@ export class Version { /** * Numeric components of version. */ - public readonly components: number[]; + private readonly components: number[]; + + /** + * @inheritdoc + */ + public get majorVersion(): number { + return this.components[0]; + } + + /** + * @inheritdoc + */ + public get minorVersion(): number { + return this.components[1]; + } + + /** + * @inheritdoc + */ + public get releaseVersion(): number { + return this.components[2]; + } + + /** + * @inheritdoc + */ + public get patchVersion(): number { + return this.components[3]; + } constructor(components: number[]) { + // validations + if(components.length != 4) { + throw new TypeError('Invalid version format. Version should contain exactly 4 components.'); + } + components.forEach((component) => { + if (component < 0) { + throw new TypeError('Invalid version format. None of the version components can be negative.'); + } + }); + this.components = components; } @@ -190,26 +233,6 @@ export class Version { * constructs which version of Deadline you want them to use, and be configured for. */ export class VersionQuery extends VersionQueryBase { - /** - * Parses a version string of the format: - * - * ... - * - * and extracts the components. - * - * @param versionstr The input version string - */ - public static parseVersionString(versionstr: string): IPatchVersion { - const version = Version.parse(versionstr); - - return { - majorVersion: version.components[0], - minorVersion: version.components[1], - releaseVersion: version.components[2], - patchVersion: version.components[3], - }; - } - /** * Specify a Deadline version from a fully-qualified Deadline patch version. * @@ -285,7 +308,7 @@ export class VersionQuery extends VersionQueryBase { * @param versionString A fully qualified version string (e.g. 10.1.9.2) */ public static exactString(scope: Construct, id: string, versionString: string) { - return VersionQuery.exact(scope, id, VersionQuery.parseVersionString(versionString)); + return VersionQuery.exact(scope, id, Version.parse(versionString)); } /** diff --git a/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts b/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts index fd8628965..700ba872c 100644 --- a/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts +++ b/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts @@ -56,6 +56,7 @@ import { import { IRenderQueue, } from './render-queue'; +import { Version } from './version'; /** * Interface for Deadline Worker Fleet. @@ -548,6 +549,7 @@ export class WorkerInstanceFleet extends WorkerInstanceFleetBase { `'${groups}'`, `'${pools}'`, `'${props.region || ''}'`, + `'${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, ], }); } diff --git a/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 b/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 index 1746cbe20..5ede6e11d 100644 --- a/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 +++ b/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 @@ -9,7 +9,9 @@ param ( [Parameter(Mandatory=$True)] $workerPools, [Parameter(Mandatory=$True)] - $workerRegion + $workerRegion, + [Parameter(Mandatory=$True)] + $minimumSupportedDeadlineVersion ) Set-PSDebug -Trace 1 diff --git a/packages/aws-rfdk/lib/deadline/test/version.test.ts b/packages/aws-rfdk/lib/deadline/test/version.test.ts index 7b08ce9f0..d222c2682 100644 --- a/packages/aws-rfdk/lib/deadline/test/version.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/version.test.ts @@ -114,7 +114,7 @@ describe('Version', () => { }); }); - describe('.isLessThan constructor', () => { + describe('.isLessThan using constructor', () => { // WHEN const lhs = new Version([10, 0, 9, 2]); @@ -123,39 +123,79 @@ describe('Version', () => { expect(result).toEqual(true); }); - describe('.parse', () => { - test.each<[string, { version: string, expectedValue: boolean }]>([ + describe('constructor validation', () => { + test.each<[string, { version: number[], expectedException?: RegExp }]>([ + [ + 'incorrect component count', + { + version: [10, 1, 9], + expectedException: /Invalid version format/, + }, + ], [ + 'negative value', + { + version: [10, -1, 9], + expectedException: /Invalid version format/, + }, + ], [ + 'decimal value', + { + version: [10, 1, 9.2], + expectedException: /Invalid version format/, + }, + ], [ + 'correct value', + { + version: [10, 1, 9, 2], + }, + ], + ])('%s', (_name, testcase) => { + const { version, expectedException } = testcase; + + // WHEN + if (expectedException) { + expect(() => new Version(version)).toThrow(expectedException); + } else { + expect(() => new Version(version)).not.toThrow(); + } + }); + }); + + describe('.parse throws exception', () => { + test.each<[string, { version: string, expectedException?: RegExp }]>([ [ 'ending with .', { version: '10.1.9.', - expectedValue: false, + expectedException: /Invalid version format/, }, ], [ 'empty string', { version: '', - expectedValue: false, + expectedException: /Invalid version format/, + }, + ], [ + 'negative value', + { + version: '10.-1.9.2', + expectedException: /Invalid version format/, }, ], [ 'correct version', { version: '10.1.9.2', - expectedValue: true, }, ], ])('%s', (_name, testcase) => { - const { version, expectedValue } = testcase; + const { version, expectedException } = testcase; + // WHEN - let result = false; - try { - Version.parse(version); - result = true; - } catch (error) { - } finally { + if(expectedException) { + expect(() => Version.parse(version)).toThrow(expectedException); + } else { + expect(() => Version.parse(version)).not.toThrow(); } - - expect(result).toEqual(expectedValue); }); }); }); diff --git a/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts b/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts index 08494476e..eb8beafe2 100644 --- a/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts @@ -46,6 +46,7 @@ import { Repository, VersionQuery, WorkerInstanceFleet, + Version, } from '../lib'; import { CONFIG_WORKER_ASSET_LINUX, @@ -685,7 +686,7 @@ test('default worker fleet is created correctly custom subnet values', () => { }, ], }, - "' '6161' '' '' ''", + `' '6161' '' '' '' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, ], ], }); @@ -1085,7 +1086,7 @@ test('default worker fleet is created correctly with groups, pools and region', }, ], }, - "' '63415' 'a,b' 'c,d' 'E'", + `' '63415' 'a,b' 'c,d' 'E' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, ]], }); }); From 4c37b8788081bc4c8de9791610917ac6800a7714 Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Wed, 16 Sep 2020 20:43:33 +0000 Subject: [PATCH 13/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/version.ts | 4 ++-- packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts | 2 -- .../lib/deadline/scripts/powershell/configureWorker.ps1 | 4 +--- packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts | 5 ++--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index 01f1d7beb..f0045aea8 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -154,11 +154,11 @@ export class Version implements IPatchVersion { constructor(components: number[]) { // validations if(components.length != 4) { - throw new TypeError('Invalid version format. Version should contain exactly 4 components.'); + throw new Error('Invalid version format. Version should contain exactly 4 components.'); } components.forEach((component) => { if (component < 0) { - throw new TypeError('Invalid version format. None of the version components can be negative.'); + throw new RangeError('Invalid version format. None of the version components can be negative.'); } }); diff --git a/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts b/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts index 700ba872c..fd8628965 100644 --- a/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts +++ b/packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts @@ -56,7 +56,6 @@ import { import { IRenderQueue, } from './render-queue'; -import { Version } from './version'; /** * Interface for Deadline Worker Fleet. @@ -549,7 +548,6 @@ export class WorkerInstanceFleet extends WorkerInstanceFleetBase { `'${groups}'`, `'${pools}'`, `'${props.region || ''}'`, - `'${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, ], }); } diff --git a/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 b/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 index 5ede6e11d..1746cbe20 100644 --- a/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 +++ b/packages/aws-rfdk/lib/deadline/scripts/powershell/configureWorker.ps1 @@ -9,9 +9,7 @@ param ( [Parameter(Mandatory=$True)] $workerPools, [Parameter(Mandatory=$True)] - $workerRegion, - [Parameter(Mandatory=$True)] - $minimumSupportedDeadlineVersion + $workerRegion ) Set-PSDebug -Trace 1 diff --git a/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts b/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts index eb8beafe2..08494476e 100644 --- a/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts @@ -46,7 +46,6 @@ import { Repository, VersionQuery, WorkerInstanceFleet, - Version, } from '../lib'; import { CONFIG_WORKER_ASSET_LINUX, @@ -686,7 +685,7 @@ test('default worker fleet is created correctly custom subnet values', () => { }, ], }, - `' '6161' '' '' '' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, + "' '6161' '' '' ''", ], ], }); @@ -1086,7 +1085,7 @@ test('default worker fleet is created correctly with groups, pools and region', }, ], }, - `' '63415' 'a,b' 'c,d' 'E' '${Version.MINIMUM_SUPPORTED_DEADLINE_VERSION.toString()}'`, + "' '63415' 'a,b' 'c,d' 'E'", ]], }); }); From 5ec81c8a381793497bb8f73a59ac6c87b98917bb Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Wed, 16 Sep 2020 23:27:29 +0000 Subject: [PATCH 14/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/version.ts | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index f0045aea8..437292add 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -178,12 +178,7 @@ export class Version implements IPatchVersion { throw new TypeError('Component count in both the versions should be same.'); } - for (let i = 0; i < this.components.length; i++) { - if (this.components[i] != version.components[i]) { - return this.components[i] > version.components[i]; - } - } - return false; + return this.compare(version) > 0; } /** @@ -199,12 +194,7 @@ export class Version implements IPatchVersion { throw new TypeError('Component count in both the versions should be same.'); } - for (let i = 0; i < this.components.length; i++) { - if (this.components[i] != version.components[i]) { - return this.components[i] < version.components[i]; - } - } - return false; + return this.compare(version) < 0; } /** @@ -213,6 +203,25 @@ export class Version implements IPatchVersion { public toString(): string { return this.components.join('.'); } + + /** + * This method compares 2 versions. + * + * @param version version to compare + * + * @returns negative value if this version is less than the provided version; + * 0 if both the versions are equal; + * positive value if this version is greater than the provided verison. + */ + private compare(version: Version): number { + for (let i = 0; i < version.components.length; i++) { + const diff = this.components[i] - version.components[i]; + if (diff != 0) { + return diff; + } + } + return 0; + } } /** From c76cdac309a490c738d76a8c944abd12bf8ac2fd Mon Sep 17 00:00:00 2001 From: Yash Datre Date: Thu, 17 Sep 2020 01:45:09 +0000 Subject: [PATCH 15/15] review feedback --- packages/aws-rfdk/lib/deadline/lib/version.ts | 24 ++++++++----- .../lib/deadline/test/version.test.ts | 35 +++++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/version.ts b/packages/aws-rfdk/lib/deadline/lib/version.ts index 437292add..cf97ad064 100644 --- a/packages/aws-rfdk/lib/deadline/lib/version.ts +++ b/packages/aws-rfdk/lib/deadline/lib/version.ts @@ -174,10 +174,6 @@ export class Version implements IPatchVersion { * false if this version is less than or equal to the provided verison. */ public isGreaterThan(version: Version): boolean { - if (this.components.length != version.components.length) { - throw new TypeError('Component count in both the versions should be same.'); - } - return this.compare(version) > 0; } @@ -190,13 +186,21 @@ export class Version implements IPatchVersion { * false if this version is greater than or equal to the provided verison. */ public isLessThan(version: Version): boolean { - if (this.components.length != version.components.length) { - throw new TypeError('Component count in both the versions should be same.'); - } - return this.compare(version) < 0; } + /** + * This method compares two version strings + * + * @param version + * + * @returns true if this version is equal to the provided version; + * false otherwise. + */ + public isEqual(version: Version): boolean { + return this.compare(version) == 0; + } + /** * The method returns the version components in dot separated string format. */ @@ -214,6 +218,10 @@ export class Version implements IPatchVersion { * positive value if this version is greater than the provided verison. */ private compare(version: Version): number { + if (this.components.length != version.components.length) { + throw new TypeError('Component count in both the versions should be same.'); + } + for (let i = 0; i < version.components.length; i++) { const diff = this.components[i] - version.components[i]; if (diff != 0) { diff --git a/packages/aws-rfdk/lib/deadline/test/version.test.ts b/packages/aws-rfdk/lib/deadline/test/version.test.ts index d222c2682..3c8c0eeec 100644 --- a/packages/aws-rfdk/lib/deadline/test/version.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/version.test.ts @@ -114,6 +114,41 @@ describe('Version', () => { }); }); + describe('.isEqual', () => { + test.each<[string, { firstVersion: string, secondVersion: string, expectedValue: boolean }]>([ + [ + 'equal version', + { + firstVersion: '1.1.1.1', + secondVersion: '1.1.1.1', + expectedValue: true, + }, + ], [ + 'unequal', + { + firstVersion: '2.1.1.1', + secondVersion: '1.1.1.1', + expectedValue: false, + }, + ], [ + 'less than', + { + firstVersion: '1.1.1.1', + secondVersion: '1.1.1.2', + expectedValue: false, + }, + ], + ])('%s', (_name, testcase) => { + const { firstVersion, secondVersion, expectedValue } = testcase; + + // WHEN + const lhs = Version.parse(firstVersion); + const result = lhs.isEqual(Version.parse(secondVersion)); + + expect(result).toEqual(expectedValue); + }); + }); + describe('.isLessThan using constructor', () => { // WHEN