-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
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
There was a problem hiding this 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!
Signed-off-by: Bernhard Kaindl <[email protected]>
Signed-off-by: Bernhard Kaindl <[email protected]>
Co-authored-by: Bernhard Kaindl <[email protected]>
7c2bf15
to
27d076b
Compare
a56152c
to
ee123b2
Compare
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( |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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.
plugins-base/XSFeatureNTP.py
Outdated
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)]) |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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( |
XSConsoleConstants.py
Outdated
@@ -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"] |
There was a problem hiding this comment.
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:
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
Data.Inst().NTPServersSet( | ||
["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)] |
There was a problem hiding this comment.
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:
Data.Inst().NTPServersSet( | |
["%d%s" % (i, DEFAULT_NTP_DOMAINS[0]) for i in range(4)] | |
Data.Inst().NTPServersSet(DEFAULT_NTP_SERVERS) |
db0e7e9
to
f8a6181
Compare
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