ipaddr filter - return a network address when given an address with /32 subnet (#47539)

* fix #17872

* add changelog fragment and enable unit test
pull/48360/head
Jack Haden-Enneking 6 years ago committed by Sam Doran
parent 6ec820e264
commit 15e77ebfe8

@ -0,0 +1,2 @@
bugfixes:
- ipaddr - fix issue where network address was blank for 0-size networks (https://github.com/ansible/ansible/issues/17872)

@ -249,7 +249,6 @@ def _netmask_query(v):
def _network_query(v):
'''Return the network of a given IP or subnet'''
if v.size > 1:
return str(v.network)

@ -38,15 +38,14 @@ class TestIpFilter(unittest.TestCase):
self.assertEqual(ipaddr(address, 'netmask'), '255.255.255.255')
def test_network(self):
# Unfixable in current state
# address = '1.12.1.34/32'
# self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
# address = '1.12.1.34/255.255.255.255'
# self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
# address = '1.12.1.34'
# self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
# address = '1.12.1.35/31'
# self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
address = '1.12.1.34/32'
self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
address = '1.12.1.34/255.255.255.255'
self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
address = '1.12.1.34'
self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
address = '1.12.1.35/31'
self.assertEqual(ipaddr(address, 'network'), '1.12.1.34')
address = '1.12.1.34/24'
self.assertEqual(ipaddr(address, 'network'), '1.12.1.0')

Loading…
Cancel
Save