Merge lp:~mpontillo/maas/netplan--part2--tests into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Superseded
Proposed branch: lp:~mpontillo/maas/netplan--part2--tests
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~mpontillo/maas/netplan--part2
Diff against target: 186 lines (+171/-1)
1 file modified
src/maasserver/tests/test_preseed_network.py (+171/-1)
To merge this branch: bzr merge lp:~mpontillo/maas/netplan--part2--tests
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+317715@code.launchpad.net

This proposal has been superseded by a proposal from 2017-03-06.

Commit message

Implement tests for Netplan YAML.Support netplan (v2 YAML) rendering in the network preseed generator.

Drive-by fix to allow preseed YAML to be rendered for nodes with NULL IP addresses (such as AUTO addresses that have not been assigned yet) to be rendered (without those addresses). It would be nice if a special syntax existed for "TBD" addresses, so we could show these for debugging purposes.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/tests/test_preseed_network.py'
--- src/maasserver/tests/test_preseed_network.py 2017-02-22 14:55:09 +0000
+++ src/maasserver/tests/test_preseed_network.py 2017-03-06 09:05:41 +0000
@@ -16,7 +16,10 @@
16 IPADDRESS_TYPE,16 IPADDRESS_TYPE,
17)17)
18from maasserver.models.staticroute import StaticRoute18from maasserver.models.staticroute import StaticRoute
19from maasserver.preseed_network import compose_curtin_network_config19from maasserver.preseed_network import (
20 compose_curtin_network_config,
21 NodeNetworkConfiguration,
22)
20from maasserver.testing.factory import factory23from maasserver.testing.factory import factory
21from maasserver.testing.testcase import MAASServerTestCase24from maasserver.testing.testcase import MAASServerTestCase
22from netaddr import IPNetwork25from netaddr import IPNetwork
@@ -461,3 +464,170 @@
461 net_config += self.collectDNSConfig(node)464 net_config += self.collectDNSConfig(node)
462 config = compose_curtin_network_config(node)465 config = compose_curtin_network_config(node)
463 self.assertNetworkConfig(net_config, config)466 self.assertNetworkConfig(net_config, config)
467
468
469class TestNetplan(MAASServerTestCase):
470
471 def _render_netplan_dict(self, node):
472 return NodeNetworkConfiguration(node, version=2).config
473
474 def test__single_ethernet_interface(self):
475 node = factory.make_Node()
476 factory.make_Interface(
477 node=node, name='eth0', mac_address="00:01:02:03:04:05")
478 netplan = self._render_netplan_dict(node)
479 expected_netplan = {
480 'network': {
481 'version': 2,
482 'ethernets': {
483 'eth0': {
484 'match': {'macaddress': '00:01:02:03:04:05'},
485 'mtu': 1500,
486 'set-name': 'eth0'
487 },
488 },
489 }
490 }
491 self.expectThat(netplan, Equals(expected_netplan))
492
493 def test__multiple_ethernet_interfaces(self):
494 node = factory.make_Node()
495 factory.make_Interface(
496 node=node, name='eth0', mac_address="00:01:02:03:04:05")
497 factory.make_Interface(
498 node=node, name='eth1', mac_address="02:01:02:03:04:05")
499 netplan = self._render_netplan_dict(node)
500 expected_netplan = {
501 'network': {
502 'version': 2,
503 'ethernets': {
504 'eth0': {
505 'match': {'macaddress': '00:01:02:03:04:05'},
506 'mtu': 1500,
507 'set-name': 'eth0'
508 },
509 'eth1': {
510 'match': {'macaddress': '02:01:02:03:04:05'},
511 'mtu': 1500,
512 'set-name': 'eth1'
513 },
514 },
515 },
516 }
517 self.expectThat(netplan, Equals(expected_netplan))
518
519 def test__bond(self):
520 node = factory.make_Node()
521 eth0 = factory.make_Interface(
522 node=node, name='eth0', mac_address="00:01:02:03:04:05")
523 eth1 = factory.make_Interface(
524 node=node, name='eth1', mac_address="02:01:02:03:04:05")
525 factory.make_Interface(
526 INTERFACE_TYPE.BOND,
527 node=node, name='bond0', parents=[eth0, eth1])
528 netplan = self._render_netplan_dict(node)
529 expected_netplan = {
530 'network': {
531 'version': 2,
532 'ethernets': {
533 'eth0': {
534 'match': {'macaddress': '00:01:02:03:04:05'},
535 'mtu': 1500,
536 'set-name': 'eth0'
537 },
538 'eth1': {
539 'match': {'macaddress': '02:01:02:03:04:05'},
540 'mtu': 1500,
541 'set-name': 'eth1'
542 },
543 },
544 'bonds': {
545 'bond0': {
546 'interfaces': ['eth0', 'eth1'],
547 'mtu': 1500
548 },
549 },
550 }
551 }
552 self.expectThat(netplan, Equals(expected_netplan))
553
554 def test__bridge(self):
555 node = factory.make_Node()
556 eth0 = factory.make_Interface(
557 node=node, name='eth0', mac_address="00:01:02:03:04:05")
558 eth1 = factory.make_Interface(
559 node=node, name='eth1', mac_address="02:01:02:03:04:05")
560 factory.make_Interface(
561 INTERFACE_TYPE.BRIDGE,
562 node=node, name='br0', parents=[eth0, eth1])
563 netplan = self._render_netplan_dict(node)
564 expected_netplan = {
565 'network': {
566 'version': 2,
567 'ethernets': {
568 'eth0': {
569 'match': {'macaddress': '00:01:02:03:04:05'},
570 'mtu': 1500,
571 'set-name': 'eth0'
572 },
573 'eth1': {
574 'match': {'macaddress': '02:01:02:03:04:05'},
575 'mtu': 1500,
576 'set-name': 'eth1'
577 },
578 },
579 'bridges': {
580 'br0': {
581 'interfaces': ['eth0', 'eth1'],
582 'mtu': 1500
583 },
584 },
585 }
586 }
587 self.expectThat(netplan, Equals(expected_netplan))
588
589 def test__bridged_bond(self):
590 node = factory.make_Node()
591 eth0 = factory.make_Interface(
592 node=node, name='eth0', mac_address="00:01:02:03:04:05")
593 eth1 = factory.make_Interface(
594 node=node, name='eth1', mac_address="02:01:02:03:04:05")
595 bond0 = factory.make_Interface(
596 INTERFACE_TYPE.BOND,
597 node=node, name='bond0', parents=[eth0, eth1])
598 factory.make_Interface(
599 INTERFACE_TYPE.BRIDGE,
600 node=node, name='br0', parents=[bond0])
601 netplan = self._render_netplan_dict(node)
602 expected_netplan = {
603 'network': {
604 'version': 2,
605 'ethernets': {
606 'eth0': {
607 'match': {'macaddress': '00:01:02:03:04:05'},
608 'mtu': 1500,
609 'set-name': 'eth0'
610 },
611 'eth1': {
612 'match': {'macaddress': '02:01:02:03:04:05'},
613 'mtu': 1500,
614 'set-name': 'eth1'
615 },
616 },
617 'bonds': {
618 'bond0': {
619 'interfaces': ['eth0', 'eth1'],
620 'mtu': 1500
621 },
622 },
623 'bridges': {
624 'br0': {
625 'interfaces': ['bond0'],
626 'mtu': 1500
627 },
628 },
629 }
630 }
631 self.expectThat(netplan, Equals(expected_netplan))
632
633