Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
959b19f
Remove APIs that are not available in Python 3.6 (#17716)
shenglol Apr 16, 2021
d1dfa89
[KeyVault] Hotfix: GA for managed-HSM ralated commands and parameters…
houk-ms Apr 19, 2021
c6c67ac
removing validation from onprem command (#17749)
fengzhou-msft Apr 19, 2021
135b525
{Core} Hotfix: Fix inifite extension install loop (#17698)
fengzhou-msft Apr 19, 2021
0294cb8
Hot fix for version 2.22.1 (#17752)
zhoxing-ms Apr 19, 2021
03bfa70
[Compute] Zone-redundant storage (ZRS) managed disks (#17754)
qwordy Apr 19, 2021
485fd9d
[AKS] Support updating Windows password (#17684)
AbelHu Apr 19, 2021
e207d54
[BACKUP] az backup vault create: Add tags as an optional argument (#1…
akshayneema Apr 20, 2021
0fa7095
Merge branch 'dev' into release_2.22.1
zhoxing-ms Apr 20, 2021
823b9c6
[Style] Define theme for Cloud Shell (#17283)
jiasli Apr 20, 2021
52096b5
{Network} Network support extendedLocation (#17623)
msyyc Apr 20, 2021
07e8013
Merge branch 'release_2.22.1' into dev
zhoxing-ms Apr 20, 2021
821ccb0
{DNS} Migrate to track 2 (#17787)
jsntcy Apr 21, 2021
b2e26af
{Network} Software Load Balance 100% depth (#17729)
kairu-ms Apr 21, 2021
89f9f2f
storage bump version (#17782)
evelyn-ys Apr 21, 2021
1f5f3e1
{SQL} Fixing failing test for log replay (#17672)
milanbrkic-ms Apr 21, 2021
84b1aef
{Network} application gateway 100% support (#17753)
kairu-ms Apr 21, 2021
0216604
{Core} `az login`: support `--scope` (#17778)
yonzhan Apr 21, 2021
dc32281
{batchai} Refine test with storage account APIs (#17799)
Juliehzl Apr 22, 2021
842de15
{KeyVault} Bump keyvault mgmt sdk version to 2021-04-01-preview (#17679)
houk-ms Apr 22, 2021
0ee45c4
[Role] `az role assignment create/update`: auto complete `assignee_pr…
evelyn-ys Apr 22, 2021
f65800a
[sqlvm] Make SqlServerLicenseType as optional #17766
vasivara-MSFT Apr 22, 2021
f3602f5
{KeyVault} Replace `_token_retriever` with `get_raw_token` (#17812)
jiasli Apr 22, 2021
6728379
{Logging} Redact headers from SDK HTTP log (#17671)
jiasli Apr 22, 2021
2ff95ab
fix 404 in LRO (#15884)
fengzhou-msft Apr 22, 2021
8a0cce9
{Doc} Update track 2 migration roadmap (#17730)
jsntcy Apr 22, 2021
902b942
{Core} Fix: In Cloud Shell, cross-tenant authentication fails for use…
jiasli Apr 22, 2021
cb4471d
{Core} Add `__init__.py` to `azure.cli.core.sdk` (#17817)
jiasli Apr 22, 2021
de212eb
[Compute] disk create: Trusted launch; [Compute] disk create: Hiberna…
qwordy Apr 23, 2021
993537f
{Core} Work around long-running delete or purge operation with 404 st…
houk-ms Apr 23, 2021
f82c201
{Network} vpn 100% support (#17664)
kairu-ms Apr 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove APIs that are not available in Python 3.6 (Azure#17716)
  • Loading branch information
shenglol authored Apr 16, 2021
commit 959b19f9578f41e839337b329c993394563eb75f
5 changes: 3 additions & 2 deletions src/azure-cli/azure/cli/command_modules/resource/_bicep.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
_bicep_installation_dir = os.path.join(_config_dir, "bin")
_bicep_version_check_file_path = os.path.join(_config_dir, "bicepVersionCheck.json")
_bicep_version_check_cache_ttl = timedelta(minutes=10)
_bicep_version_check_time_format = "%Y-%m-%dT%H:%M:%S.%f"

_logger = get_logger(__name__)

Expand Down Expand Up @@ -149,7 +150,7 @@ def _load_bicep_version_check_result_from_cache():
with open(_bicep_version_check_file_path, "r") as version_check_file:
version_check_data = json.load(version_check_file)
latest_release_tag = version_check_data["latestReleaseTag"]
last_check_time = datetime.fromisoformat(version_check_data["lastCheckTime"])
last_check_time = datetime.strptime(version_check_data["lastCheckTime"], _bicep_version_check_time_format)
cache_expired = datetime.now() - last_check_time > _bicep_version_check_cache_ttl

return latest_release_tag, cache_expired
Expand All @@ -160,7 +161,7 @@ def _load_bicep_version_check_result_from_cache():
def _refresh_bicep_version_check_cache(lastest_release_tag):
with open(_bicep_version_check_file_path, "w+") as version_check_file:
version_check_data = {
"lastCheckTime": datetime.now().isoformat(timespec="microseconds"),
"lastCheckTime": datetime.now().strftime(_bicep_version_check_time_format),
"latestReleaseTag": lastest_release_tag,
}
json.dump(version_check_data, version_check_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import contextlib
import unittest
import mock

Expand All @@ -11,6 +13,7 @@
ensure_bicep_installation,
run_bicep_command,
validate_bicep_target_scope,
_bicep_version_check_file_path,
)
from azure.cli.core.azclierror import InvalidTemplateError

Expand Down Expand Up @@ -49,6 +52,34 @@ def test_run_bicep_command_check_version(
"v2.0.0",
)

@mock.patch("azure.cli.command_modules.resource._bicep._logger.warning")
@mock.patch("azure.cli.command_modules.resource._bicep._run_command")
@mock.patch("azure.cli.command_modules.resource._bicep.ensure_bicep_installation")
@mock.patch("azure.cli.command_modules.resource._bicep.get_bicep_latest_release_tag")
@mock.patch("azure.cli.command_modules.resource._bicep._get_bicep_installed_version")
@mock.patch("os.path.isfile")
def test_run_bicep_command_check_version_cache_read_write(
self,
isfile_stub,
_get_bicep_installed_version_stub,
get_bicep_latest_release_tag_stub,
ensure_bicep_installation_mock,
_run_command_mock,
warning_mock,
):
try:
self._remove_bicep_version_check_file()

isfile_stub.return_value = True
_get_bicep_installed_version_stub.return_value = "1.0.0"
get_bicep_latest_release_tag_stub.return_value = "v2.0.0"

run_bicep_command(["--version"], check_version=True)

self.assertTrue(os.path.isfile(_bicep_version_check_file_path))
finally:
self._remove_bicep_version_check_file()

@mock.patch("os.path.isfile")
@mock.patch("azure.cli.command_modules.resource._bicep._get_bicep_installed_version")
@mock.patch("os.path.dirname")
Expand All @@ -73,8 +104,14 @@ def test_validate_target_scope_raise_error_if_target_scope_does_not_match_deploy
def test_validate_target_scope_success_if_target_scope_matches_deployment_scope(self):
for template_schema, deployment_scope in [
("https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#", "resourceGroup"),
("https://schema.management.azure.com/schemas/2019-08-01/subscriptionDeploymentTemplate.json#", "subscription"),
("https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", "managementGroup"),
(
"https://schema.management.azure.com/schemas/2019-08-01/subscriptionDeploymentTemplate.json#",
"subscription",
),
(
"https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"managementGroup",
),
("https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#", "tenant"),
]:
with self.subTest(template_schema=template_schema, deployment_scope=deployment_scope):
Expand All @@ -84,3 +121,7 @@ def test_validate_target_scope_success_if_target_scope_matches_deployment_scope(
self.fail(e.error_msg)
except:
self.fail("Encountered an unexpected exception.")

def _remove_bicep_version_check_file(self):
with contextlib.suppress(FileNotFoundError):
os.remove(_bicep_version_check_file_path)