Skip to content
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

Merged
merged 21 commits into from Sep 10, 2020
Merged

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Jul 16, 2020

The new snap reboot command will reboot into the given recovery
system with the given mode.

The new `snap reboot` command will reboot into the given recovery
system with the given mode.
zyga
zyga previously approved these changes Jul 17, 2020
Copy link
Collaborator

@zyga zyga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

tests/core/uc20-recovery/task.yaml Outdated Show resolved Hide resolved
cmd/snap/cmd_reboot.go Outdated Show resolved Hide resolved
cmd/snap/cmd_reboot.go Outdated Show resolved Hide resolved
cmd/snap/cmd_reboot.go Outdated Show resolved Hide resolved
cmd/snap/cmd_reboot.go Outdated Show resolved Hide resolved
@pedronis pedronis self-requested a review August 5, 2020 17:37
Copy link
Collaborator

@pedronis pedronis left a 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 Show resolved Hide resolved
return err
}

if err := x.client.DoSystemAction(x.Positional.Label, action); err != nil {
Copy link
Collaborator

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.

}

if err := x.client.DoSystemAction(x.Positional.Label, action); err != nil {
return fmt.Errorf("cannot reboot into system %q: %v", x.Positional.Label, err)
Copy link
Collaborator

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

@pedronis
Copy link
Collaborator

pedronis commented Aug 12, 2020

@mvo5 about default behavior, two remarks:

  • we agreed to make it so that recovery is not permanent, so basically we need to change the boot env back to run at some point
  • if that's the case I think "snap reboot" without any option if we support it should simply reboot what is current, without changing the boot env first (another reason to have a dedicated action)

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.

@anonymouse64
Copy link
Member

we agreed to make it so that recovery is not permanent, so basically we need to change the boot env back to run at some point

@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

@pedronis
Copy link
Collaborator

@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)

@anonymouse64
Copy link
Member

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

@pedronis pedronis added the UC20 label Sep 2, 2020
@pedronis pedronis added this to the 2.47 milestone Sep 2, 2020
@@ -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"},
Copy link
Contributor Author

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"

@@ -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 {
Copy link
Contributor Author

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()"?

Copy link
Collaborator

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?

@mvo5 mvo5 closed this Sep 8, 2020
@mvo5 mvo5 reopened this Sep 8, 2020
@pedronis pedronis self-requested a review September 8, 2020 11:09
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some detail comments

return err
}

if err := x.client.DoSystemReboot(x.Positional.Label, mode); err != nil {
Copy link
Collaborator

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.
Copy link
Collaborator

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

}

if err := x.client.DoSystemReboot(x.Positional.Label, mode); err != nil {
if x.Positional.Label != "" {
Copy link
Collaborator

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

@pedronis pedronis dismissed zyga’s stale review September 10, 2020 08:30

this has changed quite a bit since review time

@pedronis pedronis self-requested a review September 10, 2020 08:30
Copy link
Collaborator

@pedronis pedronis left a 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

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/-abel/label/

Copy link
Contributor

@stolowski stolowski left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

continue
}
if mode != "" {
return "", fmt.Errorf("Please specify a single mode")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n?

Comment on lines 114 to 121
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")
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor

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".

@mvo5 mvo5 merged commit 93efba1 into snapcore:master Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants