Skip to content

Commit 6b4dddf

Browse files
papriwalnargokul
authored andcommitted
UPDATE CFN PARAM IN JINJA FILE (#198)
* UPDATE CFN PARAM IN JINJA FILE **Description** Updated cfn cluster creation template. **Testing Done** * FIX UNIT TEST CASES FOR CFN PARAM **Description** Updated the unit test cases for the process cfn param util. **Testing Done** All the unit test cases pass. * Remove unused function and fix CloudFormation template issues **Description** - Removed redundant _process_cfn_template_content function from init_utils.py - Fixed missing InstanceGroupSettings1 and RigSettings1 parameters in CFN template by changing loop range from (2,21) to (1,21) - Removed duplicate load_config_and_validate function definition **Testing Done** - Verified CloudFormation template generates all required parameters 1-20 - Confirmed no duplicate function definitions remain - Updated unit test cases and the whole suite passes
1 parent 4a4aa04 commit 6b4dddf

File tree

3 files changed

+728
-348
lines changed

3 files changed

+728
-348
lines changed

src/sagemaker/hyperpod/cli/init_utils.py

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,11 @@ def save_cfn_jinja(directory: str, content: str):
3939
Path(directory).mkdir(parents=True, exist_ok=True)
4040
path = os.path.join(directory, "cfn_params.jinja")
4141

42-
# Process content to handle array conversion
43-
processed_content = _process_cfn_template_content(content)
44-
4542
with open(path, "w", encoding="utf-8") as f:
46-
f.write(processed_content)
43+
f.write(content)
4744
click.secho(f"Cloudformation Parameters Jinja template saved to: {path}")
4845
return path
4946

50-
def _process_cfn_template_content(content: str) -> str:
51-
"""
52-
Process CFN template content to include the full CloudFormation template.
53-
"""
54-
try:
55-
# Get the full CloudFormation template
56-
full_template = HpClusterStack.get_template()
57-
except Exception as e:
58-
# Output the error and format as JSON in the file
59-
click.secho(f"⚠️ Failed to generate CloudFormation template: {str(e)}", fg="red")
60-
full_template = ""
61-
62-
# Add the complete template
63-
template_content = f"""
64-
# CloudFormation Template:
65-
{full_template}
66-
"""
67-
68-
# Insert the template at the beginning
69-
return template_content + "\n" + content
70-
7147
def save_k8s_jinja(directory: str, content: str):
7248
Path(directory).mkdir(parents=True, exist_ok=True)
7349
path = os.path.join(directory, "k8s.jinja")
@@ -530,28 +506,6 @@ def load_config_and_validate(dir_path: Path = None) -> Tuple[dict, str, str]:
530506
return data, template, version
531507

532508

533-
def load_config_and_validate(dir_path: Path = None) -> Tuple[dict, str, str]:
534-
"""
535-
Load config.yaml, validate it exists, and extract template and version.
536-
Returns (config_data, template, version)
537-
Exits on validation errors - use for commands that require valid config.
538-
"""
539-
data, template, version = load_config(dir_path)
540-
validation_errors = validate_config_against_model(data, template, version)
541-
542-
is_valid = display_validation_results(
543-
validation_errors,
544-
success_message="config.yaml is valid!",
545-
error_prefix="Config validation errors:"
546-
)
547-
548-
if not is_valid:
549-
sys.exit(1)
550-
551-
552-
return data, template, version
553-
554-
555509
def validate_config_against_model(config_data: dict, template: str, version: str) -> list:
556510
"""
557511
Validate config data against the appropriate Pydantic model.
@@ -905,4 +859,4 @@ def pascal_to_kebab(pascal_str):
905859
if char.isupper() and i > 0:
906860
result.append('-')
907861
result.append(char.lower())
908-
return ''.join(result)
862+
return ''.join(result)

0 commit comments

Comments
 (0)