Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:c392b94fde1b7b538fc52b478aae2d2d0d5fcd51
https://jenkins.ubuntu.com/server/job/cloud-init-ci/48/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/48/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:feature/pregen-locale into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:2a44d6f5d36db7c322891f590752e38069b75b08
https://jenkins.ubuntu.com/server/job/cloud-init-ci/47/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/47/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327532
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:feature/pregen-locale into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:7ac6f05b6ca5d5ac568264acb9262c271d436c9f
https://jenkins.ubuntu.com/server/job/cloud-init-ci/46/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/46/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Scott Moser
The proposal to merge ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into 
cloud-init:master has been updated.

Commit Message changed to:

tests: fixes for issues uncovered when moving to python3.6

This includes 2 different fixes both found when testing with python 3.6.
 - fix eni renderer when target is None
   This just uses the util.target_path() in the event that target is None.
 - change test cases to not rely on the cached result of util.get_cmdline()
 - mock calls to system_is_snappy from the create_users test cases.

LP: #1703697

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Scott Moser
The proposal to merge ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into 
cloud-init:master has been updated.

Commit Message changed to:

tests: fixes for issues uncovered when moving to python3.6

This includes 2 different fixes both found when testing with python 3.6.
 - fix eni renderer when target is None
   This just uses the util.target_path() in the event that target is None.
 - change test cases to not rely on the cached result of util.get_cmdline()

LP: #1703697

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master

2017-07-17 Thread Scott Moser


Diff comments:

> diff --git a/tests/unittests/test_datasource/test_ec2.py 
> b/tests/unittests/test_datasource/test_ec2.py
> new file mode 100644
> index 000..a5485ff
> --- /dev/null
> +++ b/tests/unittests/test_datasource/test_ec2.py
> @@ -0,0 +1,201 @@
> +# This file is part of cloud-init. See LICENSE file for license information.
> +
> +import httpretty
> +import mock
> +
> +from .. import helpers as test_helpers
> +from cloudinit import helpers
> +from cloudinit.sources import DataSourceEc2 as ec2
> +
> +
> +# collected from api version 2009-04-04/ with
> +# python3 -c 'import json
> +# from cloudinit.ec2_utils import get_instance_metadata as gm
> +# print(json.dumps(gm("2009-04-04"), indent=1, sort_keys=True))'
> +DEFAULT_METADATA = {
> +"ami-id": "ami-80861296",
> +"ami-launch-index": "0",
> +"ami-manifest-path": "(unknown)",
> +"block-device-mapping": {"ami": "/dev/sda1", "root": "/dev/sda1"},
> +"hostname": "ip-10-0-0-149",
> +"instance-action": "none",
> +"instance-id": "i-0052913950685138c",
> +"instance-type": "t2.micro",
> +"local-hostname": "ip-10-0-0-149",
> +"local-ipv4": "10.0.0.149",
> +"placement": {"availability-zone": "us-east-1b"},
> +"profile": "default-hvm",
> +"public-hostname": "",
> +"public-ipv4": "107.23.188.247",
> +"public-keys": {"brickies": ["ssh-rsa B3Nzw== brickies"]},
> +"reservation-id": "r-00a2c173fb5782a08",
> +"security-groups": "wide-open"
> +}
> +
> +
> +def register_ssh_keys(rfunc, base_url, keys_data):
> +"""handle ssh key inconsistencies.
> +
> +public-keys in the ec2 metadata is inconsistently formated compared
> +to other entries.
> +Given keys_data of {name1: pubkey1, name2: pubkey2}
> +
> +This registers the following urls:
> +   base_url 0={name1}\n1={name2} # (for each name)
> +   base_url/0={name1}\n1={name2} # (for each name)
> +   base_url/0   openssh-key
> +   base_url/0/  openssh-key
> +   base_url/0/openssh-key   {pubkey1}
> +   base_url/0/openssh-key/  {pubkey1}
> +   ...
> +"""
> +
> +base_url = base_url.rstrip("/")
> +odd_index = '\n'.join(
> +["{0}={1}".format(n, name)
> + for n, name in enumerate(sorted(keys_data))])
> +
> +rfunc(base_url, odd_index)
> +rfunc(base_url + "/", odd_index)
> +
> +for n, name in enumerate(sorted(keys_data)):
> +val = keys_data[name]
> +if isinstance(val, list):
> +val = '\n'.join(val)
> +burl = base_url + "/%s" % n
> +rfunc(burl, "openssh-key")
> +rfunc(burl + "/", "openssh-key")
> +rfunc(burl + "/%s/openssh-key" % name, val)
> +rfunc(burl + "/%s/openssh-key/" % name, val)
> +
> +
> +def register_mock_metaserver(base_url, data):
> +"""Register with httpretty a ec2 metadata like service serving 'data'.
> +
> +If given a dictionary, it will populate urls under base_url for
> +that dictionary.  For example, input of
> +   {"instance-id": "i-abc", "mac": "00:16:3e:00:00:00"}
> +populates
> +   base_url  with 'instance-id\nmac'
> +   base_url/ with 'instance-id\nmac'
> +   base_url/instance-id with i-abc
> +   base_url/mac with 00:16:3e:00:00:00
> +"""
> +def register_helper(register, base_url, body):
> +if isinstance(body, str):
> +register(base_url, body)
> +elif isinstance(body, list):
> +register(base_url.rstrip('/'), '\n'.join(body) + '\n')

