Skip to content

NTP DHCP system layout change - #91

Open
semarie wants to merge 1 commit into
xapi-project:masterfrom
xcp-ng:srt/ntp-dhcp-layout
Open

semarie wants to merge 1 commit into
xapi-project:masterfrom
xcp-ng:srt/ntp-dhcp-layout

Conversation

@semarie

@semarie semarie commented Oct 22, 2026

Copy link
Copy Markdown

Following xapi-project/xen-api#7332, this commit changes the way the DHCP mode of NTP is implemented.

Instead of relying on executable permission of chrony.sh (dhclient hook), use the presence of sourcedir line in chrony.conf.

It makes the implementation to depend only on chrony instead of both chrony and dhclient.

Tracking-reference: XCPNG-1094

@semarie

semarie commented Oct 22, 2026

Copy link
Copy Markdown
Author

This PR should not be committed before xapi-project/xen-api#7332 .
Else xsconsole will report faulty NTP status.

@semarie

semarie commented Oct 22, 2026

Copy link
Copy Markdown
Author

Cc @changlei-li

@semarie

semarie commented Oct 22, 2026

Copy link
Copy Markdown
Author

Tests:

  • run xsconsole with older xapi (faulty status)
  • run xsconsole with new xapi (correct status: DHCP / Default / Manual / Disabled )
  • use xsconsole to change the different modes (with network static and with network DHCP)

Comment thread XSConsoleData.py Outdated
self.data['ntp']['sourcedir'].append(match.group(1))
continue

self.data['ntp']['othercontents'].append(line)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just query the NTP mode from XAPI? Then we wouldn't need to maintain the logic in two places going forward.
Previously, NTP could only be configured through xsconsole. After XAPI added support for configuring NTP, the control path in xsconsole was changed to use the XAPI APIs to avoid breaking XAPI's state.
Now that the detection rule may change on the host (DHCP mode relies on the sourcedir line rather than the execute permission of chrony.sh here), I think it would be better to reuse the XAPI APIs in the query path as well. I think this should be doable, though I haven't gone through the related code yet.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the whole NTP code to query XAPI instead of looking at system (chrony.conf, service status, etc...)

It makes xsconsole changes independent of xapi-project/xen-api#7332 : it could be committed before it.

It makes xsconsole independant of the XAPI implementation for NTP DHCP (which is 
changed by xapi-project/xen-api#7332).

Tracking-reference: XCPNG-1094
Signed-off-by: Sebastien Rodot <sebastien.rodot@vates.tech>
@semarie
semarie force-pushed the srt/ntp-dhcp-layout branch from b272c17 to ea131c1 Compare October 23, 2026 13:56
@semarie

semarie commented Oct 23, 2026

Copy link
Copy Markdown
Author

Last push:

  • lighter UpdateNTP to update only the NTP part (as UpdateNTPFromConf before)
  • remove unused stat import

@semarie
semarie requested a review from changlei-li October 23, 2026 13:58
Comment thread XSConsoleData.py
self.RequireSession()
if self.session is not None:
try:
self.data['ntp']['method'] = self.session.xenapi.host.get_ntp_mode(self.data['host']['opaqueref'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xsconsole uses DHCP, Manual, Default and None (XSFeatureNTP.py line19-23). So a mapping is needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the write path (Commit function in XSFeatureNTP.py:383-390), a mapping is need because we are using the dialog state-machine choices and write it to XAPI mode.

Here, in the read path, the raw XAPI value is used. It has only 2 consumers:

  • StatusUpdateHandler (XSFeatureNTP.py:417) which compares "Disabled" and ["DHCP", "Factory"]
  • XSMenuLayout.py:79 which displays the XAPI value

The NTP dialogue's INITIAL pane never reads ntp.method to preselect/highlight the current state, so the state machine values (DHCP/DEFAULT/MANUAL/NONE) are purely internal flow identifiers and never compared against data['ntp']['method'].

But I agree that the output in xsconsole isn't consistent as XSMenuLayout.py:79 displays the XAPI value instead of the historical DHCP, Manual, Default and None. I will change that.

Comment thread XSConsoleData.py
if self.session is not None:
try:
self.data['ntp']['method'] = self.session.xenapi.host.get_ntp_mode(self.data['host']['opaqueref'])
self.data['ntp']['servers'] = self.session.xenapi.host.get_ntp_custom_servers(self.data['host']['opaqueref'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.data['ntp']['servers'] meaning is changed. Before it is whatever in chrony.conf. Now it is host.ntp-custom-servers. I am not clear whether it is consistent in the new logic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that self.data['ntp']['servers'] meaning is changed. It is now exactly host.ntp_custom_servers, i.e.
only meaningful when ntp_mode is Custom.

I don't think parsing chrony.conf is the right answer: the factory servers live in XAPI's product config (factory_ntp_servers), no XAPI field carries them, and deriving them from the conf file would duplicate in xsconsole the detection logic that XAPI owns.

After reviewing the logic, I will do some changes.

So the read path stays purely XAPI-based, split by purpose:

  • servers = host.ntp_custom_servers: the draft list for Custom mode. Consumed only by the edit flow (MANUAL pane add/remove), where it's the value actually written back.
  • Status display shows the effective sources via host.get_ntp_servers_status in all modes (Custom included), instead of shelling out to chronyc directly. Note that in DHCP mode that's the DHCP-lease servers, in Factory the factory servers.

One consequence I'll fix in xsconsole: AdjustNTPForStaticNetwork infers the mode from whether the servers list is empty, which no longer holds since the field isn't cleared when leaving Custom. I'll make it branch on ntp_mode instead.

Comment thread XSConsoleData.py
self.SetNTPMode('Disabled')

self.DisableService("chrony-wait")
self.DisableService("chronyd")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two disables are legacy behaviors. I think it need more consideration for the remove. What is chrony-wait and what is the impact.

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