def test_is_valid_ipv4_address(self): to_test = {'192.168.33.10': True, '10.10.1.0': True, 'node-1': False, '2001:0DB8:AC10:FE01::': False} for test_ip, should_be_valid in to_test.iteritems(): self.assertEqual(AppEngineHelper.is_valid_ipv4_address(test_ip), should_be_valid, '{} should be {}'.format(test_ip, should_be_valid))
def test_is_valid_ipv4_address(self): to_test = { '192.168.33.10': True, '10.10.1.0': True, 'node-1': False, '2001:0DB8:AC10:FE01::': False } for test_ip, should_be_valid in to_test.iteritems(): self.assertEqual( AppEngineHelper.is_valid_ipv4_address(test_ip), should_be_valid, '{} should be {}'.format(test_ip, should_be_valid))
def get_ips_from_options(ips): """ Gets ips from run time options and validates that they are valid ip addresses. Args: ips: A list or dict containing the ips attribute of the run time options. Raises: AssertionError if any ip addresses are not valid. """ try: all_ips = set(ips.values()) except AttributeError: all_ips = set() for node_set in ips: all_ips.update(node_set['nodes'] if isinstance(node_set['nodes'], list)\ else [node_set['nodes']]) assert all(AppEngineHelper.is_valid_ipv4_address(ip) for ip in all_ips), \ 'Invalid IP address in {}'.format(all_ips) return all_ips