Merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking
- subnet-creation
- Merge into networking
Status: | Merged |
---|---|
Approved by: | Raphaël Badin |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4123 |
Proposed branch: | lp:~rvb/maas/subnet-creation |
Merge into: | lp:~maas-maintainers/maas/networking |
Prerequisite: | lp:~rvb/maas/connect-interf-subnet |
Diff against target: |
151 lines (+54/-13) 5 files modified
src/maasserver/models/interface.py (+7/-3) src/maasserver/models/subnet.py (+12/-0) src/maasserver/models/tests/test_interface.py (+21/-7) src/maasserver/models/tests/test_subnet.py (+10/-0) src/metadataserver/models/tests/test_commissioningscript.py (+4/-3) |
To merge this branch: | bzr merge lp:~rvb/maas/subnet-creation |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Blake Rouse | Pending | ||
Review via email: mp+265415@code.launchpad.net |
This proposal supersedes a proposal from 2015-07-20.
Commit message
During commissioning, create unknown Subnets.
Description of the change
Blake Rouse (blake-rouse) wrote : Posted in a previous version of this proposal | # |
Raphaël Badin (rvb) : Posted in a previous version of this proposal | # |
Raphaël Badin (rvb) wrote : | # |
Just changed the target branch. Self-approving.
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Hit http://
Ign http://
Hit http://
Get:1 http://
Hit http://
Get:2 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:3 http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,270 kB in 3s (342 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Hit http://
Ign http://
Hit http://
Get:1 http://
Hit http://
Get:2 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Get:3 http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Hit http://
Fetched 1,270 kB in 3s (348 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking failed. Below is the output from the failed tests.
Ign http://
Hit http://
Hit http://
Ign http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/subnet-creation into lp:~maas-maintainers/maas/networking failed. Below is the output from the failed tests.
Ign http://
Hit http://
Hit http://
Ign http://
Ign http://
Hit http://
Get:1 http://
Hit http://
Get:2 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Get:3 http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Hit http://
Fetched 1,270 kB in 9s (140 kB/s)
Reading package lists...
sudo DEBIAN_
--
Preview Diff
1 | === modified file 'src/maasserver/models/interface.py' |
2 | --- src/maasserver/models/interface.py 2015-07-20 09:03:26 +0000 |
3 | +++ src/maasserver/models/interface.py 2015-07-22 10:47:10 +0000 |
4 | @@ -42,6 +42,7 @@ |
5 | VerboseRegexValidator, |
6 | ) |
7 | from maasserver.models.cleansave import CleanSave |
8 | +from maasserver.models.space import Space |
9 | from maasserver.models.timestampedmodel import TimestampedModel |
10 | from netaddr import IPNetwork |
11 | from provisioningserver.logger import get_maas_logger |
12 | @@ -140,10 +141,13 @@ |
13 | try: |
14 | subnet = Subnet.objects.get(cidr=cidr, vlan__fabric=fabric) |
15 | except Subnet.DoesNotExist: |
16 | - maaslog.warning( |
17 | - "Skipping unknown subnet %s connected to interface %s " |
18 | + vlan = fabric.get_default_vlan() |
19 | + space = Space.objects.get_default_space() |
20 | + subnet = Subnet.objects.create_from_cidr( |
21 | + cidr=cidr, vlan=vlan, space=space) |
22 | + maaslog.info( |
23 | + "Creating subnet %s connected to interface %s " |
24 | "of node %s.", cidr, self, self.get_node()) |
25 | - continue |
26 | |
27 | # This code needs to deal with both: |
28 | # - legacy statically configured IPs (subnet=None, mac=mac) for |
29 | |
30 | === modified file 'src/maasserver/models/subnet.py' |
31 | --- src/maasserver/models/subnet.py 2015-06-26 01:03:50 +0000 |
32 | +++ src/maasserver/models/subnet.py 2015-07-22 10:47:10 +0000 |
33 | @@ -22,6 +22,7 @@ |
34 | from django.db.models import ( |
35 | CharField, |
36 | ForeignKey, |
37 | + Manager, |
38 | PROTECT, |
39 | ) |
40 | from djorm_pgarray.fields import ArrayField |
41 | @@ -46,6 +47,15 @@ |
42 | return VLAN.objects.get_default_vlan() |
43 | |
44 | |
45 | +class SubnetManager(Manager): |
46 | + """Manager for :class:`Subnet` model.""" |
47 | + |
48 | + def create_from_cidr(self, cidr, vlan, space): |
49 | + """Create a subnet from the given CIDR.""" |
50 | + name = "subnet-" + unicode(cidr) |
51 | + return self.create(name=name, cidr=cidr, vlan=vlan, space=space) |
52 | + |
53 | + |
54 | class Subnet(CleanSave, TimestampedModel): |
55 | |
56 | class Meta(DefaultMeta): |
57 | @@ -54,6 +64,8 @@ |
58 | ('name', 'space'), |
59 | ) |
60 | |
61 | + objects = SubnetManager() |
62 | + |
63 | name = CharField( |
64 | blank=False, editable=True, max_length=255, |
65 | validators=[SUBNET_NAME_VALIDATOR], |
66 | |
67 | === modified file 'src/maasserver/models/tests/test_interface.py' |
68 | --- src/maasserver/models/tests/test_interface.py 2015-07-17 11:14:36 +0000 |
69 | +++ src/maasserver/models/tests/test_interface.py 2015-07-22 10:47:10 +0000 |
70 | @@ -20,7 +20,10 @@ |
71 | IPADDRESS_TYPE, |
72 | ) |
73 | from maasserver.models import ( |
74 | + Fabric, |
75 | MACAddress, |
76 | + Space, |
77 | + Subnet, |
78 | VLAN, |
79 | ) |
80 | from maasserver.models.interface import ( |
81 | @@ -192,16 +195,27 @@ |
82 | |
83 | class UpdateIpAddressesTest(MAASServerTestCase): |
84 | |
85 | - def test__ignores_missing_subnet(self): |
86 | + def test__creates_missing_subnet(self): |
87 | mac = factory.make_MACAddress_with_Node() |
88 | interface = factory.make_Interface( |
89 | mac=mac, type=INTERFACE_TYPE.PHYSICAL) |
90 | - cidr_list = [ |
91 | - unicode(factory.make_ip4_or_6_network()) for _ in range(3)] |
92 | - |
93 | - interface.update_ip_addresses(cidr_list) |
94 | - |
95 | - self.assertItemsEqual([], interface.ip_addresses.all()) |
96 | + network = factory.make_ip4_or_6_network() |
97 | + cidr = unicode(network) |
98 | + address = unicode(network.ip) |
99 | + interface.update_ip_addresses([cidr]) |
100 | + |
101 | + default_fabric = Fabric.objects.get_default_fabric() |
102 | + default_space = Space.objects.get_default_space() |
103 | + subnets = Subnet.objects.filter( |
104 | + cidr=unicode(network.cidr), vlan__fabric=default_fabric, |
105 | + space=default_space) |
106 | + self.assertEqual(1, len(subnets)) |
107 | + self.assertEqual(1, interface.ip_addresses.count()) |
108 | + self.assertThat( |
109 | + interface.ip_addresses.first(), |
110 | + MatchesStructure.byEquality( |
111 | + alloc_type=IPADDRESS_TYPE.DHCP, subnet=subnets[0], |
112 | + ip=address)) |
113 | |
114 | def test__creates_dhcp_ip_addresses(self): |
115 | mac = factory.make_MACAddress_with_Node() |
116 | |
117 | === modified file 'src/maasserver/models/tests/test_subnet.py' |
118 | --- src/maasserver/models/tests/test_subnet.py 2015-06-19 09:53:30 +0000 |
119 | +++ src/maasserver/models/tests/test_subnet.py 2015-07-22 10:47:10 +0000 |
120 | @@ -52,3 +52,13 @@ |
121 | self.assertEqual( |
122 | {'gateway_ip': ["Gateway IP must be within CIDR range."]}, |
123 | error.message_dict) |
124 | + |
125 | + def test_create_from_cidr_creates_subnet(self): |
126 | + vlan = factory.make_VLAN() |
127 | + cidr = unicode(factory.make_ip4_or_6_network().cidr) |
128 | + space = factory.make_Space() |
129 | + name = "subnet-" + cidr |
130 | + subnet = Subnet.objects.create_from_cidr(cidr, vlan, space) |
131 | + self.assertThat(subnet, MatchesStructure.byEquality( |
132 | + name=name, vlan=vlan, cidr=cidr, space=space, |
133 | + gateway_ip=None, dns_servers=[])) |
134 | |
135 | === modified file 'src/metadataserver/models/tests/test_commissioningscript.py' |
136 | --- src/metadataserver/models/tests/test_commissioningscript.py 2015-07-16 15:44:24 +0000 |
137 | +++ src/metadataserver/models/tests/test_commissioningscript.py 2015-07-22 10:47:10 +0000 |
138 | @@ -1413,9 +1413,10 @@ |
139 | |
140 | update_node_network_information(node, self.IP_ADDR_OUTPUT, 0) |
141 | eth0 = Interface.objects.get(mac__node=node, name='eth0') |
142 | - self.assertEqual(1, eth0.ip_addresses.count()) |
143 | + address = unicode(IPNetwork(cidr).ip) |
144 | + ipv4_ip = eth0.ip_addresses.get(ip=address) |
145 | self.assertThat( |
146 | - eth0.ip_addresses.first(), |
147 | + ipv4_ip, |
148 | MatchesStructure.byEquality( |
149 | alloc_type=IPADDRESS_TYPE.DHCP, subnet=subnet, |
150 | - ip=unicode(IPNetwork(cidr).ip))) |
151 | + ip=address)) |
Looks good. Other than the comment below.