Merge ~raharper/cloud-init:default-lang-c-utf8 into cloud-init:master
| Status: | Merged |
|---|---|
| Approved by: | Scott Moser on 2017-08-31 |
| Approved revision: | 29ab5e4724b755c1fe2346cc1e9a48bdcc216386 |
| Merged at revision: | 7e76c57b590c7c2c13f7b1a2a8b5b7d4f2d18396 |
| Proposed branch: | ~raharper/cloud-init:default-lang-c-utf8 |
| Merge into: | cloud-init:master |
| Diff against target: |
435 lines (+195/-52) 7 files modified
cloudinit/distros/__init__.py (+3/-0) cloudinit/distros/debian.py (+71/-23) cloudinit/sources/__init__.py (+8/-1) tests/unittests/test_distros/test_debian.py (+42/-24) tests/unittests/test_distros/test_generic.py (+16/-0) tests/unittests/test_handler/test_handler_debug.py (+7/-4) tests/unittests/test_handler/test_handler_locale.py (+48/-0) |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Scott Moser | 2017-08-16 | Approve on 2017-08-31 | |
| Server Team CI bot | continuous-integration | Needs Fixing on 2017-08-30 | |
| Chad Smith | Approve on 2017-08-30 | ||
|
Review via email:
|
|||
Description of the Change
distro: allow distro to specify a default locale
Currently the cloud-init default locale (en_US.UTF-8) is set by
the base datasource class. This patch allows a distro to overide
the fallback value with one that's available in the distro. For
Debian and Ubuntu, the C.UTF-8 lang is available and built-in to
cloud-images. Adjust apply_locale logic to skip locale-regen if
the specified LANG value is C.UTF-8, it does not require regeneration.
Further add unittests to exercise the default paths for Ubuntu and
non-ubuntu paths to validate they get the LANG expected.
| Ryan Harper (raharper) wrote : | # |
PASSED: Continuous integration, rev:8fe47a4abc1
https:/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: MAAS Compatability Testing
IN_PROGRESS: Declarative: Post Actions
Click here to trigger a rebuild:
https:/
PASSED: Continuous integration, rev:aaec147b763
https:/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: MAAS Compatability Testing
IN_PROGRESS: Declarative: Post Actions
Click here to trigger a rebuild:
https:/
| Chad Smith (chad.smith) wrote : | # |
Looks good, just some inline nits and questions
| Scott Moser (smoser) wrote : | # |
The distro can already override the default locale by simply providing /etc/cloud/
The bigger issue with this is that it changes the default locale for any instance with cloud-initnit from en_US.UTF-8 to C.UTF_8. That is a behavior change that we'd then have to revert in Ubuntu stable releases. Admittedly, I'm not sure of the real-world affect of that change other than having 'locale' mention it, but I think that change was generally not intended or thought out.
The one other comment I have is that it'd be best if we chose to not regenerate any locale that was already generated. Currently what we do is simply not generate (or regenerate) the locale if it is configured to be the system default locale.
| Ryan Harper (raharper) wrote : | # |
On Fri, Aug 18, 2017 at 3:57 PM, Scott Moser <email address hidden> wrote:
> Review: Needs Information
>
> The distro can already override the default locale by simply providing
> /etc/cloud/
> that there is a reason to have the added complexity of looking this up in
> the distro object. Arguably we should support configuring locale under
> "system_info" as it is OS configuration similar to "default_user".
>
In general, I think default locale is something only the distro can
provide; I don;t think it's something that should be in the datasource (the
default value)
A distro can tell cloud-init what the current settings are:
(read LANG from env)
See what's available:
locale -a
And possible generate new locales
(locale-gen)
If anything, it would be better to remove the "Default" value from
Datasource base-class and leave it to the distro (to determine default).
>
> The bigger issue with this is that it changes the default locale for any
> instance with cloud-initnit from en_US.UTF-8 to C.UTF_8. That is a
> behavior change that we'd then have to revert in Ubuntu stable releases.
> Admittedly, I'm not sure of the real-world affect of that change other than
> having 'locale' mention it, but I think that change was generally not
> intended or thought out.
>
Yes, that's true; I don't think we can change this in previous stable
releases.
>
>
> The one other comment I have is that it'd be best if we chose to not
> regenerate any locale that was already generated. Currently what we do is
> simply not generate (or regenerate) the locale if it is configured to be
> the system default locale.
>
Yes, I was hoping to avoid more exec'ing but with some thought, I probably
makes sense to
1) determine the current LANG setting
2) check if there's a system configured LANG setting (/etc/default/
3) check what's available (locale -a)
compare that to what's being requested
And only locale-gen if the requested locale isn't already available (1, 2)
If the requested locale is available (whether we regen or not) we should
update
the system_conf file with the requested locale.
Does that make sense?
>
> --
> https:/
> cloud-init/
> You are the owner of ~raharper/
>
| Scott Moser (smoser) wrote : | # |
> On Fri, Aug 18, 2017 at 3:57 PM, Scott Moser <email address hidden> wrote:
>
> > Review: Needs Information
> >
> > The distro can already override the default locale by simply providing
> > /etc/cloud/
> > that there is a reason to have the added complexity of looking this up in
> > the distro object. Arguably we should support configuring locale under
> > "system_info" as it is OS configuration similar to "default_user".
> >
>
> In general, I think default locale is something only the distro can
> provide; I don;t think it's something that should be in the datasource (the
> default value)
I agree that the datasource seems an odd place for this setting.
One example of it not being all that odd, though is if it came from the
metadata service. Ie, it isn't that far fetched at all to consider
a China based cloud-provider to want to default to having a Chinese locale.
We're not doing anything dynamic with the locale currently, though.
So for now I have to agree.
> A distro can tell cloud-init what the current settings are:
>
> (read LANG from env)
Well, not really. LANG is just the LANG of the user running cloud-init.
Most of the time that would be the LANG that is set in the init system.
That definitely could contain 'LANG', but to my knowledge usually doesnt.
From my desktop:
$ cat /etc/default/locale
LANG=
$ sudo cat /proc/1/environ | tr '\0' '\n'
HOME=/
init=/sbin/init
recovery=
TERM=linux
drop_caps=
BOOT_
PATH=
PWD=/
rootmnt=/root
Thats the environment that cloud-init would inherit when running in normal
boot, it does not have a LANG set.
> If anything, it would be better to remove the "Default" value from
> Datasource base-class and leave it to the distro (to determine default).
Yes, you've convinced me of this. But your 'get_locale' method that
you've added to distro should read /etc/default/locale on Debian/Ubuntu.
That way we read the "correct" place for such a definition and the
image-builder does not have to repeat themselves or patch cloud-init
to get that change done.
Basically, get_locale should do
if //etc/default/
return that
else
return 'en_US.UTF-8'
That would make cloud-init respect the wishes of the image builder
and also allow the cloud-images team to make the change if they so
choose.
The only issue I see with this is that they wont' necessarily think that
through, and a bug will be opened against cloud-init for behavioral change...
> > The bigger issue with this is that it changes the default locale for any
> > instance with cloud-initnit from en_US.UTF-8 to C.UTF_8. That is a
> > behavior change that we'd then have to revert in Ubuntu stable releases.
> > Admittedly, I'm not sure of the real-world affect of that change other than
> > having 'locale' mention it, but I think that change was generally not
> > intended or thought out.
> >
> Yes, that's true; I don't think we can change this in previous stable
> releases.
I'm willing to push that burden off onto to the cloud-images team if they
agree.
> ...
| Scott Moser (smoser) wrote : | # |
I moved to work-in-progress.
Please feel free to respond and/or disagree with above and then move it back to 'needs review'.
PASSED: Continuous integration, rev:cf1c4106545
https:/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: MAAS Compatability Testing
IN_PROGRESS: Declarative: Post Actions
Click here to trigger a rebuild:
https:/
| Chad Smith (chad.smith) wrote : | # |
Changeset looks good to me assuming (as you said) we can rely on image creators to properly write /etc/default/locale +1.
| Scott Moser (smoser) wrote : | # |
some comments in line.
| Ryan Harper (raharper) wrote : | # |
Thanks for review, will fix up.
FAILED: Continuous integration, rev:29ab5e4724b
https:/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
FAILED: Ubuntu LTS: Build
Click here to trigger a rebuild:
https:/
| Scott Moser (smoser) wrote : | # |
your tests failed due to some bad test in master.
i fixed that with 300e4516f78dbb0
and then fixed your copy of that bad test too.
http://
I'm 'approving' and merging with my change above.


Current Ubuntu (and Debian) images already include the C.UTF-8 locale. Updating the default in cloud-init (for Ubuntu and Debian) means we can realize a non-zero speed up during boot.
Building cloud-init from this branch, injecting it into an artful image and comparing time spent in locale-gen vs. existing artful image with older cloud-init (which will locale-gen en_US.UTF-8) there's a non-zero improvement
# existing artful image log/cloud- init.log - | PYTHONPATH=`pwd` python3 -m cloudinit.analyze blame -i - | grep locale config/ config- locale)
% lxc file pull a3/var/
01.07200s (modules-
# modified artful image (updated cloud-init, LANG=C.UTF-8 in /etc/default/ locale) log/cloud- init.log - | PYTHONPATH=`pwd` python3 -m cloudinit.analyze blame -i - | grep locale config/ config- locale)
% lxc file pull a1/var/
00.00200s (modules-