Merge lp:~smoser/cloud-init/trunk.smartos-fabric into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Scott Moser
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
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://eng.joyent.com/mdata/datadict.html

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)
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.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Scott Moser (smoser) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cloudinit/sources/DataSourceSmartOS.py'
--- cloudinit/sources/DataSourceSmartOS.py 2016-07-13 22:18:46 +0000
+++ cloudinit/sources/DataSourceSmartOS.py 2016-07-25 15:23:44 +0000
@@ -60,11 +60,15 @@
60 'availability_zone': ('sdc:datacenter_name', True),60 'availability_zone': ('sdc:datacenter_name', True),
61 'vendor-data': ('sdc:vendor-data', False),61 'vendor-data': ('sdc:vendor-data', False),
62 'operator-script': ('sdc:operator-script', False),62 'operator-script': ('sdc:operator-script', False),
63 'hostname': ('sdc:hostname', True),
64 'dns_domain': ('sdc:dns_domain', True),
63}65}
6466
65SMARTOS_ATTRIB_JSON = {67SMARTOS_ATTRIB_JSON = {
66 # Cloud-init Key : (SmartOS Key known JSON)68 # Cloud-init Key : (SmartOS Key known JSON)
67 'network-data': 'sdc:nics',69 'network-data': 'sdc:nics',
70 'dns_servers': 'sdc:resolvers',
71 'routes': 'sdc:routes',
68}72}
6973
70SMARTOS_ENV_LX_BRAND = "lx-brand"74SMARTOS_ENV_LX_BRAND = "lx-brand"
@@ -311,7 +315,10 @@
311 if self._network_config is None:315 if self._network_config is None:
312 if self.network_data is not None:316 if self.network_data is not None:
313 self._network_config = (317 self._network_config = (
314 convert_smartos_network_data(self.network_data))318 convert_smartos_network_data(
319 network_data=self.network_data,
320 dns_servers=self.metadata['dns_servers'],
321 dns_domain=self.metadata['dns_domain']))
315 return self._network_config322 return self._network_config
316323
317324
@@ -445,7 +452,8 @@
445452
446453
447class JoyentMetadataSocketClient(JoyentMetadataClient):454class JoyentMetadataSocketClient(JoyentMetadataClient):
448 def __init__(self, socketpath):455 def __init__(self, socketpath, smartos_type=SMARTOS_ENV_LX_BRAND):
456 super(JoyentMetadataSocketClient, self).__init__(smartos_type)
449 self.socketpath = socketpath457 self.socketpath = socketpath
450458
451 def open_transport(self):459 def open_transport(self):
@@ -461,7 +469,7 @@
461469
462470
463class JoyentMetadataSerialClient(JoyentMetadataClient):471class JoyentMetadataSerialClient(JoyentMetadataClient):
464 def __init__(self, device, timeout=10, smartos_type=None):472 def __init__(self, device, timeout=10, smartos_type=SMARTOS_ENV_KVM):
465 super(JoyentMetadataSerialClient, self).__init__(smartos_type)473 super(JoyentMetadataSerialClient, self).__init__(smartos_type)
466 self.device = device474 self.device = device
467 self.timeout = timeout475 self.timeout = timeout
@@ -583,7 +591,8 @@
583 device=serial_device, timeout=serial_timeout,591 device=serial_device, timeout=serial_timeout,
584 smartos_type=smartos_type)592 smartos_type=smartos_type)
585 elif smartos_type == SMARTOS_ENV_LX_BRAND:593 elif smartos_type == SMARTOS_ENV_LX_BRAND:
586 return JoyentMetadataSocketClient(socketpath=metadata_sockfile)594 return JoyentMetadataSocketClient(socketpath=metadata_sockfile,
595 smartos_type=smartos_type)
587596
588 raise ValueError("Unknown value for smartos_type: %s" % smartos_type)597 raise ValueError("Unknown value for smartos_type: %s" % smartos_type)
589598
@@ -671,8 +680,9 @@
671 return None680 return None
672681
673682
674# Covert SMARTOS 'sdc:nics' data to network_config yaml683# Convert SMARTOS 'sdc:nics' data to network_config yaml
675def convert_smartos_network_data(network_data=None):684def convert_smartos_network_data(network_data=None,
685 dns_servers=None, dns_domain=None):
676 """Return a dictionary of network_config by parsing provided686 """Return a dictionary of network_config by parsing provided
677 SMARTOS sdc:nics configuration data687 SMARTOS sdc:nics configuration data
678688
@@ -706,9 +716,7 @@
706 'broadcast',716 'broadcast',
707 'dns_nameservers',717 'dns_nameservers',
708 'dns_search',718 'dns_search',
709 'gateway',
710 'metric',719 'metric',
711 'netmask',
712 'pointopoint',720 'pointopoint',
713 'routes',721 'routes',
714 'scope',722 'scope',
@@ -716,6 +724,29 @@
716 ],724 ],
717 }725 }
718726
727 if dns_servers:
728 if not isinstance(dns_servers, (list, tuple)):
729 dns_servers = [dns_servers]
730 else:
731 dns_servers = []
732
733 if dns_domain:
734 if not isinstance(dns_domain, (list, tuple)):
735 dns_domain = [dns_domain]
736 else:
737 dns_domain = []
738
739 def is_valid_ipv4(addr):
740 return '.' in addr
741
742 def is_valid_ipv6(addr):
743 return ':' in addr
744
745 pgws = {
746 'ipv4': {'match': is_valid_ipv4, 'gw': None},
747 'ipv6': {'match': is_valid_ipv6, 'gw': None},
748 }
749
719 config = []750 config = []
720 for nic in network_data:751 for nic in network_data:
721 cfg = dict((k, v) for k, v in nic.items()752 cfg = dict((k, v) for k, v in nic.items()
@@ -727,18 +758,40 @@
727 cfg.update({'mac_address': nic['mac']})758 cfg.update({'mac_address': nic['mac']})
728759
729 subnets = []760 subnets = []
730 for ip, gw in zip(nic['ips'], nic['gateways']):761 for ip in nic.get('ips', []):
731 subnet = dict((k, v) for k, v in nic.items()762 if ip == "dhcp":
732 if k in valid_keys['subnet'])763 subnet = {'type': 'dhcp4'}
733 subnet.update({764 else:
734 'type': 'static',765 subnet = dict((k, v) for k, v in nic.items()
735 'address': ip,766 if k in valid_keys['subnet'])
736 'gateway': gw,767 subnet.update({
737 })768 'type': 'static',
769 'address': ip,
770 })
771
772 proto = 'ipv4' if is_valid_ipv4(ip) else 'ipv6'
773 # Only use gateways for 'primary' nics
774 if 'primary' in nic and nic.get('primary', False):
775 # the ips and gateways list may be N to M, here
776 # we map the ip index into the gateways list,
777 # and handle the case that we could have more ips
778 # than gateways. we only consume the first gateway
779 if not pgws[proto]['gw']:
780 gateways = [gw for gw in nic.get('gateways', [])
781 if pgws[proto]['match'](gw)]
782 if len(gateways):
783 pgws[proto]['gw'] = gateways[0]
784 subnet.update({'gateway': pgws[proto]['gw']})
785
738 subnets.append(subnet)786 subnets.append(subnet)
739 cfg.update({'subnets': subnets})787 cfg.update({'subnets': subnets})
740 config.append(cfg)788 config.append(cfg)
741789
790 if dns_servers:
791 config.append(
792 {'type': 'nameserver', 'address': dns_servers,
793 'search': dns_domain})
794
742 return {'version': 1, 'config': config}795 return {'version': 1, 'config': config}
743796
744797
@@ -761,21 +814,36 @@
761 sys.exit(1)814 sys.exit(1)
762 if len(sys.argv) == 1:815 if len(sys.argv) == 1:
763 keys = (list(SMARTOS_ATTRIB_JSON.keys()) +816 keys = (list(SMARTOS_ATTRIB_JSON.keys()) +
764 list(SMARTOS_ATTRIB_MAP.keys()))817 list(SMARTOS_ATTRIB_MAP.keys()) + ['network_config'])
765 else:818 else:
766 keys = sys.argv[1:]819 keys = sys.argv[1:]
767820
768 data = {}821 def load_key(client, key, data):
769 for key in keys:822 if key in data:
823 return data[key]
824
770 if key in SMARTOS_ATTRIB_JSON:825 if key in SMARTOS_ATTRIB_JSON:
771 keyname = SMARTOS_ATTRIB_JSON[key]826 keyname = SMARTOS_ATTRIB_JSON[key]
772 data[key] = jmc.get_json(keyname)827 data[key] = client.get_json(keyname)
828 elif key == "network_config":
829 for depkey in ('network-data', 'dns_servers', 'dns_domain'):
830 load_key(client, depkey, data)
831 data[key] = convert_smartos_network_data(
832 network_data=data['network-data'],
833 dns_servers=data['dns_servers'],
834 dns_domain=data['dns_domain'])
773 else:835 else:
774 if key in SMARTOS_ATTRIB_MAP:836 if key in SMARTOS_ATTRIB_MAP:
775 keyname, strip = SMARTOS_ATTRIB_MAP[key]837 keyname, strip = SMARTOS_ATTRIB_MAP[key]
776 else:838 else:
777 keyname, strip = (key, False)839 keyname, strip = (key, False)
778 val = jmc.get(keyname, strip=strip)840 data[key] = client.get(keyname, strip=strip)
779 data[key] = jmc.get(keyname, strip=strip)841
780842 return data[key]
781 print(json.dumps(data, indent=1))843
844 data = {}
845 for key in keys:
846 load_key(client=jmc, key=key, data=data)
847
848 print(json.dumps(data, indent=1, sort_keys=True,
849 separators=(',', ': ')))
782850
=== modified file 'tests/unittests/test_datasource/test_smartos.py'
--- tests/unittests/test_datasource/test_smartos.py 2016-06-10 21:22:17 +0000
+++ tests/unittests/test_datasource/test_smartos.py 2016-07-25 15:23:44 +0000
@@ -36,6 +36,8 @@
3636
37from cloudinit import serial37from cloudinit import serial
38from cloudinit.sources import DataSourceSmartOS38from cloudinit.sources import DataSourceSmartOS
39from cloudinit.sources.DataSourceSmartOS import (
40 convert_smartos_network_data as convert_net)
3941
40import six42import six
4143
@@ -86,6 +88,229 @@
86]88]
87""")89""")
8890
91
92SDC_NICS_ALT = json.loads("""
93[
94 {
95 "interface": "net0",
96 "mac": "90:b8:d0:ae:64:51",
97 "vlan_id": 324,
98 "nic_tag": "external",
99 "gateway": "8.12.42.1",
100 "gateways": [
101 "8.12.42.1"
102 ],
103 "netmask": "255.255.255.0",
104 "ip": "8.12.42.51",
105 "ips": [
106 "8.12.42.51/24"
107 ],
108 "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
109 "model": "virtio",
110 "mtu": 1500,
111 "primary": true
112 },
113 {
114 "interface": "net1",
115 "mac": "90:b8:d0:bd:4f:9c",
116 "vlan_id": 600,
117 "nic_tag": "internal",
118 "netmask": "255.255.255.0",
119 "ip": "10.210.1.217",
120 "ips": [
121 "10.210.1.217/24"
122 ],
123 "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
124 "model": "virtio",
125 "mtu": 1500
126 }
127]
128""")
129
130SDC_NICS_DHCP = json.loads("""
131[
132 {
133 "interface": "net0",
134 "mac": "90:b8:d0:ae:64:51",
135 "vlan_id": 324,
136 "nic_tag": "external",
137 "gateway": "8.12.42.1",
138 "gateways": [
139 "8.12.42.1"
140 ],
141 "netmask": "255.255.255.0",
142 "ip": "8.12.42.51",
143 "ips": [
144 "8.12.42.51/24"
145 ],
146 "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
147 "model": "virtio",
148 "mtu": 1500,
149 "primary": true
150 },
151 {
152 "interface": "net1",
153 "mac": "90:b8:d0:bd:4f:9c",
154 "vlan_id": 600,
155 "nic_tag": "internal",
156 "netmask": "255.255.255.0",
157 "ip": "10.210.1.217",
158 "ips": [
159 "dhcp"
160 ],
161 "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
162 "model": "virtio",
163 "mtu": 1500
164 }
165]
166""")
167
168SDC_NICS_MIP = json.loads("""
169[
170 {
171 "interface": "net0",
172 "mac": "90:b8:d0:ae:64:51",
173 "vlan_id": 324,
174 "nic_tag": "external",
175 "gateway": "8.12.42.1",
176 "gateways": [
177 "8.12.42.1"
178 ],
179 "netmask": "255.255.255.0",
180 "ip": "8.12.42.51",
181 "ips": [
182 "8.12.42.51/24",
183 "8.12.42.52/24"
184 ],
185 "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
186 "model": "virtio",
187 "mtu": 1500,
188 "primary": true
189 },
190 {
191 "interface": "net1",
192 "mac": "90:b8:d0:bd:4f:9c",
193 "vlan_id": 600,
194 "nic_tag": "internal",
195 "netmask": "255.255.255.0",
196 "ip": "10.210.1.217",
197 "ips": [
198 "10.210.1.217/24",
199 "10.210.1.151/24"
200 ],
201 "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
202 "model": "virtio",
203 "mtu": 1500
204 }
205]
206""")
207
208SDC_NICS_MIP_IPV6 = json.loads("""
209[
210 {
211 "interface": "net0",
212 "mac": "90:b8:d0:ae:64:51",
213 "vlan_id": 324,
214 "nic_tag": "external",
215 "gateway": "8.12.42.1",
216 "gateways": [
217 "8.12.42.1"
218 ],
219 "netmask": "255.255.255.0",
220 "ip": "8.12.42.51",
221 "ips": [
222 "2001:4800:78ff:1b:be76:4eff:fe06:96b3/64",
223 "8.12.42.51/24"
224 ],
225 "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
226 "model": "virtio",
227 "mtu": 1500,
228 "primary": true
229 },
230 {
231 "interface": "net1",
232 "mac": "90:b8:d0:bd:4f:9c",
233 "vlan_id": 600,
234 "nic_tag": "internal",
235 "netmask": "255.255.255.0",
236 "ip": "10.210.1.217",
237 "ips": [
238 "10.210.1.217/24"
239 ],
240 "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
241 "model": "virtio",
242 "mtu": 1500
243 }
244]
245""")
246
247SDC_NICS_IPV4_IPV6 = json.loads("""
248[
249 {
250 "interface": "net0",
251 "mac": "90:b8:d0:ae:64:51",
252 "vlan_id": 324,
253 "nic_tag": "external",
254 "gateway": "8.12.42.1",
255 "gateways": ["8.12.42.1", "2001::1", "2001::2"],
256 "netmask": "255.255.255.0",
257 "ip": "8.12.42.51",
258 "ips": ["2001::10/64", "8.12.42.51/24", "2001::11/64",
259 "8.12.42.52/32"],
260 "network_uuid": "992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
261 "model": "virtio",
262 "mtu": 1500,
263 "primary": true
264 },
265 {
266 "interface": "net1",
267 "mac": "90:b8:d0:bd:4f:9c",
268 "vlan_id": 600,
269 "nic_tag": "internal",
270 "netmask": "255.255.255.0",
271 "ip": "10.210.1.217",
272 "ips": ["10.210.1.217/24"],
273 "gateways": ["10.210.1.210"],
274 "network_uuid": "98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
275 "model": "virtio",
276 "mtu": 1500
277 }
278]
279""")
280
281SDC_NICS_SINGLE_GATEWAY = json.loads("""
282[
283 {
284 "interface":"net0",
285 "mac":"90:b8:d0:d8:82:b4",
286 "vlan_id":324,
287 "nic_tag":"external",
288 "gateway":"8.12.42.1",
289 "gateways":["8.12.42.1"],
290 "netmask":"255.255.255.0",
291 "ip":"8.12.42.26",
292 "ips":["8.12.42.26/24"],
293 "network_uuid":"992fc7ce-6aac-4b74-aed6-7b9d2c6c0bfe",
294 "model":"virtio",
295 "mtu":1500,
296 "primary":true
297 },
298 {
299 "interface":"net1",
300 "mac":"90:b8:d0:0a:51:31",
301 "vlan_id":600,
302 "nic_tag":"internal",
303 "netmask":"255.255.255.0",
304 "ip":"10.210.1.27",
305 "ips":["10.210.1.27/24"],
306 "network_uuid":"98657fdf-11f4-4ee2-88a4-ce7fe73e33a6",
307 "model":"virtio",
308 "mtu":1500
309 }
310]
311""")
312
313
89MOCK_RETURNS = {314MOCK_RETURNS = {
90 'hostname': 'test-host',315 'hostname': 'test-host',
91 'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname',316 'root_authorized_keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname',
@@ -524,20 +749,135 @@
524749
525750
526class TestNetworkConversion(TestCase):751class TestNetworkConversion(TestCase):
527
528 def test_convert_simple(self):752 def test_convert_simple(self):
529 expected = {753 expected = {
530 'version': 1,754 'version': 1,
531 'config': [755 'config': [
532 {'name': 'net0', 'type': 'physical',756 {'name': 'net0', 'type': 'physical',
533 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',757 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',
534 'netmask': '255.255.255.0',
535 'address': '8.12.42.102/24'}],758 'address': '8.12.42.102/24'}],
536 'mtu': 1500, 'mac_address': '90:b8:d0:f5:e4:f5'},759 'mtu': 1500, 'mac_address': '90:b8:d0:f5:e4:f5'},
537 {'name': 'net1', 'type': 'physical',760 {'name': 'net1', 'type': 'physical',
538 'subnets': [{'type': 'static', 'gateway': '192.168.128.1',761 'subnets': [{'type': 'static',
539 'netmask': '255.255.252.0',
540 'address': '192.168.128.93/22'}],762 'address': '192.168.128.93/22'}],
541 'mtu': 8500, 'mac_address': '90:b8:d0:a5:ff:cd'}]}763 'mtu': 8500, 'mac_address': '90:b8:d0:a5:ff:cd'}]}
542 found = DataSourceSmartOS.convert_smartos_network_data(SDC_NICS)764 found = convert_net(SDC_NICS)
765 self.assertEqual(expected, found)
766
767 def test_convert_simple_alt(self):
768 expected = {
769 'version': 1,
770 'config': [
771 {'name': 'net0', 'type': 'physical',
772 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',
773 'address': '8.12.42.51/24'}],
774 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'},
775 {'name': 'net1', 'type': 'physical',
776 'subnets': [{'type': 'static',
777 'address': '10.210.1.217/24'}],
778 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]}
779 found = convert_net(SDC_NICS_ALT)
780 self.assertEqual(expected, found)
781
782 def test_convert_simple_dhcp(self):
783 expected = {
784 'version': 1,
785 'config': [
786 {'name': 'net0', 'type': 'physical',
787 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',
788 'address': '8.12.42.51/24'}],
789 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'},
790 {'name': 'net1', 'type': 'physical',
791 'subnets': [{'type': 'dhcp4'}],
792 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]}
793 found = convert_net(SDC_NICS_DHCP)
794 self.assertEqual(expected, found)
795
796 def test_convert_simple_multi_ip(self):
797 expected = {
798 'version': 1,
799 'config': [
800 {'name': 'net0', 'type': 'physical',
801 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',
802 'address': '8.12.42.51/24'},
803 {'type': 'static',
804 'address': '8.12.42.52/24'}],
805 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'},
806 {'name': 'net1', 'type': 'physical',
807 'subnets': [{'type': 'static',
808 'address': '10.210.1.217/24'},
809 {'type': 'static',
810 'address': '10.210.1.151/24'}],
811 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]}
812 found = convert_net(SDC_NICS_MIP)
813 self.assertEqual(expected, found)
814
815 def test_convert_with_dns(self):
816 expected = {
817 'version': 1,
818 'config': [
819 {'name': 'net0', 'type': 'physical',
820 'subnets': [{'type': 'static', 'gateway': '8.12.42.1',
821 'address': '8.12.42.51/24'}],
822 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'},
823 {'name': 'net1', 'type': 'physical',
824 'subnets': [{'type': 'dhcp4'}],
825 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'},
826 {'type': 'nameserver',
827 'address': ['8.8.8.8', '8.8.8.1'], 'search': ["local"]}]}
828 found = convert_net(
829 network_data=SDC_NICS_DHCP, dns_servers=['8.8.8.8', '8.8.8.1'],
830 dns_domain="local")
831 self.assertEqual(expected, found)
832
833 def test_convert_simple_multi_ipv6(self):
834 expected = {
835 'version': 1,
836 'config': [
837 {'name': 'net0', 'type': 'physical',
838 'subnets': [{'type': 'static', 'address':
839 '2001:4800:78ff:1b:be76:4eff:fe06:96b3/64'},
840 {'type': 'static', 'gateway': '8.12.42.1',
841 'address': '8.12.42.51/24'}],
842 'mtu': 1500, 'mac_address': '90:b8:d0:ae:64:51'},
843 {'name': 'net1', 'type': 'physical',
844 'subnets': [{'type': 'static',
845 'address': '10.210.1.217/24'}],
846 'mtu': 1500, 'mac_address': '90:b8:d0:bd:4f:9c'}]}
847 found = convert_net(SDC_NICS_MIP_IPV6)
848 self.assertEqual(expected, found)
849
850 def test_convert_simple_both_ipv4_ipv6(self):
851 expected = {
852 'version': 1,
853 'config': [
854 {'mac_address': '90:b8:d0:ae:64:51', 'mtu': 1500,
855 'name': 'net0', 'type': 'physical',
856 'subnets': [{'address': '2001::10/64', 'gateway': '2001::1',
857 'type': 'static'},
858 {'address': '8.12.42.51/24',
859 'gateway': '8.12.42.1',
860 'type': 'static'},
861 {'address': '2001::11/64', 'type': 'static'},
862 {'address': '8.12.42.52/32', 'type': 'static'}]},
863 {'mac_address': '90:b8:d0:bd:4f:9c', 'mtu': 1500,
864 'name': 'net1', 'type': 'physical',
865 'subnets': [{'address': '10.210.1.217/24',
866 'type': 'static'}]}]}
867 found = convert_net(SDC_NICS_IPV4_IPV6)
868 self.assertEqual(expected, found)
869
870 def test_gateways_not_on_all_nics(self):
871 expected = {
872 'version': 1,
873 'config': [
874 {'mac_address': '90:b8:d0:d8:82:b4', 'mtu': 1500,
875 'name': 'net0', 'type': 'physical',
876 'subnets': [{'address': '8.12.42.26/24',
877 'gateway': '8.12.42.1', 'type': 'static'}]},
878 {'mac_address': '90:b8:d0:0a:51:31', 'mtu': 1500,
879 'name': 'net1', 'type': 'physical',
880 'subnets': [{'address': '10.210.1.27/24',
881 'type': 'static'}]}]}
882 found = convert_net(SDC_NICS_SINGLE_GATEWAY)
543 self.assertEqual(expected, found)883 self.assertEqual(expected, found)