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

EVG-20880: Add hosts section for static providers #2058

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cypress/integration/distroSettings/provider_section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe("provider section", () => {
});
cy.contains("button", "Add security group").click();
cy.getInputByLabel("Security Group ID").type("group-1234");
cy.contains("button", "Add host").click();
cy.getInputByLabel("Name").type("host-1234");
save();
cy.validateToast("success");

Expand All @@ -27,7 +29,8 @@ describe("provider section", () => {
cy.getInputByLabel("Merge with existing user data").uncheck({
force: true,
});
cy.dataCy("delete-item-button").click();
cy.dataCy("delete-item-button").first().click();
cy.dataCy("delete-item-button").first().click();
save();
cy.validateToast("success");
});
Expand Down
35 changes: 29 additions & 6 deletions cypress/integration/distroSettings/task_section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@ import { save } from "./utils";

describe("task section", () => {
beforeEach(() => {
cy.visit("/distro/localhost/settings/task");
cy.visit("/distro/ubuntu1804-workstation/settings/task");
});

it("should only show tunable options if planner version is tunable", () => {
cy.getInputByLabel("Task Planner Version").should("contain.text", "Legacy");
cy.dataCy("tunable-options").should("not.exist");
cy.selectLGOption("Task Planner Version", "Tunable");
cy.dataCy("tunable-options").should("be.visible");
describe("providers", () => {
describe("static provider", () => {
it("should not show tunable options", () => {
cy.visit("/distro/localhost/settings/task");
cy.selectLGOption("Task Planner Version", "Tunable");
cy.dataCy("tunable-options").should("not.exist");
});
});

describe("docker provider", () => {
it("should not show tunable options", () => {
cy.visit("/distro/ubuntu1604-container-test/settings/task");
cy.selectLGOption("Task Planner Version", "Tunable");
cy.dataCy("tunable-options").should("not.exist");
});
});

describe("ec2 provider", () => {
it("should only show tunable options if planner version is tunable", () => {
cy.getInputByLabel("Task Planner Version").should(
"contain.text",
"Legacy"
);
cy.dataCy("tunable-options").should("not.exist");
cy.selectLGOption("Task Planner Version", "Tunable");
cy.dataCy("tunable-options").should("be.visible");
});
});
});

it("should surface warnings for invalid number inputs", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/distroSettings/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export const DistroSettingsTabs: React.FC<Props> = ({ distro }) => {
<Route
path={DistroSettingsTabRoutes.Task}
element={
<TaskTab distroData={tabData[DistroSettingsTabRoutes.Task]} />
<TaskTab
distroData={tabData[DistroSettingsTabRoutes.Task]}
provider={distro.provider}
/>
}
/>
<Route
Expand Down
6 changes: 5 additions & 1 deletion src/pages/distroSettings/tabs/ProviderTab/getFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export const getFormSchema = ({
"ui:addButtonText": "Add security group",
"ui:orderable": false,
},
hosts: {
"ui:orderable": false,
"ui:addButtonText": "Add host",
},
},
dockerProviderSettings: {
"ui:data-cy": "docker-provider-settings",
Expand Down Expand Up @@ -285,7 +289,7 @@ const textAreaCSS = css`
box-sizing: border-box;
max-width: ${STANDARD_FIELD_WIDTH}px;
textarea {
min-height: 140px;
min-height: 120px;
}
`;

Expand Down
16 changes: 16 additions & 0 deletions src/pages/distroSettings/tabs/ProviderTab/schemaFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ const securityGroups = {
},
};

const hosts = {
type: "array" as "array",
title: "Hosts",
items: {
type: "object" as "object",
properties: {
name: {
type: "string" as "string",
title: "Name",
minLength: 1,
},
},
},
};

const imageUrl = {
type: "string" as "string",
title: "Docker Image URL",
Expand Down Expand Up @@ -229,6 +244,7 @@ export const staticProviderSettings = {
mergeUserData,
userData,
securityGroups,
hosts,
};

export const dockerProviderSettings = {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/distroSettings/tabs/ProviderTab/transformerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ProviderSettingsList {
build_type: string;
docker_registry_user: string;
docker_registry_pw: string;
hosts: Array<{ name: string; ssh_port: string }>;
ami: string;
instance_type: string;
key_name: string;
Expand Down Expand Up @@ -57,6 +58,7 @@ export const formProviderSettings = (
userData: providerSettings.user_data ?? "",
mergeUserData: providerSettings.merge_user_data_parts ?? false,
securityGroups: providerSettings.security_group_ids ?? [],
hosts: providerSettings.hosts?.map((h) => ({ name: h.name })) ?? [],
},
dockerProviderSettings: {
userData: providerSettings.user_data ?? "",
Expand Down Expand Up @@ -111,6 +113,10 @@ export const gqlProviderSettings = (
user_data: providerSettings.userData,
merge_user_data_parts: providerSettings.mergeUserData,
security_group_ids: providerSettings.securityGroups,
hosts:
providerSettings.hosts?.map((h) => ({
name: h.name,
})) ?? [],
},
dockerProviderSettings: {
user_data: providerSettings.userData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaultFormState = {
userData: "",
mergeUserData: false,
securityGroups: ["1"],
hosts: [],
},
dockerProviderSettings: {
imageUrl: "",
Expand Down Expand Up @@ -56,6 +57,7 @@ describe("provider tab", () => {
user_data: "",
merge_user_data: false,
security_group_ids: ["1"],
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
],
};
Expand All @@ -69,6 +71,7 @@ describe("provider tab", () => {
userData: "",
mergeUserData: false,
securityGroups: ["1"],
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
};

Expand All @@ -81,6 +84,7 @@ describe("provider tab", () => {
merge_user_data_parts: false,
security_group_ids: ["1"],
user_data: "",
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
],
};
Expand Down
3 changes: 3 additions & 0 deletions src/pages/distroSettings/tabs/ProviderTab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export type ProviderFormState = {
userData: string;
mergeUserData: boolean;
securityGroups: string[];
hosts: Array<{
name: string;
}>;
};
dockerProviderSettings: {
imageUrl: string;
Expand Down
10 changes: 3 additions & 7 deletions src/pages/distroSettings/tabs/TaskTab/TaskTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import { BaseTab } from "../BaseTab";
import { getFormSchema } from "./getFormSchema";
import { TabProps } from "./types";

export const TaskTab: React.FC<TabProps> = ({ distroData }) => {
const initialFormState = distroData;
export const TaskTab: React.FC<TabProps> = ({ distroData, provider }) => {
const formSchema = useMemo(() => getFormSchema({ provider }), [provider]);

const formSchema = useMemo(() => getFormSchema(), []);

return (
<BaseTab formSchema={formSchema} initialFormState={initialFormState} />
);
return <BaseTab formSchema={formSchema} initialFormState={distroData} />;
};
Loading