From 11e30f6125b06826e1465a21d7562baa980a00dc Mon Sep 17 00:00:00 2001 From: Eugene Kozlov <68875428+kozlove-aws@users.noreply.github.com> Date: Thu, 24 Jun 2021 11:01:29 -0500 Subject: [PATCH] fix(core): Convert group names in SpotEventPluginFleet to lowercase (#465) --- .../lib/deadline/lib/configure-spot-event-plugin.ts | 2 +- .../lib/deadline/lib/spot-event-plugin-fleet.ts | 12 ++++++------ .../deadline/test/spot-event-plugin-fleet.test.ts | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/aws-rfdk/lib/deadline/lib/configure-spot-event-plugin.ts b/packages/aws-rfdk/lib/deadline/lib/configure-spot-event-plugin.ts index 37da04da4..0abc9a39b 100644 --- a/packages/aws-rfdk/lib/deadline/lib/configure-spot-event-plugin.ts +++ b/packages/aws-rfdk/lib/deadline/lib/configure-spot-event-plugin.ts @@ -577,7 +577,7 @@ export class ConfigureSpotEventPlugin extends Construct { const spotFleetRequestConfigurations = fleet.deadlineGroups.map(group => { const spotFleetRequestConfiguration: SpotFleetRequestConfiguration = { - [group]: spotFleetRequestProps, + [group.toLowerCase()]: spotFleetRequestProps, }; return spotFleetRequestConfiguration; }); diff --git a/packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts b/packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts index c8b89ccf1..2b5732010 100644 --- a/packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts +++ b/packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts @@ -412,6 +412,7 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF constructor(scope: Construct, id: string, props: SpotEventPluginFleetProps) { super(scope, id); + this.deadlineGroups = props.deadlineGroups.map(group => group.toLocaleLowerCase()); this.validateProps(props); this.securityGroups = props.securityGroups ?? [ new SecurityGroup(this, 'SpotFleetSecurityGroup', { vpc: props.vpc }) ]; @@ -447,7 +448,6 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF this.maxCapacity = props.maxCapacity; this.validUntil = props.validUntil; this.keyName = props.keyName; - this.deadlineGroups = props.deadlineGroups; const imageConfig = props.workerMachineImage.getImage(this); this.osType = imageConfig.osType; @@ -462,8 +462,8 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF }, renderQueue: props.renderQueue, workerSettings: { - groups: props.deadlineGroups, - pools: props.deadlinePools, + groups: this.deadlineGroups, + pools: props.deadlinePools?.map(pool => pool.toLocaleLowerCase()), region: props.deadlineRegion, }, userDataProvider: props.userDataProvider, @@ -498,7 +498,7 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF this.validateFleetInstanceRole(props.fleetInstanceRole); this.validateInstanceTypes(props.instanceTypes); this.validateSubnets(props.vpc, props.vpcSubnets); - this.validateGroups('deadlineGroups', props.deadlineGroups); + this.validateGroups('deadlineGroups', this.deadlineGroups); this.validateRegion('deadlineRegion', props.deadlineRegion); this.validateBlockDevices(props.blockDevices); } @@ -525,13 +525,13 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF } private validateGroups(property: string, array: string[]): void { - const regex: RegExp = /^(?!none$)[a-zA-Z0-9-_]+$/i; + const regex: RegExp = /^(?!none$)[a-z0-9-_]+$/g; if (array.length === 0) { throw new Error('At least one Deadline Group is required for a Spot Fleet Request Configuration'); } array.forEach(value => { if (!regex.test(value)) { - throw new Error(`Invalid value: ${value} for property '${property}'. Valid characters are A-Z, a-z, 0-9, - and _. Also, group 'none' is reserved as the default group.`); + throw new Error(`Invalid value: ${value} for property '${property}'. Valid characters are a-z, 0-9, - and _. Also, group 'none' is reserved as the default group.`); } }); } diff --git a/packages/aws-rfdk/lib/deadline/test/spot-event-plugin-fleet.test.ts b/packages/aws-rfdk/lib/deadline/test/spot-event-plugin-fleet.test.ts index e8e96bfff..e0eea3857 100644 --- a/packages/aws-rfdk/lib/deadline/test/spot-event-plugin-fleet.test.ts +++ b/packages/aws-rfdk/lib/deadline/test/spot-event-plugin-fleet.test.ts @@ -70,7 +70,7 @@ let vpc: IVpc; let renderQueue: IRenderQueue; let rcsImage: AssetImage; -const groupName = 'group_name'; +const groupName = 'Group_Name'; const deadlineGroups = [ groupName, ]; @@ -238,7 +238,7 @@ describe('SpotEventPluginFleet', () => { // THEN expect(fleet.userData).toBeDefined(); - expect(renderedUserData).toMatch(groupName); + expect(renderedUserData).toMatch(groupName.toLocaleLowerCase()); }); test('adds RFDK tags', () => { @@ -360,7 +360,7 @@ describe('SpotEventPluginFleet', () => { const imageConfig = workerMachineImage.getImage(fleet); // THEN - expect(fleet.deadlineGroups).toBe(deadlineGroups); + expect(fleet.deadlineGroups).toStrictEqual(deadlineGroups.map(group => group.toLocaleLowerCase())); expect(fleet.instanceTypes).toBe(instanceTypes); expect(fleet.imageId).toBe(imageConfig.imageId); expect(fleet.osType).toBe(imageConfig.osType); @@ -642,7 +642,7 @@ describe('SpotEventPluginFleet', () => { test('adds deadline pools to user data', () => { // GIVEN - const pool1 = 'pool1'; + const pool1 = 'Pool1'; const pool2 = 'pool2'; // WHEN @@ -661,8 +661,8 @@ describe('SpotEventPluginFleet', () => { const renderedUserData = fleet.userData.render(); // THEN - expect(renderedUserData).toMatch(pool1); - expect(renderedUserData).toMatch(pool2); + expect(renderedUserData).toMatch(pool1.toLocaleLowerCase()); + expect(renderedUserData).toMatch(pool2.toLocaleLowerCase()); }); test('uses provided ssh key name', () => {