diff --git a/tests/iac_integration/cdk/test_sam_cdk_integration.py b/tests/iac_integration/cdk/test_sam_cdk_integration.py new file mode 100644 index 0000000000..702aa4e0bc --- /dev/null +++ b/tests/iac_integration/cdk/test_sam_cdk_integration.py @@ -0,0 +1,132 @@ +from unittest import TestCase +from subprocess import Popen, PIPE +import os +import random +from pathlib import Path +import threading + +import pytest +import requests +from parameterized import parameterized_class, parameterized + +from tests.testing_utils import run_command, start_persistent_process, read_until_string, kill_process + + +@parameterized_class( + ("cdk_project_path", "cdk_version", "cdk_stack_template"), + [ + ("/testdata/cdk_v1/typescript", "1.x", "TestStack.template.json"), + ("/testdata/cdk_v2/typescript", "2.x", "TestStack.template.json"), + ("/testdata/cdk_v1/python", "1.x", "TestStack.template.json"), + ("/testdata/cdk_v2/python", "2.x", "TestStack.template.json"), + ("/testdata/cdk_v1/java", "1.x", "TestStack.template.json"), + ("/testdata/cdk_v2/java", "2.x", "TestStack.template.json"), + ], +) +class TestSamCdkIntegration(TestCase): + integration_dir = str(Path(__file__).resolve().parents[0]) + cdk_project_path = "" + cdk_version = "" + cdk_stack_template = "" + + @classmethod + def setUpClass(cls): + cls.cdk_project = cls.integration_dir + cls.cdk_project_path + cls.api_port = str(TestSamCdkIntegration.random_port()) + cls.build_cdk_project() + cls.build() + + cls.start_api() + cls.url = "http://127.0.0.1:{}".format(cls.api_port) + + @classmethod + def build_cdk_project(cls): + command_list = ["npx", f"aws-cdk@{cls.cdk_version}", "synth", "--no-staging"] + working_dir = cls.cdk_project + result = run_command(command_list, cwd=working_dir) + if result.process.returncode != 0: + raise Exception("cdk synth command failed") + + @classmethod + def build(cls): + command = "sam" + if os.getenv("SAM_CLI_DEV"): + command = "samdev" + command_list = [command, "build", "-t", cls.cdk_stack_template] + working_dir = cls.cdk_project + "/cdk.out" + result = run_command(command_list, cwd=working_dir) + if result.process.returncode != 0: + raise Exception("sam build command failed") + + @classmethod + def start_api(cls): + command = "sam" + if os.getenv("SAM_CLI_DEV"): + command = "samdev" + + command_list = [command, "local", "start-api", "-p", cls.api_port] + + working_dir = cls.cdk_project + "/cdk.out" + cls.start_api_process = Popen(command_list, cwd=working_dir, stderr=PIPE, shell=True,) + + while True: + line = cls.start_api_process.stderr.readline() + if "Press CTRL+C to quit" in str(line): + break + + cls.stop_api_reading_thread = False + + def read_sub_process_stderr(): + while not cls.stop_api_reading_thread: + cls.start_api_process.stderr.readline() + + cls.api_read_threading = threading.Thread(target=read_sub_process_stderr, daemon=True) + cls.api_read_threading.start() + + @classmethod + def tearDownClass(cls): + # After all the tests run, we need to kill the start_lambda process. + cls.stop_api_reading_thread = True + kill_process(cls.start_api_process) + + @staticmethod + def random_port(): + return random.randint(30000, 40000) + + @parameterized.expand( + [ + ("/httpapis/nestedPythonFunction", "Hello World from Nested Python Function Construct 7"), + ("/restapis/spec/pythonFunction", "Hello World from python function construct 7"), + ("/restapis/normal/pythonFunction", "Hello World from python function construct 7"), + ("/restapis/normal/functionPythonRuntime", "Hello World from function construct with python runtime 7"), + ("/restapis/normal/preBuiltFunctionPythonRuntime", "Hello World from python pre built function 7"), + ( + "/restapis/normal/bundledFunctionPythonRuntime", + "Hello World from bundled function construct with python runtime 7", + ), + ("/restapis/normal/nodejsFunction", "Hello World from nodejs function construct 7"), + ("/restapis/normal/functionNodeJsRuntime", "Hello World from function construct with nodejs runtime 7"), + ("/restapis/normal/preBuiltFunctionNodeJsRuntime", "Hello World from nodejs pre built function 7"), + ("/restapis/normal/goFunction", "Hello World from go function construct"), + ("/restapis/normal/functionGoRuntime", "Hello World from function construct with go runtime"), + ("/restapis/normal/dockerImageFunction", "Hello World from docker image function construct"), + ("/restapis/normal/functionImageAsset", "Hello World from function construct with image asset"), + ( + "/restapis/normal/dockerImageFunctionWithSharedCode", + "Hello World from docker image function construct " + "with a Dockerfile that shares code with another Dockerfile", + ), + ( + "/restapis/normal/functionImageAssetWithSharedCode", + "Hello World from function construct with image asset " + "with a Dockerfile that shares code with another Dockerfile", + ), + ] + ) + @pytest.mark.flaky(reruns=3) + @pytest.mark.timeout(timeout=1000, method="thread") + def test_invoke_api(self, url_suffix, expected_message): + response = requests.get(self.url + url_suffix, timeout=800) + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json().get("message"), expected_message) diff --git a/tests/integration/buildcmd/test_build_terraform_applications.py b/tests/integration/buildcmd/test_build_terraform_applications.py index 8a0044d4e7..ce8327d93c 100644 --- a/tests/integration/buildcmd/test_build_terraform_applications.py +++ b/tests/integration/buildcmd/test_build_terraform_applications.py @@ -57,7 +57,7 @@ def setUp(self): shutil.copytree(Path(self.terraform_application_path), Path(self.working_dir)) def run_command(self, command_list, env=None, input=None): - process = Popen(command_list, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env, cwd=self.working_dir) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env, cwd=self.working_dir, shell=True) try: (stdout, stderr) = process.communicate(input=input) return stdout, stderr, process.returncode diff --git a/tests/integration/init/test_init_command.py b/tests/integration/init/test_init_command.py index b852f5493c..150dabe601 100644 --- a/tests/integration/init/test_init_command.py +++ b/tests/integration/init/test_init_command.py @@ -53,6 +53,7 @@ def test_init_command_passes_and_dir_created(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -82,7 +83,8 @@ def test_init_command_passes_and_dir_created_image(self): "--no-interactive", "-o", temp, - ] + ], + shell = True, ) try: process.communicate(timeout=TIMEOUT) @@ -113,6 +115,7 @@ def test_init_new_app_template(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -145,6 +148,7 @@ def test_init_command_java_maven(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -177,6 +181,7 @@ def test_init_command_java_gradle(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -209,6 +214,7 @@ def test_init_command_go_provided_image(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -243,6 +249,7 @@ def test_init_command_with_extra_context_parameter(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -277,6 +284,7 @@ def test_init_command_passes_with_arm_architecture(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -311,6 +319,7 @@ def test_init_command_passes_with_x86_64_architecture(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -342,7 +351,8 @@ def test_init_command_passes_with_unknown_architecture(self): temp, "--architecture", "unknown_arch", - ] + ], + shell=True, ) capture_output = "" try: @@ -374,7 +384,8 @@ def test_init_command_passes_with_enabled_tracing(self): "-o", temp, "--tracing", - ] + ], + shell=True, ) try: process.communicate(timeout=TIMEOUT) @@ -404,7 +415,8 @@ def test_init_command_passes_with_disabled_tracing(self): "-o", temp, "--no-tracing", - ] + ], + shell=True, ) try: process.communicate(timeout=TIMEOUT) @@ -434,7 +446,8 @@ def test_init_command_passes_with_enabled_application_insights(self): "-o", temp, "--application-insights", - ] + ], + shell=True, ) try: process.communicate(timeout=TIMEOUT) @@ -464,7 +477,8 @@ def test_init_command_passes_with_disabled_application_insights(self): "-o", temp, "--no-application-insights", - ] + ], + shell=True, ) try: process.communicate(timeout=TIMEOUT) @@ -524,6 +538,7 @@ def test_init_command_no_interactive_missing_name(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -553,6 +568,7 @@ def test_init_command_no_interactive_apptemplate_location(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -585,6 +601,7 @@ def test_init_command_no_interactive_runtime_location(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -616,6 +633,7 @@ def test_init_command_no_interactive_base_image_location(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -648,6 +666,7 @@ def test_init_command_no_interactive_base_image_no_dependency(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -677,6 +696,7 @@ def test_init_command_no_interactive_packagetype_location(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -707,6 +727,7 @@ def test_init_command_no_interactive_base_image_no_packagetype(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -733,6 +754,7 @@ def test_init_command_wrong_packagetype(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -785,7 +807,7 @@ def test_arbitrary_project(self, project_name): if project_name: args.extend(["--name", project_name]) - process = Popen(args) + process = Popen(args, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -801,7 +823,7 @@ def test_zip_not_exists(self): with tempfile.TemporaryDirectory() as temp: args = [get_sam_command(), "init", "--location", str(Path("invalid", "zip", "path")), "-o", temp] - process = Popen(args) + process = Popen(args, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -825,7 +847,7 @@ def test_location_with_no_interactive_and_name(self): "-o", tmp, ] - process = Popen(args) + process = Popen(args, shell=True,) try: process.communicate(timeout=TIMEOUT) @@ -937,6 +959,7 @@ def _run_init(self, cwd): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -977,6 +1000,7 @@ def test_zip_template_config(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -1012,6 +1036,7 @@ def test_image_template_config(self): ], stdout=PIPE, stderr=PIPE, + shell=True, ) try: stdout_data, stderr_data = process.communicate(timeout=TIMEOUT) @@ -1072,7 +1097,7 @@ class TestInitCommand(InitIntegBase): def test_graceful_exit(self): # Run the Base Command command_list = self.get_command() - process_execute = Popen(command_list, stdout=PIPE, stderr=PIPE) + process_execute = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) # Wait for binary to be ready before sending interrupts. time.sleep(self.BINARY_READY_WAIT_TIME) diff --git a/tests/integration/local/generate_event/test_cli_integ.py b/tests/integration/local/generate_event/test_cli_integ.py index 30ff3ae6b8..fc06da777e 100644 --- a/tests/integration/local/generate_event/test_cli_integ.py +++ b/tests/integration/local/generate_event/test_cli_integ.py @@ -7,6 +7,6 @@ class Test_EventGeneration_Integ(TestCase): def test_generate_event_substitution(self): - process = Popen([get_sam_command(), "local", "generate-event", "s3", "put"]) + process = Popen([get_sam_command(), "local", "generate-event", "s3", "put"], shell=True,) process.communicate() self.assertEqual(process.returncode, 0) diff --git a/tests/integration/local/invoke/invoke_integ_base.py b/tests/integration/local/invoke/invoke_integ_base.py index 844c2725a6..e8049fa866 100644 --- a/tests/integration/local/invoke/invoke_integ_base.py +++ b/tests/integration/local/invoke/invoke_integ_base.py @@ -110,7 +110,7 @@ def get_build_command_list( return command_list def run_command(self, command_list, env=None): - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: (stdout, stderr) = process.communicate(timeout=TIMEOUT) return stdout, stderr, process.returncode diff --git a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py index 751474b64b..07ea2b20ab 100644 --- a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py +++ b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py @@ -40,7 +40,7 @@ def test_runtime_zip(self, function_name): function_name, template_path=self.template_path, event_path=self.events_file_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -59,7 +59,7 @@ def test_custom_provided_runtime(self): command_list = command_list + ["--skip-pull-image"] - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/local/invoke/test_integration_cli_images.py b/tests/integration/local/invoke/test_integration_cli_images.py index fdc8d5a60f..c449c915a9 100644 --- a/tests/integration/local/invoke/test_integration_cli_images.py +++ b/tests/integration/local/invoke/test_integration_cli_images.py @@ -56,7 +56,7 @@ def test_invoke_returncode_is_zero(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -78,7 +78,7 @@ def test_invoke_returns_execpted_results(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -94,7 +94,7 @@ def test_invoke_of_lambda_function(self): "HelloWorldLambdaFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -110,7 +110,7 @@ def test_invoke_of_lambda_function_with_function_name_override(self): "func-name-override", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -130,7 +130,7 @@ def test_invoke_with_timeout_set(self, function_name): ) start = timer() - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -163,7 +163,7 @@ def test_invoke_with_env_vars(self): env_var_path=self.env_var_path, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -179,7 +179,7 @@ def test_invoke_with_env_vars_with_functionname_defined(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path, env_var_path=self.env_var_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -195,7 +195,7 @@ def test_invoke_with_global_env_vars_function(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path, env_var_path=self.env_var_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -210,7 +210,7 @@ def test_invoke_when_function_writes_stdout(self): "WriteToStdoutFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: stdout, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -229,7 +229,7 @@ def test_invoke_when_function_writes_stderr(self): "WriteToStderrFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -243,7 +243,7 @@ def test_invoke_when_function_writes_stderr(self): @pytest.mark.flaky(reruns=3) def test_invoke_returns_expected_result_when_no_event_given(self): command_list = InvokeIntegBase.get_command_list("EchoEventFunction", template_path=self.template_path) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -264,7 +264,7 @@ def test_invoke_with_env_using_parameters(self): parameter_overrides={"DefaultTimeout": "100"}, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -295,7 +295,7 @@ def test_invoke_with_env_using_parameters_with_custom_region(self): "EchoEnvWithParameters", template_path=self.template_path, event_path=self.event_path, region=custom_region ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -325,7 +325,7 @@ def test_invoke_with_env_with_aws_creds(self): env["AWS_SECRET_ACCESS_KEY"] = secret env["AWS_SESSION_TOKEN"] = session - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -350,7 +350,7 @@ def test_invoke_with_docker_network_of_host(self): docker_network="host", ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -369,7 +369,7 @@ def test_invoke_with_docker_network_of_host_in_env_var(self): env = os.environ.copy() env["SAM_DOCKER_NETWORK"] = "non-existing-network" - process = Popen(command_list, stderr=PIPE, env=env) + process = Popen(command_list, stderr=PIPE, env=env, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -390,7 +390,7 @@ def test_sam_template_file_env_var_set(self): env = os.environ.copy() env["SAM_TEMPLATE_FILE"] = str(self.test_data_path.joinpath("invoke", "sam-template-image.yaml")) - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -406,7 +406,7 @@ def test_invoke_with_error_during_image_build(self): "ImageDoesntExistFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -471,7 +471,7 @@ def test_building_new_rapid_image_removes_old_rapid_images(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -498,7 +498,7 @@ def test_building_existing_rapid_image_does_not_remove_old_rapid_images(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -522,7 +522,7 @@ def test_building_new_rapid_image_doesnt_remove_images_in_other_repos(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/local/invoke/test_integrations_cli.py b/tests/integration/local/invoke/test_integrations_cli.py index b295d81f6c..1b51b3be7c 100644 --- a/tests/integration/local/invoke/test_integrations_cli.py +++ b/tests/integration/local/invoke/test_integrations_cli.py @@ -38,7 +38,7 @@ def test_invoke_returncode_is_zero(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -54,7 +54,7 @@ def test_invoke_with_utf8_event(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_utf8_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -69,7 +69,7 @@ def test_function_with_metadata(self): "FunctionWithMetadata", template_path=self.template_path, no_event=True ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -93,7 +93,7 @@ def test_invoke_returns_execpted_results(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -109,7 +109,7 @@ def test_invoke_of_lambda_function(self): "HelloWorldLambdaFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -125,7 +125,7 @@ def test_invoke_of_lambda_function_with_function_name_override(self): "func-name-override", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -145,7 +145,7 @@ def test_invoke_with_timeout_set(self, function_name): ) start = timer() - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -180,7 +180,7 @@ def test_invoke_with_env_vars(self): env_var_path=self.env_var_path, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -196,7 +196,7 @@ def test_invoke_with_env_vars_with_functionname_defined(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path, env_var_path=self.env_var_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -212,7 +212,7 @@ def test_invoke_with_global_env_vars_function(self, function_name): function_name, template_path=self.template_path, event_path=self.event_path, env_var_path=self.env_var_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -230,7 +230,7 @@ def test_invoke_with_invoke_image_provided(self): invoke_image="amazon/aws-sam-cli-emulation-image-python3.7", ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -246,7 +246,7 @@ def test_invoke_when_function_writes_stdout(self): "WriteToStdoutFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: stdout, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -265,7 +265,7 @@ def test_invoke_when_function_writes_stderr(self): "WriteToStderrFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stderr=PIPE, stdout=PIPE) + process = Popen(command_list, stderr=PIPE, stdout=PIPE, shell=True,) try: stdout, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -281,7 +281,7 @@ def test_invoke_when_function_writes_stderr(self): @pytest.mark.flaky(reruns=3) def test_invoke_returns_expected_result_when_no_event_given(self): command_list = InvokeIntegBase.get_command_list("EchoEventFunction", template_path=self.template_path) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -323,7 +323,7 @@ def test_invoke_with_env_using_parameters(self): parameter_overrides={"MyRuntimeVersion": "v0", "DefaultTimeout": "100"}, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -355,7 +355,7 @@ def test_invoke_with_env_using_parameters_with_custom_region(self): "EchoEnvWithParameters", template_path=self.template_path, event_path=self.event_path, region=custom_region ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -385,7 +385,7 @@ def test_invoke_with_env_with_aws_creds(self): env["AWS_SECRET_ACCESS_KEY"] = secret env["AWS_SESSION_TOKEN"] = session - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -410,7 +410,7 @@ def test_invoke_with_docker_network_of_host(self): docker_network="host", ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -429,7 +429,7 @@ def test_invoke_with_docker_network_of_host_in_env_var(self): env = os.environ.copy() env["SAM_DOCKER_NETWORK"] = "non-existing-network" - process = Popen(command_list, stderr=PIPE, env=env) + process = Popen(command_list, stderr=PIPE, env=env, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -450,7 +450,7 @@ def test_sam_template_file_env_var_set(self): env = os.environ.copy() env["SAM_TEMPLATE_FILE"] = str(self.test_data_path.joinpath("invoke", "sam-template.yaml")) - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -473,7 +473,7 @@ def test_skip_pull_image_in_env_var(self): env = os.environ.copy() env["SAM_SKIP_PULL_IMAGE"] = "True" - process = Popen(command_list, stderr=PIPE, env=env) + process = Popen(command_list, stderr=PIPE, env=env, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -491,7 +491,7 @@ def test_invoke_returns_expected_results_from_git_function(self): "GitLayerFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -512,7 +512,7 @@ def test_invoke_returns_expected_results_from_git_function_with_parameters(self) parameter_overrides={"LayerVersion": "5"}, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -532,7 +532,7 @@ def test_resolve_instrincs_which_runs_plugins(self): "HelloWorldServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -576,7 +576,7 @@ def test_existing_env_variables_precedence_over_profiles(self): env["AWS_CONFIG_FILE"] = custom_config env["AWS_SHARED_CREDENTIALS_FILE"] = custom_cred - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -614,7 +614,7 @@ def test_default_profile_with_custom_configs(self): env["AWS_CONFIG_FILE"] = custom_config env["AWS_SHARED_CREDENTIALS_FILE"] = custom_cred - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -650,7 +650,7 @@ def test_custom_profile_with_custom_configs(self): env["AWS_CONFIG_FILE"] = custom_config env["AWS_SHARED_CREDENTIALS_FILE"] = custom_cred - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -691,7 +691,7 @@ def test_custom_profile_through_envrionment_variables(self): env["AWS_SHARED_CREDENTIALS_FILE"] = custom_cred env["AWS_PROFILE"] = "custom" - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -793,7 +793,7 @@ def test_reference_of_layer_version(self, function_logical_id): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -814,7 +814,7 @@ def test_invoke_with_invoke_image_provided(self): invoke_image="amazon/aws-sam-cli-emulation-image-python3.9", ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -835,7 +835,7 @@ def test_download_one_layer(self, function_logical_id): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -861,7 +861,7 @@ def test_publish_changed_download_layer(self, function_logical_id): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -886,7 +886,7 @@ def test_publish_changed_download_layer(self, function_logical_id): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate() except TimeoutExpired: @@ -910,7 +910,7 @@ def test_download_two_layers(self, function_logical_id): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -934,7 +934,7 @@ def test_caching_two_layers(self): parameter_overrides=self.layer_utils.parameters_overrides, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -955,7 +955,7 @@ def test_caching_two_layers_with_layer_cache_env_set(self): env = os.environ.copy() env["SAM_LAYER_CACHE_BASEDIR"] = str(self.layer_cache) - process = Popen(command_list, stdout=PIPE, env=env) + process = Popen(command_list, stdout=PIPE, env=env, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1012,7 +1012,7 @@ def test_layer_does_not_exist(self): parameter_overrides={"NonExistentLayerArn": non_existent_layer_arn}, ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1035,7 +1035,7 @@ def test_account_does_not_exist_for_layer(self): region=self.region, ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1067,7 +1067,7 @@ def test_unresolved_layer_due_to_bad_instrinsic(self): parameter_overrides={"LayerVersion": "1"}, ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1099,7 +1099,7 @@ def test_invoke_with_function_name_will_call_functions_in_top_level_stacks(self, function_identifier, template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1117,7 +1117,7 @@ def test_invoke_with_function_full_path_will_call_functions_in_specified_stack(s "SubApp/SubSubApp/FunctionA", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1135,7 +1135,7 @@ def test_invoke_with_non_existent_function_full_path(self): "SubApp/SubSubApp/Function404", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1157,7 +1157,7 @@ def test_invoke_returncode_is_zero(self): "NoInlineCodeServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -1172,7 +1172,7 @@ def test_invoke_inline_code_function(self): "InlineCodeServerlessFunction", template_path=self.template_path, event_path=self.event_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/local/invoke/test_invoke_terraform_applications.py b/tests/integration/local/invoke/test_invoke_terraform_applications.py index 1421e0fa9b..ddc13fce55 100644 --- a/tests/integration/local/invoke/test_invoke_terraform_applications.py +++ b/tests/integration/local/invoke/test_invoke_terraform_applications.py @@ -36,7 +36,9 @@ def setUpClass(cls): @classmethod def run_command(cls, command_list, env=None, input=None): - process = Popen(command_list, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env, cwd=cls.terraform_application_path) + process = Popen( + command_list, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env, cwd=cls.terraform_application_path, shell=True, + ) try: (stdout, stderr) = process.communicate(input=input, timeout=TIMEOUT) LOG.info("sam stdout: %s", stdout.decode("utf-8")) diff --git a/tests/integration/local/start_api/start_api_integ_base.py b/tests/integration/local/start_api/start_api_integ_base.py index 77f755aec8..795062ae54 100644 --- a/tests/integration/local/start_api/start_api_integ_base.py +++ b/tests/integration/local/start_api/start_api_integ_base.py @@ -104,10 +104,11 @@ def start_api(cls): command_list += ["--invoke-image", image] cls.start_api_process = ( - Popen(command_list, stderr=PIPE, stdout=PIPE) + Popen(command_list, stderr=PIPE, stdout=PIPE, shell=True,) if not cls.project_directory - else Popen(command_list, stderr=PIPE, stdout=PIPE, cwd=cls.project_directory) + else Popen(command_list, stderr=PIPE, stdout=PIPE, cwd=cls.project_directory, shell=True,) ) + cls.start_api_process_output = wait_for_local_process( cls.start_api_process, cls.port, collect_output=cls.do_collect_cmd_init_output ) diff --git a/tests/integration/local/start_lambda/start_lambda_api_integ_base.py b/tests/integration/local/start_lambda/start_lambda_api_integ_base.py index 028f95460b..ca096fdb58 100644 --- a/tests/integration/local/start_lambda/start_lambda_api_integ_base.py +++ b/tests/integration/local/start_lambda/start_lambda_api_integ_base.py @@ -144,7 +144,7 @@ def start_lambda(cls, wait_time=5, input=None, env=None): beta_features=cls.beta_features, ) - cls.start_lambda_process = Popen(command_list, stderr=PIPE, stdin=PIPE, env=env, cwd=cls.working_dir) + cls.start_lambda_process = Popen(command_list, stderr=PIPE, stdin=PIPE, env=env, cwd=cls.working_dir, shell=True,) cls.start_lambda_process_output = "" if input: diff --git a/tests/integration/local/start_lambda/test_start_lambda_terraform_applications.py b/tests/integration/local/start_lambda/test_start_lambda_terraform_applications.py index 0d5eee03c0..8646fb922b 100644 --- a/tests/integration/local/start_lambda/test_start_lambda_terraform_applications.py +++ b/tests/integration/local/start_lambda/test_start_lambda_terraform_applications.py @@ -61,7 +61,7 @@ def setUpClass(cls): @classmethod def _run_command(cls, command_list, env=None, tf_application=None): - process = Popen(command_list, stdout=PIPE, stderr=PIPE, env=env, cwd=tf_application) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, env=env, cwd=tf_application, shell=True,) try: (stdout, stderr) = process.communicate(timeout=300) return stdout, stderr, process.returncode diff --git a/tests/integration/package/test_package_command_image.py b/tests/integration/package/test_package_command_image.py index 8c5b36649d..3223446c80 100644 --- a/tests/integration/package/test_package_command_image.py +++ b/tests/integration/package/test_package_command_image.py @@ -54,7 +54,7 @@ def test_package_template_without_image_repository(self, template_file): template_path = self.test_data_path.joinpath(template_file) command_list = PackageIntegBase.get_command_list(template=template_path) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: stdout, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -78,7 +78,7 @@ def test_package_template_with_image_repository(self, template_file): template_path = self.test_data_path.joinpath(template_file) command_list = PackageIntegBase.get_command_list(image_repository=self.ecr_repo_name, template=template_path) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -103,7 +103,7 @@ def test_package_template_with_image_repositories(self, resource_id, template_fi image_repositories=f"{resource_id}={self.ecr_repo_name}", template=template_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -133,7 +133,7 @@ def test_package_template_with_image_repositories_nested_stack(self, resource_id image_repositories=f"{resource_id}={self.ecr_repo_name}", template=template_path, resolve_s3=True ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -157,7 +157,7 @@ def test_package_template_with_non_ecr_repo_uri_image_repository(self, template_ image_repository="non-ecr-repo-uri", template=template_path, resolve_s3=True ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -181,7 +181,7 @@ def test_package_template_and_s3_bucket(self, template_file): s3_bucket=self.s3_bucket, s3_prefix=self.s3_prefix, template=template_path ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -212,7 +212,7 @@ def test_package_template_with_image_function_in_nested_application(self, templa output_template_file=packaged_file.name, ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -254,7 +254,7 @@ def test_package_with_deep_nested_template_image(self): image_repository=self.ecr_repo_name, resolve_s3=True, template=template_path, force_upload=True ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/package/test_package_command_zip.py b/tests/integration/package/test_package_command_zip.py index 85d2f36ab5..8c2ece3c5b 100644 --- a/tests/integration/package/test_package_command_zip.py +++ b/tests/integration/package/test_package_command_zip.py @@ -32,7 +32,7 @@ def test_package_template_flag(self, template_file): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template=template_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -54,7 +54,7 @@ def test_package_nested_template(self, template_file, uploading_count): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template=template_path, force_upload=True ) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -97,7 +97,7 @@ def test_package_barebones(self, template_file): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template_file=template_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -110,7 +110,7 @@ def test_package_barebones(self, template_file): def test_package_without_required_args(self): command_list = PackageIntegBase.get_command_list() - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -150,7 +150,7 @@ def test_package_with_prefix(self, template_file): s3_bucket=self.s3_bucket.name, template_file=template_path, s3_prefix=self.s3_prefix ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -199,7 +199,7 @@ def test_package_with_output_template_file(self, template_file): output_template_file=output_template.name, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -255,7 +255,7 @@ def test_package_with_json(self, template_file): use_json=True, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -313,7 +313,7 @@ def test_package_with_force_upload(self, template_file): force_upload=True, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -370,7 +370,7 @@ def test_package_with_kms_key(self, template_file): kms_key_id=self.kms_key, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -427,7 +427,7 @@ def test_package_with_metadata(self, template_file): metadata={"integ": "yes"}, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -482,7 +482,7 @@ def test_package_with_resolve_s3(self, template_file): resolve_s3=True, ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -514,7 +514,7 @@ def test_package_with_no_progressbar(self, no_progressbar): resolve_s3=True, ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -546,7 +546,7 @@ def test_package_with_warning_template(self, template_file, warning_keyword): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template=template_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -576,7 +576,7 @@ def test_package_with_deep_nested_template(self): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template=template_path, force_upload=True ) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -622,7 +622,7 @@ def test_package_with_stackset(self): prevdir = os.getcwd() os.chdir(os.path.expanduser(os.path.dirname(template_path))) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -665,7 +665,7 @@ def test_package_with_stackset_in_a_substack(self): prevdir = os.getcwd() os.chdir(os.path.expanduser(os.path.dirname(template_path))) - process = Popen(command_list, stdout=PIPE, stderr=PIPE) + process = Popen(command_list, stdout=PIPE, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -698,7 +698,7 @@ def test_package_logs_warning_for_cdk_project(self, template_file): s3_bucket=self.s3_bucket.name, s3_prefix=self.s3_prefix, template_file=template_path ) - process = Popen(command_list, stdout=PIPE) + process = Popen(command_list, stdout=PIPE, shell=True,) try: stdout, _ = process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/publish/test_command_integ.py b/tests/integration/publish/test_command_integ.py index 6d6d759f2b..951d0c805b 100644 --- a/tests/integration/publish/test_command_integ.py +++ b/tests/integration/publish/test_command_integ.py @@ -112,7 +112,7 @@ def test_publish_not_packaged_template(self): template_path = self.temp_dir.joinpath("template_not_packaged.yaml") command_list = self.get_command_list(template_path=template_path, region=self.region_name) - process = Popen(command_list, stderr=PIPE) + process = Popen(command_list, stderr=PIPE, shell=True,) try: _, stderr = process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/integration/scripts/test_copy_terraform_built_artifacts.py b/tests/integration/scripts/test_copy_terraform_built_artifacts.py index 911ceee261..7f3038feb8 100644 --- a/tests/integration/scripts/test_copy_terraform_built_artifacts.py +++ b/tests/integration/scripts/test_copy_terraform_built_artifacts.py @@ -46,7 +46,7 @@ def test_script_output_path_directory(self): json_str, ] subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) self.assertEqual(os.listdir(self.directory), [self.artifact_name]) @@ -65,7 +65,7 @@ def test_script_output_path_zip(self): json_str, ] subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) self.assertEqual(os.listdir(self.directory), [self.artifact_name]) @@ -85,7 +85,7 @@ def test_script_output_path_directory_invalid_directory(self): ] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_directory_invalid_expression(self): @@ -107,7 +107,7 @@ def test_script_output_path_directory_invalid_expression(self): ] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_directory_valid_expression_invalid_extracted_path(self): @@ -129,7 +129,7 @@ def test_script_output_path_directory_valid_expression_invalid_extracted_path(se ] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_directory_same_directory_and_extracted_path(self): @@ -148,7 +148,7 @@ def test_script_output_path_directory_same_directory_and_extracted_path(self): ] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_no_target_and_no_json(self): @@ -162,7 +162,7 @@ def test_script_output_path_no_target_and_no_json(self): self.expression, ] subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_both_target_and_option(self): @@ -182,7 +182,7 @@ def test_script_output_path_both_target_and_option(self): ] with self.assertRaises(subprocess.CalledProcessError): subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) def test_script_output_path_invalid_json(self): @@ -198,5 +198,5 @@ def test_script_output_path_invalid_json(self): "invalid_json", ] subprocess.check_call( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=self.working_dir, shell=True, ) diff --git a/tests/integration/telemetry/integ_base.py b/tests/integration/telemetry/integ_base.py index 157fd78962..f4b9e0b132 100644 --- a/tests/integration/telemetry/integ_base.py +++ b/tests/integration/telemetry/integ_base.py @@ -59,7 +59,7 @@ def run_cmd(self, cmd_list=None, stdin_data="", optout_envvar_value=None): env["__SAM_CLI_TELEMETRY_ENDPOINT_URL"] = "{}/metrics".format(TELEMETRY_ENDPOINT_URL) process = subprocess.Popen( - cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env + cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, shell=True, ) return process diff --git a/tests/regression/deploy/regression_deploy_base.py b/tests/regression/deploy/regression_deploy_base.py index 2154ad6910..f82e71d8c0 100644 --- a/tests/regression/deploy/regression_deploy_base.py +++ b/tests/regression/deploy/regression_deploy_base.py @@ -94,7 +94,7 @@ def deploy_regression_check(self, args, sam_return_code=0, aws_return_code=0, co del args["aws_stack_name"] aws_command_list = self.get_deploy_command_list(base="aws", stack_name=aws_stack_name, **args) - process = Popen(aws_command_list, stdout=PIPE) + process = Popen(aws_command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -103,7 +103,7 @@ def deploy_regression_check(self, args, sam_return_code=0, aws_return_code=0, co self.assertEqual(process.returncode, aws_return_code) sam_command_list = self.get_deploy_command_list(stack_name=sam_stack_name, **args) - process = Popen(sam_command_list, stdout=PIPE) + process = Popen(sam_command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/regression/deploy/test_deploy_regression.py b/tests/regression/deploy/test_deploy_regression.py index 9581cd44bb..66ac7bee38 100644 --- a/tests/regression/deploy/test_deploy_regression.py +++ b/tests/regression/deploy/test_deploy_regression.py @@ -42,7 +42,7 @@ def prepare_package(self, template_file): s3_bucket=self.s3_bucket.name, template_file=template_path, output_template_file=output_template_file.name ) - package_process = Popen(package_command_list, stdout=PIPE) + package_process = Popen(package_command_list, stdout=PIPE, shell=True,) try: stdout, _ = package_process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/regression/package/regression_package_base.py b/tests/regression/package/regression_package_base.py index eece11503e..877b92951d 100644 --- a/tests/regression/package/regression_package_base.py +++ b/tests/regression/package/regression_package_base.py @@ -88,7 +88,7 @@ def get_command_list( def regression_check(self, args, skip_sam_metadata=True): with tempfile.NamedTemporaryFile(delete=False) as output_template_file_sam: sam_command_list = self.get_command_list(output_template_file=output_template_file_sam.name, **args) - process = Popen(sam_command_list, stdout=PIPE) + process = Popen(sam_command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: @@ -101,7 +101,7 @@ def regression_check(self, args, skip_sam_metadata=True): aws_command_list = self.get_command_list( base="aws", output_template_file=output_template_file_aws.name, **args ) - process = Popen(aws_command_list, stdout=PIPE) + process = Popen(aws_command_list, stdout=PIPE, shell=True,) try: process.communicate(timeout=TIMEOUT) except TimeoutExpired: diff --git a/tests/smoke/test_all_commands.py b/tests/smoke/test_all_commands.py index 78cd0fb08d..7a30c96c1e 100644 --- a/tests/smoke/test_all_commands.py +++ b/tests/smoke/test_all_commands.py @@ -52,7 +52,7 @@ def run_and_verify_no_crash(self, cmd_name, args): # if a previous smoke test run have been killed, re-running them will fail. so run them in a temp folder with tempfile.TemporaryDirectory() as temp: process = subprocess.Popen( - [sam_cmd, cmd_name] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=temp + [sam_cmd, cmd_name] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=temp, shell=True, ) stdout, stderr = process.communicate() diff --git a/tests/testing_utils.py b/tests/testing_utils.py index a52898f90b..6c04cb9f7b 100644 --- a/tests/testing_utils.py +++ b/tests/testing_utils.py @@ -58,7 +58,7 @@ def method_to_stack_name(method_name): def run_command(command_list, cwd=None, env=None, timeout=TIMEOUT) -> CommandResult: LOG.info("Running command: %s", " ".join(command_list)) - process_execute = Popen(command_list, cwd=cwd, env=env, stdout=PIPE, stderr=PIPE) + process_execute = Popen(command_list, cwd=cwd, env=env, stdout=PIPE, stderr=PIPE, shell=True,) try: stdout_data, stderr_data = process_execute.communicate(timeout=timeout) LOG.info(f"Stdout: {stdout_data.decode('utf-8')}") @@ -74,7 +74,7 @@ def run_command(command_list, cwd=None, env=None, timeout=TIMEOUT) -> CommandRes def run_command_with_input(command_list, stdin_input, timeout=TIMEOUT, cwd=None) -> CommandResult: LOG.info("Running command: %s", " ".join(command_list)) LOG.info("With input: %s", stdin_input) - process_execute = Popen(command_list, cwd=cwd, stdout=PIPE, stderr=PIPE, stdin=PIPE) + process_execute = Popen(command_list, cwd=cwd, stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True,) try: stdout_data, stderr_data = process_execute.communicate(stdin_input, timeout=timeout) LOG.info(f"Stdout: {stdout_data.decode('utf-8')}") @@ -104,6 +104,7 @@ def start_persistent_process( encoding="utf-8", bufsize=1, cwd=cwd, + shell=True, ) diff --git a/tests/unit/commands/init/test_cli.py b/tests/unit/commands/init/test_cli.py index 15c892a114..7a701b6ec8 100644 --- a/tests/unit/commands/init/test_cli.py +++ b/tests/unit/commands/init/test_cli.py @@ -91,6 +91,7 @@ def check_output_mock(cls, commands, cwd, stderr): [git_executable, "clone", url, clone_name], cwd=tempdir, stderr=stderr, + shell = True, ) cls.clone_cache[url] = Path(tempdir, clone_name)