Merge lp:~mpontillo/maas/view-current-gateway--bug-1674807--2.1 into lp:maas/2.1

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 5599
Proposed branch: lp:~mpontillo/maas/view-current-gateway--bug-1674807--2.1
Merge into: lp:maas/2.1
Diff against target: 188 lines (+123/-2)
4 files modified
docs/changelog.rst (+3/-1)
src/maasserver/api/machines.py (+18/-0)
src/maasserver/api/tests/test_enlistment.py (+2/-0)
src/maasserver/api/tests/test_machine.py (+100/-1)
To merge this branch: bzr merge lp:~mpontillo/maas/view-current-gateway--bug-1674807--2.1
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+321499@code.launchpad.net

Commit message

Allow viewing the currently-set default gateways for a machine using the API.

 * Merges revision 5895 from trunk to fix bug #1674807.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Self-approve backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'docs/changelog.rst'
--- docs/changelog.rst 2017-03-30 17:18:49 +0000
+++ docs/changelog.rst 2017-03-30 23:38:15 +0000
@@ -8,7 +8,9 @@
8Bugs fixed in this release8Bugs fixed in this release
9--------------------------9--------------------------
1010
11LP: ##1677507 Fix potential IP allocation from incorrect range.11LP: #1677507 Fix potential IP allocation from incorrect range.
12
13LP: #1674807 Fix missing default_gateways entry in machine API output.
1214
1315
142.1.5162.1.5
1517
=== modified file 'src/maasserver/api/machines.py'
--- src/maasserver/api/machines.py 2016-12-09 07:07:02 +0000
+++ src/maasserver/api/machines.py 2017-03-30 23:38:15 +0000
@@ -125,6 +125,7 @@
125 'node_type',125 'node_type',
126 'node_type_name',126 'node_type_name',
127 'special_filesystems',127 'special_filesystems',
128 'default_gateways',
128)129)
129130
130# Limited set of machine fields exposed on the anonymous API.131# Limited set of machine fields exposed on the anonymous API.
@@ -185,6 +186,23 @@
185 """The network interface which is used to boot over the network."""186 """The network interface which is used to boot over the network."""
186 return machine.get_boot_interface()187 return machine.get_boot_interface()
187188
189 @classmethod
190 def default_gateways(handler, machine):
191 """The default gateways that will be used for this machine."""
192 gateways = machine.get_default_gateways()
193 ipv4 = gateways.ipv4.gateway_ip if gateways.ipv4 is not None else None
194 ipv6 = gateways.ipv6.gateway_ip if gateways.ipv6 is not None else None
195 return {
196 "ipv4": {
197 "gateway_ip": ipv4,
198 "link_id": machine.gateway_link_ipv4_id,
199 },
200 "ipv6": {
201 "gateway_ip": ipv6,
202 "link_id": machine.gateway_link_ipv6_id,
203 }
204 }
205
188 @admin_method206 @admin_method
189 def update(self, request, system_id):207 def update(self, request, system_id):
190 """Update a specific Machine.208 """Update a specific Machine.
191209
=== modified file 'src/maasserver/api/tests/test_enlistment.py'
--- src/maasserver/api/tests/test_enlistment.py 2016-10-20 19:41:25 +0000
+++ src/maasserver/api/tests/test_enlistment.py 2017-03-30 23:38:15 +0000
@@ -493,6 +493,7 @@
493 self.assertItemsEqual(493 self.assertItemsEqual(
494 [494 [
495 'hostname',495 'hostname',
496 'default_gateways',
496 'domain',497 'domain',
497 'fqdn',498 'fqdn',
498 'owner',499 'owner',
@@ -652,6 +653,7 @@
652 self.assertItemsEqual(653 self.assertItemsEqual(
653 [654 [
654 'hostname',655 'hostname',
656 'default_gateways',
655 'domain',657 'domain',
656 'fqdn',658 'fqdn',
657 'owner',659 'owner',
658660
=== modified file 'src/maasserver/api/tests/test_machine.py'
--- src/maasserver/api/tests/test_machine.py 2016-10-28 08:43:09 +0000
+++ src/maasserver/api/tests/test_machine.py 2017-03-30 23:38:15 +0000
@@ -1830,7 +1830,7 @@
1830 "using status %d" % status)1830 "using status %d" % status)
18311831
18321832
1833class TestClearDefaultGateways(APITestCase.ForUser):1833class TestDefaultGateways(APITestCase.ForUser):
18341834
1835 def get_machine_uri(self, machine):1835 def get_machine_uri(self, machine):
1836 """Get the API URI for `machine`."""1836 """Get the API URI for `machine`."""
@@ -1873,6 +1873,105 @@
1873 self.assertIsNone(machine.gateway_link_ipv4)1873 self.assertIsNone(machine.gateway_link_ipv4)
1874 self.assertIsNone(machine.gateway_link_ipv6)1874 self.assertIsNone(machine.gateway_link_ipv6)
18751875
1876 def test__returns_null_gateway_if_no_explicit_gateway_exists(self):
1877 machine = factory.make_Node(
1878 owner=self.user, status=NODE_STATUS.ALLOCATED)
1879 interface = factory.make_Interface(
1880 INTERFACE_TYPE.PHYSICAL, node=machine)
1881 network_v4 = factory.make_ipv4_network()
1882 subnet_v4 = factory.make_Subnet(
1883 cidr=str(network_v4.cidr), vlan=interface.vlan, gateway_ip=None)
1884 factory.make_StaticIPAddress(
1885 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1886 subnet=subnet_v4, interface=interface)
1887 network_v6 = factory.make_ipv6_network()
1888 subnet_v6 = factory.make_Subnet(
1889 cidr=str(network_v6.cidr), vlan=interface.vlan, gateway_ip=None)
1890 factory.make_StaticIPAddress(
1891 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1892 subnet=subnet_v6, interface=interface)
1893 response = self.client.get(self.get_machine_uri(machine))
1894 self.assertEqual(
1895 http.client.OK, response.status_code, response.content)
1896 response = json_load_bytes(response.content)
1897 self.assertThat(response['default_gateways'], Equals({
1898 "ipv4": {
1899 "link_id": None,
1900 "gateway_ip": None,
1901 },
1902 "ipv6": {
1903 "link_id": None,
1904 "gateway_ip": None,
1905 },
1906 }))
1907
1908 def test__returns_effective_gateway_if_no_explicit_gateway_set(self):
1909 machine = factory.make_Node(
1910 owner=self.user, status=NODE_STATUS.ALLOCATED)
1911 interface = factory.make_Interface(
1912 INTERFACE_TYPE.PHYSICAL, node=machine)
1913 network_v4 = factory.make_ipv4_network()
1914 subnet_v4 = factory.make_Subnet(
1915 cidr=str(network_v4.cidr), vlan=interface.vlan)
1916 factory.make_StaticIPAddress(
1917 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1918 subnet=subnet_v4, interface=interface)
1919 network_v6 = factory.make_ipv6_network()
1920 subnet_v6 = factory.make_Subnet(
1921 cidr=str(network_v6.cidr), vlan=interface.vlan)
1922 factory.make_StaticIPAddress(
1923 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1924 subnet=subnet_v6, interface=interface)
1925 response = self.client.get(self.get_machine_uri(machine))
1926 self.assertEqual(
1927 http.client.OK, response.status_code, response.content)
1928 response = json_load_bytes(response.content)
1929 self.assertThat(response['default_gateways'], Equals({
1930 "ipv4": {
1931 "link_id": None,
1932 "gateway_ip": str(subnet_v4.gateway_ip),
1933 },
1934 "ipv6": {
1935 "link_id": None,
1936 "gateway_ip": str(subnet_v6.gateway_ip),
1937 },
1938 }))
1939
1940 def test__returns_links_if_set(self):
1941 machine = factory.make_Node(
1942 owner=self.user, status=NODE_STATUS.ALLOCATED)
1943 interface = factory.make_Interface(
1944 INTERFACE_TYPE.PHYSICAL, node=machine)
1945 network_v4 = factory.make_ipv4_network()
1946 subnet_v4 = factory.make_Subnet(
1947 cidr=str(network_v4.cidr), vlan=interface.vlan)
1948 link_v4 = factory.make_StaticIPAddress(
1949 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1950 subnet=subnet_v4, interface=interface)
1951 machine.gateway_link_ipv4 = link_v4
1952 network_v6 = factory.make_ipv6_network()
1953 subnet_v6 = factory.make_Subnet(
1954 cidr=str(network_v6.cidr), vlan=interface.vlan)
1955 link_v6 = factory.make_StaticIPAddress(
1956 alloc_type=IPADDRESS_TYPE.AUTO, ip="",
1957 subnet=subnet_v6, interface=interface)
1958 machine.gateway_link_ipv6 = link_v6
1959 machine.save()
1960 response = self.client.get(self.get_machine_uri(machine))
1961 self.assertEqual(
1962 http.client.OK, response.status_code, response.content)
1963 response = json_load_bytes(response.content)
1964 self.assertThat(response['default_gateways'], Equals({
1965 "ipv4": {
1966 "link_id": link_v4.id,
1967 "gateway_ip": str(subnet_v4.gateway_ip),
1968 },
1969 "ipv6": {
1970 "link_id": link_v6.id,
1971 "gateway_ip": str(subnet_v6.gateway_ip),
1972 },
1973 }))
1974
18761975
1877class TestGetCurtinConfig(APITestCase.ForUser):1976class TestGetCurtinConfig(APITestCase.ForUser):
18781977

Subscribers

People subscribed via source and target branches

to all changes: