Esempio n. 1
0
def test_backwards_compatibility():
    # Tests backwards compatibility with the old endpoint generation tooling.
    # There are snapshots of the two endpoint formats at a single point in
    # time. Given the snapshot of the new endpoint file, this asserts that
    # we can generate the exact data in the snapshot of the old endpoints file.
    # A single 'test' is generated for each service.
    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')
    new_endpoints_file = os.path.join(data_dir, 'new_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(new_endpoints_file) as f:
        new_endpoints = json.load(f)

    resolver = BotoEndpointResolver(new_endpoints)
    builder = StaticEndpointBuilder(resolver)
    services = resolver.get_available_services()
    built = builder.build_static_endpoints(services)

    for service in services:
        old = old_endpoints[service]
        new = built[service]
        case = EndpointTestCase(service, old, new)
        yield case.run
Esempio n. 2
0
def test_backwards_compatibility():
    # Tests backwards compatibility with the old endpoint generation tooling.
    # There are snapshots of the two endpoint formats at a single point in
    # time. Given the snapshot of the new endpoint file, this asserts that
    # we can generate the exact data in the snapshot of the old endpoints file.
    # A single 'test' is generated for each service.
    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')
    new_endpoints_file = os.path.join(data_dir, 'new_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(new_endpoints_file) as f:
        new_endpoints = json.load(f)

    resolver = BotoEndpointResolver(new_endpoints)
    builder = StaticEndpointBuilder(resolver)
    services = resolver.get_available_services()
    built = builder.build_static_endpoints(services)

    for service in services:
        old = old_endpoints[service]
        new = built[service]
        case = EndpointTestCase(service, old, new)
        yield case.run
Esempio n. 3
0
def _load_builtin_endpoints(_cache=_endpoints_cache):
    """Loads the builtin endpoints in the legacy format."""
    # If there's a cached response, return it
    if _cache:
        return _cache

    # Load the endpoints file
    endpoints = _load_json_file(boto.ENDPOINTS_PATH)

    # Build the endpoints into the legacy format
    resolver = BotoEndpointResolver(endpoints)
    builder = StaticEndpointBuilder(resolver)
    endpoints = builder.build_static_endpoints()

    # Cache the endpoints and then return them
    _cache.update(endpoints)
    return _cache
Esempio n. 4
0
def _load_builtin_endpoints(_cache=_endpoints_cache):
    """Loads the builtin endpoints in the legacy format."""
    # If there's a cached response, return it
    if _cache:
        return _cache

    # Load the endpoints file
    endpoints = _load_json_file(boto.ENDPOINTS_PATH)

    # Build the endpoints into the legacy format
    resolver = BotoEndpointResolver(endpoints)
    builder = StaticEndpointBuilder(resolver)
    endpoints = builder.build_static_endpoints()

    # Cache the endpoints and then return them
    _cache.update(endpoints)
    return _cache
Esempio n. 5
0
def test_no_lost_endpoints():
    # This makes sure that a bad sync doesn't cause us to loose any services

    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(boto.ENDPOINTS_PATH) as f:
        new_endpoints = json.load(f)

    builder = StaticEndpointBuilder(BotoEndpointResolver(new_endpoints))
    built = builder.build_static_endpoints()

    # Assert no services are lost
    for service, service_endpoints in old_endpoints.items():
        new_service_endpoints = built.get(service, {})
        for region, regional_endpoint in service_endpoints.items():
            new_regional_endpoint = new_service_endpoints.get(region)
            case = EndpointPreservedTestCase(
                service, region, regional_endpoint, new_regional_endpoint)
            yield case.run
Esempio n. 6
0
def test_no_lost_endpoints():
    # This makes sure that a bad sync doesn't cause us to loose any services

    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    old_endpoints_file = os.path.join(data_dir, 'old_endpoints.json')

    with open(old_endpoints_file) as f:
        old_endpoints = json.load(f)

    with open(boto.ENDPOINTS_PATH) as f:
        new_endpoints = json.load(f)

    builder = StaticEndpointBuilder(BotoEndpointResolver(new_endpoints))
    built = builder.build_static_endpoints()

    # Assert no services are lost
    for service, service_endpoints in old_endpoints.items():
        new_service_endpoints = built.get(service, {})
        for region, regional_endpoint in service_endpoints.items():
            new_regional_endpoint = new_service_endpoints.get(region)
            case = EndpointPreservedTestCase(service, region,
                                             regional_endpoint,
                                             new_regional_endpoint)
            yield case.run
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--endpoints-file',
        help=('Path to endpoints.json.  If this argument is not given, '
              'then the endpoints.json file bundled with botocore will be '
              'used.'))

    # Since the built in endpoints are no longer in the legacy format,
    # overwrite should not be allowed with legacy format output.
    exclusive = parser.add_mutually_exclusive_group()
    exclusive.add_argument(
        '--overwrite', action='store_true',
        help=('Overwrite the endpoints file built into boto2. This is not '
              'compatible with the legacy format.'))
    exclusive.add_argument(
        '--legacy-format', action='store_true',
        help=('Generate the endpoints in the legacy format, suitable for use '
              'as custom endpoints.'))
    args = parser.parse_args()
    endpoints_data = load_endpoints(args.endpoints_file)
    filter_services(endpoints_data)

    if args.legacy_format:
        builder = StaticEndpointBuilder(BotoEndpointResolver(endpoints_data))
        endpoints_data = builder.build_static_endpoints()

    json_data = json.dumps(
        endpoints_data, indent=2, separators=(',', ': '))

    if args.overwrite:
        with open(EXISTING_ENDPOINTS_FILE, 'w') as f:
            f.write(json_data)
            f.write('\n')
    else:
        print(json_data)
Esempio n. 8
0
 def setUp(self):
     self.resolver = mock.Mock(spec=BotoEndpointResolver)
     self.builder = StaticEndpointBuilder(self.resolver)
Esempio n. 9
0
class TestStaticEndpointBuilder(unittest.TestCase):
    def setUp(self):
        self.resolver = mock.Mock(spec=BotoEndpointResolver)
        self.builder = StaticEndpointBuilder(self.resolver)

    def test_build_single_service(self):
        regions = ['mars-west-1', 'moon-darkside-1']
        self.resolver.get_all_available_regions.return_value = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com'
        ]
        endpoints = self.builder.build_static_endpoints(['fake-service'])
        expected_endpoints = {
            'fake-service': {
                'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
                'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
            }
        }
        self.assertEqual(endpoints, expected_endpoints)

    def test_build_multiple_services(self):
        regions = [['mars-west-1', 'moon-darkside-1'], ['mars-west-1']]
        self.resolver.get_all_available_regions.side_effect = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com',
            'sample-service.mars-west-1.amazonaws.com'
        ]
        services = ['fake-service', 'sample-service']
        endpoints = self.builder.build_static_endpoints(services)
        expected_endpoints = {
            'fake-service': {
                'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
                'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
            },
            'sample-service': {
                'mars-west-1': 'sample-service.mars-west-1.amazonaws.com'
            }
        }
        self.assertEqual(endpoints, expected_endpoints)

    def test_build_all_services(self):
        regions = [['mars-west-1', 'moon-darkside-1'], ['mars-west-1']]
        self.resolver.get_all_available_regions.side_effect = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com',
            'sample-service.mars-west-1.amazonaws.com'
        ]

        # Set the list of available services on the resolver so it doesn't
        # have to be specified on the call to build_static_endpoints
        services = ['fake-service', 'sample-service']
        self.resolver.get_available_services.return_value = services

        endpoints = self.builder.build_static_endpoints()
        expected_endpoints = {
            'fake-service': {
                'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
                'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
            },
            'sample-service': {
                'mars-west-1': 'sample-service.mars-west-1.amazonaws.com'
            }
        }
        self.assertEqual(endpoints, expected_endpoints)
Esempio n. 10
0
 def setUp(self):
     self.resolver = mock.Mock(spec=BotoEndpointResolver)
     self.builder = StaticEndpointBuilder(self.resolver)
Esempio n. 11
0
class TestStaticEndpointBuilder(unittest.TestCase):
    def setUp(self):
        self.resolver = mock.Mock(spec=BotoEndpointResolver)
        self.builder = StaticEndpointBuilder(self.resolver)

    def test_build_single_service(self):
        regions = ['mars-west-1', 'moon-darkside-1']
        self.resolver.get_all_available_regions.return_value = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com'
        ]
        endpoints = self.builder.build_static_endpoints(['fake-service'])
        expected_endpoints = {'fake-service': {
            'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
            'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
        }}
        self.assertEqual(endpoints, expected_endpoints)

    def test_build_multiple_services(self):
        regions = [['mars-west-1', 'moon-darkside-1'], ['mars-west-1']]
        self.resolver.get_all_available_regions.side_effect = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com',
            'sample-service.mars-west-1.amazonaws.com'
        ]
        services = ['fake-service', 'sample-service']
        endpoints = self.builder.build_static_endpoints(services)
        expected_endpoints = {
            'fake-service': {
                'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
                'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
            },
            'sample-service': {
                'mars-west-1': 'sample-service.mars-west-1.amazonaws.com'
            }
        }
        self.assertEqual(endpoints, expected_endpoints)

    def test_build_all_services(self):
        regions = [['mars-west-1', 'moon-darkside-1'], ['mars-west-1']]
        self.resolver.get_all_available_regions.side_effect = regions
        self.resolver.resolve_hostname.side_effect = [
            'fake-service.mars-west-1.amazonaws.com',
            'fake-service.moon-darkside-1.amazonaws.com',
            'sample-service.mars-west-1.amazonaws.com'
        ]
        
        # Set the list of available services on the resolver so it doesn't
        # have to be specified on the call to build_static_endpoints
        services = ['fake-service', 'sample-service']
        self.resolver.get_available_services.return_value = services

        endpoints = self.builder.build_static_endpoints()
        expected_endpoints = {
            'fake-service': {
                'mars-west-1': 'fake-service.mars-west-1.amazonaws.com',
                'moon-darkside-1': 'fake-service.moon-darkside-1.amazonaws.com'
            },
            'sample-service': {
                'mars-west-1': 'sample-service.mars-west-1.amazonaws.com'
            }
        }
        self.assertEqual(endpoints, expected_endpoints)