def test_non_dict(self): errors = validation.check_static_ip_in_cidr(None, {}) self.assertEqual(len(errors), 1) self.assertEqual('The networks argument must be a dictionary.', errors[0]) errors = validation.check_static_ip_in_cidr({}, None) self.assertEqual(len(errors), 1) self.assertEqual('The static_ips argument must be a dictionary.', errors[0])
def test_missing_cidr(self): static_ips = {'ControllerIps': {'storage': ['192.168.100.120']}} errors = validation.check_static_ip_in_cidr({}, static_ips) self.assertEqual(len(errors), 1) self.assertEqual( "Service 'storage' does not have a corresponding" " range: 'StorageNetCidr'.", errors[0])
def test_invalid_cidr(self): errors = validation.check_static_ip_in_cidr( {'StorageNetCidr': 'breakit'}, {}) self.assertEqual(len(errors), 1) self.assertEqual( "Network 'StorageNetCidr' has an invalid CIDR:" " 'breakit'", errors[0])
def test_static_ips_not_a_list(self): networks = { 'InternalApiNetCidr': '10.35.191.0/24', } static_ips = { 'ControllerIps': { 'internal_api': None, } } errors = validation.check_static_ip_in_cidr(networks, static_ips) self.assertEqual(len(errors), 1) self.assertEqual('The ControllerIps->internal_api must be a list.', errors[0])
def test_address_not_within_cidr(self): networks = { 'StorageNetCidr': '192.168.100.0/24', } static_ips = { 'ControllerIps': { 'storage': ['192.168.100.120', '192.168.101.0'] } } errors = validation.check_static_ip_in_cidr(networks, static_ips) self.assertEqual(len(errors), 1) self.assertEqual( 'The IP address 192.168.101.0 is outside of the' ' StorageNetCidr range: 192.168.100.0/24', errors[0])
def test_addresses_within_cidr(self): networks = { 'StorageNetCidr': '192.168.100.0/24', 'InternalApiNetCidr': '10.35.191.0/24', } static_ips = { 'ControllerIps': { 'storage': ['192.168.100.1', '192.168.100.2', '192.168.100.3'], 'internal_api': ['10.35.191.60', '10.35.191.70'] }, 'ComputeIps': { 'storage': ['192.168.100.125', '192.168.100.135'], 'internal_api': ['10.35.191.100', '10.35.191.110'], } } errors = validation.check_static_ip_in_cidr(networks, static_ips) self.assertEqual([], errors)
def test_service_not_a_dict(self): static_ips = {'ControllerIps': None} errors = validation.check_static_ip_in_cidr({}, static_ips) self.assertEqual(len(errors), 1) self.assertEqual('The ControllerIps must be a dictionary.', errors[0])
def test_empty(self): errors = validation.check_static_ip_in_cidr({}, {}) self.assertEqual([], errors)