8000 remove deprecated USE_MOTO_CF config switch; resolve refs in ExportNa… · riddopic/localstack@bef8107 · GitHub
[go: up one dir, main page]

Skip to content

Commit bef8107

Browse files
committed
remove deprecated USE_MOTO_CF config switch; resolve refs in ExportName of CF stacks
1 parent 34e52f8 commit bef8107

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

localstack/config.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import os
33
import json
4+
import time
45
import socket
56
import logging
67
import platform
@@ -13,6 +14,9 @@
1314
DEFAULT_SERVICE_PORTS, LOCALHOST, LOCALHOST_IP, DEFAULT_PORT_WEB_UI, TRUE_STRINGS, FALSE_STRINGS,
1415
DEFAULT_LAMBDA_CONTAINER_REGISTRY, DEFAULT_PORT_EDGE, AWS_REGION_US_EAST_1, LOG_LEVELS)
1516

17+
# keep track of start time, for performance debugging
18+
load_start_time = time.time()
19+
1620

1721
def is_env_true(env_var_name):
1822
""" Whether the given environment variable has a truthy value. """
@@ -229,8 +233,7 @@ def is_linux():
229233
'WINDOWS_DOCKER_MOUNT_PREFIX', 'USE_HTTP2_SERVER',
230234
'SYNCHRONOUS_API_GATEWAY_EVENTS', 'SYNCHRONOUS_KINESIS_EVENTS',
231235
'SYNCHRONOUS_SNS_EVENTS', 'SYNCHRONOUS_SQS_EVENTS', 'SYNCHRONOUS_DYNAMODB_EVENTS',
232-
'DYNAMODB_HEAP_SIZE', 'MAIN_CONTAINER_NAME', 'LAMBDA_DOCKER_DNS',
233-
'USE_MOTO_CF']
236+
'DYNAMODB_HEAP_SIZE', 'MAIN_CONTAINER_NAME', 'LAMBDA_DOCKER_DNS']
234237

235238
for key, value in six.iteritems(DEFAULT_SERVICE_PORTS):
236239
clean_key = key.upper().replace('-', '_')
@@ -426,9 +429,6 @@ def get_edge_url():
426429
# whether to use a CPU/memory profiler when running the integration tests
427430
USE_PROFILER = is_env_true('USE_PROFILER')
428431

429-
# whether to use the legacy CF deployment based on moto (TODO: remove in a future release)
430-
USE_MOTO_CF = is_env_true('USE_MOTO_CF')
431-
432432

433433
def load_config_file(config_file=None):
434434
from localstack.utils.common import get_or_create_file, to_str
@@ -440,3 +440,9 @@ def load_config_file(config_file=None):
440440
print('Unable to load local config file %s as JSON: %s' % (config_file, e))
441441
return {}
442442
return configs
443+
444+
445+
if LS_LOG == 'trace':
446+
load_end_time = time.time()
447+
LOG = logging.getLogger(__name__)
448+
LOG.debug('Initializing the configuration took %s ms' % int((load_end_time - load_start_time) * 1000))

localstack/plugins.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def do_register_localstack_plugins():
3939
)
4040
from localstack.services.acm import acm_starter
4141
from localstack.services.apigateway import apigateway_listener, apigateway_starter
42-
from localstack.services.cloudformation import cloudformation_starter, cloudformation_listener
4342
from localstack.services.cloudwatch import cloudwatch_listener, cloudwatch_starter
4443
from localstack.services.dynamodb import dynamodb_listener, dynamodb_starter
4544
from localstack.services.ec2 import ec2_starter, ec2_listener
@@ -75,18 +74,10 @@ def do_register_localstack_plugins():
7574
start=apigateway_starter.start_apigateway,
7675
listener=apigateway_listener.UPDATE_APIGATEWAY))
7776

78-
if config.USE_MOTO_CF:
79-
# TODO: deprecated - remove in a future iteration
80-
register_plugin(Plugin(
81-
'cloudformation',
82-
start=cloudformation_starter.start_cloudformation,
83-
listener=cloudformation_listener.UPDATE_CLOUDFORMATION
84-
))
85-
else:
86-
register_plugin(Plugin(
87-
'cloudformation',
88-
start=start_cloudformation
89-
))
77+
register_plugin(Plugin(
78+
'cloudformation',
79+
start=start_cloudformation
80+
))
9081

