Project

General

Profile

« Previous | Next » 

Revision a406cf2b

Added by Matěj Mudra 8 months ago

fixes #36160 - Redefine append domain names setting

This PR aims to unify the format of host names stored in the database and the way they are displayed.
With this change, the name of the host is always going to be stored with the domain name appended.
The setting formerly named `append_domain_name_for_hosts` is now renamed to `display_fqdn_for_hosts`
because it will only impact how the names are displayed from now.
This means dashboards and breadcrumbs are going to display the whole FQDN if you choose to.

View differences:

app/assets/javascripts/host_edit_interfaces.js
function construct_host_name() {
var host_name_el = $('#host_name')
var host_name = host_name_el.val();
if (host_name_el.data('appendDomainNameForHosts') === false) {
return host_name;
}
var domain_name = primary_nic_form()
.find('.interface_domain option:selected')
.text();
app/helpers/application_helper.rb
destroyVmOnHostDelete: Setting['destroy_vm_on_host_delete'],
labFeatures: Setting[:lab_features],
safeMode: Setting[:safemode_render],
displayFqdnForHosts: Setting[:display_fqdn_for_hosts],
}
end
app/models/host/base.rb
:domain=, :domain_id=, :domain_name=, :to => :primary_interface
attr_writer :updated_virtuals
def updated_virtuals
@updated_virtuals ||= []
end
......
template.render(host: self, **params)
end
def to_label
if Setting[:display_fqdn_for_hosts]
name
else
name.split('.')[0]
end
end
private
def parse_ip_address(address, ignore_link_local: true)
app/registries/foreman/settings/general.rb
description: N_("Whether or not to show a menu to access experimental lab features (requires reload of page)"),
default: false,
full_name: N_('Show Experimental Labs'))
setting('append_domain_name_for_hosts',
setting('display_fqdn_for_hosts',
type: :boolean,
description: N_('Foreman will append domain names when new hosts are provisioned'),
description: N_('Display names of hosts as FQDNs. If disabled, only display names of hosts as hostnames.'),
default: true,
full_name: N_('Append domain names to the host'))
full_name: N_('Display FQDN for hosts'))
setting('outofsync_interval',
type: :integer,
description: N_('Duration in minutes after servers are classed as out of sync. ' \
app/services/name_synchronizer.rb
private
def interface_name
Setting[:append_domain_name_for_hosts] ? @interface.name : @interface.shortname
@interface.name
end
end
app/views/api/v2/hosts/base.json.rabl
object @host
attributes :name, :id
node :display_name do |host|
host.to_label
end
app/views/dashboard/_hosts_in_build_mode_widget_host_list.html.erb
<tbody>
<% hosts.each do |host| %>
<tr>
<td class="ellipsis"><%= host_build_status_icon(host) %> <%= link_to host.name, current_host_details_path(host) %></td>
<td class="ellipsis"><%= host_build_status_icon(host) %> <%= link_to host, current_host_details_path(host) %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host.owner %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= build_duration(host) %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= date_time_relative(host.token&.expires)%></td>
app/views/dashboard/_new_hosts_widget_host_list.html.erb
<tbody>
<% hosts.each do |host| %>
<tr>
<td class="ellipsis"><%= link_to host.name, current_host_details_path(host) %></td>
<td class="ellipsis"><%= link_to host, current_host_details_path(host) %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= safe_join([icon(host.operatingsystem, :size => '16x16'), host.operatingsystem.to_label]) if host.operatingsystem.present? %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host.owner %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= date_time_relative(host.created_at) %></td>
app/views/hosts/_form.html.erb
<%= text_f f, :name, :size => "col-md-4", :value => name_field(@host),
:input_group_btn => randomize_mac_link,
:help_inline => _("This value is used also as the host's primary interface name."),
:data => { 'append_domain_name_for_hosts' => Setting[:append_domain_name_for_hosts] }
:data => {}
%>
<% if show_organization_tab? %>
db/migrate/20230414091257_rename_append_domain_setting.rb
class RenameAppendDomainSetting < ActiveRecord::Migration[6.1]
def change
Setting.find_by(name: 'append_domain_name_for_hosts')&.update_attribute(:name, 'display_fqdn_for_hosts')
end
end
db/migrate/20230418075940_assign_fqdn_to_host_name.rb
class AssignFqdnToHostName < ActiveRecord::Migration[6.1]
def up
Host.find_in_batches(batch_size: 1000) do |hosts|
hosts.each do |host|
host.update_attribute(:name, host.fqdn)
end
end
end
end
test/controllers/api/v2/settings_controller_test.rb
end
test "should get all settings through index" do
Setting['append_domain_name_for_hosts'] = false
Setting['display_fqdn_for_hosts'] = false
get :index, params: { per_page: 'all' }
assert_response :success
settings = ActiveSupport::JSON.decode(@response.body)['results']
......
foreman_url = settings.detect { |s| s['name'] == 'foreman_url' }
assert_equal Setting['foreman_url'], foreman_url['value']
assert_equal Foreman.settings.find('foreman_url').default, foreman_url['default']
append_domain_name_for_hosts = settings.detect { |s| s['name'] == 'append_domain_name_for_hosts' }
assert_equal false, append_domain_name_for_hosts['value']
display_fqdn_for_hosts = settings.detect { |s| s['name'] == 'display_fqdn_for_hosts' }
assert_equal false, display_fqdn_for_hosts['value']
end
test "should get index with organization and location params" do
......
end
test "properly show overriden false value" do
Setting['append_domain_name_for_hosts'] = value = false
get :show, params: { :id => 'append_domain_name_for_hosts' }
Setting['display_fqdn_for_hosts'] = value = false
get :show, params: { :id => 'display_fqdn_for_hosts' }
assert_response :success
show_response = ActiveSupport::JSON.decode(@response.body)
assert_equal value, show_response['value']
test/integration/host_js_test.rb
find('h5', :text => /newhost2.*/) # wait for the new host details page
end
test "redirects correctly with append_domain_name_for_hosts turned off" do
Setting['append_domain_name_for_hosts'] = false
test "redirects correctly with display_fqdn_for_hosts turned off" do
Setting['display_fqdn_for_hosts'] = false
compute_resource = FactoryBot.create(:compute_resource, :libvirt)
os = FactoryBot.create(:ubuntu14_10, :with_associations)
Nic::Managed.any_instance.stubs(:dns_conflict_detected?).returns(true)
test/models/lookup_value_test.rb
end
end
test "can create lookup value if match fqdn= does match existing host" do
as_admin do
Setting[:append_domain_name_for_hosts] = false
domain = FactoryBot.create(:domain)
host = FactoryBot.create(:host, interfaces: [FactoryBot.build(:nic_managed, identifier: 'fqdn_test', primary: true, domain: domain)])
attrs = { :match => "fqdn=#{host.primary_interface.fqdn}", :value => "123", :lookup_key_id => lookup_key.id }
refute_match /#{domain.name}/, host.name, "#{host.name} shouldn't be FQDN"
assert_difference('LookupValue.count') do
LookupValue.create!(attrs)
end
end
end
test "can create lookup value if user has matching hostgroup " do
attrs = valid_attrs2 # create key outside as_user
as_user :one do
test/unit/name_synchronizer_test.rb
context "synchronizer build from host on shortnames" do
before do
Setting[:append_domain_name_for_hosts] = false
Setting[:display_fqdn_for_hosts] = false
end
test "#sync_required? detects difference between names" do
refute_equal @host.name, @host.primary_interface.shortname
webpack/assets/javascripts/react_app/components/HostDetails/Tabs/Details/Cards/SystemProperties/index.js
import SkeletonLoader from '../../../../../common/SkeletonLoader';
import DefaultLoaderEmptyState from '../../../../DetailsCard/DefaultLoaderEmptyState';
import { STATUS } from '../../../../../../constants';
import { useForemanSettings } from '../../../../../../Root/Context/ForemanContext';
const SystemPropertiesCard = ({ status, hostDetails }) => {
const { displayFqdnForHosts } = useForemanSettings();
const {
name,
model_name: model,
......
hoverTip={__('Copy to clipboard')}
clickTip={__('Copied to clipboard')}
>
{name}
{displayFqdnForHosts ? name : name?.replace(`.${domain}`, '')}
</ClipboardCopy>
)}
</SkeletonLoader>
webpack/assets/javascripts/react_app/components/HostDetails/index.js
import { foremanUrl } from '../../common/helpers';
import { CardExpansionContextWrapper } from './CardExpansionContext';
import Head from '../Head';
import { useForemanSettings } from '../../Root/Context/ForemanContext';
const HostDetails = ({
match: {
......
location: { hash },
history,
}) => {
const { displayFqdnForHosts } = useForemanSettings();
const { response, status } = useAPI(
'get',
`/api/hosts/${id}?show_hidden_parameters=true`,
......
}}
breadcrumbItems={[
{ caption: __('Hosts'), url: foremanUrl('/hosts') },
{ caption: response.name },
{
caption: displayFqdnForHosts
? response.name
: response.name?.replace(`.${response.domain_name}`, ''),
},
]}
/>
)}
......
headingLevel="h5"
size="2xl"
>
{response.name}
{displayFqdnForHosts
? response.name
: response.name?.replace(
`.${response.domain_name}`,
''
)}
</Title>
)}
</SkeletonLoader>
webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecords.fixtures.js
updatedAt: '2018-01-22 14:03:38 +0100',
readonly: false,
id: 177,
name: 'append_domain_name_for_hosts',
name: 'display_fqdn_for_hosts',
fullName: 'Append domain names to the host',
selectValues: null,
value: true,
......
item => item.name === 'global_PXELinux'
);
export const boolSetting = settings.find(
item => item.name === 'append_domain_name_for_hosts'
item => item.name === 'display_fqdn_for_hosts'
);
export const arraySetting = settings.find(
item => item.name === 'http_proxy_except_list'
webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/__snapshots__/SettingRecordsReducer.test.js.snap
"encrypted": false,
"fullName": "Append domain names to the host",
"id": 177,
"name": "append_domain_name_for_hosts",
"name": "display_fqdn_for_hosts",
"readonly": false,
"selectValues": null,
"settingsType": "boolean",
......
"encrypted": false,
"fullName": "Append domain names to the host",
"id": 177,
"name": "append_domain_name_for_hosts",
"name": "display_fqdn_for_hosts",
"readonly": false,
"selectValues": null,
"settingsType": "boolean",
webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/__snapshots__/SettingRecordsSelectors.test.js.snap
"encrypted": false,
"fullName": "Append domain names to the host",
"id": 177,
"name": "append_domain_name_for_hosts",
"name": "display_fqdn_for_hosts",
"readonly": false,
"selectValues": null,
"settingsType": "boolean",
......
"encrypted": false,
"fullName": "Append domain names to the host",
"id": 177,
"name": "append_domain_name_for_hosts",
"name": "display_fqdn_for_hosts",
"readonly": false,
"selectValues": null,
"settingsType": "boolean",
webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/__snapshots__/SettingsTable.test.js.snap
"encrypted": false,
"fullName": "Append domain names to the host",
"id": 177,
"name": "append_domain_name_for_hosts",
"name": "display_fqdn_for_hosts",
"readonly": false,
"selectValues": null,
"settingsType": "boolean",

Also available in: Unified diff