Merge ~chad.smith/cloud-init:ubuntu/zesty into cloud-init:ubuntu/zesty
- Git
- lp:~chad.smith/cloud-init
- ubuntu/zesty
- Merge into ubuntu/zesty
Proposed by
Chad Smith
Status: | Merged |
---|---|
Merged at revision: | 91c0f668530566b4eb943fdda537b96454f0dc7d |
Proposed branch: | ~chad.smith/cloud-init:ubuntu/zesty |
Merge into: | cloud-init:ubuntu/zesty |
Diff against target: |
307 lines (+160/-12) 4 files modified
cloudinit/distros/gentoo.py (+1/-1) cloudinit/sources/DataSourceEc2.py (+19/-5) debian/changelog (+10/-0) tests/unittests/test_datasource/test_ec2.py (+130/-6) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Server Team CI bot | continuous-integration | Approve | |
Scott Moser | Pending | ||
Review via email: mp+333050@code.launchpad.net |
Commit message
Description of the change
Upstream snapshot for SRU
To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/cloudinit/distros/gentoo.py b/cloudinit/distros/gentoo.py | |||
2 | index 0ad2f03..dc57717 100644 | |||
3 | --- a/cloudinit/distros/gentoo.py | |||
4 | +++ b/cloudinit/distros/gentoo.py | |||
5 | @@ -24,7 +24,7 @@ class Distro(distros.Distro): | |||
6 | 24 | network_conf_fn = '/etc/conf.d/net' | 24 | network_conf_fn = '/etc/conf.d/net' |
7 | 25 | resolve_conf_fn = '/etc/resolv.conf' | 25 | resolve_conf_fn = '/etc/resolv.conf' |
8 | 26 | hostname_conf_fn = '/etc/conf.d/hostname' | 26 | hostname_conf_fn = '/etc/conf.d/hostname' |
10 | 27 | init_cmd = ['service'] # init scripts | 27 | init_cmd = ['rc-service'] # init scripts |
11 | 28 | 28 | ||
12 | 29 | def __init__(self, name, cfg, paths): | 29 | def __init__(self, name, cfg, paths): |
13 | 30 | distros.Distro.__init__(self, name, cfg, paths) | 30 | distros.Distro.__init__(self, name, cfg, paths) |
14 | diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py | |||
15 | index 41367a8..0ef2217 100644 | |||
16 | --- a/cloudinit/sources/DataSourceEc2.py | |||
17 | +++ b/cloudinit/sources/DataSourceEc2.py | |||
18 | @@ -64,6 +64,9 @@ class DataSourceEc2(sources.DataSource): | |||
19 | 64 | # Whether we want to get network configuration from the metadata service. | 64 | # Whether we want to get network configuration from the metadata service. |
20 | 65 | get_network_metadata = False | 65 | get_network_metadata = False |
21 | 66 | 66 | ||
22 | 67 | # Track the discovered fallback nic for use in configuration generation. | ||
23 | 68 | fallback_nic = None | ||
24 | 69 | |||
25 | 67 | def __init__(self, sys_cfg, distro, paths): | 70 | def __init__(self, sys_cfg, distro, paths): |
26 | 68 | sources.DataSource.__init__(self, sys_cfg, distro, paths) | 71 | sources.DataSource.__init__(self, sys_cfg, distro, paths) |
27 | 69 | self.metadata_address = None | 72 | self.metadata_address = None |
28 | @@ -89,16 +92,18 @@ class DataSourceEc2(sources.DataSource): | |||
29 | 89 | elif self.cloud_platform == Platforms.NO_EC2_METADATA: | 92 | elif self.cloud_platform == Platforms.NO_EC2_METADATA: |
30 | 90 | return False | 93 | return False |
31 | 91 | 94 | ||
32 | 95 | self.fallback_nic = net.find_fallback_nic() | ||
33 | 92 | if self.get_network_metadata: # Setup networking in init-local stage. | 96 | if self.get_network_metadata: # Setup networking in init-local stage. |
34 | 93 | if util.is_FreeBSD(): | 97 | if util.is_FreeBSD(): |
35 | 94 | LOG.debug("FreeBSD doesn't support running dhclient with -sf") | 98 | LOG.debug("FreeBSD doesn't support running dhclient with -sf") |
36 | 95 | return False | 99 | return False |
38 | 96 | dhcp_leases = dhcp.maybe_perform_dhcp_discovery() | 100 | dhcp_leases = dhcp.maybe_perform_dhcp_discovery(self.fallback_nic) |
39 | 97 | if not dhcp_leases: | 101 | if not dhcp_leases: |
40 | 98 | # DataSourceEc2Local failed in init-local stage. DataSourceEc2 | 102 | # DataSourceEc2Local failed in init-local stage. DataSourceEc2 |
41 | 99 | # will still run in init-network stage. | 103 | # will still run in init-network stage. |
42 | 100 | return False | 104 | return False |
43 | 101 | dhcp_opts = dhcp_leases[-1] | 105 | dhcp_opts = dhcp_leases[-1] |
44 | 106 | self.fallback_nic = dhcp_opts.get('interface') | ||
45 | 102 | net_params = {'interface': dhcp_opts.get('interface'), | 107 | net_params = {'interface': dhcp_opts.get('interface'), |
46 | 103 | 'ip': dhcp_opts.get('fixed-address'), | 108 | 'ip': dhcp_opts.get('fixed-address'), |
47 | 104 | 'prefix_or_mask': dhcp_opts.get('subnet-mask'), | 109 | 'prefix_or_mask': dhcp_opts.get('subnet-mask'), |
48 | @@ -297,8 +302,13 @@ class DataSourceEc2(sources.DataSource): | |||
49 | 297 | 302 | ||
50 | 298 | result = None | 303 | result = None |
51 | 299 | net_md = self.metadata.get('network') | 304 | net_md = self.metadata.get('network') |
52 | 305 | # Limit network configuration to only the primary/fallback nic | ||
53 | 306 | macs_to_nics = { | ||
54 | 307 | net.get_interface_mac(self.fallback_nic): self.fallback_nic} | ||
55 | 300 | if isinstance(net_md, dict): | 308 | if isinstance(net_md, dict): |
57 | 301 | result = convert_ec2_metadata_network_config(net_md) | 309 | result = convert_ec2_metadata_network_config( |
58 | 310 | net_md, macs_to_nics=macs_to_nics, | ||
59 | 311 | fallback_nic=self.fallback_nic) | ||
60 | 302 | else: | 312 | else: |
61 | 303 | LOG.warning("unexpected metadata 'network' key not valid: %s", | 313 | LOG.warning("unexpected metadata 'network' key not valid: %s", |
62 | 304 | net_md) | 314 | net_md) |
63 | @@ -458,15 +468,18 @@ def _collect_platform_data(): | |||
64 | 458 | return data | 468 | return data |
65 | 459 | 469 | ||
66 | 460 | 470 | ||
68 | 461 | def convert_ec2_metadata_network_config(network_md, macs_to_nics=None): | 471 | def convert_ec2_metadata_network_config(network_md, macs_to_nics=None, |
69 | 472 | fallback_nic=None): | ||
70 | 462 | """Convert ec2 metadata to network config version 1 data dict. | 473 | """Convert ec2 metadata to network config version 1 data dict. |
71 | 463 | 474 | ||
72 | 464 | @param: network_md: 'network' portion of EC2 metadata. | 475 | @param: network_md: 'network' portion of EC2 metadata. |
73 | 465 | generally formed as {"interfaces": {"macs": {}} where | 476 | generally formed as {"interfaces": {"macs": {}} where |
74 | 466 | 'macs' is a dictionary with mac address as key and contents like: | 477 | 'macs' is a dictionary with mac address as key and contents like: |
75 | 467 | {"device-number": "0", "interface-id": "...", "local-ipv4s": ...} | 478 | {"device-number": "0", "interface-id": "...", "local-ipv4s": ...} |
77 | 468 | @param: macs_to_name: Optional dict mac addresses and the nic name. If | 479 | @param: macs_to_nics: Optional dict of mac addresses and nic names. If |
78 | 469 | not provided, get_interfaces_by_mac is called to get it from the OS. | 480 | not provided, get_interfaces_by_mac is called to get it from the OS. |
79 | 481 | @param: fallback_nic: Optionally provide the primary nic interface name. | ||
80 | 482 | This nic will be guaranteed to minimally have a dhcp4 configuration. | ||
81 | 470 | 483 | ||
82 | 471 | @return A dict of network config version 1 based on the metadata and macs. | 484 | @return A dict of network config version 1 based on the metadata and macs. |
83 | 472 | """ | 485 | """ |
84 | @@ -480,7 +493,8 @@ def convert_ec2_metadata_network_config(network_md, macs_to_nics=None): | |||
85 | 480 | continue # Not a physical nic represented in metadata | 493 | continue # Not a physical nic represented in metadata |
86 | 481 | nic_cfg = {'type': 'physical', 'name': nic_name, 'subnets': []} | 494 | nic_cfg = {'type': 'physical', 'name': nic_name, 'subnets': []} |
87 | 482 | nic_cfg['mac_address'] = mac | 495 | nic_cfg['mac_address'] = mac |
89 | 483 | if nic_metadata.get('public-ipv4s'): | 496 | if (nic_name == fallback_nic or nic_metadata.get('public-ipv4s') or |
90 | 497 | nic_metadata.get('local-ipv4s')): | ||
91 | 484 | nic_cfg['subnets'].append({'type': 'dhcp4'}) | 498 | nic_cfg['subnets'].append({'type': 'dhcp4'}) |
92 | 485 | if nic_metadata.get('ipv6s'): | 499 | if nic_metadata.get('ipv6s'): |
93 | 486 | nic_cfg['subnets'].append({'type': 'dhcp6'}) | 500 | nic_cfg['subnets'].append({'type': 'dhcp6'}) |
94 | diff --git a/debian/changelog b/debian/changelog | |||
95 | index 86a8d0c..8a1fc27 100644 | |||
96 | --- a/debian/changelog | |||
97 | +++ b/debian/changelog | |||
98 | @@ -1,3 +1,13 @@ | |||
99 | 1 | cloud-init (17.1-27-geb292c18-0ubuntu1~17.04.1) zesty-proposed; urgency=medium | ||
100 | 2 | |||
101 | 3 | * New upstream snapshot. | ||
102 | 4 | - EC2: Limit network config to fallback nic, fix local-ipv4 only | ||
103 | 5 | instances. (LP: #1728152) | ||
104 | 6 | - Gentoo: Use "rc-service" rather than "service". | ||
105 | 7 | [ckonstanski] (LP: #1727121) | ||
106 | 8 | |||
107 | 9 | -- Chad Smith <chad.smith@canonical.com> Tue, 31 Oct 2017 13:08:43 -0600 | ||
108 | 10 | |||
109 | 1 | cloud-init (17.1-25-g17a15f9e-0ubuntu1~17.04.1) zesty-proposed; urgency=medium | 11 | cloud-init (17.1-25-g17a15f9e-0ubuntu1~17.04.1) zesty-proposed; urgency=medium |
110 | 2 | 12 | ||
111 | 3 | * New upstream snapshot. | 13 | * New upstream snapshot. |
112 | diff --git a/tests/unittests/test_datasource/test_ec2.py b/tests/unittests/test_datasource/test_ec2.py | |||
113 | index a7301db..6af699a 100644 | |||
114 | --- a/tests/unittests/test_datasource/test_ec2.py | |||
115 | +++ b/tests/unittests/test_datasource/test_ec2.py | |||
116 | @@ -51,6 +51,29 @@ DEFAULT_METADATA = { | |||
117 | 51 | "vpc-ipv4-cidr-block": "172.31.0.0/16", | 51 | "vpc-ipv4-cidr-block": "172.31.0.0/16", |
118 | 52 | "vpc-ipv4-cidr-blocks": "172.31.0.0/16", | 52 | "vpc-ipv4-cidr-blocks": "172.31.0.0/16", |
119 | 53 | "vpc-ipv6-cidr-blocks": "2600:1f16:aeb:b200::/56" | 53 | "vpc-ipv6-cidr-blocks": "2600:1f16:aeb:b200::/56" |
120 | 54 | }, | ||
121 | 55 | "06:17:04:d7:26:0A": { | ||
122 | 56 | "device-number": "1", # Only IPv4 local config | ||
123 | 57 | "interface-id": "eni-e44ef49f", | ||
124 | 58 | "ipv4-associations": {"": "172.3.3.16"}, | ||
125 | 59 | "ipv6s": "", # No IPv6 config | ||
126 | 60 | "local-hostname": ("ip-172-3-3-16.us-east-2." | ||
127 | 61 | "compute.internal"), | ||
128 | 62 | "local-ipv4s": "172.3.3.16", | ||
129 | 63 | "mac": "06:17:04:d7:26:0A", | ||
130 | 64 | "owner-id": "950047163771", | ||
131 | 65 | "public-hostname": ("ec2-172-3-3-16.us-east-2." | ||
132 | 66 | "compute.amazonaws.com"), | ||
133 | 67 | "public-ipv4s": "", # No public ipv4 config | ||
134 | 68 | "security-group-ids": "sg-5a61d333", | ||
135 | 69 | "security-groups": "wide-open", | ||
136 | 70 | "subnet-id": "subnet-20b8565b", | ||
137 | 71 | "subnet-ipv4-cidr-block": "172.31.16.0/20", | ||
138 | 72 | "subnet-ipv6-cidr-blocks": "", | ||
139 | 73 | "vpc-id": "vpc-87e72bee", | ||
140 | 74 | "vpc-ipv4-cidr-block": "172.31.0.0/16", | ||
141 | 75 | "vpc-ipv4-cidr-blocks": "172.31.0.0/16", | ||
142 | 76 | "vpc-ipv6-cidr-blocks": "" | ||
143 | 54 | } | 77 | } |
144 | 55 | } | 78 | } |
145 | 56 | } | 79 | } |
146 | @@ -209,12 +232,20 @@ class TestEc2(test_helpers.HttprettyTestCase): | |||
147 | 209 | 232 | ||
148 | 210 | @httpretty.activate | 233 | @httpretty.activate |
149 | 211 | def test_network_config_property_returns_version_1_network_data(self): | 234 | def test_network_config_property_returns_version_1_network_data(self): |
151 | 212 | """network_config property returns network version 1 for metadata.""" | 235 | """network_config property returns network version 1 for metadata. |
152 | 236 | |||
153 | 237 | Only one device is configured even when multiple exist in metadata. | ||
154 | 238 | """ | ||
155 | 213 | ds = self._setup_ds( | 239 | ds = self._setup_ds( |
156 | 214 | platform_data=self.valid_platform_data, | 240 | platform_data=self.valid_platform_data, |
157 | 215 | sys_cfg={'datasource': {'Ec2': {'strict_id': True}}}, | 241 | sys_cfg={'datasource': {'Ec2': {'strict_id': True}}}, |
158 | 216 | md=DEFAULT_METADATA) | 242 | md=DEFAULT_METADATA) |
160 | 217 | ds.get_data() | 243 | find_fallback_path = ( |
161 | 244 | 'cloudinit.sources.DataSourceEc2.net.find_fallback_nic') | ||
162 | 245 | with mock.patch(find_fallback_path) as m_find_fallback: | ||
163 | 246 | m_find_fallback.return_value = 'eth9' | ||
164 | 247 | ds.get_data() | ||
165 | 248 | |||
166 | 218 | mac1 = '06:17:04:d7:26:09' # Defined in DEFAULT_METADATA | 249 | mac1 = '06:17:04:d7:26:09' # Defined in DEFAULT_METADATA |
167 | 219 | expected = {'version': 1, 'config': [ | 250 | expected = {'version': 1, 'config': [ |
168 | 220 | {'mac_address': '06:17:04:d7:26:09', 'name': 'eth9', | 251 | {'mac_address': '06:17:04:d7:26:09', 'name': 'eth9', |
169 | @@ -222,9 +253,48 @@ class TestEc2(test_helpers.HttprettyTestCase): | |||
170 | 222 | 'type': 'physical'}]} | 253 | 'type': 'physical'}]} |
171 | 223 | patch_path = ( | 254 | patch_path = ( |
172 | 224 | 'cloudinit.sources.DataSourceEc2.net.get_interfaces_by_mac') | 255 | 'cloudinit.sources.DataSourceEc2.net.get_interfaces_by_mac') |
173 | 256 | get_interface_mac_path = ( | ||
174 | 257 | 'cloudinit.sources.DataSourceEc2.net.get_interface_mac') | ||
175 | 258 | with mock.patch(patch_path) as m_get_interfaces_by_mac: | ||
176 | 259 | with mock.patch(find_fallback_path) as m_find_fallback: | ||
177 | 260 | with mock.patch(get_interface_mac_path) as m_get_mac: | ||
178 | 261 | m_get_interfaces_by_mac.return_value = {mac1: 'eth9'} | ||
179 | 262 | m_find_fallback.return_value = 'eth9' | ||
180 | 263 | m_get_mac.return_value = mac1 | ||
181 | 264 | self.assertEqual(expected, ds.network_config) | ||
182 | 265 | |||
183 | 266 | @httpretty.activate | ||
184 | 267 | def test_network_config_property_set_dhcp4_on_private_ipv4(self): | ||
185 | 268 | """network_config property configures dhcp4 on private ipv4 nics. | ||
186 | 269 | |||
187 | 270 | Only one device is configured even when multiple exist in metadata. | ||
188 | 271 | """ | ||
189 | 272 | ds = self._setup_ds( | ||
190 | 273 | platform_data=self.valid_platform_data, | ||
191 | 274 | sys_cfg={'datasource': {'Ec2': {'strict_id': True}}}, | ||
192 | 275 | md=DEFAULT_METADATA) | ||
193 | 276 | find_fallback_path = ( | ||
194 | 277 | 'cloudinit.sources.DataSourceEc2.net.find_fallback_nic') | ||
195 | 278 | with mock.patch(find_fallback_path) as m_find_fallback: | ||
196 | 279 | m_find_fallback.return_value = 'eth9' | ||
197 | 280 | ds.get_data() | ||
198 | 281 | |||
199 | 282 | mac1 = '06:17:04:d7:26:0A' # IPv4 only in DEFAULT_METADATA | ||
200 | 283 | expected = {'version': 1, 'config': [ | ||
201 | 284 | {'mac_address': '06:17:04:d7:26:0A', 'name': 'eth9', | ||
202 | 285 | 'subnets': [{'type': 'dhcp4'}], | ||
203 | 286 | 'type': 'physical'}]} | ||
204 | 287 | patch_path = ( | ||
205 | 288 | 'cloudinit.sources.DataSourceEc2.net.get_interfaces_by_mac') | ||
206 | 289 | get_interface_mac_path = ( | ||
207 | 290 | 'cloudinit.sources.DataSourceEc2.net.get_interface_mac') | ||
208 | 225 | with mock.patch(patch_path) as m_get_interfaces_by_mac: | 291 | with mock.patch(patch_path) as m_get_interfaces_by_mac: |
211 | 226 | m_get_interfaces_by_mac.return_value = {mac1: 'eth9'} | 292 | with mock.patch(find_fallback_path) as m_find_fallback: |
212 | 227 | self.assertEqual(expected, ds.network_config) | 293 | with mock.patch(get_interface_mac_path) as m_get_mac: |
213 | 294 | m_get_interfaces_by_mac.return_value = {mac1: 'eth9'} | ||
214 | 295 | m_find_fallback.return_value = 'eth9' | ||
215 | 296 | m_get_mac.return_value = mac1 | ||
216 | 297 | self.assertEqual(expected, ds.network_config) | ||
217 | 228 | 298 | ||
218 | 229 | def test_network_config_property_is_cached_in_datasource(self): | 299 | def test_network_config_property_is_cached_in_datasource(self): |
219 | 230 | """network_config property is cached in DataSourceEc2.""" | 300 | """network_config property is cached in DataSourceEc2.""" |
220 | @@ -321,9 +391,11 @@ class TestEc2(test_helpers.HttprettyTestCase): | |||
221 | 321 | 391 | ||
222 | 322 | @httpretty.activate | 392 | @httpretty.activate |
223 | 323 | @mock.patch('cloudinit.net.EphemeralIPv4Network') | 393 | @mock.patch('cloudinit.net.EphemeralIPv4Network') |
224 | 394 | @mock.patch('cloudinit.net.find_fallback_nic') | ||
225 | 324 | @mock.patch('cloudinit.net.dhcp.maybe_perform_dhcp_discovery') | 395 | @mock.patch('cloudinit.net.dhcp.maybe_perform_dhcp_discovery') |
226 | 325 | @mock.patch('cloudinit.sources.DataSourceEc2.util.is_FreeBSD') | 396 | @mock.patch('cloudinit.sources.DataSourceEc2.util.is_FreeBSD') |
228 | 326 | def test_ec2_local_performs_dhcp_on_non_bsd(self, m_is_bsd, m_dhcp, m_net): | 397 | def test_ec2_local_performs_dhcp_on_non_bsd(self, m_is_bsd, m_dhcp, |
229 | 398 | m_fallback_nic, m_net): | ||
230 | 327 | """Ec2Local returns True for valid platform data on non-BSD with dhcp. | 399 | """Ec2Local returns True for valid platform data on non-BSD with dhcp. |
231 | 328 | 400 | ||
232 | 329 | DataSourceEc2Local will setup initial IPv4 network via dhcp discovery. | 401 | DataSourceEc2Local will setup initial IPv4 network via dhcp discovery. |
233 | @@ -331,6 +403,7 @@ class TestEc2(test_helpers.HttprettyTestCase): | |||
234 | 331 | When the platform data is valid, return True. | 403 | When the platform data is valid, return True. |
235 | 332 | """ | 404 | """ |
236 | 333 | 405 | ||
237 | 406 | m_fallback_nic.return_value = 'eth9' | ||
238 | 334 | m_is_bsd.return_value = False | 407 | m_is_bsd.return_value = False |
239 | 335 | m_dhcp.return_value = [{ | 408 | m_dhcp.return_value = [{ |
240 | 336 | 'interface': 'eth9', 'fixed-address': '192.168.2.9', | 409 | 'interface': 'eth9', 'fixed-address': '192.168.2.9', |
241 | @@ -344,7 +417,7 @@ class TestEc2(test_helpers.HttprettyTestCase): | |||
242 | 344 | 417 | ||
243 | 345 | ret = ds.get_data() | 418 | ret = ds.get_data() |
244 | 346 | self.assertTrue(ret) | 419 | self.assertTrue(ret) |
246 | 347 | m_dhcp.assert_called_once_with() | 420 | m_dhcp.assert_called_once_with('eth9') |
247 | 348 | m_net.assert_called_once_with( | 421 | m_net.assert_called_once_with( |
248 | 349 | broadcast='192.168.2.255', interface='eth9', ip='192.168.2.9', | 422 | broadcast='192.168.2.255', interface='eth9', ip='192.168.2.9', |
249 | 350 | prefix_or_mask='255.255.255.0', router='192.168.2.1') | 423 | prefix_or_mask='255.255.255.0', router='192.168.2.1') |
250 | @@ -389,6 +462,57 @@ class TestConvertEc2MetadataNetworkConfig(test_helpers.CiTestCase): | |||
251 | 389 | ec2.convert_ec2_metadata_network_config( | 462 | ec2.convert_ec2_metadata_network_config( |
252 | 390 | network_metadata_ipv6, macs_to_nics)) | 463 | network_metadata_ipv6, macs_to_nics)) |
253 | 391 | 464 | ||
254 | 465 | def test_convert_ec2_metadata_network_config_handles_local_dhcp4(self): | ||
255 | 466 | """Config dhcp4 when there are no public addresses in public-ipv4s.""" | ||
256 | 467 | macs_to_nics = {self.mac1: 'eth9'} | ||
257 | 468 | network_metadata_ipv6 = copy.deepcopy(self.network_metadata) | ||
258 | 469 | nic1_metadata = ( | ||
259 | 470 | network_metadata_ipv6['interfaces']['macs'][self.mac1]) | ||
260 | 471 | nic1_metadata['local-ipv4s'] = '172.3.3.15' | ||
261 | 472 | nic1_metadata.pop('public-ipv4s') | ||
262 | 473 | expected = {'version': 1, 'config': [ | ||
263 | 474 | {'mac_address': self.mac1, 'type': 'physical', | ||
264 | 475 | 'name': 'eth9', 'subnets': [{'type': 'dhcp4'}]}]} | ||
265 | 476 | self.assertEqual( | ||
266 | 477 | expected, | ||
267 | 478 | ec2.convert_ec2_metadata_network_config( | ||
268 | 479 | network_metadata_ipv6, macs_to_nics)) | ||
269 | 480 | |||
270 | 481 | def test_convert_ec2_metadata_network_config_handles_absent_dhcp4(self): | ||
271 | 482 | """Config dhcp4 on fallback_nic when there are no ipv4 addresses.""" | ||
272 | 483 | macs_to_nics = {self.mac1: 'eth9'} | ||
273 | 484 | network_metadata_ipv6 = copy.deepcopy(self.network_metadata) | ||
274 | 485 | nic1_metadata = ( | ||
275 | 486 | network_metadata_ipv6['interfaces']['macs'][self.mac1]) | ||
276 | 487 | nic1_metadata['public-ipv4s'] = '' | ||
277 | 488 | |||
278 | 489 | # When no ipv4 or ipv6 content but fallback_nic set, set dhcp4 config. | ||
279 | 490 | expected = {'version': 1, 'config': [ | ||
280 | 491 | {'mac_address': self.mac1, 'type': 'physical', | ||
281 | 492 | 'name': 'eth9', 'subnets': [{'type': 'dhcp4'}]}]} | ||
282 | 493 | self.assertEqual( | ||
283 | 494 | expected, | ||
284 | 495 | ec2.convert_ec2_metadata_network_config( | ||
285 | 496 | network_metadata_ipv6, macs_to_nics, fallback_nic='eth9')) | ||
286 | 497 | |||
287 | 498 | def test_convert_ec2_metadata_network_config_handles_local_v4_and_v6(self): | ||
288 | 499 | """When dhcp6 is public and dhcp4 is set to local enable both.""" | ||
289 | 500 | macs_to_nics = {self.mac1: 'eth9'} | ||
290 | 501 | network_metadata_both = copy.deepcopy(self.network_metadata) | ||
291 | 502 | nic1_metadata = ( | ||
292 | 503 | network_metadata_both['interfaces']['macs'][self.mac1]) | ||
293 | 504 | nic1_metadata['ipv6s'] = '2620:0:1009:fd00:e442:c88d:c04d:dc85/64' | ||
294 | 505 | nic1_metadata.pop('public-ipv4s') | ||
295 | 506 | nic1_metadata['local-ipv4s'] = '10.0.0.42' # Local ipv4 only on vpc | ||
296 | 507 | expected = {'version': 1, 'config': [ | ||
297 | 508 | {'mac_address': self.mac1, 'type': 'physical', | ||
298 | 509 | 'name': 'eth9', | ||
299 | 510 | 'subnets': [{'type': 'dhcp4'}, {'type': 'dhcp6'}]}]} | ||
300 | 511 | self.assertEqual( | ||
301 | 512 | expected, | ||
302 | 513 | ec2.convert_ec2_metadata_network_config( | ||
303 | 514 | network_metadata_both, macs_to_nics)) | ||
304 | 515 | |||
305 | 392 | def test_convert_ec2_metadata_network_config_handles_dhcp4_and_dhcp6(self): | 516 | def test_convert_ec2_metadata_network_config_handles_dhcp4_and_dhcp6(self): |
306 | 393 | """Config both dhcp4 and dhcp6 when both vpc-ipv6 and ipv4 exists.""" | 517 | """Config both dhcp4 and dhcp6 when both vpc-ipv6 and ipv4 exists.""" |
307 | 394 | macs_to_nics = {self.mac1: 'eth9'} | 518 | macs_to_nics = {self.mac1: 'eth9'} |
PASSED: Continuous integration, rev:91c0f668530 566b4eb943fdda5 37b96454f0dc7d /jenkins. ubuntu. com/server/ job/cloud- init-ci/ 455/
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: /jenkins. ubuntu. com/server/ job/cloud- init-ci/ 455/rebuild
https:/