summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-02-25 14:33:16 -0500
committerScott Moser <smoser@ubuntu.com>2016-02-25 14:33:16 -0500
commit4d8e7324c7242e1c969c8561462def6c1cda747c (patch)
tree6ab76ff494ceeb75b567b7c247791d1b6dac03a3
parentb20191f04c586147165a304b88a2b89c89f79225 (diff)
parentdf6af3e1433b9e5564bec7cd452cfb3a0fb403e9 (diff)
downloadvyos-cloud-init-4d8e7324c7242e1c969c8561462def6c1cda747c.tar.gz
vyos-cloud-init-4d8e7324c7242e1c969c8561462def6c1cda747c.zip
merge with trunk
-rw-r--r--ChangeLog6
-rw-r--r--cloudinit/sources/helpers/azure.py26
-rw-r--r--doc/examples/cloud-config-user-groups.txt6
-rw-r--r--tests/unittests/test_datasource/test_azure_helper.py76
4 files changed, 70 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index a2bab1da..6b58f1d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -72,10 +72,14 @@
- systemd/power_state: fix power_state to work even if cloud-final
exited non-zero (LP: #1449318)
- SmartOS: Add support for Joyent LX-Brand Zones (LP: #1540965)
- - lxd: add support for setting up lxd using 'lxd init' (LP: #1522879)
[Robert C Jennings]
- systemd: support using systemd-detect-virt to detect container
(LP: #1539016) [Martin Pitt]
+ - docs: fix lock_passwd documentation [Robert C Jennings]
+ - Azure: Handle escaped quotes in WALinuxAgentShim.find_endpoint.
+ (LP: #1488891) [Dan Watkins]
+ - lxd: add support for setting up lxd using 'lxd init' (LP: #1522879)
+
0.7.6:
- open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986)
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index d90c22fd..018cac6d 100644
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -197,6 +197,21 @@ class WALinuxAgentShim(object):
self.openssl_manager.clean_up()
@staticmethod
+ def get_ip_from_lease_value(lease_value):
+ unescaped_value = lease_value.replace('\\', '')
+ if len(unescaped_value) > 4:
+ hex_string = ''
+ for hex_pair in unescaped_value.split(':'):
+ if len(hex_pair) == 1:
+ hex_pair = '0' + hex_pair
+ hex_string += hex_pair
+ packed_bytes = struct.pack(
+ '>L', int(hex_string.replace(':', ''), 16))
+ else:
+ packed_bytes = unescaped_value.encode('utf-8')
+ return socket.inet_ntoa(packed_bytes)
+
+ @staticmethod
def find_endpoint():
LOG.debug('Finding Azure endpoint...')
content = util.load_file('/var/lib/dhcp/dhclient.eth0.leases')
@@ -206,16 +221,7 @@ class WALinuxAgentShim(object):
value = line.strip(' ').split(' ', 2)[-1].strip(';\n"')
if value is None:
raise Exception('No endpoint found in DHCP config.')
- if ':' in value:
- hex_string = ''
- for hex_pair in value.split(':'):
- if len(hex_pair) == 1:
- hex_pair = '0' + hex_pair
- hex_string += hex_pair
- value = struct.pack('>L', int(hex_string.replace(':', ''), 16))
- else:
- value = value.encode('utf-8')
- endpoint_ip_address = socket.inet_ntoa(value)
+ endpoint_ip_address = WALinuxAgentShim.get_ip_from_lease_value(value)
LOG.debug('Azure endpoint found at %s', endpoint_ip_address)
return endpoint_ip_address
diff --git a/doc/examples/cloud-config-user-groups.txt b/doc/examples/cloud-config-user-groups.txt
index 31491faf..0e8ed243 100644
--- a/doc/examples/cloud-config-user-groups.txt
+++ b/doc/examples/cloud-config-user-groups.txt
@@ -15,14 +15,14 @@ users:
selinux-user: staff_u
expiredate: 2012-09-01
ssh-import-id: foobar
- lock-passwd: false
+ lock_passwd: false
passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
- name: barfoo
gecos: Bar B. Foo
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users, admin
ssh-import-id: None
- lock-passwd: true
+ lock_passwd: true
ssh-authorized-keys:
- <ssh pub key 1>
- <ssh pub key 2>
@@ -42,7 +42,7 @@ users:
# selinux-user: Optional. The SELinux user for the user's login, such as
# "staff_u". When this is omitted the system will select the default
# SELinux user.
-# lock-passwd: Defaults to true. Lock the password to disable password login
+# lock_passwd: Defaults to true. Lock the password to disable password login
# inactive: Create the user as inactive
# passwd: The hash -- not the password itself -- of the password you want
# to use for this user. You can generate a safe hash via:
diff --git a/tests/unittests/test_datasource/test_azure_helper.py b/tests/unittests/test_datasource/test_azure_helper.py
index 0638c974..8dbdfb0b 100644
--- a/tests/unittests/test_datasource/test_azure_helper.py
+++ b/tests/unittests/test_datasource/test_azure_helper.py
@@ -75,48 +75,64 @@ class TestFindEndpoint(TestCase):
self.assertRaises(Exception,
azure_helper.WALinuxAgentShim.find_endpoint)
- def _build_lease_content(self, ip_address, use_hex=True):
- ip_address_repr = ':'.join(
- [hex(int(part)).replace('0x', '')
- for part in ip_address.split('.')])
- if not use_hex:
- ip_address_repr = struct.pack(
- '>L', int(ip_address_repr.replace(':', ''), 16))
- ip_address_repr = '"{0}"'.format(ip_address_repr.decode('utf-8'))
+ @staticmethod
+ def _build_lease_content(encoded_address):
return '\n'.join([
'lease {',
' interface "eth0";',
- ' option unknown-245 {0};'.format(ip_address_repr),
+ ' option unknown-245 {0};'.format(encoded_address),
'}'])
- def test_hex_string(self):
- ip_address = '98.76.54.32'
- file_content = self._build_lease_content(ip_address)
+ def test_latest_lease_used(self):
+ encoded_addresses = ['5:4:3:2', '4:3:2:1']
+ file_content = '\n'.join([self._build_lease_content(encoded_address)
+ for encoded_address in encoded_addresses])
self.load_file.return_value = file_content
- self.assertEqual(ip_address,
+ self.assertEqual(encoded_addresses[-1].replace(':', '.'),
azure_helper.WALinuxAgentShim.find_endpoint())
+
+class TestExtractIpAddressFromLeaseValue(TestCase):
+
+ def test_hex_string(self):
+ ip_address, encoded_address = '98.76.54.32', '62:4c:36:20'
+ self.assertEqual(
+ ip_address,
+ azure_helper.WALinuxAgentShim.get_ip_from_lease_value(
+ encoded_address
+ ))
+
def test_hex_string_with_single_character_part(self):
- ip_address = '4.3.2.1'
- file_content = self._build_lease_content(ip_address)
- self.load_file.return_value = file_content
- self.assertEqual(ip_address,
- azure_helper.WALinuxAgentShim.find_endpoint())
+ ip_address, encoded_address = '4.3.2.1', '4:3:2:1'
+ self.assertEqual(
+ ip_address,
+ azure_helper.WALinuxAgentShim.get_ip_from_lease_value(
+ encoded_address
+ ))
def test_packed_string(self):
- ip_address = '98.76.54.32'
- file_content = self._build_lease_content(ip_address, use_hex=False)
- self.load_file.return_value = file_content
- self.assertEqual(ip_address,
- azure_helper.WALinuxAgentShim.find_endpoint())
+ ip_address, encoded_address = '98.76.54.32', 'bL6 '
+ self.assertEqual(
+ ip_address,
+ azure_helper.WALinuxAgentShim.get_ip_from_lease_value(
+ encoded_address
+ ))
- def test_latest_lease_used(self):
- ip_addresses = ['4.3.2.1', '98.76.54.32']
- file_content = '\n'.join([self._build_lease_content(ip_address)
- for ip_address in ip_addresses])
- self.load_file.return_value = file_content
- self.assertEqual(ip_addresses[-1],
- azure_helper.WALinuxAgentShim.find_endpoint())
+ def test_packed_string_with_escaped_quote(self):
+ ip_address, encoded_address = '100.72.34.108', 'dH\\"l'
+ self.assertEqual(
+ ip_address,
+ azure_helper.WALinuxAgentShim.get_ip_from_lease_value(
+ encoded_address
+ ))
+
+ def test_packed_string_containing_a_colon(self):
+ ip_address, encoded_address = '100.72.58.108', 'dH:l'
+ self.assertEqual(
+ ip_address,
+ azure_helper.WALinuxAgentShim.get_ip_from_lease_value(
+ encoded_address
+ ))
class TestGoalStateParsing(TestCase):