diff --git a/cypress/integration/distroSettings/provider_section.ts b/cypress/integration/distroSettings/provider_section.ts index 57552dd990..28a11730fa 100644 --- a/cypress/integration/distroSettings/provider_section.ts +++ b/cypress/integration/distroSettings/provider_section.ts @@ -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"); @@ -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"); }); diff --git a/cypress/integration/distroSettings/task_section.ts b/cypress/integration/distroSettings/task_section.ts index 9fd3138da0..9db2ef9f38 100644 --- a/cypress/integration/distroSettings/task_section.ts +++ b/cypress/integration/distroSettings/task_section.ts @@ -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", () => { diff --git a/src/pages/distroSettings/Tabs.tsx b/src/pages/distroSettings/Tabs.tsx index 51f2299a84..4f11d8e1b0 100644 --- a/src/pages/distroSettings/Tabs.tsx +++ b/src/pages/distroSettings/Tabs.tsx @@ -58,7 +58,10 @@ export const DistroSettingsTabs: React.FC = ({ distro }) => { + } /> ; ami: string; instance_type: string; key_name: string; @@ -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 ?? "", @@ -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, diff --git a/src/pages/distroSettings/tabs/ProviderTab/transformers.test.ts b/src/pages/distroSettings/tabs/ProviderTab/transformers.test.ts index c72c1fd45b..bb281bc2e7 100644 --- a/src/pages/distroSettings/tabs/ProviderTab/transformers.test.ts +++ b/src/pages/distroSettings/tabs/ProviderTab/transformers.test.ts @@ -8,6 +8,7 @@ const defaultFormState = { userData: "", mergeUserData: false, securityGroups: ["1"], + hosts: [], }, dockerProviderSettings: { imageUrl: "", @@ -56,6 +57,7 @@ describe("provider tab", () => { user_data: "", merge_user_data: false, security_group_ids: ["1"], + hosts: [{ name: "localhost-1" }, { name: "localhost-2" }], }, ], }; @@ -69,6 +71,7 @@ describe("provider tab", () => { userData: "", mergeUserData: false, securityGroups: ["1"], + hosts: [{ name: "localhost-1" }, { name: "localhost-2" }], }, }; @@ -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" }], }, ], }; diff --git a/src/pages/distroSettings/tabs/ProviderTab/types.ts b/src/pages/distroSettings/tabs/ProviderTab/types.ts index 85d2e13323..5ce0dc04fa 100644 --- a/src/pages/distroSettings/tabs/ProviderTab/types.ts +++ b/src/pages/distroSettings/tabs/ProviderTab/types.ts @@ -19,6 +19,9 @@ export type ProviderFormState = { userData: string; mergeUserData: boolean; securityGroups: string[]; + hosts: Array<{ + name: string; + }>; }; dockerProviderSettings: { imageUrl: string; diff --git a/src/pages/distroSettings/tabs/TaskTab/TaskTab.tsx b/src/pages/distroSettings/tabs/TaskTab/TaskTab.tsx index c382ebe5d3..3fa04319b0 100644 --- a/src/pages/distroSettings/tabs/TaskTab/TaskTab.tsx +++ b/src/pages/distroSettings/tabs/TaskTab/TaskTab.tsx @@ -3,12 +3,8 @@ import { BaseTab } from "../BaseTab"; import { getFormSchema } from "./getFormSchema"; import { TabProps } from "./types"; -export const TaskTab: React.FC = ({ distroData }) => { - const initialFormState = distroData; +export const TaskTab: React.FC = ({ distroData, provider }) => { + const formSchema = useMemo(() => getFormSchema({ provider }), [provider]); - const formSchema = useMemo(() => getFormSchema(), []); - - return ( - - ); + return ; }; diff --git a/src/pages/distroSettings/tabs/TaskTab/getFormSchema.ts b/src/pages/distroSettings/tabs/TaskTab/getFormSchema.ts index 5ea2e1cbeb..78ab84bd8b 100644 --- a/src/pages/distroSettings/tabs/TaskTab/getFormSchema.ts +++ b/src/pages/distroSettings/tabs/TaskTab/getFormSchema.ts @@ -4,194 +4,205 @@ import { FinderVersion, PlannerVersion, DispatcherVersion, + Provider, } from "gql/generated/types"; -export const getFormSchema = (): ReturnType => ({ - fields: {}, - schema: { - type: "object" as "object", - properties: { - finderSettings: { - type: "object" as "object", - title: "Task Finder", - properties: { - version: { - type: "string" as "string", - title: "Task Finder Version", - oneOf: [ - { - type: "string" as "string", - title: "Legacy", - enum: [FinderVersion.Legacy], - }, - { - type: "string" as "string", - title: "Parallel", - enum: [FinderVersion.Parallel], - }, - { - type: "string" as "string", - title: "Pipeline", - enum: [FinderVersion.Pipeline], - }, - { - type: "string" as "string", - title: "Alternate", - enum: [FinderVersion.Alternate], - }, - ], +export const getFormSchema = ({ + provider, +}: { + provider: Provider; +}): ReturnType => { + const hasEC2Provider = + provider !== Provider.Static && provider !== Provider.Docker; + + return { + fields: {}, + schema: { + type: "object" as "object", + properties: { + finderSettings: { + type: "object" as "object", + title: "Task Finder", + properties: { + version: { + type: "string" as "string", + title: "Task Finder Version", + oneOf: [ + { + type: "string" as "string", + title: "Legacy", + enum: [FinderVersion.Legacy], + }, + { + type: "string" as "string", + title: "Parallel", + enum: [FinderVersion.Parallel], + }, + { + type: "string" as "string", + title: "Pipeline", + enum: [FinderVersion.Pipeline], + }, + { + type: "string" as "string", + title: "Alternate", + enum: [FinderVersion.Alternate], + }, + ], + }, }, }, - }, - plannerSettings: { - type: "object" as "object", - title: "Task Planner", - properties: { - version: { - type: "string" as "string", - title: "Task Planner Version", - oneOf: [ - { - type: "string" as "string", - title: "Legacy", - enum: [PlannerVersion.Legacy], - }, - { - type: "string" as "string", - title: "Tunable", - enum: [PlannerVersion.Tunable], - }, - ], + plannerSettings: { + type: "object" as "object", + title: "Task Planner", + properties: { + version: { + type: "string" as "string", + title: "Task Planner Version", + oneOf: [ + { + type: "string" as "string", + title: "Legacy", + enum: [PlannerVersion.Legacy], + }, + { + type: "string" as "string", + title: "Tunable", + enum: [PlannerVersion.Tunable], + }, + ], + }, }, - }, - dependencies: { - version: { - oneOf: [ - { - properties: { - version: { - enum: [PlannerVersion.Legacy], + dependencies: { + version: { + oneOf: [ + { + properties: { + version: { + enum: [PlannerVersion.Legacy], + }, }, }, - }, - { - properties: { - version: { - enum: [PlannerVersion.Tunable], - }, - tunableOptions: { - type: "object" as "object", - title: "", - properties: { - targetTime: { - type: "number" as "number", - title: "Target Time (seconds)", - default: 0, - minimum: 0, - maximum: 1800, - }, - patchFactor: { - type: "number" as "number", - title: "Patch Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - patchTimeInQueueFactor: { - type: "number" as "number", - title: - "Patch Time in Queue Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - mainlineTimeInQueueFactor: { - type: "number" as "number", - title: - "Mainline Time in Queue Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - commitQueueFactor: { - type: "number" as "number", - title: "Commit Queue Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - expectedRuntimeFactor: { - type: "number" as "number", - title: "Expected Runtime Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - generateTaskFactor: { - type: "number" as "number", - title: "Generate Task Factor (0 to 100 inclusive)", - default: 0, - minimum: 0, - maximum: 100, - }, - groupVersions: { - type: "boolean" as "boolean", - title: "Group versions", - default: false, + { + properties: { + version: { + enum: [PlannerVersion.Tunable], + }, + tunableOptions: { + type: "object" as "object", + title: "", + properties: { + targetTime: { + type: "number" as "number", + title: "Target Time (seconds)", + default: 0, + minimum: 0, + maximum: 1800, + }, + patchFactor: { + type: "number" as "number", + title: "Patch Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + patchTimeInQueueFactor: { + type: "number" as "number", + title: + "Patch Time in Queue Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + mainlineTimeInQueueFactor: { + type: "number" as "number", + title: + "Mainline Time in Queue Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + commitQueueFactor: { + type: "number" as "number", + title: "Commit Queue Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + expectedRuntimeFactor: { + type: "number" as "number", + title: "Expected Runtime Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + generateTaskFactor: { + type: "number" as "number", + title: "Generate Task Factor (0 to 100 inclusive)", + default: 0, + minimum: 0, + maximum: 100, + }, + groupVersions: { + type: "boolean" as "boolean", + title: "Group versions", + default: false, + }, }, }, }, }, - }, - ], + ], + }, }, }, - }, - dispatcherSettings: { - type: "object" as "object", - title: "Task Dispatcher", - properties: { - version: { - type: "string" as "string", - title: "Task Dispatcher Version", - oneOf: [ - { - type: "string" as "string", - title: "Revised", - enum: [DispatcherVersion.Revised], - }, - { - type: "string" as "string", - title: "Revised with dependencies", - enum: [DispatcherVersion.RevisedWithDependencies], - }, - ], + dispatcherSettings: { + type: "object" as "object", + title: "Task Dispatcher", + properties: { + version: { + type: "string" as "string", + title: "Task Dispatcher Version", + oneOf: [ + { + type: "string" as "string", + title: "Revised", + enum: [DispatcherVersion.Revised], + }, + { + type: "string" as "string", + title: "Revised with dependencies", + enum: [DispatcherVersion.RevisedWithDependencies], + }, + ], + }, }, }, }, }, - }, - uiSchema: { - finderSettings: { - "ui:ObjectFieldTemplate": CardFieldTemplate, - version: { - "ui:allowDeselect": false, - }, - }, - plannerSettings: { - "ui:ObjectFieldTemplate": CardFieldTemplate, - version: { - "ui:allowDeselect": false, + uiSchema: { + finderSettings: { + "ui:ObjectFieldTemplate": CardFieldTemplate, + version: { + "ui:allowDeselect": false, + }, }, - tunableOptions: { - "ui:field-data-cy": "tunable-options", + plannerSettings: { + "ui:ObjectFieldTemplate": CardFieldTemplate, + version: { + "ui:allowDeselect": false, + }, + tunableOptions: { + "ui:field-data-cy": "tunable-options", + ...(!hasEC2Provider && { "ui:widget": "hidden" }), + }, }, - }, - dispatcherSettings: { - "ui:ObjectFieldTemplate": CardFieldTemplate, - version: { - "ui:allowDeselect": false, + dispatcherSettings: { + "ui:ObjectFieldTemplate": CardFieldTemplate, + version: { + "ui:allowDeselect": false, + }, }, }, - }, -}); + }; +}; diff --git a/src/pages/distroSettings/tabs/TaskTab/types.ts b/src/pages/distroSettings/tabs/TaskTab/types.ts index c47705382f..ef9f1b57fc 100644 --- a/src/pages/distroSettings/tabs/TaskTab/types.ts +++ b/src/pages/distroSettings/tabs/TaskTab/types.ts @@ -2,6 +2,7 @@ import { FinderVersion, PlannerVersion, DispatcherVersion, + Provider, } from "gql/generated/types"; export interface TaskFormState { @@ -28,4 +29,5 @@ export interface TaskFormState { export type TabProps = { distroData: TaskFormState; + provider: Provider; };