Skip to content

Commit

Permalink
feat: 「管控区域」「agent版本」筛选能力优化 (closde TencentBlueKing#1752)
Browse files Browse the repository at this point in the history
, # Reviewed, transaction id: 4093
  • Loading branch information
Huayeaaa committed Mar 19, 2024
1 parent a274490 commit 9e5a315
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class KeyEnum(Enum):
ADD_HOST_CLOUD_BLACKLIST = "ADD_HOST_CLOUD_BLACKLIST"
# 消息中心开关
ENABLE_NOTICE_CENTER = "ENABLE_NOTICE_CENTER"
# 禁用已停用插件
DISABLE_STOPPED_PLUGIN = "DISABLE_STOPPED_PLUGIN"

key = models.CharField(_("键"), max_length=255, db_index=True, primary_key=True)
v_json = JSONField(_("值"))
Expand Down
13 changes: 12 additions & 1 deletion apps/node_man/serializers/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
JobType,
ProcType,
)
from apps.node_man.models import GsePluginDesc, Packages, ProcControl, ProcessStatus
from apps.node_man.models import (
GlobalSettings,
GsePluginDesc,
Packages,
ProcControl,
ProcessStatus,
)
from apps.node_man.serializers import base


Expand Down Expand Up @@ -248,6 +254,11 @@ def validate(self, attrs):
raise ValidationError(_("插件参数 plugin_params 和 plugin_params_list 参数不能同时为空"))

if attrs.get("plugin_params"):
if GlobalSettings.get_config(key=GlobalSettings.KeyEnum.DISABLE_STOPPED_PLUGIN.value, default=True):
plugin_name = attrs["plugin_params"]["name"]
if GsePluginDesc.objects.filter(name=plugin_name, is_ready=False).first() is not None:
raise ValidationError(_("插件{}已被禁用,不能执行相关操作").format(plugin_name))

# 把2.0.x 的参数转为 2.1.x 的参数
attrs["plugin_params_list"] = [attrs.get("plugin_params")]

Expand Down
21 changes: 21 additions & 0 deletions apps/node_man/tests/test_views/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,24 @@ def test_common_plugin_list(self):
response = self.client.get(f"/api/plugin/{self.PLUGIN_NAME}/package/", {"os": "LINUX"})
self.assertFalse(response["result"])
self.assertRegex(response["message"], r"bk_collector_not-found in.*")


class PluginOperateViewTestCase(PluginViewTestCase):
PLUGIN_NAME = "stopped_plugin"

def setUp(self) -> None:
super().setUp()
models.GsePluginDesc.objects.filter(name=self.PLUGIN_NAME).update(is_ready=False)

def test_stopped_plugin_operate(self):
response = self.client.post(
"/api/plugin/operate/",
data={
"job_type": "MAIN_INSTALL_PLUGIN",
"bk_host_id": [111],
"plugin_params": {"name": "stopped_plugin", "version": "latest"},
},
)
print(response)
self.assertFalse(response["result"])
self.assertEqual(response["message"], f"插件{self.PLUGIN_NAME}已被禁用,不能执行相关操作(3800001)")

0 comments on commit 9e5a315

Please sign in to comment.