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 (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt authored and khelif96 committed Oct 2, 2023
1 parent b784c8c commit 74f42a0
Show file tree
Hide file tree
Showing 9 changed files with 826 additions and 360 deletions.
93 changes: 85 additions & 8 deletions cypress/integration/distroSettings/provider_section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("provider section", () => {
cy.contains("button", "Add host").click();
cy.getInputByLabel("Name").type("host-1234");
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");

// Revert fields to original values.
cy.getInputByLabel("User Data").clear();
Expand All @@ -32,7 +32,7 @@ describe("provider section", () => {
cy.dataCy("delete-item-button").first().click();
cy.dataCy("delete-item-button").first().click();
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");
});
});

Expand Down Expand Up @@ -71,7 +71,7 @@ describe("provider section", () => {
force: true,
});
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");

// Revert fields to original values.
cy.selectLGOption("Image Build Method", "Import");
Expand All @@ -83,7 +83,7 @@ describe("provider section", () => {
force: true,
});
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");
});
});

Expand Down Expand Up @@ -127,7 +127,7 @@ describe("provider section", () => {
cy.getInputByLabel("Device Name").type("device name");
cy.getInputByLabel("Size").type("200");
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");

// Revert fields to original values.
cy.selectLGOption("Region", "us-east-1");
Expand All @@ -138,7 +138,7 @@ describe("provider section", () => {
cy.dataCy("delete-item-button").click();
});
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");
});

it("can add and delete region settings", () => {
Expand All @@ -155,12 +155,89 @@ describe("provider section", () => {
cy.contains("button", "Add security group").click();
cy.getInputByLabel("Security Group ID").type("security-group-1234");
save();
cy.validateToast("success");
cy.validateToast("success", "Updated distro.");

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

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", "Updated distro.");

// 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", "Updated distro.");
});

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", "Updated distro.");

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

cy.contains("button", "Add region settings").should("exist");
});
Expand Down
23 changes: 17 additions & 6 deletions src/pages/distroSettings/tabs/ProviderTab/ProviderTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,39 @@ 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 || {};

const selectedPoolId = formData?.dockerProviderSettings?.containerPoolId;
const selectedPool = pools?.find((p) => p.id === selectedPoolId) ?? null;
const poolMappingInfo = selectedPool
? JSON.stringify(omitTypename(selectedPool), null, 4)
? JSON.stringify(omitTypename(selectedPool), null, 2)
: "";

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 74f42a0

Please sign in to comment.