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
snap: implement new snap reboot
command
#9021
Conversation
The new `snap reboot` command will reboot into the given recovery system with the given mode.
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.
LGTM
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
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.
This needs a bit more work, in terms of what combination of action and system (current vs not) are possible and when the system should have a default.
As we also discussed, probably adding a dedicated API variant action: "reboot"
of the API makes also sense.
cmd/snap/cmd_reboot.go
Outdated
return err | ||
} | ||
|
||
if err := x.client.DoSystemAction(x.Positional.Label, action); err != nil { |
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.
For run label can only be the current system, so it could also be omitted. Same for recover.
In general the label can be left out and default to current.
cmd/snap/cmd_reboot.go
Outdated
} | ||
|
||
if err := x.client.DoSystemAction(x.Positional.Label, action); err != nil { | ||
return fmt.Errorf("cannot reboot into system %q: %v", x.Positional.Label, err) |
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.
we maybe want a client.RebootSystem(label, mode) method, that should map to a different variant of the API that has action: "reboot"
the action: "do"
setup was mostly meant for the chooser, where possibly some actions might not be reboots
@mvo5 about default behavior, two remarks:
Basically, in run mode, "snap reboot" reboots the run mode, in recovery mode once the first remark is implemented it goes back to run mode. |
@pedronis this is on my TODO, I was waiting for some more of my things to land before proposing this, but I think I can make this change, I was going to change the bootenv at the end of the seeding task so after seeding is done (when a user could login) any reboot will go back to run mode |
is login only possible after seeding? (me doesn't remember the details) |
ah you're right that login is actually possible before seeding, however you don't see the message telling you that you can now login until after seeding is done. I still think it's reasonable to do this in the seeding task of recover, but perhaps we should sync shortly on this if you think now is a good time to make that change |
@@ -216,7 +216,7 @@ var helpCategories = []helpCategory{ | |||
}, { | |||
Label: i18n.G("Other"), | |||
Description: i18n.G("miscellanea"), | |||
Commands: []string{"version", "warnings", "okay", "ack", "known", "model", "create-cohort", "recovery"}, | |||
Commands: []string{"version", "warnings", "okay", "ack", "known", "model", "create-cohort", "recovery", "reboot"}, |
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.
We probably need to rethink "other" at some point and maybe add "Device Management", "Device" or "Ubuntu Core" or something what then has "model", "recovery", "reboot"
client/systems.go
Outdated
@@ -103,3 +103,25 @@ func (client *Client) DoSystemAction(systemLabel string, action *SystemAction) e | |||
} | |||
return nil | |||
} | |||
|
|||
// DoSystemReboot issues a request to reboot into the given label/mode | |||
func (client *Client) DoSystemReboot(systemLabel, mode string) error { |
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.
Should this be called just "SystemReboot()"?
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.
Mabye RebootToSystem? also the doc comment needs to be expanded to explain what happens if label and/or mode are empty?
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.
some detail comments
cmd/snap/cmd_reboot.go
Outdated
return err | ||
} | ||
|
||
if err := x.client.DoSystemReboot(x.Positional.Label, mode); err != nil { |
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.
this has a new name now, no?
var shortRebootHelp = i18n.G("Reboot into selected system and mode") | ||
var longRebootHelp = i18n.G(` | ||
The reboot command reboots the system into a particular mode of the selected | ||
recovery system. |
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.
this should also explain what happens if mode or label are omitted
cmd/snap/cmd_reboot.go
Outdated
} | ||
|
||
if err := x.client.DoSystemReboot(x.Positional.Label, mode); err != nil { | ||
if x.Positional.Label != "" { |
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.
feels like we should move the error formatting logic into client itself, so here we just use what it returns, it means we get a less repetitive error
this has changed quite a bit since review time
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.
thank you, this probably needs a master merge now that uc20-recovery was maybe fixed
cmd/snap/cmd_reboot.go
Outdated
When called without a system label and without a mode it will just | ||
trigger a regular reboot. | ||
|
||
When called without a system -abel but with a mode it will use the |
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.
s/-abel/label/
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.
Thank, looks very nice! Two questions.
func (x *cmdReboot) modeFromCommandline() (string, error) { | ||
var mode string | ||
|
||
for _, arg := range []struct { |
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.
Nice.
cmd/snap/cmd_reboot.go
Outdated
continue | ||
} | ||
if mode != "" { | ||
return "", fmt.Errorf("Please specify a single mode") |
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.
i18n?
cmd/snap/cmd_reboot.go
Outdated
case x.Positional.Label != "" && mode != "": | ||
fmt.Fprintf(Stdout, "Reboot into %q %q mode.\n", x.Positional.Label, mode) | ||
case x.Positional.Label != "": | ||
fmt.Fprintf(Stdout, "Reboot into %q.\n", x.Positional.Label) | ||
case mode != "": | ||
fmt.Fprintf(Stdout, "Reboot into %q mode.\n", mode) | ||
default: | ||
fmt.Fprintf(Stdout, "Reboot\n") |
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.
The reboot is not immediate right? If so, should we say "Reboot ... requested" or something like this?
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.
A good question, happy about ideas :)
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.
It's not super important to be clear... My suggestion is to just append "requested" to all messages, e.g. "Reboot into %q mode requested".
The new
snap reboot
command will reboot into the given recoverysystem with the given mode.