From 06cf638f21c5afbfaedb7b56f53cd7da7b8f1bff Mon Sep 17 00:00:00 2001 From: Pramod Valavala Date: Mon, 8 May 2023 16:57:30 -0400 Subject: [PATCH 1/3] Fix similar bicep commands with version checks --- src/azure-cli/azure/cli/command_modules/resource/custom.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 8f362c8f711..455fb886e9b 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -3775,6 +3775,8 @@ def format_bicep_file(cmd, file, stdout=None, outdir=None, outfile=None, newline def publish_bicep_file(cmd, file, target, documentationUri=None): + ensure_bicep_installation(cmd.cli_ctx) + minimum_supported_version = "0.4.1008" if bicep_version_greater_than_or_equal_to(minimum_supported_version): args = ["publish", file, "--target", target] @@ -3790,6 +3792,8 @@ def publish_bicep_file(cmd, file, target, documentationUri=None): def restore_bicep_file(cmd, file, force=None): + ensure_bicep_installation(cmd.cli_ctx) + minimum_supported_version = "0.4.1008" if bicep_version_greater_than_or_equal_to(minimum_supported_version): args = ["restore", file] @@ -3816,6 +3820,8 @@ def list_bicep_cli_versions(cmd): def generate_params_file(cmd, file, no_restore=None, outdir=None, outfile=None, stdout=None): + ensure_bicep_installation(cmd.cli_ctx) + minimum_supported_version = "0.7.4" if bicep_version_greater_than_or_equal_to(minimum_supported_version): args = ["generate-params", file] From 571867c742100d3c70cabfb2d0e15b1be273047a Mon Sep 17 00:00:00 2001 From: Pramod Valavala Date: Mon, 8 May 2023 17:04:07 -0400 Subject: [PATCH 2/3] Update tests for clean installs on each run --- .../azure/cli/testsdk/base.py | 11 +++- .../resource/tests/latest/test_resource.py | 51 ++++++++++++++++++- .../tests/latest/test_resource_bicep.py | 2 - 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/base.py b/src/azure-cli-testsdk/azure/cli/testsdk/base.py index d82186a2ffe..a717c63c218 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/base.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/base.py @@ -217,15 +217,22 @@ def tearDown(self): @live_only() class LiveScenarioTest(IntegrationTestBase, CheckerMixin, unittest.TestCase): - def __init__(self, method_name): + def __init__(self, method_name, random_config_dir=False): super(LiveScenarioTest, self).__init__(method_name) - self.cli_ctx = get_dummy_cli() + self.cli_ctx = get_dummy_cli(random_config_dir=random_config_dir) + self.random_config_dir = random_config_dir self.kwargs = {} self.test_resources_count = 0 def setUp(self): patch_main_exception_handler(self) + def tearDown(self): + if self.random_config_dir: + from azure.cli.core.util import rmtree_with_retry + rmtree_with_retry(self.cli_ctx.config.config_dir) + super(LiveScenarioTest, self).tearDown() + def cmd(self, command, checks=None, expect_failure=False): command = self._apply_kwargs(command) return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks) diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py index bc21bb9af5a..2cba8200eb0 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py @@ -4016,7 +4016,18 @@ def test_bicep_list_versions(self): # Because don't want to record bicep cli binary class BicepBuildTest(LiveScenarioTest): - + + def __init__(self, *arg, **kwargs): + super().__init__(*arg, random_config_dir=True, **kwargs) + + def setup(self): + super().setup() + self.cmd('az bicep uninstall') + + def tearDown(self): + super().tearDown() + self.cmd('az bicep uninstall') + def test_bicep_build_decompile(self): curr_dir = os.path.dirname(os.path.realpath(__file__)) tf = os.path.join(curr_dir, 'storage_account_deploy.bicep').replace('\\', '\\\\') @@ -4039,6 +4050,17 @@ def test_bicep_build_decompile(self): class BicepGenerateParamsTest(LiveScenarioTest): + def __init__(self, *arg, **kwargs): + super().__init__(*arg, random_config_dir=True, **kwargs) + + def setup(self): + super().setup() + self.cmd('az bicep uninstall') + + def tearDown(self): + super().tearDown() + self.cmd('az bicep uninstall') + def test_bicep_generate_params(self): curr_dir = os.path.dirname(os.path.realpath(__file__)) tf = os.path.join(curr_dir, 'sample_params.bicep').replace('\\', '\\\\') @@ -4085,6 +4107,18 @@ def test_install_and_upgrade(self): class BicepRestoreTest(LiveScenarioTest): + + def __init__(self, *arg, **kwargs): + super().__init__(*arg, random_config_dir=True, **kwargs) + + def setup(self): + super().setup() + self.cmd('az bicep uninstall') + + def tearDown(self): + super().tearDown() + self.cmd('az bicep uninstall') + def test_restore(self): curr_dir = os.path.dirname(os.path.realpath(__file__)) bf = os.path.join(curr_dir, 'data', 'external_modules.bicep').replace('\\', '\\\\') @@ -4103,6 +4137,18 @@ def test_restore(self): class BicepFormatTest(LiveScenarioTest): + + def __init__(self, *arg, **kwargs): + super().__init__(*arg, random_config_dir=True, **kwargs) + + def setup(self): + super().setup() + self.cmd('az bicep uninstall') + + def tearDown(self): + super().tearDown() + self.cmd('az bicep uninstall') + def test_format(self): curr_dir = os.path.dirname(os.path.realpath(__file__)) bf = os.path.join(curr_dir, 'storage_account_deploy.bicep').replace('\\', '\\\\') @@ -4119,6 +4165,9 @@ def test_format(self): class DeploymentWithBicepScenarioTest(LiveScenarioTest): + def __init__(self, *arg, **kwargs): + super().__init__(*arg, random_config_dir=True, **kwargs) + def setup(self): super.setup() self.cmd('az bicep uninstall') diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py index 15e81c9b1ba..52eaa051f28 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py @@ -194,5 +194,3 @@ def test_validate_target_scope_success_if_target_scope_matches_deployment_scope( def _remove_bicep_version_check_file(self): with contextlib.suppress(FileNotFoundError): os.remove(_bicep_version_check_file_path) - - From 9abd1de8dee78d2b3999d89fbe2f65b3d3456e0e Mon Sep 17 00:00:00 2001 From: Pramod Valavala Date: Wed, 10 May 2023 17:30:42 -0400 Subject: [PATCH 3/3] Revert random_config_dir for LiveScenarioTests --- src/azure-cli-testsdk/azure/cli/testsdk/base.py | 11 ++--------- .../resource/tests/latest/test_resource.py | 14 -------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/azure-cli-testsdk/azure/cli/testsdk/base.py b/src/azure-cli-testsdk/azure/cli/testsdk/base.py index a717c63c218..d82186a2ffe 100644 --- a/src/azure-cli-testsdk/azure/cli/testsdk/base.py +++ b/src/azure-cli-testsdk/azure/cli/testsdk/base.py @@ -217,22 +217,15 @@ def tearDown(self): @live_only() class LiveScenarioTest(IntegrationTestBase, CheckerMixin, unittest.TestCase): - def __init__(self, method_name, random_config_dir=False): + def __init__(self, method_name): super(LiveScenarioTest, self).__init__(method_name) - self.cli_ctx = get_dummy_cli(random_config_dir=random_config_dir) - self.random_config_dir = random_config_dir + self.cli_ctx = get_dummy_cli() self.kwargs = {} self.test_resources_count = 0 def setUp(self): patch_main_exception_handler(self) - def tearDown(self): - if self.random_config_dir: - from azure.cli.core.util import rmtree_with_retry - rmtree_with_retry(self.cli_ctx.config.config_dir) - super(LiveScenarioTest, self).tearDown() - def cmd(self, command, checks=None, expect_failure=False): command = self._apply_kwargs(command) return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks) diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py index 2cba8200eb0..434cb8fa367 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py @@ -4017,9 +4017,6 @@ def test_bicep_list_versions(self): # Because don't want to record bicep cli binary class BicepBuildTest(LiveScenarioTest): - def __init__(self, *arg, **kwargs): - super().__init__(*arg, random_config_dir=True, **kwargs) - def setup(self): super().setup() self.cmd('az bicep uninstall') @@ -4050,9 +4047,6 @@ def test_bicep_build_decompile(self): class BicepGenerateParamsTest(LiveScenarioTest): - def __init__(self, *arg, **kwargs): - super().__init__(*arg, random_config_dir=True, **kwargs) - def setup(self): super().setup() self.cmd('az bicep uninstall') @@ -4108,9 +4102,6 @@ def test_install_and_upgrade(self): class BicepRestoreTest(LiveScenarioTest): - def __init__(self, *arg, **kwargs): - super().__init__(*arg, random_config_dir=True, **kwargs) - def setup(self): super().setup() self.cmd('az bicep uninstall') @@ -4138,9 +4129,6 @@ def test_restore(self): class BicepFormatTest(LiveScenarioTest): - def __init__(self, *arg, **kwargs): - super().__init__(*arg, random_config_dir=True, **kwargs) - def setup(self): super().setup() self.cmd('az bicep uninstall') @@ -4165,8 +4153,6 @@ def test_format(self): class DeploymentWithBicepScenarioTest(LiveScenarioTest): - def __init__(self, *arg, **kwargs): - super().__init__(*arg, random_config_dir=True, **kwargs) def setup(self): super.setup()