Skip to content

<fix>[flatNetwork]: delete namespace and dnsmasq when disabling DHCP (ZSTAC-78498)#3640

Open
ZStack-Robot wants to merge 1 commit into5.5.12from
sync/ye.zou/fix/ZSTAC-78498
Open

<fix>[flatNetwork]: delete namespace and dnsmasq when disabling DHCP (ZSTAC-78498)#3640
ZStack-Robot wants to merge 1 commit into5.5.12from
sync/ye.zou/fix/ZSTAC-78498

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

Problem

When DHCP service is disabled on an L3 network, the dnsmasq process and network namespace are not deleted. They remain running even after DHCP is disabled.

Root Cause

disableNetworkService in FlatDhcpBackend always called flushDhcpConfig which sends a "flush" command to kvmagent — this only clears DHCP config but intentionally keeps the namespace alive (to avoid breaking userdata if it shares the namespace). However, when userdata service is NOT enabled on the L3 network, there is no reason to keep the namespace, and it should be deleted.

Fix

Check whether userdata service is also enabled on the L3 network before deciding what to do:

  • Userdata enabled: keep calling flushDhcpConfig (namespace shared with userdata, cannot delete)
  • Userdata NOT enabled: delete the namespace entirely via deleteNameSpace, which removes dnsmasq and the network namespace

Fixes: ZSTAC-78498

sync from gitlab !9502

…without userdata service (ZSTAC-78498)

When disabling DHCP service on an L3 network, if userdata service is not
also enabled, the namespace and dnsmasq process should be deleted entirely.
Previously the code always called flushDhcpConfig which only flushed DHCP
config but kept the namespace alive (to avoid breaking shared userdata usage).
Now it checks whether userdata is also enabled: if not, it calls deleteNameSpace
to clean up dnsmasq and the network namespace completely.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: e4431059-9119-48eb-9c62-636bf75354aa

📥 Commits

Reviewing files that changed from the base of the PR and between 226b20b and fd4a2bb.

📒 Files selected for processing (1)
  • plugin/flatNetworkProvider/src/main/java/org/zstack/network/service/flat/FlatDhcpBackend.java

功能概述

FlatDhcpBackend.disableNetworkService() 方法现在在禁用网络服务时检查 L3 网络是否同时启用了用户数据网络服务提供者。当用户数据服务启用时,仅清空 DHCP 配置并删除 DHCP 服务器 IP 标签,跳过命名空间删除;否则保持原有行为:删除 DHCP 服务器 IP 后删除命名空间。

变更内容

组件 / 文件 总结
FlatDhcpBackend 资源清理逻辑
plugin/flatNetworkProvider/src/main/java/org/zstack/network/service/flat/FlatDhcpBackend.java
disableNetworkService() 方法中新增用户数据服务检查。当用户数据服务启用时,采用 DHCP 配置清空分支(刷新配置后删除服务器 IP 标签);未启用时执行命名空间删除。包含新的错误处理路径和提前返回逻辑。

代码审查难度评估

🎯 3 (中等复杂) | ⏱️ ~20 分钟

庆贺诗

🐰 一个条件判断轻轻来,
用户数据现身时徘徊,
DHCP 清空莫删房,
共生共存多漂亮,
资源管理更聪慧,
代码逻辑绽光彩! ✨


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Title check ❌ Error 标题超过了72字符的限制(实际82字符),不符合格式要求。 将标题缩短至72字符以内,例如:'[flatNetwork]: Delete namespace when disabling DHCP (ZSTAC-78498)'
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed 描述充分解释了问题、根本原因和解决方案,与变更集高度相关。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/ye.zou/fix/ZSTAC-78498

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants