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 1 commit
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
4 changes: 4 additions & 0 deletions src/pages/distroSettings/tabs/ProviderTab/getFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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
28 changes: 22 additions & 6 deletions src/pages/distroSettings/tabs/ProviderTab/schemaFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ 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,
},
},
},
};

export const staticProviderSettings = {
userData,
mergeUserData,
securityGroups,
hosts,
};

const imageUrl = {
type: "string" as "string",
title: "Docker Image URL",
Expand Down Expand Up @@ -62,12 +84,6 @@ const poolMappingInfo = {
title: "Pool Mapping Information",
};

export const staticProviderSettings = {
userData,
mergeUserData,
securityGroups,
};

export const dockerProviderSettings = {
imageUrl,
buildType,
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 @@ -8,6 +8,7 @@ interface ProviderSettingsList {
build_type: string;
docker_registry_user: string;
docker_registry_pw: string;
hosts: Array<{ name: string; ssh_port: string }>;
}

export const formProviderSettings = (
Expand All @@ -17,6 +18,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 All @@ -39,6 +41,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 @@ -14,6 +14,7 @@ describe("provider tab", () => {
user_data: "",
merge_user_data: false,
security_group_ids: ["1"],
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
],
};
Expand All @@ -26,6 +27,7 @@ describe("provider tab", () => {
userData: "",
mergeUserData: false,
securityGroups: ["1"],
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
dockerProviderSettings: {
imageUrl: "",
Expand All @@ -49,6 +51,7 @@ describe("provider tab", () => {
merge_user_data_parts: false,
security_group_ids: ["1"],
user_data: "",
hosts: [{ name: "localhost-1" }, { name: "localhost-2" }],
},
],
};
Expand Down Expand Up @@ -88,6 +91,7 @@ describe("provider tab", () => {
userData: "",
mergeUserData: false,
securityGroups: ["1"],
hosts: [],
},
dockerProviderSettings: {
imageUrl: "https://some-url",
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 @@ -13,6 +13,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