Skip to content

Commit

Permalink
fix(biz/validators): 修复缺少stage查询条件问题 (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
F-cq authored Nov 5, 2024
1 parent d0f54d4 commit 24516ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/dashboard/apigateway/apigateway/biz/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _validate_stage_backends(self):
if resource["proxy"].get("backend_id", None)
}
)
backend_configs = BackendConfig.objects.filter(backend_id__in=backend_ids)
backend_configs = BackendConfig.objects.filter(stage=self.stage, backend_id__in=backend_ids)
else:
backend_configs = BackendConfig.objects.filter(stage=self.stage)

Expand All @@ -207,9 +207,10 @@ def _validate_stage_backends(self):
if not core_constants.HOST_WITHOUT_SCHEME_PATTERN.match(host["host"]):
raise ReleaseValidationError(
_(
"网关环境【{stage_name}】中的配置【后端服务地址】不合法。请在网关 `后端服务` 中进行配置。"
"网关环境【{stage_name}】中的配置【后端服务 {backend_name} 地址】不合法。请在网关 `后端服务` 中进行配置。"
).format(
stage_name=self.stage.name,
backend_name=backend_config.backend.name,
)
)

Expand Down
25 changes: 22 additions & 3 deletions src/dashboard/apigateway/apigateway/tests/biz/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,37 @@ def test_validate_stage_backends(self, fake_stage, fake_gateway):
description="test",
)

backend_config = G(
stage2 = G(
Stage,
gateway=fake_gateway,
name="test_stage2",
description="test",
)

G(
BackendConfig,
gateway=fake_gateway,
backend_id=backend.id,
stage_id=227,
backend=backend,
stage=fake_stage,
config={
"timeout": 30,
"loadbalance": "roundrobin",
"hosts": [{"scheme": "http", "host": "ee.com", "weight": 100}],
},
)

G(
BackendConfig,
gateway=fake_gateway,
backend=backend,
stage=stage2,
config={
"timeout": 30,
"loadbalance": "roundrobin",
"hosts": [{"scheme": "", "host": "", "weight": 100}],
},
)

resource_version = G(
ResourceVersion,
gateway=fake_gateway,
Expand Down

0 comments on commit 24516ea

Please sign in to comment.