fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
AutoFix Bot
2026-03-03 06:03:38 +08:00
parent 2a0ed6af4d
commit 9fd1da8fb7
41 changed files with 901 additions and 768 deletions

View File

@@ -129,7 +129,7 @@ class TestOpsManager:
# 更新告警规则
updated_rule = self.manager.update_alert_rule(
rule1.id, threshold=85.0, description="更新后的描述"
rule1.id, threshold=85.0, description="更新后的描述",
)
assert updated_rule.threshold == 85.0
self.log(f"Updated alert rule threshold to {updated_rule.threshold}")
@@ -421,7 +421,7 @@ class TestOpsManager:
# 模拟扩缩容评估
event = self.manager.evaluate_scaling_policy(
policy_id=policy.id, current_instances=3, current_utilization=0.85
policy_id=policy.id, current_instances=3, current_utilization=0.85,
)
if event:
@@ -439,7 +439,7 @@ class TestOpsManager:
with self.manager._get_db() as conn:
conn.execute("DELETE FROM scaling_events WHERE tenant_id = ?", (self.tenant_id,))
conn.execute(
"DELETE FROM auto_scaling_policies WHERE tenant_id = ?", (self.tenant_id,)
"DELETE FROM auto_scaling_policies WHERE tenant_id = ?", (self.tenant_id,),
)
conn.commit()
self.log("Cleaned up auto scaling test data")
@@ -530,7 +530,7 @@ class TestOpsManager:
# 发起故障转移
event = self.manager.initiate_failover(
config_id=config.id, reason="Primary region health check failed"
config_id=config.id, reason="Primary region health check failed",
)
if event:
@@ -638,7 +638,7 @@ class TestOpsManager:
# 生成成本报告
now = datetime.now()
report = self.manager.generate_cost_report(
tenant_id=self.tenant_id, year=now.year, month=now.month
tenant_id=self.tenant_id, year=now.year, month=now.month,
)
self.log(f"Generated cost report: {report.id}")
@@ -656,7 +656,7 @@ class TestOpsManager:
self.log(
f" Idle resource: {resource.resource_name} (est. cost: {
resource.estimated_monthly_cost
}/month)"
}/month)",
)
# 生成成本优化建议
@@ -666,7 +666,7 @@ class TestOpsManager:
for suggestion in suggestions:
self.log(f" Suggestion: {suggestion.title}")
self.log(
f" Potential savings: {suggestion.potential_savings} {suggestion.currency}"
f" Potential savings: {suggestion.potential_savings} {suggestion.currency}",
)
self.log(f" Confidence: {suggestion.confidence}")
self.log(f" Difficulty: {suggestion.difficulty}")
@@ -691,7 +691,7 @@ class TestOpsManager:
)
conn.execute("DELETE FROM idle_resources WHERE tenant_id = ?", (self.tenant_id,))
conn.execute(
"DELETE FROM resource_utilizations WHERE tenant_id = ?", (self.tenant_id,)
"DELETE FROM resource_utilizations WHERE tenant_id = ?", (self.tenant_id,),
)
conn.execute("DELETE FROM cost_reports WHERE tenant_id = ?", (self.tenant_id,))
conn.commit()