9182
register_plugin(Plugin(
9283
'cloudwatch',

localstack/services/awslambda/lambda_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ def execute(event, context):
704704
return result
705705
return execute
706706
raise ClientError(error_response(
707-
'Unable to extract Java Lambda handler - file is not a valid zip/jar file', 400, error_type='ValidationError'))
707+
'Unable to extract Java Lambda handler - file is not a valid zip/jar file (%s, %s bytes)' %
708+
(main_file, len(zip_file_content or '')), 400, error_type='ValidationError'))
708709

709710

710711
def set_archive_code(code, lambda_name, zip_file_content=None):

localstack/services/awslambda/lambda_executors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def idle_container_destroyer(self):
636636
been inactive for longer than MAX_CONTAINER_IDLE_TIME_MS.
637637
:return: None
638638
"""
639-
LOG.info('Checking if there are idle containers.')
639+
LOG.debug('Checking if there are idle containers ...')
640640
current_time = int(time.time() * 1000)
641641
for func_arn, last_run_time in dict(self.function_invoke_times).items():
642642
duration = current_time - last_run_time

localstack/services/cloudformation/cloudformation_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def outputs(self):
232232
LOG.debug('Unable to resolve references in stack outputs: %s - %s' % (details, e))
233233
exports = details.get('Export') or {}
234234
export = exports.get('Name')
235+
export = template_deployer.resolve_refs_recursively(self.stack_name, export, self.resources)
235236
description = details.get('Description')
236237
entry = {'OutputKey': k, 'OutputValue': value, 'Description': description, 'ExportName': export}
237238
result.append(entry)
@@ -484,7 +485,8 @@ def update_stack_set(req_params):
484485
def describe_stacks(req_params):
485486
state = CloudFormationRegion.get()
486487
stack_name = req_params.get('StackName')
487-
stacks = [s.describe_details() for s in state.stacks.values() if stack_name in [None, s.stack_name, s.stack_id]]
488+
stack_list = list(state.stacks.values())
489+
stacks = [s.describe_details() for s in stack_list if stack_name in [None, s.stack_name, s.stack_id]]
488490
if stack_name and not stacks:
489491
return error_response('Stack with id %s does not exist' % stack_name,
490492
code=400, code_string='ValidationError')
@@ -495,7 +497,8 @@ def describe_stacks(req_params):
495497
def list_stacks(req_params):
496498
state = CloudFormationRegion.get()
497499
filter = req_params.get('StackStatusFilter')
498-
stacks = [s.describe_details() for s in state.stacks.values() if filter in [None, s.status]]
500+
stack_list = list(state.stacks.values())
501+
stacks = [s.describe_details() for s in stack_list if filter in [None, s.status]]
499502
attrs = ['StackId', 'StackName', 'TemplateDescription', 'CreationTime', 'LastUpdatedTime', 'DeletionTime',
500503
'StackStatus', 'StackStatusReason', 'ParentId', 'RootId', 'DriftInformation']
501504
stacks = [select_attributes(stack, attrs) for stack in stacks]

localstack/utils/cloudformation/template_deployer.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from moto.ec2.utils import generate_route_id
1010
from moto.core import CloudFormationModel as MotoCloudFormationModel
1111
from moto.cloudformation import parsing
12-
from moto.cloudformation.models import cloudformation_backends
13-
from localstack import config
1412
from localstack.utils import common
1513
from localstack.utils.aws import aws_stack
1614
from localstack.constants import TEST_AWS_ACCOUNT_ID, FALSE_STRINGS
@@ -893,10 +891,6 @@ def resolve_refs_recursively(stack_name, value, resources):
893891

894892
if stripped_fn_lower == 'importvalue':
895893
import_value_key = resolve_refs_recursively(stack_name, value[keys_list[0]], resources)
896-
if config.USE_MOTO_CF:
897-
exports = cloudformation_backends[aws_stack.get_region()].exports
898-
export = exports[import_value_key]
899-
return export.value
900894
stack = find_stack(stack_name)
901895
return stack.exports_map[import_value_key]['Value']
902896

0 commit comments

Comments
 (0)
0