Improve system detection robustness
- Enhanced detect-system.sh with better SSH options - Added BatchMode and StrictHostKeyChecking=no for automation - Increased timeout from 5 to 10 seconds - Explicit exit codes for clarity - Improved cert-manager.py detection function: - Checks if detect script exists before running - Validates return code - Checks for empty output - Better timeout handling (15 seconds) - More detailed error messages - Handles TimeoutExpired exception separately
This commit is contained in:
@@ -101,14 +101,33 @@ def yes_no_prompt(prompt, default=True):
|
||||
def detect_system_type(target_host, script_dir):
|
||||
"""Detect the type of system on the target host"""
|
||||
try:
|
||||
detect_script = script_dir / 'detect-system.sh'
|
||||
if not detect_script.exists():
|
||||
print(f"Warning: detect-system.sh not found at {detect_script}")
|
||||
return 'unknown'
|
||||
|
||||
result = subprocess.run(
|
||||
[str(script_dir / 'detect-system.sh'), target_host],
|
||||
[str(detect_script), target_host],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10
|
||||
timeout=15
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"Warning: Detection script returned error code {result.returncode}")
|
||||
if result.stderr:
|
||||
print(f"Error output: {result.stderr}")
|
||||
return 'unknown'
|
||||
|
||||
system_type = result.stdout.strip()
|
||||
if not system_type:
|
||||
print("Warning: Detection script returned empty output")
|
||||
return 'unknown'
|
||||
|
||||
return system_type if system_type in SYSTEM_TYPES else 'unknown'
|
||||
except subprocess.TimeoutExpired:
|
||||
print(f"Warning: System detection timed out for {target_host}")
|
||||
return 'unknown'
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not detect system type: {e}")
|
||||
return 'unknown'
|
||||
|
||||
Reference in New Issue
Block a user