|
12 | 12 | import secrets |
13 | 13 | import base64 |
14 | 14 | import inspect |
| 15 | +import warnings |
15 | 16 | from pathlib import Path |
16 | 17 | from typing import Any |
17 | 18 |
|
18 | 19 | # APIM Samples imports |
19 | 20 | import azure_resources as az |
20 | 21 | from apimtypes import APIM_SKU, HTTP_VERB, INFRASTRUCTURE, Endpoints, Output, get_project_root |
21 | 22 | from console import print_error, print_info, print_message, print_ok, print_plain, print_warning, print_val |
| 23 | +from logging_config import get_configured_level_name |
| 24 | + |
| 25 | +# Configure warning filter to suppress IPython exit warnings |
| 26 | +warnings.filterwarnings( |
| 27 | + 'ignore', |
| 28 | + message = r"To exit: use 'exit', 'quit', or Ctrl-D\.", |
| 29 | + category = UserWarning, |
| 30 | + module = r'IPython\.core\.interactiveshell', |
| 31 | +) |
22 | 32 |
|
23 | 33 |
|
24 | 34 | # ------------------------------ |
25 | 35 | # HELPER FUNCTIONS |
26 | 36 | # ------------------------------ |
27 | 37 |
|
| 38 | +def get_deployment_failure_message(deployment_name: str) -> str: |
| 39 | + """ |
| 40 | + Generate a deployment failure message that conditionally includes debug instruction. |
| 41 | +
|
| 42 | + Args: |
| 43 | + deployment_name (str): The name of the failed deployment. |
| 44 | +
|
| 45 | + Returns: |
| 46 | + str: Appropriate failure message based on current logging level. |
| 47 | + """ |
| 48 | + base_message = f"Deployment '{deployment_name}' failed. View deployment details in Azure Portal." |
| 49 | + |
| 50 | + # Only suggest enabling DEBUG logging if it's not already enabled |
| 51 | + current_level = get_configured_level_name() |
| 52 | + if current_level != 'DEBUG': |
| 53 | + return f"{base_message} Enable DEBUG logging in workspace root .env file, then rerun to see details." |
| 54 | + |
| 55 | + return base_message |
| 56 | + |
28 | 57 | def build_infrastructure_tags(infrastructure: str | INFRASTRUCTURE, custom_tags: dict | None = None) -> dict: |
29 | 58 | """ |
30 | 59 | Build standard tags for infrastructure resource groups, including required 'infrastructure' tag. |
@@ -83,7 +112,7 @@ def __init__(self, rg_location: str, deployment: INFRASTRUCTURE, index: int, api |
83 | 112 | self.index = index |
84 | 113 | self.apim_sku = apim_sku |
85 | 114 |
|
86 | | - print_message('Initializing Infrastructure Notebook Helper with the following parameters:', blank_above=True) |
| 115 | + print_message('Initializing Infrastructure Notebook Helper with the following parameters:', blank_above = True, blank_below = True) |
87 | 116 | print_val('Location', self.rg_location) |
88 | 117 | print_val('Infrastructure', self.deployment.value) |
89 | 118 | print_val('Index', self.index) |
@@ -166,7 +195,6 @@ def create_infrastructure(self, bypass_infrastructure_check: bool = False, allow |
166 | 195 | process.wait() |
167 | 196 |
|
168 | 197 | if process.returncode: |
169 | | - print_error('Infrastructure creation failed!') |
170 | 198 | raise SystemExit(1) |
171 | 199 |
|
172 | 200 | return True |
@@ -595,7 +623,7 @@ def create_bicep_deployment_group(rg_name: str, rg_location: str, deployment: st |
595 | 623 | cmd += ' --debug' |
596 | 624 |
|
597 | 625 | print_plain('\nDeploying bicep...\n') |
598 | | - return az.run(cmd, f"Deployment '{deployment_name}' succeeded", f"Deployment '{deployment_name}' failed.") |
| 626 | + return az.run(cmd, f"Deployment '{deployment_name}' succeeded", get_deployment_failure_message(deployment_name)) |
599 | 627 |
|
600 | 628 | # TODO: Reconcile this with apimtypes.py get_project_root |
601 | 629 | def find_project_root() -> str: |
@@ -689,7 +717,7 @@ def _prompt_for_infrastructure_update(rg_name: str) -> tuple[bool, int | None]: |
689 | 717 | - new_index: None if no index change, integer if user selected option 2 |
690 | 718 | """ |
691 | 719 | print_ok(f'Infrastructure already exists: {rg_name}') |
692 | | - print_plain('🔄 Infrastructure Update Options:\n') |
| 720 | + print_plain('🔄 Infrastructure Update Options:\n', blank_above = True) |
693 | 721 | print_plain(' This infrastructure notebook can update the existing infrastructure.') |
694 | 722 | print_plain(' Updates are additive and will:') |
695 | 723 | print_plain(' • Add new APIs and policy fragments defined in the infrastructure') |
@@ -751,7 +779,7 @@ def does_infrastructure_exist(infrastructure: INFRASTRUCTURE, index: int, allow_ |
751 | 779 | print_ok(f'Infrastructure already exists: {rg_name}') |
752 | 780 |
|
753 | 781 | if allow_update_option: |
754 | | - print_plain('🔄 Infrastructure Update Options:\n') |
| 782 | + print_plain('🔄 Infrastructure Update Options:\n', blank_above = True) |
755 | 783 | print_plain(' This infrastructure notebook can update the existing infrastructure. Updates are additive and will:\n') |
756 | 784 | print_plain(' • Add new APIs and policy fragments defined in the infrastructure') |
757 | 785 | print_plain(' • Update existing infrastructure components to match the template') |
|
0 commit comments