Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
EVG-19948: Support EC2 On-Demand on provider settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt committed Sep 28, 2023
1 parent 62a296c commit 59193d0
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 176 deletions.
77 changes: 77 additions & 0 deletions cypress/integration/distroSettings/provider_section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,81 @@ describe("provider section", () => {
cy.contains("button", "Add region settings").should("exist");
});
});

describe("ec2 on-demand", () => {
beforeEach(() => {
cy.visit("/distro/ubuntu1604-parent/settings/provider");
});

it("shows and hides fields correctly", () => {
// VPC options.
cy.dataCy("use-vpc").should("be.checked");
cy.contains("Default VPC Subnet ID").should("exist");
cy.contains("VPC Subnet Prefix").should("exist");

cy.dataCy("use-vpc").uncheck({ force: true });
cy.contains("Default VPC Subnet ID").should("not.exist");
cy.contains("VPC Subnet Prefix").should("not.exist");
});

it("successfully updates ec2 on-demand provider fields", () => {
cy.dataCy("provider-select").contains("EC2 On Demand");

// Correct section is displayed.
cy.dataCy("ec2-on-demand-provider-settings").should("exist");
cy.dataCy("region-select").contains("us-east-1");

// Change field values.
cy.selectLGOption("Region", "us-west-1");
cy.getInputByLabel("EC2 AMI ID").as("amiInput");
cy.get("@amiInput").clear();
cy.get("@amiInput").type("ami-1234560");
cy.getInputByLabel("SSH Key Name").as("keyNameInput");
cy.get("@keyNameInput").clear();
cy.get("@keyNameInput").type("my ssh key");
cy.getInputByLabel("User Data").type("<powershell></powershell>");
cy.getInputByLabel("Merge with existing user data").check({
force: true,
});
save();
cy.validateToast("success");

// Revert fields to original values.
cy.selectLGOption("Region", "us-east-1");
cy.get("@amiInput").clear();
cy.get("@amiInput").type("ami-0000");
cy.get("@keyNameInput").clear();
cy.get("@keyNameInput").type("mci");
cy.getInputByLabel("User Data").clear();
cy.getInputByLabel("Merge with existing user data").uncheck({
force: true,
});
save();
cy.validateToast("success");
});

it("can add and delete region settings", () => {
cy.dataCy("ec2-on-demand-provider-settings").should("exist");

// Add item for new region.
cy.contains("button", "Add region settings").click();
cy.contains("button", "Add region settings").should("not.exist");

// Save new region.
cy.selectLGOption("Region", "us-west-1");
cy.getInputByLabel("EC2 AMI ID").type("ami-1234");
cy.getInputByLabel("Instance Type").type("m5.xlarge");
cy.contains("button", "Add security group").click();
cy.getInputByLabel("Security Group ID").type("security-group-1234");
save();
cy.validateToast("success");

// Revert to original state by deleting the new region.
cy.dataCy("delete-item-button").first().click();
save();
cy.validateToast("success");

cy.contains("button", "Add region settings").should("exist");
});
});
});
21 changes: 16 additions & 5 deletions src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export const ProviderTab: React.FC<TabProps> = ({ distro, distroData }) => {
AWS_REGIONS
);
const { awsRegions } = awsData || {};
const configuredRegions = formData?.ec2FleetProviderSettings?.map(
(p) => p.region
);

const { containerPools } = useSpruceConfig();
const { pools } = containerPools || {};
Expand All @@ -44,15 +41,29 @@ export const ProviderTab: React.FC<TabProps> = ({ distro, distroData }) => {
? JSON.stringify(omitTypename(selectedPool), null, 4)
: "";

const fleetRegionsInUse = formData?.ec2FleetProviderSettings?.map(
(p) => p.region
);
const onDemandRegionsInUse = formData?.ec2OnDemandProviderSettings?.map(
(p) => p.region
);

const formSchema = useMemo(
() =>
getFormSchema({
awsRegions: awsRegions || [],
configuredRegions: configuredRegions || [],
fleetRegionsInUse: fleetRegionsInUse || [],
onDemandRegionsInUse: onDemandRegionsInUse || [],
pools: pools || [],
poolMappingInfo,
}),
[awsRegions, configuredRegions, pools, poolMappingInfo]
[
awsRegions,
fleetRegionsInUse,
onDemandRegionsInUse,
pools,
poolMappingInfo,
]
);

return (
Expand Down
Loading

0 comments on commit 59193d0

Please sign in to comment.