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

* fix #17872

* add changelog fragment and enable unit test
This commit is contained in:
Jack Haden-Enneking 2018-11-08 08:49:42 -08:00 committed by Sam Doran
parent 6ec820e264
commit 15e77ebfe8
3 changed files with 11 additions and 11 deletions

View file

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

View file

@ -249,8 +249,7 @@ 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)
return str(v.network)
def _network_id_query(v):

View file

@ -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')