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

Fixes #36982 - display short hostname on REX job pages #859

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

nofaralfasi
Copy link
Contributor

@nofaralfasi nofaralfasi commented Dec 14, 2023

If the display_fqdn_for_hosts setting is set to false, show the short hostname on REX job pages.

Requires:

@nofaralfasi
Copy link
Contributor Author

@MariaAga Any idea why the tests are failing?

@MariaAga
Copy link
Member

TypeError: (0 , _ForemanContext.useForemanSettings) is not a function
It needs to have a mock in the __mocks__ folder

@nofaralfasi
Copy link
Contributor Author

TypeError: (0 , _ForemanContext.useForemanSettings) is not a function It needs to have a mock in the __mocks__ folder

Would adding this line here resolve the issue?
export const useForemanSettings = () => {};

Or is there a way I can test it locally? I couldn't find how.

@MariaAga
Copy link
Member

MariaAga commented Dec 18, 2023

Yeah it should fix it. You can run npm install npm test in the plugin folder to test

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch 2 times, most recently from a0252cd to 68405c3 Compare December 20, 2023 15:30
Copy link
Member

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

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

The changes to the ruby code seem quite OK, but the JS doesn't have to know about this setting. It should just use display_name where it is possible.

webpack/JobWizard/steps/HostsAndInputs/HostPreviewModal.js Outdated Show resolved Hide resolved
webpack/JobWizard/steps/ReviewDetails/index.js Outdated Show resolved Hide resolved
webpack/JobWizard/steps/form/SearchSelect.js Show resolved Hide resolved
@@ -31,7 +33,7 @@ const SelectedChip = ({ selected, setSelected, categoryName }) => {
onClick={() => deleteItem(id)}
closeBtnAriaLabel={`Remove ${name}`}
>
{name}
{displayFqdnForHosts ? name : name.split('.')[0]}
Copy link
Member

Choose a reason for hiding this comment

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

selected variable is a set of hosts returned by the API, they all have display_name property, you can use it here, as long as you change the map statement:
instead of:

selected.map(({ name, id }, index) => (...)

You can add the display_name:

selected.map(({ name, display_name, id }, index) => (...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we are using here gql for the query, which means that we don't have access to the display_name property.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like we are missing display_name from GQL definition in foreman. Let's add it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

theforeman/foreman#9968 added to the description

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from 68405c3 to 3fe4eb7 Compare December 26, 2023 11:21
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch 3 times, most recently from c4dad98 to a8b8619 Compare December 27, 2023 13:42
@nofaralfasi nofaralfasi marked this pull request as draft December 27, 2023 14:11
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from a8b8619 to 33ff5f6 Compare December 27, 2023 14:43
@nofaralfasi nofaralfasi marked this pull request as ready for review December 27, 2023 14:44
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from 33ff5f6 to cdf48ef Compare January 1, 2024 16:56
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

If this still depends on theforeman/foreman#9968, can you raise the minimum required Foreman version so we don't accidentally cherry pick it?

<Button
component="a"
href={foremanUrl(`/hosts/${host}`)}
href={foremanUrl(`/hosts/${host.name}`)}
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to use host IDs in URLs, not names to avoid breaking when you rename hosts. I know Foreman is inconsistent about that. This is why I think we should avoid constructing URLs all over the place and instead rely on helpers. foremanUrl is really an anti-pattern.

If the UI relies on it so much, we should do what GH did and include html_url in the API response.

@@ -84,7 +84,7 @@ const ReviewDetails = ({
return __('No Target Hosts');
}
if (hosts.length === 1 || hosts.length === 2) {
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but I'd have written < 3 and probably made 3 some constant.

@nofaralfasi nofaralfasi marked this pull request as draft January 3, 2024 11:28
@nofaralfasi nofaralfasi changed the title Fixes #36982 - display short hostname on REX job pages [WIP] Fixes #36982 - display short hostname on REX job pages Jan 3, 2024
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch 2 times, most recently from b93143b to d8f5135 Compare January 7, 2024 09:29
@nofaralfasi nofaralfasi changed the title [WIP] Fixes #36982 - display short hostname on REX job pages Fixes #36982 - display short hostname on REX job pages Jan 7, 2024
@nofaralfasi nofaralfasi marked this pull request as ready for review January 7, 2024 09:30
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch 2 times, most recently from 5b87230 to 6a67c5d Compare January 9, 2024 10:47
Copy link
Contributor

@stejskalleos stejskalleos left a comment

Choose a reason for hiding this comment

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

🍏 LGTM

Did a quick test with enabled and disabled setting, with the new UI job wizard,
and worked fine.
Setting is applied everywhere and the job execution went well.

@adamruzicka @MariaAga I'll leave the final ACK on you

@adamruzicka
Copy link
Contributor

Could you please rebase? It should make packit turn green

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from 6a67c5d to f109215 Compare January 15, 2024 10:22
<Button
component="a"
href={foremanUrl(`/hosts/${host}`)}
href={foremanUrl(`/new/hosts/${host.name}`)}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be dependent on a switch?
@Ron-Lavi?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, we should check user's settings here. I'll remove it and open a separate PR for that.

Copy link
Member

Choose a reason for hiding this comment

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

I saw the same behaviour across the app so I think it is OK..

Probably we can try to load the correct host path to the React Context Settings and use that helper across the app ( but that's for another PR ). :)

@adamruzicka
Copy link
Contributor

Could you also deal with it here https://github.com/theforeman/foreman_remote_execution/blob/master/app/lib/actions/remote_execution/run_host_job.rb#L104 ?

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from f109215 to 3240802 Compare January 18, 2024 16:07
@nofaralfasi
Copy link
Contributor Author

Could you also deal with it here https://github.com/theforeman/foreman_remote_execution/blob/master/app/lib/actions/remote_execution/run_host_job.rb#L104 ?

Is there a reason for the inconsistency in saving the action attribute of the ForemanTasks model? Sometimes it stores the full hostname, and other times it uses the short hostname. Any idea why?

@adamruzicka
Copy link
Contributor

Could you give an example?

@nofaralfasi
Copy link
Contributor Author

nofaralfasi commented Jan 18, 2024

ForemanTasks

When I set the Display FQDN for hosts setting to true, and I execute any remote job on multiple hosts, some of them have the action field containing the short hostname, while others have the full hostname.

image

Update:
When I debug it, the update query contains the correct hostname, but for some reason that changes afterward and I can't figure out where.

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from 3240802 to b7ec528 Compare January 18, 2024 16:48
@adamruzicka
Copy link
Contributor

I don't know in what environment you hit that, but it sounds like that either not all processes picked up your code changes or that not all processes picked up the setting change. Either way, I'm failing to reproduce it on a fresh nightly machine

@nofaralfasi
Copy link
Contributor Author

I don't know in what environment you hit that, but it sounds like that either not all processes picked up your code changes or that not all processes picked up the setting change. Either way, I'm failing to reproduce it on a fresh nightly machine

Thanks. Restarting my local environment seems to have solved the issue for me. Everything works as expected now.

@nofaralfasi
Copy link
Contributor Author

Is there anything else required before we proceed with the merge?

@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from b7ec528 to b93fc23 Compare January 25, 2024 13:47
Copy link
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

On a relevant side note, what does RunHostJob#host_name (a thing usable in webhooks) end up being? Is it the short name or the fqdn?

app/lib/actions/remote_execution/run_host_job.rb Outdated Show resolved Hide resolved
@nofaralfasi
Copy link
Contributor Author

On a relevant side note, what does RunHostJob#host_name (a thing usable in webhooks) end up being? Is it the short name or the fqdn?

I think this shouldn't be effected at all, however I didn't test it. hostname should stay the fqdn.

If the `display_fqdn_for_hosts` setting is set to false,
show the short hostname on REX job pages.
@nofaralfasi nofaralfasi force-pushed the display_fqdn_for_hosts branch from b93fc23 to dfaad4e Compare February 19, 2024 16:55
Copy link
Contributor

@adamruzicka adamruzicka 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

@adamruzicka adamruzicka merged commit 50a621e into theforeman:master Feb 20, 2024
13 checks passed
@adamruzicka
Copy link
Contributor

Thank you @nofaralfasi !

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.

7 participants