def test_non_dict(self): errors = validation.check_allocation_pools_pairing(None, {}) self.assertEqual(len(errors), 1) self.assertEqual('The `filedata` argument must be a dictionary.', errors[0]) errors = validation.check_allocation_pools_pairing({}, None) self.assertEqual(len(errors), 1) self.assertEqual('The `pools` argument must be a dictionary.', errors[0])
def test_multiple_ranges_and_pools(self): filedata = { 'StorageNetCidr': '172.18.0.0/24', 'TenantNetCidr': '172.16.0.0/24', } pools = { 'StorageAllocationPools': [ { 'start': '172.18.0.10', 'end': '172.18.0.20' }, { 'start': '172.18.0.100', 'end': '172.18.0.200' }, ], 'TenantAllocationPools': [ { 'start': '172.16.0.20', 'end': '172.16.0.30' }, { 'start': '172.16.0.70', 'end': '172.16.0.80' }, ], } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual([], errors)
def _test_pool_invalid_range(self, addr_range): filedata = {'TestNetCidr': '172.18.0.0/24'} pools = {'TestAllocationPools': [addr_range]} errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual(len(errors), 1) self.assertEqual( 'Invalid format of the IP range in' ' TestAllocationPools: {}'.format(addr_range), errors[0])
def test_pool_with_correct_range(self): filedata = { 'StorageNetCidr': '172.18.0.0/24', } pools = { 'StorageAllocationPools': [{ 'start': '172.18.0.10', 'end': '172.18.0.200' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual([], errors)
def test_pool_outside_cidr_ipv6(self): filedata = { 'StorageNetCidr': 'fd00:fd00:fd00:3000::10/125', } pools = { 'StorageAllocationPools': [{ 'start': 'fd00:fd00:fd00:3000::10', 'end': 'fd00:fd00:fd00:3000::18' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual(len(errors), 1) self.assertIn('outside of subnet StorageNetCidr', errors[0])
def test_pool_outside_cidr(self): filedata = { 'StorageNetCidr': '172.18.0.0/25', } pools = { 'StorageAllocationPools': [{ 'start': '172.18.0.10', 'end': '172.18.0.200' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual(len(errors), 1) self.assertIn('outside of subnet StorageNetCidr', errors[0])
def test_pool_with_invalid_cidr(self): filedata = { 'StorageNetCidr': 'breakit', } pools = { 'StorageAllocationPools': [{ 'start': '172.18.0.10', 'end': '172.18.0.200' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual(len(errors), 1) self.assertEqual('Invalid IP network: breakit', errors[0])
def test_pool_without_cidr(self): filedata = {} pools = { 'StorageAllocationPools': [{ 'start': '172.18.0.10', 'end': '172.18.0.200' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual(len(errors), 1) self.assertEqual( 'The StorageNetCidr CIDR is not specified for' ' StorageAllocationPools.', errors[0])
def test_pool_very_large_range_ipv6(self): filedata = { 'StorageNetCidr': 'fd00:fd00:fd00:3000::/64', } pools = { 'StorageAllocationPools': [{ 'start': 'fd00:fd00:fd00:3000::10', 'end': 'fd00:fd00:fd00:3000:ffff:ffff:ffff:fffe' }] } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertEqual([], errors)
def test_overlapping_pools(self): filedata = { 'StorageNetCidr': '172.18.0.0/24', } pools = { 'StorageAllocationPools': [ { 'start': '172.18.0.10', 'end': '172.18.0.30' }, { 'start': '172.18.0.20', 'end': '172.18.0.200' }, ], } errors = validation.check_allocation_pools_pairing(filedata, pools) self.assertIn('Some pools in StorageAllocationPools are overlapping.', errors[0])
def test_pool_range_not_list(self): pools = {'TestPools': None} errors = validation.check_allocation_pools_pairing({}, pools) self.assertEqual(len(errors), 1) self.assertEqual('The IP ranges in TestPools must form a list.', errors[0])
def test_empty(self): errors = validation.check_allocation_pools_pairing({}, {}) self.assertEqual([], errors)