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 | 42 | VerboseRegexValidator, | 42 | VerboseRegexValidator, |
6 | 43 | ) | 43 | ) |
7 | 44 | from maasserver.models.cleansave import CleanSave | 44 | from maasserver.models.cleansave import CleanSave |
8 | 45 | from maasserver.models.space import Space | ||
9 | 45 | from maasserver.models.timestampedmodel import TimestampedModel | 46 | from maasserver.models.timestampedmodel import TimestampedModel |
10 | 46 | from netaddr import IPNetwork | 47 | from netaddr import IPNetwork |
11 | 47 | from provisioningserver.logger import get_maas_logger | 48 | from provisioningserver.logger import get_maas_logger |
12 | @@ -140,10 +141,13 @@ | |||
13 | 140 | try: | 141 | try: |
14 | 141 | subnet = Subnet.objects.get(cidr=cidr, vlan__fabric=fabric) | 142 | subnet = Subnet.objects.get(cidr=cidr, vlan__fabric=fabric) |
15 | 142 | except Subnet.DoesNotExist: | 143 | except Subnet.DoesNotExist: |
18 | 143 | maaslog.warning( | 144 | vlan = fabric.get_default_vlan() |
19 | 144 | "Skipping unknown subnet %s connected to interface %s " | 145 | space = Space.objects.get_default_space() |
20 | 146 | subnet = Subnet.objects.create_from_cidr( | ||
21 | 147 | cidr=cidr, vlan=vlan, space=space) | ||
22 | 148 | maaslog.info( | ||
23 | 149 | "Creating subnet %s connected to interface %s " | ||
24 | 145 | "of node %s.", cidr, self, self.get_node()) | 150 | "of node %s.", cidr, self, self.get_node()) |
25 | 146 | continue | ||
26 | 147 | 151 | ||
27 | 148 | # This code needs to deal with both: | 152 | # This code needs to deal with both: |
28 | 149 | # - legacy statically configured IPs (subnet=None, mac=mac) for | 153 | # - legacy statically configured IPs (subnet=None, mac=mac) for |
29 | 150 | 154 | ||
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 | 22 | from django.db.models import ( | 22 | from django.db.models import ( |
35 | 23 | CharField, | 23 | CharField, |
36 | 24 | ForeignKey, | 24 | ForeignKey, |
37 | 25 | Manager, | ||
38 | 25 | PROTECT, | 26 | PROTECT, |
39 | 26 | ) | 27 | ) |
40 | 27 | from djorm_pgarray.fields import ArrayField | 28 | from djorm_pgarray.fields import ArrayField |
41 | @@ -46,6 +47,15 @@ | |||
42 | 46 | return VLAN.objects.get_default_vlan() | 47 | return VLAN.objects.get_default_vlan() |
43 | 47 | 48 | ||
44 | 48 | 49 | ||
45 | 50 | class SubnetManager(Manager): | ||
46 | 51 | """Manager for :class:`Subnet` model.""" | ||
47 | 52 | |||
48 | 53 | def create_from_cidr(self, cidr, vlan, space): | ||
49 | 54 | """Create a subnet from the given CIDR.""" | ||
50 | 55 | name = "subnet-" + unicode(cidr) | ||
51 | 56 | return self.create(name=name, cidr=cidr, vlan=vlan, space=space) | ||
52 | 57 | |||
53 | 58 | |||
54 | 49 | class Subnet(CleanSave, TimestampedModel): | 59 | class Subnet(CleanSave, TimestampedModel): |
55 | 50 | 60 | ||
56 | 51 | class Meta(DefaultMeta): | 61 | class Meta(DefaultMeta): |
57 | @@ -54,6 +64,8 @@ | |||
58 | 54 | ('name', 'space'), | 64 | ('name', 'space'), |
59 | 55 | ) | 65 | ) |
60 | 56 | 66 | ||
61 | 67 | objects = SubnetManager() | ||
62 | 68 | |||
63 | 57 | name = CharField( | 69 | name = CharField( |
64 | 58 | blank=False, editable=True, max_length=255, | 70 | blank=False, editable=True, max_length=255, |
65 | 59 | validators=[SUBNET_NAME_VALIDATOR], | 71 | validators=[SUBNET_NAME_VALIDATOR], |
66 | 60 | 72 | ||
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 | 20 | IPADDRESS_TYPE, | 20 | IPADDRESS_TYPE, |
72 | 21 | ) | 21 | ) |
73 | 22 | from maasserver.models import ( | 22 | from maasserver.models import ( |
74 | 23 | Fabric, | ||
75 | 23 | MACAddress, | 24 | MACAddress, |
76 | 25 | Space, | ||
77 | 26 | Subnet, | ||
78 | 24 | VLAN, | 27 | VLAN, |
79 | 25 | ) | 28 | ) |
80 | 26 | from maasserver.models.interface import ( | 29 | from maasserver.models.interface import ( |
81 | @@ -192,16 +195,27 @@ | |||
82 | 192 | 195 | ||
83 | 193 | class UpdateIpAddressesTest(MAASServerTestCase): | 196 | class UpdateIpAddressesTest(MAASServerTestCase): |
84 | 194 | 197 | ||
86 | 195 | def test__ignores_missing_subnet(self): | 198 | def test__creates_missing_subnet(self): |
87 | 196 | mac = factory.make_MACAddress_with_Node() | 199 | mac = factory.make_MACAddress_with_Node() |
88 | 197 | interface = factory.make_Interface( | 200 | interface = factory.make_Interface( |
89 | 198 | mac=mac, type=INTERFACE_TYPE.PHYSICAL) | 201 | mac=mac, type=INTERFACE_TYPE.PHYSICAL) |
96 | 199 | cidr_list = [ | 202 | network = factory.make_ip4_or_6_network() |
97 | 200 | unicode(factory.make_ip4_or_6_network()) for _ in range(3)] | 203 | cidr = unicode(network) |
98 | 201 | 204 | address = unicode(network.ip) | |
99 | 202 | interface.update_ip_addresses(cidr_list) | 205 | interface.update_ip_addresses([cidr]) |
100 | 203 | 206 | ||
101 | 204 | self.assertItemsEqual([], interface.ip_addresses.all()) | 207 | default_fabric = Fabric.objects.get_default_fabric() |
102 | 208 | default_space = Space.objects.get_default_space() | ||
103 | 209 | subnets = Subnet.objects.filter( | ||
104 | 210 | cidr=unicode(network.cidr), vlan__fabric=default_fabric, | ||
105 | 211 | space=default_space) | ||
106 | 212 | self.assertEqual(1, len(subnets)) | ||
107 | 213 | self.assertEqual(1, interface.ip_addresses.count()) | ||
108 | 214 | self.assertThat( | ||
109 | 215 | interface.ip_addresses.first(), | ||
110 | 216 | MatchesStructure.byEquality( | ||
111 | 217 | alloc_type=IPADDRESS_TYPE.DHCP, subnet=subnets[0], | ||
112 | 218 | ip=address)) | ||
113 | 205 | 219 | ||
114 | 206 | def test__creates_dhcp_ip_addresses(self): | 220 | def test__creates_dhcp_ip_addresses(self): |
115 | 207 | mac = factory.make_MACAddress_with_Node() | 221 | mac = factory.make_MACAddress_with_Node() |
116 | 208 | 222 | ||
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 | 52 | self.assertEqual( | 52 | self.assertEqual( |
122 | 53 | {'gateway_ip': ["Gateway IP must be within CIDR range."]}, | 53 | {'gateway_ip': ["Gateway IP must be within CIDR range."]}, |
123 | 54 | error.message_dict) | 54 | error.message_dict) |
124 | 55 | |||
125 | 56 | def test_create_from_cidr_creates_subnet(self): | ||
126 | 57 | vlan = factory.make_VLAN() | ||
127 | 58 | cidr = unicode(factory.make_ip4_or_6_network().cidr) | ||
128 | 59 | space = factory.make_Space() | ||
129 | 60 | name = "subnet-" + cidr | ||
130 | 61 | subnet = Subnet.objects.create_from_cidr(cidr, vlan, space) | ||
131 | 62 | self.assertThat(subnet, MatchesStructure.byEquality( | ||
132 | 63 | name=name, vlan=vlan, cidr=cidr, space=space, | ||
133 | 64 | gateway_ip=None, dns_servers=[])) | ||
134 | 55 | 65 | ||
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 | 1413 | 1413 | ||
140 | 1414 | update_node_network_information(node, self.IP_ADDR_OUTPUT, 0) | 1414 | update_node_network_information(node, self.IP_ADDR_OUTPUT, 0) |
141 | 1415 | eth0 = Interface.objects.get(mac__node=node, name='eth0') | 1415 | eth0 = Interface.objects.get(mac__node=node, name='eth0') |
143 | 1416 | self.assertEqual(1, eth0.ip_addresses.count()) | 1416 | address = unicode(IPNetwork(cidr).ip) |
144 | 1417 | ipv4_ip = eth0.ip_addresses.get(ip=address) | ||
145 | 1417 | self.assertThat( | 1418 | self.assertThat( |
147 | 1418 | eth0.ip_addresses.first(), | 1419 | ipv4_ip, |
148 | 1419 | MatchesStructure.byEquality( | 1420 | MatchesStructure.byEquality( |
149 | 1420 | alloc_type=IPADDRESS_TYPE.DHCP, subnet=subnet, | 1421 | alloc_type=IPADDRESS_TYPE.DHCP, subnet=subnet, |
151 | 1421 | ip=unicode(IPNetwork(cidr).ip))) | 1422 | ip=address)) |
Looks good. Other than the comment below.