Skip to content

Commit c4b2073

Browse files
author
JingnanXu
committed
Preserve CDN scenario placeholders
1 parent 1b1aa8e commit c4b2073

2 files changed

Lines changed: 54 additions & 8 deletions

File tree

‎src/cdn/azext_cdn/tests/latest/afdx_scenario_mixin.py‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def _add_paramter_if_needed(command, paramter_name, parameter_value):
3030
return command
3131

3232

33-
def _escape_format_placeholders(command):
33+
def _escape_format_placeholders(command, format_placeholders=None):
34+
format_placeholders = format_placeholders or {}
35+
3436
def _find_escaped_placeholder_end(start):
3537
depth = 0
3638
index = start
@@ -49,6 +51,21 @@ def _find_escaped_placeholder_end(start):
4951
index += 1
5052
return None
5153

54+
def _find_format_placeholder_end(start):
55+
index = start + 1
56+
while index < len(command):
57+
current = command[index]
58+
if current == '{':
59+
return None
60+
if current == '}':
61+
field = command[start + 1:index]
62+
field_name = field.split('!', 1)[0].split(':', 1)[0].split('.', 1)[0].split('[', 1)[0]
63+
if field_name in format_placeholders:
64+
return index + 1
65+
return None
66+
index += 1
67+
return None
68+
5269
escaped = []
5370
index = 0
5471
while index < len(command):
@@ -63,8 +80,13 @@ def _find_escaped_placeholder_end(start):
6380
escaped.append('{{')
6481
index += 1
6582
elif current == '{':
66-
escaped.append('{{')
67-
index += 1
83+
end = _find_format_placeholder_end(index)
84+
if end is not None:
85+
escaped.append(command[index:end])
86+
index = end
87+
else:
88+
escaped.append('{{')
89+
index += 1
6890
elif current == '}':
6991
escaped.append('}}')
7092
index += 1
@@ -77,7 +99,8 @@ def _find_escaped_placeholder_end(start):
7799
# pylint: disable=too-many-public-methods
78100
class CdnAfdScenarioMixin:
79101
def cmd(self, command, checks=None, expect_failure=False):
80-
return super().cmd(_escape_format_placeholders(command), checks, expect_failure=expect_failure)
102+
return super().cmd(_escape_format_placeholders(command, getattr(self, 'kwargs', {})), checks,
103+
expect_failure=expect_failure)
81104

82105
def afd_profile_create_cmd(self, resource_group_name, profile_name, tags=None, checks=None, options=None,
83106
sku="Standard_AzureFrontDoor", expect_failure=False):

‎src/cdn/azext_cdn/tests/latest/scenario_mixin.py‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def _json_arg(value):
1717
return "'{}'".format(json.dumps(value, separators=(',', ':')))
1818

1919

20-
def _escape_format_placeholders(command):
20+
def _escape_format_placeholders(command, format_placeholders=None):
21+
format_placeholders = format_placeholders or {}
22+
2123
def _find_escaped_placeholder_end(start):
2224
depth = 0
2325
index = start
@@ -36,6 +38,21 @@ def _find_escaped_placeholder_end(start):
3638
index += 1
3739
return None
3840

41+
def _find_format_placeholder_end(start):
42+
index = start + 1
43+
while index < len(command):
44+
current = command[index]
45+
if current == '{':
46+
return None
47+
if current == '}':
48+
field = command[start + 1:index]
49+
field_name = field.split('!', 1)[0].split(':', 1)[0].split('.', 1)[0].split('[', 1)[0]
50+
if field_name in format_placeholders:
51+
return index + 1
52+
return None
53+
index += 1
54+
return None
55+
3956
escaped = []
4057
index = 0
4158
while index < len(command):
@@ -50,8 +67,13 @@ def _find_escaped_placeholder_end(start):
5067
escaped.append('{{')
5168
index += 1
5269
elif current == '{':
53-
escaped.append('{{')
54-
index += 1
70+
end = _find_format_placeholder_end(index)
71+
if end is not None:
72+
escaped.append(command[index:end])
73+
index = end
74+
else:
75+
escaped.append('{{')
76+
index += 1
5577
elif current == '}':
5678
escaped.append('}}')
5779
index += 1
@@ -113,7 +135,8 @@ def _response_error_detection_settings(error_types=None, failover_threshold=None
113135
# pylint: disable=too-many-public-methods
114136
class CdnScenarioMixin:
115137
def cmd(self, command, checks=None, expect_failure=False):
116-
return super().cmd(_escape_format_placeholders(command), checks, expect_failure=expect_failure)
138+
return super().cmd(_escape_format_placeholders(command, getattr(self, 'kwargs', {})), checks,
139+
expect_failure=expect_failure)
117140

118141
def profile_create_cmd(self, group, name, tags=None, checks=None, options=None, sku='STANDARD_MICROSOFT'):
119142
command = 'cdn profile create -g {} -n {}'.format(group, name)

0 commit comments

Comments
 (0)