we're just registering in the metadata service
  foo/
and
  foo
both will return a carriage-return delimited list of items "under" foo/

> +register(base_url.rstrip('/') + '/', '\n'.join(body) + '\n')
> +elif isinstance(body, dict):
> +vals = []
> +for k, v in body.items():
> +if k == 'public-keys':
> +register_ssh_keys(
> +register, base_url.rstrip('/') + '/public-keys/', v)
> +continue
> +if isinstance(v, (str, list)):
> +suffix = k.rstrip('/')
> +else:
> +suffix = k.rstrip('/') + '/'
> +vals.append(suffix)
> +url = base_url.rstrip('/') + '/' + suffix
> +register_helper(register, url, v)
> +register(base_url.rstrip('/'), '\n'.join(vals) + '\n')
> +register(base_url.rstrip('/') + '/', '\n'.join(vals) + '\n')
> +elif body is None:
> +register(base_url.rstrip('/'), 'not found', status_code=404)
> +
> +def myreg(*argc, **kwargs):
> +# print("register_url(%s, %s)" % (argc, kwargs))
> +return httpretty.register_uri(httpretty.GET, *argc, **kwargs)
> +
> +register_helper(myreg, base_url, data)
> +
> +
> +class TestEc2(test_helpers.HttprettyTestCase):
> +valid_platform_data = {
> +'uuid': 

Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:895856e7412e3f72bfc97b15f0489dae39559465
https://jenkins.ubuntu.com/server/job/cloud-init-ci/45/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/45/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master

2017-07-17 Thread Ryan Harper
Inline comment below

Diff comments:

> diff --git a/tests/unittests/test_datasource/test_ec2.py 
> b/tests/unittests/test_datasource/test_ec2.py
> new file mode 100644
> index 000..a5485ff
> --- /dev/null
> +++ b/tests/unittests/test_datasource/test_ec2.py
> @@ -0,0 +1,201 @@
> +# This file is part of cloud-init. See LICENSE file for license information.
> +
> +import httpretty
> +import mock
> +
> +from .. import helpers as test_helpers
> +from cloudinit import helpers
> +from cloudinit.sources import DataSourceEc2 as ec2
> +
> +
> +# collected from api version 2009-04-04/ with
> +# python3 -c 'import json
> +# from cloudinit.ec2_utils import get_instance_metadata as gm
> +# print(json.dumps(gm("2009-04-04"), indent=1, sort_keys=True))'
> +DEFAULT_METADATA = {
> +"ami-id": "ami-80861296",
> +"ami-launch-index": "0",
> +"ami-manifest-path": "(unknown)",
> +"block-device-mapping": {"ami": "/dev/sda1", "root": "/dev/sda1"},
> +"hostname": "ip-10-0-0-149",
> +"instance-action": "none",
> +"instance-id": "i-0052913950685138c",
> +"instance-type": "t2.micro",
> +"local-hostname": "ip-10-0-0-149",
> +"local-ipv4": "10.0.0.149",
> +"placement": {"availability-zone": "us-east-1b"},
> +"profile": "default-hvm",
> +"public-hostname": "",
> +"public-ipv4": "107.23.188.247",
> +"public-keys": {"brickies": ["ssh-rsa B3Nzw== brickies"]},
> +"reservation-id": "r-00a2c173fb5782a08",
> +"security-groups": "wide-open"
> +}
> +
> +
> +def register_ssh_keys(rfunc, base_url, keys_data):
> +"""handle ssh key inconsistencies.
> +
> +public-keys in the ec2 metadata is inconsistently formated compared
> +to other entries.
> +Given keys_data of {name1: pubkey1, name2: pubkey2}
> +
> +This registers the following urls:
> +   base_url 0={name1}\n1={name2} # (for each name)
> +   base_url/0={name1}\n1={name2} # (for each name)
> +   base_url/0   openssh-key
> +   base_url/0/  openssh-key
> +   base_url/0/openssh-key   {pubkey1}
> +   base_url/0/openssh-key/  {pubkey1}
> +   ...
> +"""
> +
> +base_url = base_url.rstrip("/")
> +odd_index = '\n'.join(
> +["{0}={1}".format(n, name)
> + for n, name in enumerate(sorted(keys_data))])
> +
> +rfunc(base_url, odd_index)
> +rfunc(base_url + "/", odd_index)
> +
> +for n, name in enumerate(sorted(keys_data)):
> +val = keys_data[name]
> +if isinstance(val, list):
> +val = '\n'.join(val)
> +burl = base_url + "/%s" % n
> +rfunc(burl, "openssh-key")
> +rfunc(burl + "/", "openssh-key")
> +rfunc(burl + "/%s/openssh-key" % name, val)
> +rfunc(burl + "/%s/openssh-key/" % name, val)
> +
> +
> +def register_mock_metaserver(base_url, data):
> +"""Register with httpretty a ec2 metadata like service serving 'data'.
> +
> +If given a dictionary, it will populate urls under base_url for
> +that dictionary.  For example, input of
> +   {"instance-id": "i-abc", "mac": "00:16:3e:00:00:00"}
> +populates
> +   base_url  with 'instance-id\nmac'
> +   base_url/ with 'instance-id\nmac'
> +   base_url/instance-id with i-abc
> +   base_url/mac with 00:16:3e:00:00:00
> +"""
> +def register_helper(register, base_url, body):
> +if isinstance(body, str):
> +register(base_url, body)
> +elif isinstance(body, list):
> +register(base_url.rstrip('/'), '\n'.join(body) + '\n')

there's a whole lot of .rstrip('/') and then appending.  Is there a more 
general way to do that?  Maybe I don't quite understand what's happening here 
so maybe a comment w.r.t all of the trailing slash stripping/appending.

> +register(base_url.rstrip('/') + '/', '\n'.join(body) + '\n')
> +elif isinstance(body, dict):
> +vals = []
> +for k, v in body.items():
> +if k == 'public-keys':
> +register_ssh_keys(
> +register, base_url.rstrip('/') + '/public-keys/', v)
> +continue
> +if isinstance(v, (str, list)):
> +suffix = k.rstrip('/')
> +else:
> +suffix = k.rstrip('/') + '/'
> +vals.append(suffix)
> +url = base_url.rstrip('/') + '/' + suffix
> +register_helper(register, url, v)
> +register(base_url.rstrip('/'), '\n'.join(vals) + '\n')
> +register(base_url.rstrip('/') + '/', '\n'.join(vals) + '\n')
> +elif body is None:
> +register(base_url.rstrip('/'), 'not found', status_code=404)
> +
> +def myreg(*argc, **kwargs):
> +# print("register_url(%s, %s)" % (argc, kwargs))
> +return httpretty.register_uri(httpretty.GET, *argc, **kwargs)
> +
> +register_helper(myreg, base_url, data)
> +
> +

Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:c2145d3b0f1bdac12d6e8cd5f6b3f3227c0eb8cb
https://jenkins.ubuntu.com/server/job/cloud-init-ci/44/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/44/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327344
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1703697-python3.6-ubuntu into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:fe6f267f52e3532693df0e7684012cd8b58792cc
https://jenkins.ubuntu.com/server/job/cloud-init-ci/43/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
SUCCESS: CentOS 6 & 7: Build & Test
IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/43/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327534
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:bug/1683038-ec2-no-warn-on-explicit into cloud-init:master

2017-07-17 Thread Scott Moser
I grabbed the initial test portions of this merge proposal and put them into 
another
at https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327534
note, those do not have the tests for WarnIfNecessary
-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/324274
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:bug/1683038-ec2-no-warn-on-explicit into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master

2017-07-17 Thread Scott Moser
The proposal to merge ~smoser/cloud-init:cleanup/ec2-initial-tests into 
cloud-init:master has been updated.

Commit Message changed to:

tests: Add initial tests for EC2 and improve a docstring.

EC2 was the original, but this adds some initial tests for that datasource.
Also updates a docstring for an internal method.

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327534
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:cleanup/ec2-initial-tests into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:feature/pregen-locale into cloud-init:master

2017-07-17 Thread Server Team CI bot
Review: Needs Fixing continuous-integration

FAILED: Continuous integration, rev:9a607ecd6efecd189a5dd3dd1b50aece02b6d281
https://jenkins.ubuntu.com/server/job/cloud-init-ci/42/
Executed test runs:
SUCCESS: Checkout
FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/42/rebuild

-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327532
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:feature/pregen-locale into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~smoser/cloud-init:feature/pregen-locale into cloud-init:master

2017-07-17 Thread Scott Moser
This is a update to
 https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/325406
with the suggestions I had to that MP fixed
(added unit tests)
-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327532
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:feature/pregen-locale into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~smoser/cloud-init:feature/pregen-locale into cloud-init:master

2017-07-17 Thread Scott Moser
Scott Moser has proposed merging ~smoser/cloud-init:feature/pregen-locale into 
cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327532
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:feature/pregen-locale into cloud-init:master.
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index d06d46a..c6c24dc 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -37,11 +37,11 @@ ENI_HEADER = """# This file is generated from information provided by
 """
 
 NETWORK_CONF_FN = "/etc/network/interfaces.d/50-cloud-init.cfg"
+LOCALE_CONF_FN = "/etc/default/locale"
 
 
 class Distro(distros.Distro):
 hostname_conf_fn = "/etc/hostname"
-locale_conf_fn = "/etc/default/locale"
 network_conf_fn = {
 "eni": "/etc/network/interfaces.d/50-cloud-init.cfg",
 "netplan": "/etc/netplan/50-cloud-init.yaml"
@@ -64,16 +64,8 @@ class Distro(distros.Distro):
 
 def apply_locale(self, locale, out_fn=None):
 if not out_fn:
-out_fn = self.locale_conf_fn
-util.subp(['locale-gen', locale], capture=False)
-util.subp(['update-locale', locale], capture=False)
-# "" provides trailing newline during join
-lines = [
-util.make_header(),
-'LANG="%s"' % (locale),
-"",
-]
-util.write_file(out_fn, "\n".join(lines))
+out_fn = LOCALE_CONF_FN
+apply_locale(locale, out_fn)
 
 def install_packages(self, pkglist):
 self.update_package_sources()
@@ -225,4 +217,37 @@ def _maybe_remove_legacy_eth0(path="/etc/network/interfaces.d/eth0.cfg"):
 
 LOG.warning(msg)
 
+
+def apply_locale(locale, sys_path=LOCALE_CONF_FN, keyname='LANG'):
+"""Apply the locale.
+
+Run locale-gen for the provided locale and set the default
+system variable 'keyname' appropriately in the provided 'path'.
+
+If sys_path indicates that this value is already the default
+('keyname=locale') then no changes will be made and locale-gen not called.
+"""
+if not locale:
+raise ValueError('Failed to provide locale value.')
+
+if not sys_path:
+raise ValueError('Invalid path: %s' % sys_path)
+
+if os.path.exists(sys_path):
+locale_content = util.load_file(sys_path)
+# if LANG isn't present, regen
+sys_defaults = util.load_shell_content(locale_content)
+sys_val = sys_defaults.get(keyname, "")
+if sys_val.lower() == locale.lower():
+LOG.debug(
+"System has '%s=%s' requested '%s', skipping regeneration.",
+keyname, sys_val, locale)
+return
+print("system = %s locale=%s" % (sys_val, locale))
+
+util.subp(['locale-gen', locale], capture=False)
+util.subp(
+['update-locale', '--locale-file=' + sys_path,
+ '%s=%s' % (keyname, locale)], capture=False)
+
 # vi: ts=4 expandtab
diff --git a/tests/unittests/test_distros/test_debian.py b/tests/unittests/test_distros/test_debian.py
new file mode 100644
index 000..8e47e0d
--- /dev/null
+++ b/tests/unittests/test_distros/test_debian.py
@@ -0,0 +1,72 @@
+# This file is part of cloud-init. See LICENSE file for license information.
+
+import os
+
+from ..helpers import (CiTestCase, mock)
+
+from cloudinit.distros.debian import apply_locale
+from cloudinit import util
+
+
+class TestDebianApplyLocale(CiTestCase):
+@mock.patch("cloudinit.distros.debian.util.subp")
+def test_no_rerun(self, m_subp):
+"""If system has defined locale, no re-run is expected."""
+spath = self.tmp_path("default-locale")
+m_subp.return_value = (None, None)
+locale = 'en_US.UTF-8'
+util.write_file(spath, 'LANG=%s\n' % locale, omode="w")
+apply_locale(locale, sys_path=spath)
+m_subp.assert_not_called()
+
+@mock.patch("cloudinit.distros.debian.util.subp")
+def test_rerun_if_different(self, m_subp):
+"""If system has different locale, locale-gen should be called."""
+spath = self.tmp_path("default-locale")
+m_subp.return_value = (None, None)
+locale = 'en_US.UTF-8'
+util.write_file(spath, 'LANG=fr_FR.UTF-8', omode="w")
+apply_locale(locale, sys_path=spath)
+self.assertEqual(
+[['locale-gen', locale],
+ ['update-locale', '--locale-file=' + spath, 'LANG=%s' % locale]],
+[p[0][0] for p in m_subp.call_args_list])
+
+@mock.patch("cloudinit.distros.debian.util.subp")
+def test_rerun_if_no_file(self, m_subp):
+"""If system has different locale, locale-gen should be called."""
+spath = self.tmp_path("default-locale")
+m_subp.return_value = (None, None)
+locale = 'en_US.UTF-8'
+apply_locale(locale, sys_path=spath)
+

[Cloud-init-dev] [Merge] ~smoser/cloud-init:feature/load_shell_content-comments into cloud-init:master

2017-07-17 Thread Scott Moser
Scott Moser has proposed merging 
~smoser/cloud-init:feature/load_shell_content-comments into cloud-init:master.

Commit message:
Support comments in content read by load_shell_content.

load_shell_content previously would not allow shell comment characters
in the content being parsed.  If comments=True is not passed then an
exception would previously be raised as the line would not be guaranteed to
have an '=' in it.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327525
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~smoser/cloud-init:feature/load_shell_content-comments into cloud-init:master.
diff --git a/cloudinit/util.py b/cloudinit/util.py
index b486e18..f570b9d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2529,7 +2529,7 @@ def load_shell_content(content, add_empty=False, empty_val=None):
 if PY26 and isinstance(blob, six.text_type):
 # Older versions don't support unicode input
 blob = blob.encode("utf8")
-return shlex.split(blob)
+return shlex.split(blob, comments=True)
 
 data = {}
 for line in _shlex_split(content):
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 65035be..f38a664 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -807,4 +807,20 @@ class TestSystemIsSnappy(helpers.FilesystemMockingTestCase):
 self.reRoot(root_d)
 self.assertTrue(util.system_is_snappy())
 
+
+class TestLoadShellContent(helpers.TestCase):
+def test_comments_handled_correctly(self):
+"""Shell comments should be allowed in the content."""
+self.assertEqual(
+{'key1': 'val1', 'key2': 'val2', 'key3': 'val3 #tricky'},
+util.load_shell_content('\n'.join([
+"#top of file comment",
+"key1=val1 #this is a comment",
+"# second comment",
+'key2="val2" # inlin comment'
+'#badkey=wark',
+'key3="val3 #tricky"',
+''])))
+
+
 # vi: ts=4 expandtab
___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~szeestraten/cloud-init:doc-fix-disk-setup-examples into cloud-init:master

2017-07-17 Thread Scott Moser
The proposal to merge ~szeestraten/cloud-init:doc-fix-disk-setup-examples into 
cloud-init:master has been updated.

Status: Needs review => Merged

For more details, see:
https://code.launchpad.net/~szeestraten/cloud-init/+git/cloud-init/+merge/327274
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~szeestraten/cloud-init:doc-fix-disk-setup-examples into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~j.kylmala/cloud-init:exceptions into cloud-init:master

2017-07-17 Thread Scott Moser
The proposal to merge ~j.kylmala/cloud-init:exceptions into cloud-init:master 
has been updated.

Status: Needs review => Merged

For more details, see:
https://code.launchpad.net/~j.kylmala/cloud-init/+git/cloud-init/+merge/327284
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~j.kylmala/cloud-init:exceptions into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp