Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-369899: Add NTP options DHCP|Default|Manual|None #35

Merged
merged 8 commits into from
Mar 19, 2024

Conversation

GeraldEV
Copy link
Collaborator

These changes implement NTP control in xsconsole to match the NTP options available in the host-installer

To keep the xsconsole time up to date, the console must use monotonic time (via ncurses) to ensure the console doesn't wait for any negative timesteps before updating (there is an open PR for this behaviour in XenServer) (the console will also update the time upon receiving user input if monotonic time is not used)

Also remove the testing option for the NTP feature as ntpstat is no longer present.

DHCP - Use DHCP server as NTP server
Default - Use the default centos pool NTP servers
Manual - Use manually specified NTP servers
None - Set time manually, no NTP

Gerald Elder-Vass added 3 commits March 13, 2024 09:25
Avoids authentication timeouts and session timeouts when the time jumps
forward, either by chrony (NTP) or manual time changes
ntpstat is no longer present by default on installations
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@bernhardkaindl bernhardkaindl left a comment

Choose a reason for hiding this comment

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

I reviewed this PR and found no issue, only suggestions.

My suggestions are not of functional nature. They are only of cosmetic preference and some optional improvements for consistent PEP8 4-character indentation and have no urgency or need.

Therefore, I'm submitting my review as an Approval!

XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
plugins-base/XSFeatureNTP.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Show resolved Hide resolved
XSConsoleData.py Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
XSConsoleData.py Outdated Show resolved Hide resolved
@GeraldEV
Copy link
Collaborator Author

Pushed a squashed commit to resolve(?) the precommit issues (removed empty line at the end of XSConsoleConstants.py)

XSConsoleData.py Outdated
self.data['ntp']['method'] = "Manual"

servers = self.data['ntp']['servers']
if len(servers) == 4 and all(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some coding standards consider the use of magic numbers a defect, I tried to get some references, because I don't understand the meaning of 4 in this context:

Today, I got feedback from a code review and learned something new. It was about "magic numbers", which are unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants.
https://dev.to/anthonyjdella/magic-numbers-in-programming-19h0

Initially, skipped adding a review comment about it, but now I recognize that the meaning 4 in this case is not obvious to me. Hence, it may deserve an explanatory comment or (and?) the use of a symbolic constant (if that is sufficient)

XSConsoleData.py Outdated
Auth.Inst().AssertAuthenticated()

Data.Inst().NTPServersSet(
["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)]
Copy link
Collaborator

@bernhardkaindl bernhardkaindl Mar 19, 2024

Choose a reason for hiding this comment

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

Here, I see the magic number 4 again, it is more clear here.
Here, [0] in DEFAULT_NTP_DOMAINS[0] looks like another non-obvious number to me.

Checking above, I see it means ".centos.pool.ntp.org", so the code would be more obvious to read this way:

CENTOS_NTP_POOL_DOMAIN = ".centos.pool.ntp.org"
DEFAULT_NTP_DOMAINS = [CENTOS_NTP_POOL_DOMAIN, ".xenserver.pool.ntp.org"]
           ["%d%s" % (ntp_host, CENTOS_NTP_POOL_DOMAIN) for ntp_host in range(4)]

Or it could be nice to move the "." to the format string of the host:

CENTOS_NTP_POOL_DOMAIN = "centos.pool.ntp.org"
DEFAULT_NTP_DOMAINS = [CENTOS_NTP_POOL_DOMAIN, "xenserver.pool.ntp.org"]
           ["%d.%s" % (ntp_host, CENTOS_NTP_POOL_DOMAIN) for ntp_host in range(4)]

I know this also affects inDefaultNTPDomains(), but not significantly.

Comment on lines 297 to 306
if inKey == 'KEY_ENTER':
inputValues = pane.GetFieldValues()
Layout.Inst().PopDialogue()
Layout.Inst().TransientBanner(Lang("Adding %s NTP Server..." % inputValues['name']))
try:
IPUtils.AssertValidNetworkName(inputValues['name'])

data=Data.Inst()
if data.ntp.method("") == "Default":
data.NTPServersSet([server for server in data.ntp.servers([]) if not inDefaultNTPDomains(server)])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this section 100% clearly: It is in HandleKeyADD to Add NTP servers, AFAICS.

When data.ntp.method("") == "Default":, data.NTPServersSet( is called with the return values (NTP servers) from data.ntp.servers([]) that are not in the NTP default domains, correct?

I've seen that "Default" means that the default NTP servers shall be configured, so I'm a bit at a loss what this last line is used for, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"Default" means to use the initial/default NTP servers ([0-3].centos.pool.ntp.org)
"Manual" means to use servers specified by the user
In the case where a user is in "Default" mode but switches to "Manual" mode, as a convenience we remove the default servers from the list
In theory this could backfire if the user manually adds the default servers to the list, then adding a new default server could remove their existing ones
The alternative here is to not remove any servers from the list when a user switches from "Default" to "Manual" mode
What do you think?

XSConsoleData.py Outdated
self.data['ntp']['method'] = "Manual"

servers = self.data['ntp']['servers']
if len(servers) == 4 and all(
Copy link
Collaborator

@bernhardkaindl bernhardkaindl Mar 19, 2024

Choose a reason for hiding this comment

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

Suggested change
if len(servers) == 4 and all(
# If 4 NTP servers are set and they are default NTP servers, set method to Default:
if len(servers) == 4 and all(

@@ -0,0 +1,2 @@
# Default NTP domains are <int>.[centos|xenserver].pool.ntp.org
DEFAULT_NTP_DOMAINS = [".centos.pool.ntp.org", ".xenserver.pool.ntp.org"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion to move the static definition of the default NTP server domain to the constants:

Suggested change
DEFAULT_NTP_DOMAINS = [".centos.pool.ntp.org", ".xenserver.pool.ntp.org"]
CENTOS_NTP_DOMAIN = "centos.pool.ntp.org"
DEFAULT_NTP_DOMAINS = [CENTOS_NTP_DOMAIN, "xenserver.pool.ntp.org"]
DEFAULT_NTP_SERVERS = ["%d.%s" % (i, CENTOS_NTP_DOMAIN) for i in range(4)]

XSConsoleData.py Outdated
Comment on lines 594 to 595
Data.Inst().NTPServersSet(
["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

And then use the new constant:

Suggested change
Data.Inst().NTPServersSet(
["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)]
Data.Inst().NTPServersSet(DEFAULT_NTP_SERVERS)

@GeraldEV GeraldEV merged commit 13d1e3e into master Mar 19, 2024
2 checks passed
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.

3 participants