Merge lp:~smoser/cloud-init/trunk.smartos-fabric into lp:~cloud-init-dev/cloud-init/trunk
- trunk.smartos-fabric
- Merge into trunk
Status: | Merged |
---|---|
Merge reported by: | Scott Moser |
Merged at revision: | not available |
Proposed branch: | lp:~smoser/cloud-init/trunk.smartos-fabric |
Merge into: | lp:~cloud-init-dev/cloud-init/trunk |
Diff against target: |
590 lines (+437/-29) 2 files modified
cloudinit/sources/DataSourceSmartOS.py (+92/-24) tests/unittests/test_datasource/test_smartos.py (+345/-5) |
To merge this branch: | bzr merge lp:~smoser/cloud-init/trunk.smartos-fabric |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Moser | Approve | ||
Server Team CI bot | continuous-integration | Approve | |
Review via email: mp+300115@code.launchpad.net |
Commit message
SmartOS: more improvements for network configuration
This improves smart os network configuration
- fix the SocketClient which was previously completely broken.
- adds support for configuring dns servers and dns search (based off the
sdc:dns_domain).
- support 'sdc:gateways' information from the datasource for configuring
default routes.
- add converted network information to output when module is run as a main
TODO: add support for sdc:routes as described at http://
Description of the change
Server Team CI bot (server-team-bot) wrote : | # |
- 1258. By Scott Moser
-
add knowledge of the 'sdc:routes' key (but do not use it)
- 1259. By Scott Moser
-
add test case covering not all nics have 'gateways' entry.
also for brevity import convert_
smartos_ network_ data as convert_net.
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:1259
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Scott Moser (smoser) wrote : | # |
Scott Moser (smoser) : | # |
Preview Diff
1 | === modified file 'cloudinit/sources/DataSourceSmartOS.py' | |||
2 | --- cloudinit/sources/DataSourceSmartOS.py 2016-07-13 22:18:46 +0000 | |||
3 | +++ cloudinit/sources/DataSourceSmartOS.py 2016-07-25 15:23:44 +0000 | |||
4 | @@ -60,11 +60,15 @@ | |||
5 | 60 | 'availability_zone': ('sdc:datacenter_name', True), | 60 | 'availability_zone': ('sdc:datacenter_name', True), |
6 | 61 | 'vendor-data': ('sdc:vendor-data', False), | 61 | 'vendor-data': ('sdc:vendor-data', False), |
7 | 62 | 'operator-script': ('sdc:operator-script', False), | 62 | 'operator-script': ('sdc:operator-script', False), |
8 | 63 | 'hostname': ('sdc:hostname', True), | ||
9 | 64 | 'dns_domain': ('sdc:dns_domain', True), | ||
10 | 63 | } | 65 | } |
11 | 64 | 66 | ||
12 | 65 | SMARTOS_ATTRIB_JSON = { | 67 | SMARTOS_ATTRIB_JSON = { |
13 | 66 | # Cloud-init Key : (SmartOS Key known JSON) | 68 | # Cloud-init Key : (SmartOS Key known JSON) |
14 | 67 | 'network-data': 'sdc:nics', | 69 | 'network-data': 'sdc:nics', |
15 | 70 | 'dns_servers': 'sdc:resolvers', | ||
16 | 71 | 'routes': 'sdc:routes', | ||
17 | 68 | } | 72 | } |
18 | 69 | 73 | ||
19 | 70 | SMARTOS_ENV_LX_BRAND = "lx-brand" | 74 | SMARTOS_ENV_LX_BRAND = "lx-brand" |
20 | @@ -311,7 +315,10 @@ | |||
21 | 311 | if self._network_config is None: | 315 | if self._network_config is None: |
22 | 312 | if self.network_data is not None: | 316 | if self.network_data is not None: |
23 | 313 | self._network_config = ( | 317 | self._network_config = ( |
25 | 314 | convert_smartos_network_data(self.network_data)) | 318 | convert_smartos_network_data( |
26 | 319 | network_data=self.network_data, | ||
27 | 320 | dns_servers=self.metadata['dns_servers'], | ||
28 | 321 | dns_domain=self.metadata['dns_domain'])) | ||
29 | 315 | return self._network_config | 322 | return self._network_config |
30 | 316 | 323 | ||
31 | 317 | 324 | ||
32 | @@ -445,7 +452,8 @@ | |||
33 | 445 | 452 | ||
34 | 446 | 453 | ||
35 | 447 | class JoyentMetadataSocketClient(JoyentMetadataClient): | 454 | class JoyentMetadataSocketClient(JoyentMetadataClient): |
37 | 448 | def __init__(self, socketpath): | 455 | def __init__(self, socketpath, smartos_type=SMARTOS_ENV_LX_BRAND): |
38 | 456 | super(JoyentMetadataSocketClient, self).__init__(smartos_type) | ||
39 | 449 | self.socketpath = socketpath | 457 | self.socketpath = socketpath |
40 | 450 | 458 | ||
41 | 451 | def open_transport(self): | 459 | def open_transport(self): |
42 | @@ -461,7 +469,7 @@ | |||
43 | 461 | 469 | ||
44 | 462 | 470 | ||
45 | 463 | class JoyentMetadataSerialClient(JoyentMetadataClient): | 471 | class JoyentMetadataSerialClient(JoyentMetadataClient): |
47 | 464 | def __init__(self, device, timeout=10, smartos_type=None): | 472 | def __init__(self, device, timeout=10, smartos_type=SMARTOS_ENV_KVM): |
48 | 465 | super(JoyentMetadataSerialClient, self).__init__(smartos_type) | 473 | super(JoyentMetadataSerialClient, self).__init__(smartos_type) |
49 | 466 | self.device = device | 474 | self.device = device |
50 | 467 | self.timeout = timeout | 475 | self.timeout = timeout |
51 | @@ -583,7 +591,8 @@ | |||
52 | 583 | device=serial_device, timeout=serial_timeout, | 591 | device=serial_device, timeout=serial_timeout, |
53 | 584 | smartos_type=smartos_type) | 592 | smartos_type=smartos_type) |
54 | 585 | elif smartos_type == SMARTOS_ENV_LX_BRAND: | 593 | elif smartos_type == SMARTOS_ENV_LX_BRAND: |
56 | 586 | return JoyentMetadataSocketClient(socketpath=metadata_sockfile) | 594 | return JoyentMetadataSocketClient(socketpath=metadata_sockfile, |
57 | 595 | smartos_type=smartos_type) | ||
58 | 587 | 596 | ||
59 | 588 | raise ValueError("Unknown value for smartos_type: %s" % smartos_type) | 597 | raise ValueError("Unknown value for smartos_type: %s" % smartos_type) |
60 | 589 | 598 | ||
61 | @@ -671,8 +680,9 @@ | |||
62 | 671 | return None | 680 | return None |
63 | 672 | 681 | ||
64 | 673 | 682 | ||
67 | 674 | # Covert SMARTOS 'sdc:nics' data to network_config yaml | 683 | # Convert SMARTOS 'sdc:nics' data to network_config yaml |
68 | 675 | def convert_smartos_network_data(network_data=None): | 684 | def convert_smartos_network_data(network_data=None, |
69 | 685 | dns_servers=None, dns_domain=None): | ||
70 | 676 | """Return a dictionary of network_config by parsing provided | 686 | """Return a dictionary of network_config by parsing provided |
71 | 677 | SMARTOS sdc:nics configuration data | 687 | SMARTOS sdc:nics configuration data |
72 | 678 | 688 | ||
73 | @@ -706,9 +716,7 @@ | |||
74 | 706 | 'broadcast', | 716 | 'broadcast', |
75 | 707 | 'dns_nameservers', | 717 | 'dns_nameservers', |
76 | 708 | 'dns_search', | 718 | 'dns_search', |
77 | 709 | 'gateway', | ||
78 | 710 | 'metric', | 719 | 'metric', |
79 | 711 | 'netmask', | ||
80 | 712 | 'pointopoint', | 720 | 'pointopoint', |
81 | 713 | 'routes', | 721 | 'routes', |
82 | 714 | 'scope', | 722 | 'scope', |
83 | @@ -716,6 +724,29 @@ | |||
84 | 716 | ], | 724 | ], |
85 | 717 | } | 725 | } |
86 | 718 | 726 | ||
87 | 727 | if dns_servers: | ||
88 | 728 | if not isinstance(dns_servers, (list, tuple)): | ||
89 | 729 | dns_servers = [dns_servers] | ||
90 | 730 | else: | ||
91 | 731 | dns_servers = [] | ||
92 | 732 | |||
93 | 733 | if dns_domain: | ||
94 | 734 | if not isinstance(dns_domain, (list, tuple)): | ||
95 | 735 | dns_domain = [dns_domain] | ||
96 | 736 | else: | ||
97 | 737 | dns_domain = [] | ||
98 | 738 | |||
99 | 739 | def is_valid_ipv4(addr): | ||
100 | 740 | return '.' in addr | ||
101 | 741 | |||
102 | 742 | def is_valid_ipv6(addr): | ||
103 | 743 | return ':' in addr | ||
104 | 744 | |||
105 | 745 | pgws = { | ||
106 | 746 | 'ipv4': {'match': is_valid_ipv4, 'gw': None}, | ||
107 | 747 | 'ipv6': {'match': is_valid_ipv6, 'gw': None}, | ||
108 | 748 | } | ||
109 | 749 | |||
110 | 719 | config = [] | 750 | config = [] |
111 | 720 | for nic in network_data: | 751 | for nic in network_data: |
112 | 721 | cfg = dict((k, v) for k, v in nic.items() | 752 | cfg = dict((k, v) for k, v in nic.items() |
113 | @@ -727,18 +758,40 @@ | |||
114 | 727 | cfg.update({'mac_address': nic['mac']}) | 758 | cfg.update({'mac_address': nic['mac']}) |
115 | 728 | 759 | ||
116 | 729 | subnets = [] | 760 | subnets = [] |
125 | 730 | for ip, gw in zip(nic['ips'], nic['gateways']): | 761 | for ip in nic.get('ips', []): |
126 | 731 | subnet = dict((k, v) for k, v in nic.items() | 762 | if ip == "dhcp": |
127 | 732 | if k in valid_keys['subnet']) | 763 | subnet = {'type': 'dhcp4'} |
128 | 733 | subnet.update({ | 764 | else: |
129 | 734 | 'type': 'static', | 765 | subnet = dict((k, v) for k, v in nic.items() |
130 | 735 | 'address': ip, | 766 | if k in valid_keys['subnet']) |
131 | 736 | 'gateway': gw, | 767 | subnet.update({ |
132 | 737 | }) | 768 | 'type': 'static', |
133 | 769 | 'address': ip, | ||
134 | 770 | }) | ||
135 | 771 | |||
136 | 772 | proto = 'ipv4' if is_valid_ipv4(ip) else 'ipv6' | ||
137 | 773 | # Only use gateways for 'primary' nics | ||
138 | 774 | if 'primary' in nic and nic.get('primary', False): | ||
139 | 775 | # the ips and gateways list may be N to M, here | ||
140 | 776 | # we map the ip index into the gateways list, | ||
141 | 777 | # and handle the case that we could have more ips | ||
142 | 778 | # than gateways. we only consume the first gateway | ||
143 | 779 | if not pgws[proto]['gw']: | ||
144 | 780 | gateways = [gw for gw in nic.get('gateways', []) | ||
145 | 781 | if pgws[proto]['match'](gw)] | ||
146 | 782 | if len(gateways): | ||
147 | 783 | pgws[proto]['gw'] = gateways[0] | ||
148 | 784 | subnet.update({'gateway': pgws[proto]['gw']}) | ||
149 | 785 | |||
150 | 738 | subnets.append(subnet) | 786 | subnets.append(subnet) |
151 | 739 | cfg.update({'subnets': subnets}) | 787 | cfg.update({'subnets': subnets}) |
152 | 740 | config.append(cfg) | 788 | config.append(cfg) |
153 | 741 | 789 | ||
154 | 790 | if dns_servers: | ||
155 | 791 | config.append( | ||
156 | 792 | {'type': 'nameserver', 'address': dns_servers, | ||
157 | 793 | 'search': dns_domain}) | ||
158 | 794 | |||
159 | 742 | return {'version': 1, 'config': config} | 795 | return {'version': 1, 'config': config} |
160 | 743 | 796 | ||
161 | 744 | 797 | ||
162 | @@ -761,21 +814,36 @@ | |||
163 | 761 | sys.exit(1) | 814 | sys.exit(1) |
164 | 762 | if len(sys.argv) == 1: | 815 | if len(sys.argv) == 1: |
165 | 763 | keys = (list(SMARTOS_ATTRIB_JSON.keys()) + | 816 | keys = (list(SMARTOS_ATTRIB_JSON.keys()) + |
167 | 764 | list(SMARTOS_ATTRIB_MAP.keys())) | 817 | list(SMARTOS_ATTRIB_MAP.keys()) + ['network_config']) |
168 | 765 | else: | 818 | else: |
169 | 766 | keys = sys.argv[1:] | 819 | keys = sys.argv[1:] |
170 | 767 | 820 | ||
173 | 768 | data = {} | 821 | def load_key(client, key, data): |
174 | 769 | for key in keys: | 822 | if key in data: |
175 | 823 | return data[key] | ||
176 | 824 | |||
177 | 770 | if key in SMARTOS_ATTRIB_JSON: | 825 | if key in SMARTOS_ATTRIB_JSON: |
178 | 771 | keyname = SMARTOS_ATTRIB_JSON[key] | 826 | keyname = SMARTOS_ATTRIB_JSON[key] |
180 | 772 | data[key] = jmc.get_json(keyname) | 827 | data[key] = client.get_json(keyname) |
181 | 828 | elif key == "network_config": | ||
182 | 829 | for depkey in ('network-data', 'dns_servers', 'dns_domain'): | ||
183 | 830 | load_key(client, depkey, data) | ||
184 | 831 | data[key] = convert_smartos_network_data( | ||
185 | 832 | network_data=data['network-data'], | ||
186 | 833 | dns_servers=data['dns_servers'], | ||
187 | 834 | dns_domain=data['dns_domain']) | ||
188 | 773 | else: | 835 | else: |
189 | 774 | if key in SMARTOS_ATTRIB_MAP: | 836 | if key in SMARTOS_ATTRIB_MAP: |
190 | 775 | keyname, strip = SMARTOS_ATTRIB_MAP[key] | 837 | keyname, strip = SMARTOS_ATTRIB_MAP[key] |
191 | 776 | else: | 838 | else: |
192 | 777 | keyname, strip = (key, False) | 839 | keyname, strip = (key, False) |
197 | 778 | val = jmc.get(keyname, strip=strip) | 840 | data[key] = client.get(keyname, strip=strip) |
198 | 779 | data[key] = jmc.get(keyname, strip=strip) | 841 | |
199 | 780 | 842 | return data[key] | |
200 | 781 | print(json.dumps(data, indent=1)) | 843 | |
201 | 844 | data = {} | ||
202 | 845 | for key in keys: | ||
203 | 846 | load_key(client=jmc, key=key, data=data) | ||
204 | 847 | |||
205 | 848 | print(json.dumps(data, indent=1, sort_keys=True, | ||
206 | 849 | separators=(',', ': '))) | ||
207 | 782 | 850 | ||
208 | === modified file 'tests/unittests/test_datasource/test_smartos.py' | |||
209 | --- tests/unittests/test_datasource/test_smartos.py 2016-06-10 21:22:17 +0000 | |||
210 | +++ tests/unittests/test_datasource/test_smartos.py 2016-07-25 15:23:44 +0000 | |||
211 | @@ -36,6 +36,8 @@ | |||
212 | 36 | 36 | ||
213 | 37 | from cloudinit import serial | 37 | from cloudinit import serial |
214 | 38 | from cloudinit.sources import DataSourceSmartOS | 38 | from cloudinit.sources import DataSourceSmartOS |
215 | 39 | from cloudinit.sources.DataSourceSmartOS import ( | ||
216 | 40 | convert_smartos_network_data as convert_net) | ||
217 | 39 | 41 | ||
218 | 40 | import six | 42 | import six |
219 | 41 | 43 | ||
220 | @@ -86,6 +88,229 @@ | |||
221 | 86 | ] | 88 | ] |
222 | 87 | """) | 89 | """) |
223 | 88 | 90 | ||
224 | 91 | |||
225 | 92 | SDC_NICS_ALT = json.loads(""" | ||
226 | 93 | [ | ||
227 | 94 | { | ||
228 | 95 | "interface": "net0", | ||
229 | 96 | "mac": "90:b8:d0:ae:64:51", | ||
230 | 97 | "vlan_id": 324, | ||
231 | 98 | "nic_tag": "external", | ||
232 | 99 | "gateway": "8.12.42.1", | ||
233 | 100 | "gateways": [ | ||
234 | 101 | "8.12.42.1" | ||
235 | 102 | ], | ||
236 | 103 | "netmask": "255.255.255.0", | ||
237 | 104 | "ip": "8.12.42.51", | ||
238 | 105 | "ips": [ | ||
239 | 106 | "8.12.42.51/24" | ||
240 | 107 | ], | ||
241 | 108 | "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
242 | 109 | "model": "virtio", | ||
243 | 110 | "mtu": 1500, | ||
244 | 111 | "primary": true | ||
245 | 112 | }, | ||
246 | 113 | { | ||
247 | 114 | "interface": "net1", | ||
248 | 115 | "mac": "90:b8:d0:bd:4f:9c", | ||
249 | 116 | "vlan_id": 600, | ||
250 | 117 | "nic_tag": "internal", | ||
251 | 118 | "netmask": "255.255.255.0", | ||
252 | 119 | "ip": "10.210.1.217", | ||
253 | 120 | "ips": [ | ||
254 | 121 | "10.210.1.217/24" | ||
255 | 122 | ], | ||
256 | 123 | "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
257 | 124 | "model": "virtio", | ||
258 | 125 | "mtu": 1500 | ||
259 | 126 | } | ||
260 | 127 | ] | ||
261 | 128 | """) | ||
262 | 129 | |||
263 | 130 | SDC_NICS_DHCP = json.loads(""" | ||
264 | 131 | [ | ||
265 | 132 | { | ||
266 | 133 | "interface": "net0", | ||
267 | 134 | "mac": "90:b8:d0:ae:64:51", | ||
268 | 135 | "vlan_id": 324, | ||
269 | 136 | "nic_tag": "external", | ||
270 | 137 | "gateway": "8.12.42.1", | ||
271 | 138 | "gateways": [ | ||
272 | 139 | "8.12.42.1" | ||
273 | 140 | ], | ||
274 | 141 | "netmask": "255.255.255.0", | ||
275 | 142 | "ip": "8.12.42.51", | ||
276 | 143 | "ips": [ | ||
277 | 144 | "8.12.42.51/24" | ||
278 | 145 | ], | ||
279 | 146 | "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
280 | 147 | "model": "virtio", | ||
281 | 148 | "mtu": 1500, | ||
282 | 149 | "primary": true | ||
283 | 150 | }, | ||
284 | 151 | { | ||
285 | 152 | "interface": "net1", | ||
286 | 153 | "mac": "90:b8:d0:bd:4f:9c", | ||
287 | 154 | "vlan_id": 600, | ||
288 | 155 | "nic_tag": "internal", | ||
289 | 156 | "netmask": "255.255.255.0", | ||
290 | 157 | "ip": "10.210.1.217", | ||
291 | 158 | "ips": [ | ||
292 | 159 | "dhcp" | ||
293 | 160 | ], | ||
294 | 161 | "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
295 | 162 | "model": "virtio", | ||
296 | 163 | "mtu": 1500 | ||
297 | 164 | } | ||
298 | 165 | ] | ||
299 | 166 | """) | ||
300 | 167 | |||
301 | 168 | SDC_NICS_MIP = json.loads(""" | ||
302 | 169 | [ | ||
303 | 170 | { | ||
304 | 171 | "interface": "net0", | ||
305 | 172 | "mac": "90:b8:d0:ae:64:51", | ||
306 | 173 | "vlan_id": 324, | ||
307 | 174 | "nic_tag": "external", | ||
308 | 175 | "gateway": "8.12.42.1", | ||
309 | 176 | "gateways": [ | ||
310 | 177 | "8.12.42.1" | ||
311 | 178 | ], | ||
312 | 179 | "netmask": "255.255.255.0", | ||
313 | 180 | "ip": "8.12.42.51", | ||
314 | 181 | "ips": [ | ||
315 | 182 | "8.12.42.51/24", | ||
316 | 183 | "8.12.42.52/24" | ||
317 | 184 | ], | ||
318 | 185 | "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
319 | 186 | "model": "virtio", | ||
320 | 187 | "mtu": 1500, | ||
321 | 188 | "primary": true | ||
322 | 189 | }, | ||
323 | 190 | { | ||
324 | 191 | "interface": "net1", | ||
325 | 192 | "mac": "90:b8:d0:bd:4f:9c", | ||
326 | 193 | "vlan_id": 600, | ||
327 | 194 | "nic_tag": "internal", | ||
328 | 195 | "netmask": "255.255.255.0", | ||
329 | 196 | "ip": "10.210.1.217", | ||
330 | 197 | "ips": [ | ||
331 | 198 | "10.210.1.217/24", | ||
332 | 199 | "10.210.1.151/24" | ||
333 | 200 | ], | ||
334 | 201 | "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
335 | 202 | "model": "virtio", | ||
336 | 203 | "mtu": 1500 | ||
337 | 204 | } | ||
338 | 205 | ] | ||
339 | 206 | """) | ||
340 | 207 | |||
341 | 208 | SDC_NICS_MIP_IPV6 = json.loads(""" | ||
342 | 209 | [ | ||
343 | 210 | { | ||
344 | 211 | "interface": "net0", | ||
345 | 212 | "mac": "90:b8:d0:ae:64:51", | ||
346 | 213 | "vlan_id": 324, | ||
347 | 214 | "nic_tag": "external", | ||
348 | 215 | "gateway": "8.12.42.1", | ||
349 | 216 | "gateways": [ | ||
350 | 217 | "8.12.42.1" | ||
351 | 218 | ], | ||
352 | 219 | "netmask": "255.255.255.0", | ||
353 | 220 | "ip": "8.12.42.51", | ||
354 | 221 | "ips": [ | ||
355 | 222 | "2001:4800:78ff:1b:be76:4eff:fe06:96b3/64", | ||
356 | 223 | "8.12.42.51/24" | ||
357 | 224 | ], | ||
358 | 225 | "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
359 | 226 | "model": "virtio", | ||
360 | 227 | "mtu": 1500, | ||
361 | 228 | "primary": true | ||
362 | 229 | }, | ||
363 | 230 | { | ||
364 | 231 | "interface": "net1", | ||
365 | 232 | "mac": "90:b8:d0:bd:4f:9c", | ||
366 | 233 | "vlan_id": 600, | ||
367 | 234 | "nic_tag": "internal", | ||
368 | 235 | "netmask": "255.255.255.0", | ||
369 | 236 | "ip": "10.210.1.217", | ||
370 | 237 | "ips": [ | ||
371 | 238 | "10.210.1.217/24" | ||
372 | 239 | ], | ||
373 | 240 | "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
374 | 241 | "model": "virtio", | ||
375 | 242 | "mtu": 1500 | ||
376 | 243 | } | ||
377 | 244 | ] | ||
378 | 245 | """) | ||
379 | 246 | |||
380 | 247 | SDC_NICS_IPV4_IPV6 = json.loads(""" | ||
381 | 248 | [ | ||
382 | 249 | { | ||
383 | 250 | "interface": "net0", | ||
384 | 251 | "mac": "90:b8:d0:ae:64:51", | ||
385 | 252 | "vlan_id": 324, | ||
386 | 253 | "nic_tag": "external", | ||
387 | 254 | "gateway": "8.12.42.1", | ||
388 | 255 | "gateways": ["8.12.42.1", "2001::1", "2001::2"], | ||
389 | 256 | "netmask": "255.255.255.0", | ||
390 | 257 | "ip": "8.12.42.51", | ||
391 | 258 | "ips": ["2001::10/64", "8.12.42.51/24", "2001::11/64", | ||
392 | 259 | "8.12.42.52/32"], | ||
393 | 260 | "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
394 | 261 | "model": "virtio", | ||
395 | 262 | "mtu": 1500, | ||
396 | 263 | "primary": true | ||
397 | 264 | }, | ||
398 | 265 | { | ||
399 | 266 | "interface": "net1", | ||
400 | 267 | "mac": "90:b8:d0:bd:4f:9c", | ||
401 | 268 | "vlan_id": 600, | ||
402 | 269 | "nic_tag": "internal", | ||
403 | 270 | "netmask": "255.255.255.0", | ||
404 | 271 | "ip": "10.210.1.217", | ||
405 | 272 | "ips": ["10.210.1.217/24"], | ||
406 | 273 | "gateways": ["10.210.1.210"], | ||
407 | 274 | "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
408 | 275 | "model": "virtio", | ||
409 | 276 | "mtu": 1500 | ||
410 | 277 | } | ||
411 | 278 | ] | ||
412 | 279 | """) | ||
413 | 280 | |||
414 | 281 | SDC_NICS_SINGLE_GATEWAY = json.loads(""" | ||
415 | 282 | [ | ||
416 | 283 | { | ||
417 | 284 | "interface":"net0", | ||
418 | 285 | "mac":"90:b8:d0:d8:82:b4", | ||
419 | 286 | "vlan_id":324, | ||
420 | 287 | "nic_tag":"external", | ||
421 | 288 | "gateway":"8.12.42.1", | ||
422 | 289 | "gateways":["8.12.42.1"], | ||
423 | 290 | "netmask":"255.255.255.0", | ||
424 | 291 | "ip":"8.12.42.26", | ||
425 | 292 | "ips":["8.12.42.26/24"], | ||
426 | 293 | "network_uuid":"992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe", | ||
427 | 294 | "model":"virtio", | ||
428 | 295 | "mtu":1500, | ||
429 | 296 | "primary":true | ||
430 | 297 | }, | ||
431 | 298 | { | ||
432 | 299 | "interface":"net1", | ||
433 | 300 | "mac":"90:b8:d0:0a:51:31", | ||
434 | 301 | "vlan_id":600, | ||
435 | 302 | "nic_tag":"internal", | ||
436 | 303 | "netmask":"255.255.255.0", | ||
437 | 304 | "ip":"10.210.1.27", | ||
438 | 305 | "ips":["10.210.1.27/24"], | ||
439 | 306 | "network_uuid":"98657fdf-11f4-4ee2-88a4-ce7fe73e33a6", | ||
440 | 307 | "model":"virtio", | ||
441 | 308 | "mtu":1500 | ||
442 | 309 | } | ||
443 | 310 | ] | ||
444 | 311 | """) | ||
445 | 312 | |||
446 | 313 | |||
447 | 89 | MOCK_RETURNS = { | 314 | MOCK_RETURNS = { |
448 | 90 | 'hostname': 'test-host', | 315 | 'hostname': 'test-host', |
449 | 91 | 'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname', | 316 | 'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname', |
450 | @@ -524,20 +749,135 @@ | |||
451 | 524 | 749 | ||
452 | 525 | 750 | ||
453 | 526 | class TestNetworkConversion(TestCase): | 751 | class TestNetworkConversion(TestCase): |
454 | 527 | |||
455 | 528 | def test_convert_simple(self): | 752 | def test_convert_simple(self): |
456 | 529 | expected = { | 753 | expected = { |
457 | 530 | 'version': 1, | 754 | 'version': 1, |
458 | 531 | 'config': [ | 755 | 'config': [ |
459 | 532 | {'name': 'net0', 'type': 'physical', | 756 | {'name': 'net0', 'type': 'physical', |
460 | 533 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', | 757 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', |
461 | 534 | 'netmask': '255.255.255.0', | ||
462 | 535 | 'address': '8.12.42.102/24'}], | 758 | 'address': '8.12.42.102/24'}], |
463 | 536 | 'mtu': 1500, 'mac_address': '90:b8:d0:f5:e4:f5'}, | 759 | 'mtu': 1500, 'mac_address': '90:b8:d0:f5:e4:f5'}, |
464 | 537 | {'name': 'net1', 'type': 'physical', | 760 | {'name': 'net1', 'type': 'physical', |
467 | 538 | 'subnets': [{'type': 'static', 'gateway': '192.168.128.1', | 761 | 'subnets': [{'type': 'static', |
466 | 539 | 'netmask': '255.255.252.0', | ||
468 | 540 | 'address': '192.168.128.93/22'}], | 762 | 'address': '192.168.128.93/22'}], |
469 | 541 | 'mtu': 8500, 'mac_address': '90:b8:d0:a5:ff:cd'}]} | 763 | 'mtu': 8500, 'mac_address': '90:b8:d0:a5:ff:cd'}]} |
471 | 542 | found = DataSourceSmartOS.convert_smartos_network_data(SDC_NICS) | 764 | found = convert_net(SDC_NICS) |
472 | 765 | self.assertEqual(expected, found) | ||
473 | 766 | |||
474 | 767 | def test_convert_simple_alt(self): | ||
475 | 768 | expected = { | ||
476 | 769 | 'version': 1, | ||
477 | 770 | 'config': [ | ||
478 | 771 | {'name': 'net0', 'type': 'physical', | ||
479 | 772 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', | ||
480 | 773 | 'address': '8.12.42.51/24'}], | ||
481 | 774 | 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'}, | ||
482 | 775 | {'name': 'net1', 'type': 'physical', | ||
483 | 776 | 'subnets': [{'type': 'static', | ||
484 | 777 | 'address': '10.210.1.217/24'}], | ||
485 | 778 | 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]} | ||
486 | 779 | found = convert_net(SDC_NICS_ALT) | ||
487 | 780 | self.assertEqual(expected, found) | ||
488 | 781 | |||
489 | 782 | def test_convert_simple_dhcp(self): | ||
490 | 783 | expected = { | ||
491 | 784 | 'version': 1, | ||
492 | 785 | 'config': [ | ||
493 | 786 | {'name': 'net0', 'type': 'physical', | ||
494 | 787 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', | ||
495 | 788 | 'address': '8.12.42.51/24'}], | ||
496 | 789 | 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'}, | ||
497 | 790 | {'name': 'net1', 'type': 'physical', | ||
498 | 791 | 'subnets': [{'type': 'dhcp4'}], | ||
499 | 792 | 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]} | ||
500 | 793 | found = convert_net(SDC_NICS_DHCP) | ||
501 | 794 | self.assertEqual(expected, found) | ||
502 | 795 | |||
503 | 796 | def test_convert_simple_multi_ip(self): | ||
504 | 797 | expected = { | ||
505 | 798 | 'version': 1, | ||
506 | 799 | 'config': [ | ||
507 | 800 | {'name': 'net0', 'type': 'physical', | ||
508 | 801 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', | ||
509 | 802 | 'address': '8.12.42.51/24'}, | ||
510 | 803 | {'type': 'static', | ||
511 | 804 | 'address': '8.12.42.52/24'}], | ||
512 | 805 | 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'}, | ||
513 | 806 | {'name': 'net1', 'type': 'physical', | ||
514 | 807 | 'subnets': [{'type': 'static', | ||
515 | 808 | 'address': '10.210.1.217/24'}, | ||
516 | 809 | {'type': 'static', | ||
517 | 810 | 'address': '10.210.1.151/24'}], | ||
518 | 811 | 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]} | ||
519 | 812 | found = convert_net(SDC_NICS_MIP) | ||
520 | 813 | self.assertEqual(expected, found) | ||
521 | 814 | |||
522 | 815 | def test_convert_with_dns(self): | ||
523 | 816 | expected = { | ||
524 | 817 | 'version': 1, | ||
525 | 818 | 'config': [ | ||
526 | 819 | {'name': 'net0', 'type': 'physical', | ||
527 | 820 | 'subnets': [{'type': 'static', 'gateway': '8.12.42.1', | ||
528 | 821 | 'address': '8.12.42.51/24'}], | ||
529 | 822 | 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'}, | ||
530 | 823 | {'name': 'net1', 'type': 'physical', | ||
531 | 824 | 'subnets': [{'type': 'dhcp4'}], | ||
532 | 825 | 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}, | ||
533 | 826 | {'type': 'nameserver', | ||
534 | 827 | 'address': ['8.8.8.8', '8.8.8.1'], 'search': ["local"]}]} | ||
535 | 828 | found = convert_net( | ||
536 | 829 | network_data=SDC_NICS_DHCP, dns_servers=['8.8.8.8', '8.8.8.1'], | ||
537 | 830 | dns_domain="local") | ||
538 | 831 | self.assertEqual(expected, found) | ||
539 | 832 | |||
540 | 833 | def test_convert_simple_multi_ipv6(self): | ||
541 | 834 | expected = { | ||
542 | 835 | 'version': 1, | ||
543 | 836 | 'config': [ | ||
544 | 837 | {'name': 'net0', 'type': 'physical', | ||
545 | 838 | 'subnets': [{'type': 'static', 'address': | ||
546 | 839 | '2001:4800:78ff:1b:be76:4eff:fe06:96b3/64'}, | ||
547 | 840 | {'type': 'static', 'gateway': '8.12.42.1', | ||
548 | 841 | 'address': '8.12.42.51/24'}], | ||
549 | 842 | 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'}, | ||
550 | 843 | {'name': 'net1', 'type': 'physical', | ||
551 | 844 | 'subnets': [{'type': 'static', | ||
552 | 845 | 'address': '10.210.1.217/24'}], | ||
553 | 846 | 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]} | ||
554 | 847 | found = convert_net(SDC_NICS_MIP_IPV6) | ||
555 | 848 | self.assertEqual(expected, found) | ||
556 | 849 | |||
557 | 850 | def test_convert_simple_both_ipv4_ipv6(self): | ||
558 | 851 | expected = { | ||
559 | 852 | 'version': 1, | ||
560 | 853 | 'config': [ | ||
561 | 854 | {'mac_address': '90:b8:d0:ae:64:51', 'mtu': 1500, | ||
562 | 855 | 'name': 'net0', 'type': 'physical', | ||
563 | 856 | 'subnets': [{'address': '2001::10/64', 'gateway': '2001::1', | ||
564 | 857 | 'type': 'static'}, | ||
565 | 858 | {'address': '8.12.42.51/24', | ||
566 | 859 | 'gateway': '8.12.42.1', | ||
567 | 860 | 'type': 'static'}, | ||
568 | 861 | {'address': '2001::11/64', 'type': 'static'}, | ||
569 | 862 | {'address': '8.12.42.52/32', 'type': 'static'}]}, | ||
570 | 863 | {'mac_address': '90:b8:d0:bd:4f:9c', 'mtu': 1500, | ||
571 | 864 | 'name': 'net1', 'type': 'physical', | ||
572 | 865 | 'subnets': [{'address': '10.210.1.217/24', | ||
573 | 866 | 'type': 'static'}]}]} | ||
574 | 867 | found = convert_net(SDC_NICS_IPV4_IPV6) | ||
575 | 868 | self.assertEqual(expected, found) | ||
576 | 869 | |||
577 | 870 | def test_gateways_not_on_all_nics(self): | ||
578 | 871 | expected = { | ||
579 | 872 | 'version': 1, | ||
580 | 873 | 'config': [ | ||
581 | 874 | {'mac_address': '90:b8:d0:d8:82:b4', 'mtu': 1500, | ||
582 | 875 | 'name': 'net0', 'type': 'physical', | ||
583 | 876 | 'subnets': [{'address': '8.12.42.26/24', | ||
584 | 877 | 'gateway': '8.12.42.1', 'type': 'static'}]}, | ||
585 | 878 | {'mac_address': '90:b8:d0:0a:51:31', 'mtu': 1500, | ||
586 | 879 | 'name': 'net1', 'type': 'physical', | ||
587 | 880 | 'subnets': [{'address': '10.210.1.27/24', | ||
588 | 881 | 'type': 'static'}]}]} | ||
589 | 882 | found = convert_net(SDC_NICS_SINGLE_GATEWAY) | ||
590 | 543 | self.assertEqual(expected, found) | 883 | self.assertEqual(expected, found) |
PASSED: Continuous integration, rev:1257 /server- team-jenkins. canonical. com/job/ cloud-init- ci/28/ /server- team-jenkins. canonical. com/job/ lp-vote- on-merge/ 2/console
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild: /server- team-jenkins. canonical. com/job/ cloud-init- ci/28/rebuild
https:/