From ad17021e71c91e74389b6029e1475686b656a115 Mon Sep 17 00:00:00 2001 From: Mohamed ElAsmar Date: Fri, 11 Aug 2023 20:09:24 -0700 Subject: [PATCH] feat: remove beta-features flag usage for terraform feature --- .../_utils/custom_options/hook_name_option.py | 83 ------ samcli/commands/build/command.py | 8 - samcli/commands/local/invoke/cli.py | 9 - samcli/commands/local/start_api/cli.py | 9 - samcli/commands/local/start_lambda/cli.py | 9 - .../test_build_terraform_applications.py | 16 - ...uild_terraform_applications_other_cases.py | 102 +------ tests/integration/local/common_utils.py | 6 +- .../test_invoke_terraform_applications.py | 196 +----------- ...st_start_api_with_terraform_application.py | 3 +- ...est_start_lambda_terraform_applications.py | 152 ---------- .../root_module/input_samconfig.yaml | 1 - .../test_hook_package_id_option.py | 280 +----------------- tests/unit/commands/buildcmd/test_command.py | 34 --- 14 files changed, 19 insertions(+), 889 deletions(-) diff --git a/samcli/commands/_utils/custom_options/hook_name_option.py b/samcli/commands/_utils/custom_options/hook_name_option.py index af730ee2f5..a226fd68e9 100644 --- a/samcli/commands/_utils/custom_options/hook_name_option.py +++ b/samcli/commands/_utils/custom_options/hook_name_option.py @@ -8,14 +8,7 @@ import click from samcli.cli.context import Context -from samcli.cli.global_config import GlobalConfig from samcli.commands._utils.constants import DEFAULT_BUILT_TEMPLATE_PATH -from samcli.commands._utils.experimental import ( - ExperimentalFlag, - prompt_experimental, - set_experimental, - update_experimental_context, -) from samcli.lib.hook.exceptions import InvalidHookWrapperException from samcli.lib.hook.hook_wrapper import IacHookWrapper, get_available_hook_packages_ids @@ -57,9 +50,6 @@ def handle_parse_result(self, ctx, opts, args): _validate_build_command_parameters(command_name, opts) - if not _check_experimental_flag(hook_name, command_name, opts, ctx.default_map): - return super().handle_parse_result(ctx, opts, args) - try: self._call_prepare_hook(iac_hook_wrapper, opts, ctx) except Exception as ex: @@ -137,79 +127,6 @@ def _validate_build_command_parameters(command_name, opts): ) -def _check_experimental_flag(hook_name, command_name, opts, default_map): - # check beta-feature - experimental_entry = ExperimentalFlag.IaCsSupport.get(hook_name) - beta_features = _get_customer_input_beta_features_option(default_map, experimental_entry, opts) - - # check if beta feature flag is required for a specific hook package - # The IaCs support experimental flag map will contain only the beta IaCs. In case we support the external - # hooks, we need to first know that the hook package is an external, and to handle the beta feature of it - # using different approach - if beta_features is None and experimental_entry is not None: - iac_support_message = _get_iac_support_experimental_prompt_message(hook_name, command_name) - if not prompt_experimental(experimental_entry, iac_support_message): - LOG.debug("Experimental flag is disabled and prepare hook is not run") - return False - elif not beta_features: - LOG.debug("--beta-features flag is disabled and prepare hook is not run") - return False - elif beta_features: - LOG.debug("--beta-features flag is enabled, enabling experimental flag.") - set_experimental(experimental_entry, True) - update_experimental_context() - return True - - -def _get_customer_input_beta_features_option(default_map, experimental_entry, opts): - # Get the beta-features flag value from the command parameters if provided. - beta_features = opts.get("beta_features") - if beta_features is not None: - return beta_features - - # Get the beta-features flag value from the SamConfig file if provided. - beta_features = default_map.get("beta_features") - if beta_features is not None: - return beta_features - - # Get the beta-features flag value from the environment variables. - if experimental_entry: - gc = GlobalConfig() - beta_features = gc.get_value(experimental_entry, default=None, value_type=bool, is_flag=True) - if beta_features is not None: - return beta_features - return gc.get_value(ExperimentalFlag.All, default=None, value_type=bool, is_flag=True) - - return None - - -def _get_iac_support_experimental_prompt_message(hook_name: str, command: str) -> str: - """ - return the customer prompt message for a specific hook package. - - Parameters - ---------- - hook_name: str - the hook name to determine what is the supported iac - - command: str - the current sam command - Returns - ------- - str - the customer prompt message for a specific IaC. - """ - - supported_iacs_messages = { - "terraform": ( - "Supporting Terraform applications is a beta feature.\n" - "Please confirm if you would like to proceed using AWS SAM CLI with terraform application.\n" - f"You can also enable this beta feature with 'sam {command} --beta-features'." - ) - } - return supported_iacs_messages.get(hook_name, "") - - def _read_parameter_value(param_name, opts, ctx, default_value=None): """ Read SAM CLI parameter value either from the parameters list or from the samconfig values diff --git a/samcli/commands/build/command.py b/samcli/commands/build/command.py index 1eab7c585e..a7fb6bad9d 100644 --- a/samcli/commands/build/command.py +++ b/samcli/commands/build/command.py @@ -8,7 +8,6 @@ import click from samcli.cli.context import Context -from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled from samcli.commands._utils.options import ( skip_prepare_infra_option, template_option_without_build, @@ -220,13 +219,6 @@ def do_cli( # pylint: disable=too-many-locals, too-many-statements """ Implementation of the ``cli`` method """ - if ( - hook_name - and ExperimentalFlag.IaCsSupport.get(hook_name) is not None - and not is_experimental_enabled(ExperimentalFlag.IaCsSupport[hook_name]) - ): - LOG.info("Terraform Support beta feature is not enabled.") - return from samcli.commands.build.build_context import BuildContext diff --git a/samcli/commands/local/invoke/cli.py b/samcli/commands/local/invoke/cli.py index f8e87f4e27..bb5de0616c 100644 --- a/samcli/commands/local/invoke/cli.py +++ b/samcli/commands/local/invoke/cli.py @@ -9,7 +9,6 @@ from samcli.cli.cli_config_file import ConfigProvider, configuration_option from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args from samcli.cli.main import common_options as cli_framework_options -from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled from samcli.commands._utils.option_value_processor import process_image_options from samcli.commands._utils.options import hook_name_click_option, skip_prepare_infra_option, terraform_plan_file_option from samcli.commands.local.cli_common.options import invoke_common_options, local_common_options @@ -162,14 +161,6 @@ def do_cli( # pylint: disable=R0914 from samcli.local.docker.manager import DockerImagePullFailedException from samcli.local.lambdafn.exceptions import FunctionNotFound - if ( - hook_name - and ExperimentalFlag.IaCsSupport.get(hook_name) is not None - and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name)) - ): - LOG.info("Terraform Support beta feature is not enabled.") - return - LOG.debug("local invoke command is called") if event: diff --git a/samcli/commands/local/start_api/cli.py b/samcli/commands/local/start_api/cli.py index 9d3247eeef..9ba18564f5 100644 --- a/samcli/commands/local/start_api/cli.py +++ b/samcli/commands/local/start_api/cli.py @@ -9,7 +9,6 @@ from samcli.cli.cli_config_file import ConfigProvider, configuration_option from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args from samcli.cli.main import common_options as cli_framework_options -from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled from samcli.commands._utils.option_value_processor import process_image_options from samcli.commands._utils.options import ( generate_next_command_recommendation, @@ -186,14 +185,6 @@ def do_cli( # pylint: disable=R0914 LOG.debug("local start-api command is called") - if ( - hook_name - and ExperimentalFlag.IaCsSupport.get(hook_name) is not None - and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name)) - ): - LOG.info("Terraform Support beta feature is not enabled.") - return - processed_invoke_images = process_image_options(invoke_image) # Pass all inputs to setup necessary context to invoke function locally. diff --git a/samcli/commands/local/start_lambda/cli.py b/samcli/commands/local/start_lambda/cli.py index 8dd78dc2f9..75184a4e58 100644 --- a/samcli/commands/local/start_lambda/cli.py +++ b/samcli/commands/local/start_lambda/cli.py @@ -9,7 +9,6 @@ from samcli.cli.cli_config_file import ConfigProvider, configuration_option from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args from samcli.cli.main import common_options as cli_framework_options -from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled from samcli.commands._utils.option_value_processor import process_image_options from samcli.commands._utils.options import ( generate_next_command_recommendation, @@ -169,14 +168,6 @@ def do_cli( # pylint: disable=R0914 from samcli.lib.providers.exceptions import InvalidLayerReference from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported - if ( - hook_name - and ExperimentalFlag.IaCsSupport.get(hook_name) is not None - and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name)) - ): - LOG.info("Terraform Support beta feature is not enabled.") - return - LOG.debug("local start_lambda command is called") processed_invoke_images = process_image_options(invoke_image) diff --git a/tests/integration/buildcmd/test_build_terraform_applications.py b/tests/integration/buildcmd/test_build_terraform_applications.py index 8a0044d4e7..983571b184 100644 --- a/tests/integration/buildcmd/test_build_terraform_applications.py +++ b/tests/integration/buildcmd/test_build_terraform_applications.py @@ -15,7 +15,6 @@ from parameterized import parameterized, parameterized_class -from samcli.lib.utils.colors import Colored from tests.integration.buildcmd.build_integ_base import BuildIntegBase from tests.testing_utils import CI_OVERRIDE, IS_WINDOWS, RUN_BY_CANARY @@ -76,7 +75,6 @@ def _verify_invoke_built_function(self, function_logical_id, overrides, expected "--no-event", "--hook-name", "terraform", - "--beta-features", ] if overrides: @@ -243,7 +241,6 @@ def setUpClass(cls): @parameterized.expand(functions) def test_build_and_invoke_lambda_functions(self, function_identifier, expected_output, should_override_code): command_list_parameters = { - "beta_features": True, "hook_name": "terraform", "function_identifier": function_identifier, } @@ -260,18 +257,6 @@ def test_build_and_invoke_lambda_functions(self, function_identifier, expected_o if should_override_code: environment_variables["TF_VAR_HELLO_FUNCTION_SRC_CODE"] = "./artifacts/HelloWorldFunction2" stdout, stderr, return_code = self.run_command(build_cmd_list, env=environment_variables) - terraform_beta_feature_prompted_text = ( - f"Supporting Terraform applications is a beta feature.{os.linesep}" - f"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.{os.linesep}" - "You can also enable this beta feature with 'sam build --beta-features'." - ) - experimental_warning = ( - f"{os.linesep}Experimental features are enabled for this session.{os.linesep}" - f"Visit the docs page to learn more about the AWS Beta terms " - f"https://aws.amazon.com/service-terms/.{os.linesep}" - ) - self.assertNotRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertIn(Colored().yellow(experimental_warning), stderr.decode("utf-8")) LOG.info("sam build stdout: %s", stdout.decode("utf-8")) LOG.info("sam build stderr: %s", stderr.decode("utf-8")) self.assertEqual(return_code, 0) @@ -374,7 +359,6 @@ def setUpClass(cls): @parameterized.expand(functions) def test_build_and_invoke_lambda_functions(self, function_identifier, expected_output, should_override_code): command_list_parameters = { - "beta_features": True, "hook_name": "terraform", "function_identifier": function_identifier, } diff --git a/tests/integration/buildcmd/test_build_terraform_applications_other_cases.py b/tests/integration/buildcmd/test_build_terraform_applications_other_cases.py index a45a7a569e..7909baf7da 100644 --- a/tests/integration/buildcmd/test_build_terraform_applications_other_cases.py +++ b/tests/integration/buildcmd/test_build_terraform_applications_other_cases.py @@ -6,7 +6,6 @@ from parameterized import parameterized, parameterized_class -from samcli.lib.utils.colors import Colored from tests.integration.buildcmd.test_build_terraform_applications import ( BuildTerraformApplicationIntegBase, BuildTerraformApplicationS3BackendIntegBase, @@ -44,7 +43,7 @@ def test_invalid_hook_name(self): self.assertNotEqual(return_code, 0) def test_exit_failed_use_container_no_build_image_hooks(self): - cmdlist = self.get_command_list(beta_features=True, hook_name="terraform", use_container=True) + cmdlist = self.get_command_list(hook_name="terraform", use_container=True) _, stderr, return_code = self.run_command(cmdlist) process_stderr = stderr.strip() self.assertRegex( @@ -54,7 +53,7 @@ def test_exit_failed_use_container_no_build_image_hooks(self): self.assertNotEqual(return_code, 0) def test_exit_failed_project_root_dir_no_hooks(self): - cmdlist = self.get_command_list(beta_features=True, project_root_dir="/path") + cmdlist = self.get_command_list(project_root_dir="/path") _, stderr, return_code = self.run_command(cmdlist) process_stderr = stderr.strip() self.assertRegex( @@ -64,7 +63,7 @@ def test_exit_failed_project_root_dir_no_hooks(self): self.assertNotEqual(return_code, 0) def test_exit_failed_project_root_dir_not_parent_of_current_directory(self): - cmdlist = self.get_command_list(beta_features=True, hook_name="terraform", project_root_dir="/path") + cmdlist = self.get_command_list(hook_name="terraform", project_root_dir="/path") _, stderr, return_code = self.run_command(cmdlist) process_stderr = stderr.strip() self.assertRegex( @@ -75,7 +74,7 @@ def test_exit_failed_project_root_dir_not_parent_of_current_directory(self): self.assertNotEqual(return_code, 0) def test_exit_failed_use_container_short_format_no_build_image_hooks(self): - cmdlist = self.get_command_list(beta_features=True, hook_name="terraform") + cmdlist = self.get_command_list(hook_name="terraform") cmdlist += ["-u"] _, stderr, return_code = self.run_command(cmdlist) process_stderr = stderr.strip() @@ -85,53 +84,6 @@ def test_exit_failed_use_container_short_format_no_build_image_hooks(self): ) self.assertNotEqual(return_code, 0) - def test_exit_success_no_beta_feature_flags_hooks(self): - cmdlist = self.get_command_list(beta_features=None, hook_name="terraform") - stdout, stderr, return_code = self.run_command(cmdlist, input=b"N\n\n") - terraform_beta_feature_prompted_text = ( - f"Supporting Terraform applications is a beta feature.{os.linesep}" - f"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.{os.linesep}" - "You can also enable this beta feature with 'sam build --beta-features'." - ) - self.assertRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertEqual(return_code, 0) - self.assertRegex(stderr.strip().decode("utf-8"), "Terraform Support beta feature is not enabled.") - - def test_exit_success_no_beta_features_flags_supplied_hooks(self): - cmdlist = self.get_command_list(beta_features=False, hook_name="terraform") - _, stderr, return_code = self.run_command(cmdlist) - self.assertEqual(return_code, 0) - self.assertRegex(stderr.strip().decode("utf-8"), "Terraform Support beta feature is not enabled.") - - def test_build_terraform_with_no_beta_feature_option_in_samconfig_toml(self): - samconfig_toml_path = Path(self.working_dir).joinpath("samconfig.toml") - samconfig_lines = [ - bytes("version = 0.1" + os.linesep, "utf-8"), - bytes("[default.global.parameters]" + os.linesep, "utf-8"), - bytes("beta_features = false" + os.linesep, "utf-8"), - ] - with open(samconfig_toml_path, "wb") as file: - file.writelines(samconfig_lines) - - cmdlist = self.get_command_list(hook_name="terraform") - _, stderr, return_code = self.run_command(cmdlist) - self.assertEqual(return_code, 0) - self.assertRegex(stderr.strip().decode("utf-8"), "Terraform Support beta feature is not enabled.") - # delete the samconfig file - try: - os.remove(samconfig_toml_path) - except FileNotFoundError: - pass - - def test_build_terraform_with_no_beta_feature_option_as_environment_variable(self): - environment_variables = os.environ.copy() - environment_variables["SAM_CLI_BETA_TERRAFORM_SUPPORT"] = "False" - - build_command_list = self.get_command_list(hook_name="terraform") - _, stderr, return_code = self.run_command(build_command_list, env=environment_variables) - self.assertEqual(return_code, 0) - self.assertRegex(stderr.strip().decode("utf-8"), "Terraform Support beta feature is not enabled.") - @skipIf( (not RUN_BY_CANARY and not CI_OVERRIDE), @@ -142,9 +94,7 @@ class TestInvalidTerraformApplicationThatReferToS3BucketNotCreatedYet(BuildTerra def test_invoke_function(self): function_identifier = "aws_lambda_function.function" - build_cmd_list = self.get_command_list( - beta_features=True, hook_name="terraform", function_identifier=function_identifier - ) + build_cmd_list = self.get_command_list(hook_name="terraform", function_identifier=function_identifier) LOG.info("command list: %s", build_cmd_list) environment_variables = os.environ.copy() @@ -175,7 +125,6 @@ class TestInvalidBuildTerraformApplicationsWithZipBasedLambdaFunctionAndS3Backen def test_build_no_s3_config(self): command_list_parameters = { - "beta_features": True, "hook_name": "terraform", } build_cmd_list = self.get_command_list(**command_list_parameters) @@ -206,9 +155,7 @@ class TestBuildTerraformApplicationsWithImageBasedLambdaFunctionAndLocalBackend( @parameterized.expand(functions) def test_build_and_invoke_lambda_functions(self, function_identifier): - build_cmd_list = self.get_command_list( - beta_features=True, hook_name="terraform", function_identifier=function_identifier - ) + build_cmd_list = self.get_command_list(hook_name="terraform", function_identifier=function_identifier) LOG.info("command list: %s", build_cmd_list) _, stderr, return_code = self.run_command(build_cmd_list) LOG.info(stderr) @@ -248,9 +195,7 @@ class TestBuildTerraformApplicationsWithImageBasedLambdaFunctionAndS3Backend( @parameterized.expand(functions) def test_build_and_invoke_lambda_functions(self, function_identifier): - build_cmd_list = self.get_command_list( - beta_features=True, hook_name="terraform", function_identifier=function_identifier - ) + build_cmd_list = self.get_command_list(hook_name="terraform", function_identifier=function_identifier) LOG.info("command list: %s", build_cmd_list) _, stderr, return_code = self.run_command(build_cmd_list) LOG.info(stderr) @@ -312,7 +257,7 @@ def test_unsupported_cases(self, app, expected_error_message): self.terraform_application_path = Path(self.terraform_application_path) / app shutil.copytree(Path(self.terraform_application_path), Path(self.working_dir)) - build_cmd_list = self.get_command_list(beta_features=True, hook_name="terraform") + build_cmd_list = self.get_command_list(hook_name="terraform") LOG.info("command list: %s", build_cmd_list) _, stderr, return_code = self.run_command(build_cmd_list) LOG.info(stderr) @@ -370,7 +315,7 @@ def tearDown(self): self.assertEqual(return_code, 0) def test_unsupported_cases_runs_after_apply(self): - build_cmd_list = self.get_command_list(beta_features=True, hook_name="terraform") + build_cmd_list = self.get_command_list(hook_name="terraform") LOG.info("command list: %s", build_cmd_list) _, _, return_code = self.run_command(build_cmd_list) self.assertEqual(return_code, 0) @@ -390,9 +335,7 @@ class TestBuildGoFunctionAndKeepPermissions(BuildTerraformApplicationIntegBase): def test_invoke_function(self): function_identifier = "hello-world-function" - build_cmd_list = self.get_command_list( - beta_features=True, hook_name="terraform", function_identifier=function_identifier - ) + build_cmd_list = self.get_command_list(hook_name="terraform", function_identifier=function_identifier) LOG.info("command list: %s", build_cmd_list) environment_variables = os.environ.copy() @@ -434,7 +377,6 @@ def tearDown(self): @parameterized.expand(functions) def test_build_and_invoke_lambda_functions(self, function_identifier, expected_output): command_list_parameters = { - "beta_features": True, "hook_name": "terraform", "function_identifier": function_identifier, "project_root_dir": "./..", @@ -445,18 +387,6 @@ def test_build_and_invoke_lambda_functions(self, function_identifier, expected_o build_cmd_list = self.get_command_list(**command_list_parameters) LOG.info("command list: %s", build_cmd_list) stdout, stderr, return_code = self.run_command(build_cmd_list) - terraform_beta_feature_prompted_text = ( - f"Supporting Terraform applications is a beta feature.{os.linesep}" - f"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.{os.linesep}" - "You can also enable this beta feature with 'sam build --beta-features'." - ) - experimental_warning = ( - f"{os.linesep}Experimental features are enabled for this session.{os.linesep}" - f"Visit the docs page to learn more about the AWS Beta terms " - f"https://aws.amazon.com/service-terms/.{os.linesep}" - ) - self.assertNotRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertIn(Colored().yellow(experimental_warning), stderr.decode("utf-8")) LOG.info("sam build stdout: %s", stdout.decode("utf-8")) LOG.info("sam build stderr: %s", stderr.decode("utf-8")) self.assertEqual(return_code, 0) @@ -500,18 +430,6 @@ def test_build_and_invoke_lambda_functions(self, function_identifier, expected_o build_cmd_list = self.get_command_list(**command_list_parameters) LOG.info("command list: %s", build_cmd_list) stdout, stderr, return_code = self.run_command(build_cmd_list) - terraform_beta_feature_prompted_text = ( - f"Supporting Terraform applications is a beta feature.{os.linesep}" - f"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.{os.linesep}" - "You can also enable this beta feature with 'sam build --beta-features'." - ) - experimental_warning = ( - f"{os.linesep}Experimental features are enabled for this session.{os.linesep}" - f"Visit the docs page to learn more about the AWS Beta terms " - f"https://aws.amazon.com/service-terms/.{os.linesep}" - ) - self.assertNotRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertIn(Colored().yellow(experimental_warning), stderr.decode("utf-8")) LOG.info("sam build stdout: %s", stdout.decode("utf-8")) LOG.info("sam build stderr: %s", stderr.decode("utf-8")) self.assertEqual(return_code, 0) diff --git a/tests/integration/local/common_utils.py b/tests/integration/local/common_utils.py index 9ed98ed361..0dbb23aa7c 100644 --- a/tests/integration/local/common_utils.py +++ b/tests/integration/local/common_utils.py @@ -28,11 +28,7 @@ def wait_for_local_process(process, port, collect_output=False) -> str: if "Address already in use" in line_as_str: LOG.info(f"Attempted to start port on {port} but it is already in use, restarting on a new port.") raise InvalidAddressException() - if ( - "Press CTRL+C to quit" in line_as_str - or "Terraform Support beta feature is not enabled." in line_as_str - or "Error: " in line_as_str - ): + if "Press CTRL+C to quit" in line_as_str or "Error: " in line_as_str: break return output diff --git a/tests/integration/local/invoke/test_invoke_terraform_applications.py b/tests/integration/local/invoke/test_invoke_terraform_applications.py index 792025f65d..e810696118 100644 --- a/tests/integration/local/invoke/test_invoke_terraform_applications.py +++ b/tests/integration/local/invoke/test_invoke_terraform_applications.py @@ -15,11 +15,8 @@ from docker.errors import APIError from parameterized import parameterized, parameterized_class -from samcli.commands._utils.experimental import EXPERIMENTAL_WARNING -from samcli.lib.utils.colors import Colored from tests.integration.local.invoke.invoke_integ_base import InvokeIntegBase, TIMEOUT from tests.integration.local.invoke.layer_utils import LayerUtils -from tests.integration.local.start_lambda.start_lambda_api_integ_base import StartLambdaIntegBaseClass from tests.testing_utils import CI_OVERRIDE, IS_WINDOWS, RUNNING_ON_CI, RUN_BY_CANARY LOG = logging.getLogger(__name__) @@ -76,7 +73,7 @@ def tearDown(self) -> None: @pytest.mark.flaky(reruns=3) def test_invoke_function(self, function_name): local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke=function_name, hook_name="terraform", beta_features=True + function_to_invoke=function_name, hook_name="terraform" ) stdout, _, return_code = self.run_command(local_invoke_command_list) @@ -97,7 +94,6 @@ def test_invoke_function_custom_plan(self, function_name): local_invoke_command_list = InvokeIntegBase.get_command_list( function_to_invoke=function_name, hook_name="terraform", - beta_features=True, terraform_plan_file="custom-plan.json", ) stdout, _, return_code = self.run_command(local_invoke_command_list) @@ -110,7 +106,7 @@ def test_invoke_function_custom_plan(self, function_name): self.assertEqual(response, expected_response) def test_exit_failed_project_root_dir_no_hooks_custom_plan_file(self): - cmdlist = self.get_command_list(beta_features=True, terraform_plan_file="/path", function_to_invoke="") + cmdlist = self.get_command_list(terraform_plan_file="/path", function_to_invoke="") _, stderr, return_code = self.run_command(cmdlist) process_stderr = stderr.strip() self.assertRegex( @@ -119,137 +115,6 @@ def test_exit_failed_project_root_dir_no_hooks_custom_plan_file(self): ) self.assertNotEqual(return_code, 0) - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @parameterized.expand(functions) - @pytest.mark.flaky(reruns=3) - def test_invoke_terraform_with_beta_feature_option_in_samconfig_toml(self, function_name): - samconfig_toml_path = Path(self.terraform_application_path).joinpath("samconfig.toml") - samconfig_lines = [ - bytes("version = 0.1" + os.linesep, "utf-8"), - bytes("[default.global.parameters]" + os.linesep, "utf-8"), - bytes("beta_features = true" + os.linesep, "utf-8"), - ] - with open(samconfig_toml_path, "wb") as file: - file.writelines(samconfig_lines) - - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke=function_name, hook_name="terraform" - ) - stdout, _, return_code = self.run_command(local_invoke_command_list) - - # Get the response without the sam-cli prompts that proceed it - response = json.loads(stdout.decode("utf-8").split("\n")[-1]) - expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}') - - self.assertEqual(return_code, 0) - self.assertEqual(response, expected_response) - # delete the samconfig file - try: - os.remove(samconfig_toml_path) - except FileNotFoundError: - pass - - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @parameterized.expand(functions) - @pytest.mark.flaky(reruns=3) - def test_invoke_terraform_with_beta_feature_option_as_environment_variable(self, function_name): - environment_variables = os.environ.copy() - environment_variables["SAM_CLI_BETA_TERRAFORM_SUPPORT"] = "1" - - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke=function_name, hook_name="terraform" - ) - stdout, _, return_code = self.run_command(local_invoke_command_list, env=environment_variables) - - # Get the response without the sam-cli prompts that proceed it - response = json.loads(stdout.decode("utf-8").split("\n")[-1]) - expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}') - - self.assertEqual(return_code, 0) - self.assertEqual(response, expected_response) - - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @pytest.mark.flaky(reruns=3) - def test_invoke_function_get_experimental_prompted(self): - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke="s3_lambda_function", hook_name="terraform" - ) - stdout, stderr, return_code = self.run_command(local_invoke_command_list, input=b"Y\n\n") - - terraform_beta_feature_prompted_text = ( - "Supporting Terraform applications is a beta feature.\n" - "Please confirm if you would like to proceed using AWS SAM CLI with terraform application.\n" - "You can also enable this beta feature with 'sam local invoke --beta-features'." - ) - self.assertRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertRegex(stderr.decode("utf-8"), EXPERIMENTAL_WARNING) - - response = json.loads(stdout.decode("utf-8").split("\n")[2][85:].strip()) - expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}') - - self.assertEqual(return_code, 0) - self.assertEqual(response, expected_response) - - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @pytest.mark.flaky(reruns=3) - def test_invoke_function_with_beta_feature_expect_warning_message(self): - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke="s3_lambda_function", hook_name="terraform", beta_features=True - ) - stdout, stderr, return_code = self.run_command(local_invoke_command_list) - - terraform_beta_feature_prompted_text = ( - "Supporting Terraform applications is a beta feature.\n" - "Please confirm if you would like to proceed using AWS SAM CLI with terraform application.\n" - "You can also enable this beta feature with 'sam local invoke --beta-features'." - ) - self.assertNotRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - self.assertTrue(Colored().yellow(EXPERIMENTAL_WARNING) in stderr.decode("utf-8")) - - response = json.loads(stdout.decode("utf-8").split("\n")[-1]) - expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}') - - self.assertEqual(return_code, 0) - self.assertEqual(response, expected_response) - - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @pytest.mark.flaky(reruns=3) - def test_invoke_function_get_experimental_prompted_input_no(self): - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke="s3_lambda_function", hook_name="terraform" - ) - stdout, stderr, return_code = self.run_command(local_invoke_command_list, input=b"N\n\n") - - terraform_beta_feature_prompted_text = ( - "Supporting Terraform applications is a beta feature.\n" - "Please confirm if you would like to proceed using AWS SAM CLI with terraform application.\n" - "You can also enable this beta feature with 'sam local invoke --beta-features'." - ) - self.assertRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - - self.assertEqual(return_code, 0) - def test_invalid_hook_name(self): local_invoke_command_list = InvokeIntegBase.get_command_list("func", hook_name="tf") _, stderr, return_code = self.run_command(local_invoke_command_list) @@ -261,58 +126,6 @@ def test_invalid_hook_name(self): ) self.assertNotEqual(return_code, 0) - def test_invoke_terraform_with_no_beta_feature_option(self): - local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke="func", hook_name="terraform", beta_features=False - ) - _, stderr, return_code = self.run_command(local_invoke_command_list) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - - def test_invoke_terraform_with_no_beta_feature_option_in_samconfig_toml(self): - samconfig_toml_path = Path(self.terraform_application_path).joinpath("samconfig.toml") - samconfig_lines = [ - bytes("version = 0.1" + os.linesep, "utf-8"), - bytes("[default.global.parameters]" + os.linesep, "utf-8"), - bytes("beta_features = false" + os.linesep, "utf-8"), - ] - with open(samconfig_toml_path, "wb") as file: - file.writelines(samconfig_lines) - - local_invoke_command_list = InvokeIntegBase.get_command_list(function_to_invoke="func", hook_name="terraform") - _, stderr, return_code = self.run_command(local_invoke_command_list) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - # delete the samconfig file - try: - os.remove(samconfig_toml_path) - except FileNotFoundError: - pass - - def test_invoke_terraform_with_no_beta_feature_option_as_environment_variable(self): - environment_variables = os.environ.copy() - environment_variables["SAM_CLI_BETA_TERRAFORM_SUPPORT"] = "False" - - local_invoke_command_list = InvokeIntegBase.get_command_list(function_to_invoke="func", hook_name="terraform") - _, stderr, return_code = self.run_command(local_invoke_command_list, env=environment_variables) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - def test_invalid_coexist_parameters(self): local_invoke_command_list = InvokeIntegBase.get_command_list( "func", hook_name="terraform", template_path="template.yaml" @@ -474,7 +287,7 @@ def tearDown(self) -> None: @pytest.mark.flaky(reruns=3) def test_invoke_function(self, function_name, expected_output): local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke=function_name, hook_name="terraform", beta_features=True + function_to_invoke=function_name, hook_name="terraform" ) stdout, _, return_code = self.run_command(local_invoke_command_list, env=self._add_tf_project_variables()) @@ -506,7 +319,7 @@ def tearDown(self) -> None: def test_invoke_function(self): function_name = "aws_lambda_function.function" local_invoke_command_list = InvokeIntegBase.get_command_list( - function_to_invoke=function_name, hook_name="terraform", beta_features=True + function_to_invoke=function_name, hook_name="terraform" ) _, stderr, return_code = self.run_command(local_invoke_command_list) process_stderr = stderr.strip() @@ -566,7 +379,6 @@ def test_invoke_image_function(self, function_name): function_to_invoke=function_name, hook_name="terraform", event_path=self.event_path, - beta_features=True, ) stdout, _, return_code = self.run_command(local_invoke_command_list) diff --git a/tests/integration/local/start_api/test_start_api_with_terraform_application.py b/tests/integration/local/start_api/test_start_api_with_terraform_application.py index 54fb6fe669..74ce8743a1 100644 --- a/tests/integration/local/start_api/test_start_api_with_terraform_application.py +++ b/tests/integration/local/start_api/test_start_api_with_terraform_application.py @@ -27,7 +27,7 @@ def setUpClass(cls): command = get_sam_command() cls.template_path = "" cls.build_before_invoke = False - cls.command_list = [command, "local", "start-api", "--hook-name", "terraform", "--beta-features"] + cls.command_list = [command, "local", "start-api", "--hook-name", "terraform"] if cls.terraform_plan_file: cls.command_list += ["--terraform-plan-file", cls.terraform_plan_file] cls.test_data_path = Path(cls.get_integ_dir()) / "testdata" / "start_api" @@ -199,7 +199,6 @@ def setUpClass(cls): "start-api", "--hook-name", "terraform", - "--beta-features", "-p", str(random_port()), ] 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 4c4a5f117e..3a24bfbd80 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 @@ -18,8 +18,6 @@ from docker.errors import APIError from parameterized import parameterized, parameterized_class -from samcli.commands._utils.experimental import EXPERIMENTAL_WARNING -from samcli.lib.utils.colors import Colored from tests.integration.local.common_utils import random_port from tests.integration.local.invoke.layer_utils import LayerUtils from tests.integration.local.start_lambda.start_lambda_api_integ_base import StartLambdaIntegBaseClass @@ -74,7 +72,6 @@ class TestLocalStartLambdaTerraformApplicationWithoutBuild(StartLambdaTerraformA terraform_application = "/testdata/invoke/terraform/simple_application_no_building_logic" template_path = None hook_name = "terraform" - beta_features = True def setUp(self): self.url = "http://127.0.0.1:{}".format(self.port) @@ -118,7 +115,6 @@ class TestLocalStartLambdaTerraformApplicationWithoutBuildCustomPlanFile(StartLa terraform_application = "/testdata/invoke/terraform/simple_application_no_building_logic" template_path = None hook_name = "terraform" - beta_features = True terraform_plan_file = "custom-plan.json" def setUp(self): @@ -175,7 +171,6 @@ class TestLocalStartLambdaTerraformApplicationWithLayersWithoutBuild(StartLambda pre_create_lambda_layers = ["simple_layer1", "simple_layer2", "simple_layer3", "simple_layer33", "simple_layer44"] template_path = None hook_name = "terraform" - beta_features = True @classmethod def setUpClass(cls): @@ -327,7 +322,6 @@ class TestInvalidTerraformApplicationThatReferToS3BucketNotCreatedYet(StartLambd terraform_application = "/testdata/invoke/terraform/invalid_no_local_code_project" template_path = None hook_name = "terraform" - beta_features = True @classmethod def setUpClass(cls): @@ -365,7 +359,6 @@ def test_invoke_function(self): command_list = self.get_start_lambda_command( port=self.port, hook_name=self.hook_name, - beta_features=self.beta_features, ) _, stderr, return_code = self._run_command(command_list, tf_application=self.working_dir) @@ -378,96 +371,6 @@ def test_invoke_function(self): self.assertNotEqual(return_code, 0) -@skipIf( - (not RUN_BY_CANARY and not CI_OVERRIDE), - "Skip Terraform test cases unless running in CI", -) -class TestLocalStartLambdaTerraformApplicationWithExperimentalPromptYes(StartLambdaTerraformApplicationIntegBase): - terraform_application = "/testdata/invoke/terraform/simple_application_no_building_logic" - template_path = None - hook_name = "terraform" - input = b"Y\n" - collect_start_lambda_process_output = True - - def setUp(self): - self.url = "http://127.0.0.1:{}".format(self.port) - self.lambda_client = boto3.client( - "lambda", - endpoint_url=self.url, - region_name="us-east-1", - use_ssl=False, - verify=False, - config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}), - ) - - @pytest.mark.flaky(reruns=3) - def test_invoke_function(self): - response = self.lambda_client.invoke(FunctionName="s3_lambda_function") - - response_body = json.loads(response.get("Payload").read().decode("utf-8")) - expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}') - - self.assertEqual(response_body, expected_response) - self.assertEqual(response.get("StatusCode"), 200) - - -@skipIf( - (not RUN_BY_CANARY and not CI_OVERRIDE), - "Skip Terraform test cases unless running in CI", -) -class TestLocalStartLambdaTerraformApplicationWithBetaFeatures(StartLambdaTerraformApplicationIntegBase): - terraform_application = "/testdata/invoke/terraform/simple_application_no_building_logic" - template_path = None - hook_name = "terraform" - beta_features = True - collect_start_lambda_process_output = True - - def setUp(self): - self.url = "http://127.0.0.1:{}".format(self.port) - self.lambda_client = boto3.client( - "lambda", - endpoint_url=self.url, - region_name="us-east-1", - use_ssl=False, - verify=False, - config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}), - ) - - @pytest.mark.flaky(reruns=3) - def test_invoke_function_and_warning_message_is_printed(self): - self.assertIn(Colored().yellow(EXPERIMENTAL_WARNING), self.start_lambda_process_error) - - -class TestLocalStartLambdaTerraformApplicationWithExperimentalPromptNo(StartLambdaTerraformApplicationIntegBase): - terraform_application = "/testdata/invoke/terraform/simple_application_no_building_logic" - template_path = None - hook_name = "terraform" - input = b"N\n" - collect_start_lambda_process_output = True - - def setUp(self): - self.url = "http://127.0.0.1:{}".format(self.port) - self.lambda_client = boto3.client( - "lambda", - endpoint_url=self.url, - region_name="us-east-1", - use_ssl=False, - verify=False, - config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}), - ) - - @skipIf( - not CI_OVERRIDE, - "Skip Terraform test cases unless running in CI", - ) - @pytest.mark.flaky(reruns=3) - def test_invoke_function(self): - self.assertRegex( - self.start_lambda_process_error, - "Terraform Support beta feature is not enabled.", - ) - - class TestLocalStartLambdaInvalidUsecasesTerraform(StartLambdaTerraformApplicationIntegBase): @classmethod def setUpClass(cls): @@ -497,60 +400,6 @@ def test_invalid_hook_name(self): ) self.assertNotEqual(return_code, 0) - def test_start_lambda_with_no_beta_feature(self): - command_list = self.get_start_lambda_command(hook_name="terraform", beta_features=False) - - _, stderr, return_code = self._run_command(command_list, tf_application=self.working_dir) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - - def test_start_lambda_with_no_beta_feature_option_in_samconfig_toml(self): - samconfig_toml_path = Path(self.working_dir).joinpath("samconfig.toml") - samconfig_lines = [ - bytes("version = 0.1" + os.linesep, "utf-8"), - bytes("[default.global.parameters]" + os.linesep, "utf-8"), - bytes("beta_features = false" + os.linesep, "utf-8"), - ] - with open(samconfig_toml_path, "wb") as file: - file.writelines(samconfig_lines) - - command_list = self.get_start_lambda_command(hook_name="terraform") - - _, stderr, return_code = self._run_command(command_list, tf_application=self.working_dir) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - # delete the samconfig file - try: - os.remove(samconfig_toml_path) - except (FileNotFoundError, PermissionError): - pass - - def test_start_lambda_with_no_beta_feature_option_in_environment_variables(self): - environment_variables = os.environ.copy() - environment_variables["SAM_CLI_BETA_TERRAFORM_SUPPORT"] = "False" - - command_list = self.get_start_lambda_command(hook_name="terraform") - _, stderr, return_code = self._run_command( - command_list, tf_application=self.working_dir, env=environment_variables - ) - - process_stderr = stderr.strip() - self.assertRegex( - process_stderr.decode("utf-8"), - "Terraform Support beta feature is not enabled.", - ) - self.assertEqual(return_code, 0) - def test_invalid_coexist_parameters(self): command_list = self.get_start_lambda_command(hook_name="terraform", template_path="path/template.yaml") _, stderr, return_code = self._run_command(command_list, tf_application=self.working_dir) @@ -572,7 +421,6 @@ class TestLocalStartLambdaTerraformApplicationWithLocalImageUri(StartLambdaTerra terraform_application = "/testdata/invoke/terraform/image_lambda_function_local_image_uri" template_path = None hook_name = "terraform" - beta_features = True functions = [ "module.image_lambda2.aws_lambda_function.this[0]", "image_lambda2", diff --git a/tests/integration/testdata/buildcmd/terraform/application_outside_root_directory/root_module/input_samconfig.yaml b/tests/integration/testdata/buildcmd/terraform/application_outside_root_directory/root_module/input_samconfig.yaml index 12d6d000fc..b594a3df22 100644 --- a/tests/integration/testdata/buildcmd/terraform/application_outside_root_directory/root_module/input_samconfig.yaml +++ b/tests/integration/testdata/buildcmd/terraform/application_outside_root_directory/root_module/input_samconfig.yaml @@ -2,7 +2,6 @@ version: 0.1 default: global: parameters: - beta_features: true hook_name: terraform build: parameters: diff --git a/tests/unit/commands/_utils/custom_options/test_hook_package_id_option.py b/tests/unit/commands/_utils/custom_options/test_hook_package_id_option.py index ad6656fdd2..5af9ab1c0f 100644 --- a/tests/unit/commands/_utils/custom_options/test_hook_package_id_option.py +++ b/tests/unit/commands/_utils/custom_options/test_hook_package_id_option.py @@ -68,15 +68,10 @@ def test_invalid_coexist_options(self, iac_hook_wrapper_mock): f"Parameters hook-name, and {','.join(self.invalid_coexist_options)} cannot be used together", ) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_only_hook_id_option( - self, iac_hook_wrapper_mock, getcwd_mock, prompt_experimental_mock, update_experimental_context_mock - ): + def test_valid_hook_package_with_only_hook_id_option(self, iac_hook_wrapper_mock, getcwd_mock): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -104,15 +99,10 @@ def test_valid_hook_package_with_only_hook_id_option( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_other_options( - self, iac_hook_wrapper_mock, getcwd_mock, prompt_experimental_mock, update_experimental_context_mock - ): + def test_valid_hook_package_with_other_options(self, iac_hook_wrapper_mock, getcwd_mock): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -146,15 +136,10 @@ def test_valid_hook_package_with_other_options( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_other_options_from_sam_config( - self, iac_hook_wrapper_mock, getcwd_mock, prompt_experimental_mock, update_experimental_context_mock - ): + def test_valid_hook_package_with_other_options_from_sam_config(self, iac_hook_wrapper_mock, getcwd_mock): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -188,8 +173,6 @@ def test_valid_hook_package_with_other_options_from_sam_config( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") @@ -198,11 +181,8 @@ def test_valid_hook_package_with_skipping_prepare_hook_and_built_path_exists( iac_hook_wrapper_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -222,227 +202,6 @@ def test_valid_hook_package_with_skipping_prepare_hook_and_built_path_exists( self.iac_hook_wrapper_instance_mock.prepare.assert_not_called() self.assertEqual(opts.get("template_file"), None) - @patch("samcli.commands._utils.custom_options.hook_name_option.GlobalConfig") - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") - @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_disable_terraform_beta_feature( - self, - iac_hook_wrapper_mock, - path_exists_mock, - getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, - global_config_mock, - ): - iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = False - gc_mock = MagicMock() - global_config_mock.return_value = gc_mock - gc_mock.get_value.return_value = False - - getcwd_mock.return_value = self.cwd_path - - hook_name_option = HookNameOption( - param_decls=(self.name, self.opt), - force_prepare=True, - invalid_coexist_options=self.invalid_coexist_options, - ) - ctx = MagicMock() - ctx.default_map = {} - opts = { - "hook_name": self.terraform, - } - args = [] - hook_name_option.handle_parse_result(ctx, opts, args) - self.iac_hook_wrapper_instance_mock.prepare.assert_not_called() - self.assertEqual(opts.get("template_file"), None) - - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") - @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_no_beta_feature_option( - self, - iac_hook_wrapper_mock, - path_exists_mock, - getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, - ): - iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = False - - getcwd_mock.return_value = self.cwd_path - - hook_name_option = HookNameOption( - param_decls=(self.name, self.opt), - force_prepare=True, - invalid_coexist_options=self.invalid_coexist_options, - ) - ctx = MagicMock() - opts = { - "hook_name": self.terraform, - "beta_features": False, - } - args = [] - hook_name_option.handle_parse_result(ctx, opts, args) - prompt_experimental_mock.assert_not_called() - self.iac_hook_wrapper_instance_mock.prepare.assert_not_called() - self.assertEqual(opts.get("template_file"), None) - - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") - @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_beta_feature_option( - self, - iac_hook_wrapper_mock, - path_exists_mock, - getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, - ): - iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = False - - getcwd_mock.return_value = self.cwd_path - - hook_name_option = HookNameOption( - param_decls=(self.name, self.opt), - force_prepare=True, - invalid_coexist_options=self.invalid_coexist_options, - ) - ctx = MagicMock() - ctx.default_map = {} - opts = { - "hook_name": self.terraform, - "beta_features": True, - } - args = [] - hook_name_option.handle_parse_result(ctx, opts, args) - prompt_experimental_mock.assert_not_called() - self.iac_hook_wrapper_instance_mock.prepare.assert_called_once_with( - os.path.join(self.cwd_path, ".aws-sam-iacs", "iacs_metadata"), - self.cwd_path, - False, - None, - None, - False, - None, - None, - ) - self.assertEqual(opts.get("template_file"), self.metadata_path) - - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") - @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_beta_feature_option_in_sam_config( - self, - iac_hook_wrapper_mock, - path_exists_mock, - getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, - ): - metadata_path = "path/metadata.json" - cwd_path = "path/current" - invalid_coexist_options = ["t", "template", "template-file", "parameters-override"] - - iac_hook_wrapper_instance_mock = MagicMock() - iac_hook_wrapper_instance_mock.prepare.return_value = metadata_path - iac_hook_wrapper_mock.return_value = iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = False - - getcwd_mock.return_value = cwd_path - - hook_name_option = HookNameOption( - param_decls=(self.name, self.opt), - force_prepare=True, - invalid_coexist_options=invalid_coexist_options, - ) - ctx = MagicMock() - ctx.default_map = {"beta_features": True} - opts = { - "hook_name": self.terraform, - } - args = [] - hook_name_option.handle_parse_result(ctx, opts, args) - prompt_experimental_mock.assert_not_called() - iac_hook_wrapper_instance_mock.prepare.assert_called_once_with( - os.path.join(cwd_path, ".aws-sam-iacs", "iacs_metadata"), - cwd_path, - False, - None, - None, - False, - None, - None, - ) - self.assertEqual(opts.get("template_file"), metadata_path) - - @patch("samcli.commands._utils.custom_options.hook_name_option.GlobalConfig") - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") - @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") - @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") - def test_valid_hook_package_with_beta_feature_option_in_environment_variable( - self, - iac_hook_wrapper_mock, - path_exists_mock, - getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, - global_config_mock, - ): - metadata_path = "path/metadata.json" - cwd_path = "path/current" - invalid_coexist_options = ["t", "template", "template-file", "parameters-override"] - - iac_hook_wrapper_instance_mock = MagicMock() - iac_hook_wrapper_instance_mock.prepare.return_value = metadata_path - iac_hook_wrapper_mock.return_value = iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = False - - getcwd_mock.return_value = cwd_path - - hook_name_option = HookNameOption( - param_decls=(self.name, self.opt), - force_prepare=True, - invalid_coexist_options=invalid_coexist_options, - ) - ctx = MagicMock() - ctx.default_map = {} - opts = { - "hook_name": self.terraform, - } - gc_mock = MagicMock() - global_config_mock.return_value = gc_mock - gc_mock.get_value.return_value = True - args = [] - hook_name_option.handle_parse_result(ctx, opts, args) - prompt_experimental_mock.assert_not_called() - iac_hook_wrapper_instance_mock.prepare.assert_called_once_with( - os.path.join(cwd_path, ".aws-sam-iacs", "iacs_metadata"), - cwd_path, - False, - None, - None, - False, - None, - None, - ) - self.assertEqual(opts.get("template_file"), metadata_path) - - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") @@ -451,11 +210,8 @@ def test_valid_hook_package_with_skipping_prepare_hook_and_built_path_does_not_e iac_hook_wrapper_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -485,8 +241,6 @@ def test_valid_hook_package_with_skipping_prepare_hook_and_built_path_does_not_e ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") @@ -495,11 +249,8 @@ def test_valid_hook_package_with_use_container_and_build_image( iac_hook_wrapper_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -532,8 +283,6 @@ def test_valid_hook_package_with_use_container_and_build_image( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") @@ -542,11 +291,8 @@ def test_invalid_hook_package_with_use_container_and_no_build_image( iac_hook_wrapper_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -570,19 +316,14 @@ def test_invalid_hook_package_with_use_container_and_no_build_image( ): hook_name_option.handle_parse_result(ctx, opts, args) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") def test_invalid_parameter_hook_with_invalid_project_root_directory( self, iac_hook_wrapper_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -606,8 +347,6 @@ def test_invalid_parameter_hook_with_invalid_project_root_directory( ): hook_name_option.handle_parse_result(ctx, opts, args) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.isabs") @@ -618,11 +357,8 @@ def test_valid_parameter_hook_with_valid_absolute_project_root_directory( path_isabs_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -655,8 +391,6 @@ def test_valid_parameter_hook_with_valid_absolute_project_root_directory( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.isabs") @@ -667,11 +401,8 @@ def test_valid_parameter_hook_with_valid_relative_project_root_directory( path_isabs_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path @@ -704,8 +435,6 @@ def test_valid_parameter_hook_with_valid_relative_project_root_directory( ) self.assertEqual(opts.get("template_file"), self.metadata_path) - @patch("samcli.commands._utils.custom_options.hook_name_option.update_experimental_context") - @patch("samcli.commands._utils.custom_options.hook_name_option.prompt_experimental") @patch("samcli.commands._utils.custom_options.hook_name_option.os.getcwd") @patch("samcli.commands._utils.custom_options.hook_name_option.os.path.exists") @patch("samcli.commands._utils.custom_options.hook_name_option.IacHookWrapper") @@ -714,11 +443,8 @@ def test_valid_hook_package_with_use_container_false_and_no_build_image( iac_hook_wrapper_mock, path_exists_mock, getcwd_mock, - prompt_experimental_mock, - update_experimental_context_mock, ): iac_hook_wrapper_mock.return_value = self.iac_hook_wrapper_instance_mock - prompt_experimental_mock.return_value = True getcwd_mock.return_value = self.cwd_path diff --git a/tests/unit/commands/buildcmd/test_command.py b/tests/unit/commands/buildcmd/test_command.py index 080ca7cbb4..b8c38bf661 100644 --- a/tests/unit/commands/buildcmd/test_command.py +++ b/tests/unit/commands/buildcmd/test_command.py @@ -68,40 +68,6 @@ def test_must_succeed_build(self, os_mock, BuildContextMock, mock_build_click): ctx_mock.run.assert_called_with() self.assertEqual(ctx_mock.run.call_count, 1) - @patch("samcli.commands.build.command.is_experimental_enabled") - @patch("samcli.commands.build.build_context.BuildContext") - def test_build_exits_supplied_hook_name(self, BuildContextMock, is_experimental_enabled_mock): - ctx_mock = Mock() - BuildContextMock.return_value.__enter__.return_value = ctx_mock - is_experimental_enabled_mock.return_value = False - - do_cli( - ctx_mock, - "function_identifier", - None, - "base_dir", - "build_dir", - "cache_dir", - "clean", - "use_container", - "cached", - "parallel", - "manifest_path", - "docker_network", - "skip_pull_image", - "parameter_overrides", - "mode", - (""), - "container_env_var_file", - (), - (), - hook_name="terraform", - build_in_source=None, - mount_with=MountMode.READ, - ) - self.assertEqual(ctx_mock.call_count, 0) - self.assertEqual(ctx_mock.run.call_count, 0) - class TestGetModeValueFromEnvvar(TestCase): def setUp(self):