Skip to content

Commit

Permalink
feat(publish): make resource_verison v1 disable publish (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Ya-Jun authored Sep 26, 2024
1 parent 7f4fa1e commit 43d18b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/dashboard/apigateway/apigateway/biz/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ def _validate_stage_vars(self, stage: Stage, resource_version_id: int):
}
)

def _validate_resource_version_schema(self):
if not self.resource_version.is_schema_v2:
raise ReleaseValidationError(
_("版本【{resource_version}】数据结构已经不兼容,不允许发布,请在【资源配置】中新建版本再发布").format(
resource_version=self.resource_version.object_display
)
)

def _validate_gateway_status(self):
if self.gateway.status != GatewayStatusEnum.ACTIVE.value:
raise ReleaseValidationError(
Expand All @@ -252,6 +260,7 @@ def __call__(self):
self._validate_stage_plugins()

if self.resource_version:
self._validate_resource_version_schema()
self._validate_stage_vars(self.stage, self.resource_version.id)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def _is_gateway_ok_for_releasing(release: Release, source: PublishSourceEnum) ->
msg = f"release(id={release.pk}) stage(name={release.stage.name}) is not active, ignored"
return False, msg

# 校验版本,现在只支持v2发布
if not release.resource_version.is_schema_v2:
msg = (
f"The data structure of version 【{release.resource_version.object_display}】 is incompatible and is not "
f"allowed to be published. Please create a new version in [Resource Configuration] before publishing."
)
return False, msg

return True, ""


Expand Down
5 changes: 5 additions & 0 deletions src/dashboard/apigateway/apigateway/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def fake_release(fake_gateway, fake_stage, fake_resource_version):
return G(Release, gateway=fake_gateway, stage=fake_stage, resource_version=fake_resource_version)


@pytest.fixture
def fake_release_v2(fake_gateway, fake_stage, fake_resource_version_v2):
return G(Release, gateway=fake_gateway, stage=fake_stage, resource_version=fake_resource_version_v2)


@pytest.fixture
def fake_release_history(fake_gateway, fake_stage, fake_resource_version):
return G(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,41 @@ def test__is_gateway_ok_for_releasing_with_inactive_stage(self, fake_stage, fake
assert ok is False
assert f"stage(name={fake_stage.name}) is not active, ignored" in msg

def test__is_gateway_ok_for_releasing_with_valid_release(self, fake_release):
def test__is_gateway_ok_for_releasing_with_valid_release(self, fake_release_v2):
source = PublishSourceEnum.CLI_SYNC
ok, msg = _is_gateway_ok_for_releasing(fake_release, source)
ok, msg = _is_gateway_ok_for_releasing(fake_release_v2, source)
assert ok is True
assert msg == ""

def test__is_gateway_ok_for_releasing_with_resource_version_v1(self, fake_stage, fake_release):
source = PublishSourceEnum.BACKEND_UPDATE
ok, msg = _is_gateway_ok_for_releasing(fake_release, source)
assert ok is False
assert (
f"The data structure of version 【{fake_release.resource_version.object_display}】 is incompatible" in msg
)

def test__save_release_history(self, fake_release):
source = PublishSourceEnum.BACKEND_UPDATE
release_history = _save_release_history(fake_release, source, "test")
assert release_history is not None
assert release_history.gateway.pk == fake_release.gateway_id
assert release_history.stage.pk == fake_release.stage_id

def test__trigger_rolling_publish(self, fake_shared_gateway, fake_release):
def test__trigger_rolling_publish(self, fake_shared_gateway, fake_release_v2):
fake_shared_gateway.id = settings.DEFAULT_MICRO_GATEWAY_ID
fake_shared_gateway.save()
source = PublishSourceEnum.BACKEND_UPDATE
release_list = [fake_release]
release_list = [fake_release_v2]
self.distributor.distribute.return_value = True, ""
_trigger_rolling_publish(source, "test", release_list, True)
self.distributor.distribute.assert_called()

def test__trigger_revoke_publish_for_disable_with_valid_release(self, fake_shared_gateway, fake_release):
def test__trigger_revoke_publish_for_disable_with_valid_release(self, fake_shared_gateway, fake_release_v2):
fake_shared_gateway.id = settings.DEFAULT_MICRO_GATEWAY_ID
fake_shared_gateway.save()
source = PublishSourceEnum.GATEWAY_DISABLE
release_list = [fake_release]
release_list = [fake_release_v2]
self.distributor.revoke.return_value = True, ""
_trigger_revoke_publish_for_disable(source, "test", release_list, True)
self.distributor.revoke.assert_called()

0 comments on commit 43d18b6

Please sign in to comment.