-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(machines): Add 'Power cycle' as a feature-flagged action MAASENG-3945 #5566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,97 +99,147 @@ export const MachineActionForm = ({ | |
if (!filter) { | ||
return null; | ||
} | ||
switch (action) { | ||
case NodeActions.CLONE: | ||
return ( | ||
<CloneForm | ||
setSearchFilter={setSearchFilter} | ||
{...commonMachineFormProps} | ||
/> | ||
); | ||
case NodeActions.COMMISSION: | ||
return <CommissionForm {...commonMachineFormProps} />; | ||
case NodeActions.DELETE: | ||
return ( | ||
<DeleteForm | ||
onAfterSuccess={clearSelectedMachines} | ||
onSubmit={() => { | ||
dispatchForSelectedMachines(machineActions.delete); | ||
}} | ||
redirectURL={urls.machines.index} | ||
{...commonNodeFormProps} | ||
/> | ||
); | ||
case NodeActions.DEPLOY: | ||
return <DeployForm {...commonMachineFormProps} />; | ||
case NodeActions.MARK_BROKEN: | ||
return <MarkBrokenForm {...commonMachineFormProps} />; | ||
case NodeActions.OVERRIDE_FAILED_TESTING: | ||
return <OverrideTestForm {...commonMachineFormProps} />; | ||
case NodeActions.RELEASE: | ||
return <ReleaseForm {...commonMachineFormProps} />; | ||
case NodeActions.SET_POOL: | ||
return <SetPoolForm {...commonMachineFormProps} />; | ||
case NodeActions.SET_ZONE: | ||
return ( | ||
<SetZoneForm<MachineEventErrors> | ||
onSubmit={(zoneID) => { | ||
dispatch(machineActions.cleanup()); | ||
dispatchForSelectedMachines(machineActions.setZone, { | ||
zone_id: zoneID, | ||
}); | ||
}} | ||
{...commonNodeFormProps} | ||
/> | ||
); | ||
case NodeActions.TAG: | ||
case NodeActions.UNTAG: | ||
return <TagForm {...commonMachineFormProps} />; | ||
case NodeActions.TEST: | ||
return ( | ||
<TestForm<MachineEventErrors> | ||
applyConfiguredNetworking={applyConfiguredNetworking} | ||
hardwareType={hardwareType} | ||
onTest={(args) => { | ||
dispatchForSelectedMachines(machineActions.test, { | ||
enable_ssh: args.enableSSH, | ||
script_input: args.scriptInputs, | ||
testing_scripts: args.scripts.map((script) => script.name), | ||
}); | ||
}} | ||
{...commonNodeFormProps} | ||
/> | ||
); | ||
case NodeActions.ABORT: | ||
case NodeActions.ACQUIRE: | ||
case NodeActions.EXIT_RESCUE_MODE: | ||
case NodeActions.LOCK: | ||
case NodeActions.MARK_FIXED: | ||
case NodeActions.ON: | ||
case NodeActions.RESCUE_MODE: | ||
case NodeActions.UNLOCK: | ||
return ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
); | ||
case NodeActions.OFF: | ||
case NodeActions.SOFT_OFF: | ||
return ( | ||
<PowerOffForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
); | ||
// No form should be opened for this, as it should only | ||
// be available for machine details, and will be dispatched | ||
// immediately on click. | ||
case NodeActions.CHECK_POWER: | ||
return null; | ||
} | ||
|
||
return formComponents[action](); | ||
}; | ||
|
||
const formComponents = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You just translated the zen of python to JS. Explicit is better than implicit. Looks cleaner albeit being a little more code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had some network glitches, sorry for the duplicates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You just translated the zen of python to JS. Explicit is better than implicit. Looks cleaner albeit being a little more code. |
||
[NodeActions.CLONE]: () => ( | ||
<CloneForm | ||
setSearchFilter={setSearchFilter} | ||
{...commonMachineFormProps} | ||
/> | ||
), | ||
[NodeActions.COMMISSION]: () => ( | ||
<CommissionForm {...commonMachineFormProps} /> | ||
), | ||
[NodeActions.DELETE]: () => ( | ||
<DeleteForm | ||
onAfterSuccess={clearSelectedMachines} | ||
onSubmit={() => { | ||
dispatchForSelectedMachines(machineActions.delete); | ||
}} | ||
redirectURL={urls.machines.index} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.DEPLOY]: () => <DeployForm {...commonMachineFormProps} />, | ||
[NodeActions.MARK_BROKEN]: () => ( | ||
<MarkBrokenForm {...commonMachineFormProps} /> | ||
), | ||
[NodeActions.OVERRIDE_FAILED_TESTING]: () => ( | ||
<OverrideTestForm {...commonMachineFormProps} /> | ||
), | ||
[NodeActions.RELEASE]: () => <ReleaseForm {...commonMachineFormProps} />, | ||
[NodeActions.SET_POOL]: () => <SetPoolForm {...commonMachineFormProps} />, | ||
[NodeActions.SET_ZONE]: () => ( | ||
<SetZoneForm<MachineEventErrors> | ||
onSubmit={(zoneID) => { | ||
dispatch(machineActions.cleanup()); | ||
dispatchForSelectedMachines(machineActions.setZone, { | ||
zone_id: zoneID, | ||
}); | ||
}} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.TAG]: () => <TagForm {...commonMachineFormProps} />, | ||
[NodeActions.UNTAG]: () => <TagForm {...commonMachineFormProps} />, | ||
[NodeActions.TEST]: () => ( | ||
<TestForm<MachineEventErrors> | ||
applyConfiguredNetworking={applyConfiguredNetworking} | ||
hardwareType={hardwareType} | ||
onTest={(args) => { | ||
dispatchForSelectedMachines(machineActions.test, { | ||
enable_ssh: args.enableSSH, | ||
script_input: args.scriptInputs, | ||
testing_scripts: args.scripts.map((script) => script.name), | ||
}); | ||
}} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.ABORT]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.ACQUIRE]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.EXIT_RESCUE_MODE]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.LOCK]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.MARK_FIXED]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.ON]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.RESCUE_MODE]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.UNLOCK]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.POWER_CYCLE]: () => ( | ||
<FieldlessForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.OFF]: () => ( | ||
<PowerOffForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
[NodeActions.SOFT_OFF]: () => ( | ||
<PowerOffForm | ||
action={action} | ||
actions={machineActions} | ||
{...commonNodeFormProps} | ||
/> | ||
), | ||
// No form should be opened for this, as it should only | ||
// be available for machine details, and will be dispatched | ||
// immediately on click. | ||
[NodeActions.CHECK_POWER]: () => null, | ||
}; | ||
|
||
if (selectedCountLoading) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { isValidPortNumber } from "."; | ||
|
||
it("returns true for any number between 0 and 65535", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though shall not smuggle in unrelated changes in a PR. |
||
for (let i = 0; i <= 65535; i++) { | ||
expect(isValidPortNumber(i)).toBe(true); | ||
} | ||
expect(isValidPortNumber(0)).toBe(true); | ||
expect(isValidPortNumber(80)).toBe(true); | ||
expect(isValidPortNumber(443)).toBe(true); | ||
expect(isValidPortNumber(1234)).toBe(true); | ||
expect(isValidPortNumber(5240)).toBe(true); | ||
expect(isValidPortNumber(8400)).toBe(true); | ||
expect(isValidPortNumber(65535)).toBe(true); | ||
}); | ||
|
||
it("returns false for numbers larger than 65535", () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just translated the zen of python to JS. Explicit is better than implicit. Looks cleaner albeit being a little more code.