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

Add an option for rhel to force the use of hostname config #859

Merged
merged 2 commits into from
Apr 15, 2021

Conversation

hamalq
Copy link
Contributor

@hamalq hamalq commented Mar 29, 2021

add prefer_fqdn_over_hostname config option

the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: #1921004

Proposed Commit Message

summary: no more than 70 characters

A description of what the change being made is and why it is being
made, if the summary line is insufficient.  The blank line above is
required. This should be wrapped at 72 characters, but otherwise has
no particular length requirements.

If you need to write multiple paragraphs, feel free.

LP: #NNNNNNN (replace with the appropriate bug reference or remove
this line entirely if there is no associated bug)

Additional Context

Test Steps

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

@hamalq hamalq force-pushed the rhel_shortname branch 2 times, most recently from 9d1b7bc to dffb162 Compare March 29, 2021 18:36
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Mar 29, 2021
RHEL always use the FQDN as hostname thats the default
behavior, adding the config rhel_use_hostname will force
RHEL to use the hostname if sent

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Mar 29, 2021
RHEL always use the FQDN as hostname thats the default
behavior, adding the config rhel_use_hostname will force
RHEL to use the hostname if sent as hostname for instance

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Mar 30, 2021
RHEL always use the FQDN as hostname thats the default
behavior, adding the config rhel_use_hostname will force
RHEL to use the hostname if sent

LP: canonical#859
@TheRealFalcon
Copy link
Member

Hi @hamalq , I think if we had a distro-independent setting along the lines of default_hostname: <hostname|fqdn>, that'd be more accessible to everybody.

@OddBloke , do you have strong opinions here? I'm hesitant about adding a new top-level key, but given how things currently work, I'm not really sure there's a better way to allow this.

@OddBloke
Copy link
Collaborator

OddBloke commented Apr 6, 2021

I strongly agree that we should name it independent of distro. We have been trying to avoid introducing new top-level keys, as you say: given that we already use the hostname key, there isn't an obvious name for a key that could gather all of these options together.

default_hostname isn't quite right either: the value of the setting isn't a hostname, it's a type of hostname. And, I suppose, it isn't really a default either: it's defining what the defaulting behaviour should be. Perhaps preferred_hostname_type?

Stepping back, actually, might it be easier to express this as a more explicit boolean: prefer_fqdn_over_hostname, for example? We already know all the types of hostname that we need to deal with, and there are two of them. RHEL should default to true for it, everything else should default to false.

hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thank you for the branch @hamalq in order to land this I think we need to minmally extend unittests which cover these affected behaviors in

https://github.com/canonical/cloud-init/blob/master/tests/unittests/test_handler/test_handler_set_hostname.py

Also it would be nice to extend the integration test below with a sample #coud-config which provides this new key
tests/integration_tests/modules/test_set_hostname.py

cloudinit/distros/rhel.py Outdated Show resolved Hide resolved
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 6, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 14, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 14, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 14, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 14, 2021
RHEL always use the FQDN as hostname thats the default
behavior, setting prefer_fqdn_over_hostname option to
to false will prefer the hostname over fqdn

for the other distros the option prefer_fqdn_over_hostname
will default to false since the default behavior is using
the hostname, if set true the fqdn will be used

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

I think what remains is documentation of this feature. I'm testing locally now to confirm behavior and double checking the need for distro.set_option

cloudinit/config/cc_set_hostname.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

I confirm that this approach is the best we have at the moment. distro class has no visibility to the merged sys_cfg which contains user-data cloud-config settings (which the datasource instances have). I was under the impression we might be able to get to it thourgh distro._cfg but that's a different subset of config entirely.

confirmed that hostnames are properly set on this new version cloud-init.

hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
hamalq pushed a commit to hamalq/cloud-init that referenced this pull request Apr 15, 2021
the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Looks good to me! I took the liberty of pushing a couple small changes:

  1. The same doc update you made to cc_set_hostname.py was also needed in cc_update_hostname.py
  2. Added an integration test for when prefer_fqdn_over_hostname is false
  3. Updated some unit tests to include both hostname and fqdn to make sure we're always choosing the right one
  4. Also updated some unit tests to not skip their verification if we're on a systemd system.

Assuming CI passes, I should be able to get this merged later today.

the above option allow the user to control the
behavior of a distro hostname selection
so if the user send hostname, FQDN Configs
if prefer_fqdn_over_hostname is true the
The FQDN will be selected as hostname
if false the hostname will be selected

LP: canonical#859
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.

None yet

4 participants