From 3964298504aa4c7bc93c0e527736ada8c2967b89 Mon Sep 17 00:00:00 2001 From: smoyer Date: Wed, 8 Jan 2014 17:49:54 -0500 Subject: [PATCH] This was introduced in 1.4.1 with d26c147. This PR sets the active hostname back to the name specified in the Vagrantfile (fqdn) and updates the unit tests. Setting it to the short name causes loads of problems while configuring the system. I've had issues with sudoers hostname matching, Weblogic certificate generation and a few others. Even if I changed all of the Chef recipes, the fqdn is set in /etc/sysconfig/network so the active hostname will switch to the fqdn after a reboot. --- plugins/guests/redhat/cap/change_host_name.rb | 6 ++--- .../shared/redhat_like_host_name_examples.rb | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/guests/redhat/cap/change_host_name.rb b/plugins/guests/redhat/cap/change_host_name.rb index ea23938ab..2bad4c9a0 100644 --- a/plugins/guests/redhat/cap/change_host_name.rb +++ b/plugins/guests/redhat/cap/change_host_name.rb @@ -34,7 +34,7 @@ module VagrantPlugins def get_current_hostname hostname = '' block = lambda do |type, data| - if type == :stdout + if type == :stdout hostname += data.chomp end end @@ -49,8 +49,8 @@ module VagrantPlugins end def update_hostname - sudo "hostname #{short_hostname}" - end + sudo "hostname #{fqdn}" + end # /etc/hosts should resemble: # 127.0.0.1 host.fqdn.com host localhost ... diff --git a/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb b/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb index 2ec31b0be..d72099589 100644 --- a/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb +++ b/test/unit/plugins/guests/support/shared/redhat_like_host_name_examples.rb @@ -1,9 +1,5 @@ shared_examples 'a partial redhat-like host name change' do shared_examples 'shared between newhostname styles' do - it 'updates hostname on the machine with the new short hostname' do - communicator.expect_command(%q(hostname newhostname)) - described_class.change_host_name(machine, new_hostname) - end it 'sets dhcp_hostname with the provided short hostname' do communicator.expect_command(%q(sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1"newhostname"/' /etc/sysconfig/network-scripts/ifcfg-*)) @@ -12,7 +8,7 @@ shared_examples 'a partial redhat-like host name change' do it 'restarts networking' do communicator.expect_command(%q(service network restart)) - described_class.change_host_name(machine, new_hostname) + described_class.change_host_name(machine, new_hostname) end end @@ -25,6 +21,11 @@ shared_examples 'a partial redhat-like host name change' do communicator.expect_command(%q(sed -i 's/\\(HOSTNAME=\\).*/\\1newhostname.newdomain.tld/' /etc/sysconfig/network)) described_class.change_host_name(machine, new_hostname) end + + it 'updates hostname on the machine with the new hostname' do + communicator.expect_command(%q(hostname newhostname.newdomain.tld)) + described_class.change_host_name(machine, new_hostname) + end end context 'when newhostname is simple' do @@ -36,6 +37,12 @@ shared_examples 'a partial redhat-like host name change' do communicator.expect_command(%q(sed -i 's/\\(HOSTNAME=\\).*/\\1newhostname/' /etc/sysconfig/network)) described_class.change_host_name(machine, new_hostname) end + + it 'updates hostname on the machine with the new hostname' do + communicator.expect_command(%q(hostname newhostname)) + described_class.change_host_name(machine, new_hostname) + end + end end @@ -66,15 +73,15 @@ shared_examples 'mutating /etc/hosts helpers' do let(:expression) { sed_command.sub(%r{^sed -i '\(.*\)' /etc/hosts$}, "\1") } let(:search) { Regexp.new(expression.split('@')[1].gsub(/\\/,'')) } let(:replace) { expression.split('@')[2] } -end +end shared_examples 'inserting hostname in /etc/hosts' do include_examples 'mutating /etc/hosts helpers' - + context 'when target hostname is qualified' do let(:new_hostname) {'newhostname.newdomain.tld'} - it 'works with a basic file' do + it 'works with a basic file' do original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '') 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6