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

cmd: add snap debug validate-seed <path> cmd #6771

Merged
merged 3 commits into from
Apr 25, 2019
Merged

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Apr 24, 2019

We had a bug where one of the recent livecd-rootfs build images
had an incorrect seed.yaml. This caused a panic of snapd on when
seeding. To prevent this here is a small helper that we can run
inside livecd-rootfs to ensure seed.yaml is good enough to not
crash snapd.

This is for https://bugs.launchpad.net/ubuntu/+source/livecd-rootfs/+bug/1825437

We had a bug where one of the recent livecd-rootfs build images
had an incorrect seed.yaml. This caused a panic of snapd on when
seeding. To prevent this here is a small helper that we can run
inside livecd-rootfs to ensure seed.yaml is good enough to not
crash snapd.
@mvo5 mvo5 changed the title cmd: add `snap debug validate-seed <path> cmd cmd: add snap debug validate-seed <path> cmd Apr 25, 2019
@mvo5 mvo5 added this to the 2.39 milestone Apr 25, 2019
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

Some comments

}

func init() {
cmd := addDebugCommand("validate-seed",
Copy link
Contributor

Choose a reason for hiding this comment

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

or validate-seed-file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, feel a bit long but I don't really mind strongly either way. Its a debug command after all :)

cmd/snap/cmd_debug_validate_seed.go Show resolved Hide resolved
cmd/snap/cmd_debug_validate_seed_test.go Outdated Show resolved Hide resolved
cmd/snap/cmd_debug_validate_seed_test.go Outdated Show resolved Hide resolved
return ErrExtraArgs
}

if _, err := snap.ReadSeedYaml(x.Positionals.SeedYamlPath); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not super important, but would it make sense to make seed yaml path argument optional, and use the default /var/lib/snapd/.../seed.yaml path if not provided, for convienience?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea, but I'm also a bit lazy :) We could do it in a followup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, no problem.

The current code in ReadSeedYaml is not doing much validation
and missing or invalid elements will be caught only (much)
later. This commit adds some basic validations to the read
of the seed.yaml.
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.

Looks good, thanks for implementing it! Just one nitpick to consider.

yamlData, err := ioutil.ReadFile(fn)
if err != nil {
return nil, fmt.Errorf("cannot read seed yaml: %s", fn)
return nil, fmt.Errorf(errPrefix+"%v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: looks a bit weird to concatenate errorPrefix that way when using fmt formatting anyway, why not simply fmt.Errorf("%s%v", errorPrefix, err) (also below)?

if err := ValidateInstanceName(sn.Name); err != nil {
return nil, fmt.Errorf(errPrefix+"%v", err)
}
if sn.Channel != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

LGTM

@bboozzoo
Copy link
Contributor

Shall we land it?

@mvo5 mvo5 merged commit 5bc867d into canonical:master Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants