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

corecfg: add "system.timezone" setting to the system settings #9102

Merged
merged 8 commits into from Aug 18, 2020

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Aug 6, 2020

This commit adds support for setting the timezone via the snap
configuration system. This allows image customizations in UC20
that used to be done via direct manipulation of the "writable"
partition in UC16/UC18.

The image customization part will be fine as is but for the runtime
setting we also need to fix LP: #1650688

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.

I think the timezone validator is incorrect.

overlord/configstate/configcore/timezone.go Outdated Show resolved Hide resolved
This commit adds support for setting the timezone via the snap
configuration system. This allows image customizations in UC20
that used to be done via direct manipulation of the "writable"
partition in UC16/UC18.

The image customization part will be fine as is but for the runtime
setting we also need to fix LP: #1650688
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 with a few nitpicks inline.

overlord/configstate/configcore/timezone.go Outdated Show resolved Hide resolved
overlord/configstate/configcore/timezone.go Outdated Show resolved Hide resolved
overlord/configstate/configcore/timezone.go Outdated Show resolved Hide resolved

func (s *timezoneSuite) TestConfigureTimezoneInvalid(c *C) {
invalidTimezones := []string{
"no-#", "no-ä", "no/tripple/slash/",
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: I believe this should be "triple" in this context?

}

var validTimezone = regexp.MustCompile(`^[a-zA-Z0-9+_-]+(/[a-zA-Z0-9+_-]+)?(/[a-zA-Z0-9+_-]+)?$`).MatchString

Copy link
Member

Choose a reason for hiding this comment

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

I validated the regexp using the timezones available in my system and it's ok now 👍 (assuming that the "right" and "posix" timezones are not valid or not meant to be used directly)

Copy link
Collaborator

@zyga zyga Aug 6, 2020

Choose a reason for hiding this comment

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

I was wondering about that myself. Perhaps we should just use: ^[a-zA-Z0-9+_-]+(/[a-zA-Z0-9+_-]+)?(/[a-zA-Z0-9+_-]+)*$ - this would allow any number of slashes.

@cmatsuoka
Copy link
Member

Thanks, LGTM, just left a couple of comments.

Comment on lines +65 to +67
# timezone is set
execute_remote "cat /etc/timezone" | MATCH "Europe/Malta"
execute_remote "readlink -f /etc/localtime" | MATCH "Europe/Malta"
Copy link
Contributor

Choose a reason for hiding this comment

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

A better check would be to use install hook of this test to inspect /etc/localtime symlink, similiar to what it does for rsyslog above. This will ensure it was applied early.

Comment on lines +48 to +49
if !validTimezone(timezone) {
return fmt.Errorf("cannot set timezone %q: name not valid", timezone)
Copy link
Contributor

Choose a reason for hiding this comment

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

Go's time module has time.LoadLocation function, not sure if it's worth it but could be used as well.

location, err := time.LoadLocation("America/Los_Angeles")
if 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.

Hmm, maybe not a good idea, it probably depends on runtime stuff that we might want to avoid e.g. with early config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, not sure about this for exactly the reason you outlined - build-host != runtime system and all that.

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, thank you!

# timezone is set
execute_remote "cat /etc/timezone" | MATCH "Europe/Malta"
execute_remote "readlink -f /etc/localtime" | MATCH "Europe/Malta"
execute_remote "cat /var/snap/pc/common/debug.txt" | MATCH "localtime symlink: /usr/share/zoneinfo/Europe/Malta"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@mvo5 mvo5 added Run nested The PR also runs tests inluded in nested suite Squash-merge Please squash this PR when merging. labels Aug 7, 2020
@mvo5 mvo5 merged commit c73ba89 into snapcore:master Aug 18, 2020
Comment on lines +11 to +12
system:
timezone: Europe/Malta
Copy link
Member

Choose a reason for hiding this comment

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

unclear how this didn't break the test as merged, but the system key here is duplicated, making the core20-early-config test fail because it can't build the gadget snap.

I think this speaks to a larger issue around our nested tests in that it's unclear if when run as a PR they are actually always including snapd from the spread branch in the test. I am led to believe that they do not.

Copy link
Member

Choose a reason for hiding this comment

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

to be clear, apparently we set BUILD_SNAPD_FROM_CURRENT to false if it is not already set, but it is set when we run nested spread tests via github actions:

BUILD_SNAPD_FROM_CURRENT: '$(HOST: echo "${SPREAD_BUILD_SNAPD_FROM_CURRENT:-false}")'

and

export SPREAD_BUILD_SNAPD_FROM_CURRENT=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run nested The PR also runs tests inluded in nested suite Squash-merge Please squash this PR when merging.
Projects
None yet
5 participants