Skip to content

Commit 7ca02c3

Browse files
committed
Fixing regex bugs
1 parent 8081758 commit 7ca02c3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

alts/shared/terraform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def get_opennebula_template_regex(
150150
if test_flavor_name and test_flavor_version:
151151
flavor = f'{test_flavor_name}-?{test_flavor_version}'
152152
regex_str = (
153-
rf'{dist_name}-{dist_version}-({arches_to_try})\.{flavor}\.'
153+
rf'^{dist_name}-{dist_version}-({arches_to_try})\.{flavor}\.'
154154
rf'test_system\.({channels})\.b\d{{8}}-\d+'
155155
)
156156
# Escape backslashes for Terraform HCL string

scripts/test_vm_image.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def load_platform_configs(path: Path) -> Set[PlatformInfo]:
9090
platform_name=distro["opennebula_image_name"],
9191
version=distro["distr_version"],
9292
arch=arch,
93-
flavor_name=distro.get("test_flavor_name"),
94-
flavor_version=distro.get("test_flavor_version")
93+
flavor_name=distro.get("test_flavor_name", "base_image"),
94+
flavor_version=distro.get("test_flavor_version", None)
9595
)
9696
data_entries.add(platform_info)
9797
return data_entries
@@ -187,7 +187,7 @@ def run_terraform_plan(workdir: Path) -> Optional[str]:
187187
)
188188
if code != 0:
189189
logger.error(f"Terraform plan failed: {stderr}")
190-
return None
190+
raise RuntimeError("Terraform plan failed.")
191191
return extract_template_names(stdout)
192192

193193

@@ -215,7 +215,7 @@ def check_template_for_platform(
215215
all_architectures = '|'.join(SUPPORTED_ARCHITECTURES)
216216
all_test_flavor_names = '|'.join(set(pl.flavor_name for pl in platforms if pl.flavor_name))
217217
all_test_flavor_names += '|base_image'
218-
optional_test_flavor_version = r'(\d+(?:\.\d+)?)?'
218+
optional_test_flavor_version = '|'.join(set(pl.flavor_version for pl in platforms if pl.flavor_version))
219219

220220
for channel in CONFIG.allowed_channel_names:
221221
renderer.render_tf_main_file(
@@ -227,7 +227,7 @@ def check_template_for_platform(
227227
vm_name='vm',
228228
package_channel=channel,
229229
test_flavor_name=f'({all_test_flavor_names})',
230-
test_flavor_version=f'({optional_test_flavor_version})',
230+
test_flavor_version=f'({optional_test_flavor_version})?',
231231
)
232232
templates = run_terraform_plan(workdir)
233233
if templates:
@@ -246,12 +246,13 @@ def get_found_platforms(found_templates: List[str]) -> Set[PlatformInfo]:
246246
Set[PlatformInfo]
247247
"""
248248
pattern = re.compile(
249-
r'^' # Anchor to start
249+
r'^'
250250
r'(?P<platform_name>\w+(?:-\w+)?)'
251251
r'-(?P<version>\d+(?:\.\d+)?)'
252-
r'-(?P<arch>\w+)'
253-
r'\.(?P<flavor_name>\w+(?:-\w+)?)'
254-
r'-?(?P<flavor_version>\d+(?:\.\d+)?)?'
252+
r'-(?P<arch>[\w]+)'
253+
r'\.(?P<flavor_name>\w+)'
254+
r'(?:-(?P<flavor_version>.+))?'
255+
r'\.test_system\b'
255256
)
256257

257258
result = set()

0 commit comments

Comments
 (0)