Merge pull request #2792 from smoyer/redhat_hostname_patch

guests/redhat: use FQDN for hostname
This commit is contained in:
Mitchell Hashimoto 2014-01-08 20:58:59 -08:00
commit 5e835f4201
2 changed files with 18 additions and 11 deletions

View File

@ -34,7 +34,7 @@ module VagrantPlugins
def get_current_hostname def get_current_hostname
hostname = '' hostname = ''
block = lambda do |type, data| block = lambda do |type, data|
if type == :stdout if type == :stdout
hostname += data.chomp hostname += data.chomp
end end
end end
@ -49,8 +49,8 @@ module VagrantPlugins
end end
def update_hostname def update_hostname
sudo "hostname #{short_hostname}" sudo "hostname #{fqdn}"
end end
# /etc/hosts should resemble: # /etc/hosts should resemble:
# 127.0.0.1 host.fqdn.com host localhost ... # 127.0.0.1 host.fqdn.com host localhost ...

View File

@ -1,9 +1,5 @@
shared_examples 'a partial redhat-like host name change' do shared_examples 'a partial redhat-like host name change' do
shared_examples 'shared between newhostname styles' 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 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-*)) 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 it 'restarts networking' do
communicator.expect_command(%q(service network restart)) 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
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)) communicator.expect_command(%q(sed -i 's/\\(HOSTNAME=\\).*/\\1newhostname.newdomain.tld/' /etc/sysconfig/network))
described_class.change_host_name(machine, new_hostname) described_class.change_host_name(machine, new_hostname)
end 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 end
context 'when newhostname is simple' do 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)) communicator.expect_command(%q(sed -i 's/\\(HOSTNAME=\\).*/\\1newhostname/' /etc/sysconfig/network))
described_class.change_host_name(machine, new_hostname) described_class.change_host_name(machine, new_hostname)
end 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
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(:expression) { sed_command.sub(%r{^sed -i '\(.*\)' /etc/hosts$}, "\1") }
let(:search) { Regexp.new(expression.split('@')[1].gsub(/\\/,'')) } let(:search) { Regexp.new(expression.split('@')[1].gsub(/\\/,'')) }
let(:replace) { expression.split('@')[2] } let(:replace) { expression.split('@')[2] }
end end
shared_examples 'inserting hostname in /etc/hosts' do shared_examples 'inserting hostname in /etc/hosts' do
include_examples 'mutating /etc/hosts helpers' include_examples 'mutating /etc/hosts helpers'
context 'when target hostname is qualified' do context 'when target hostname is qualified' do
let(:new_hostname) {'newhostname.newdomain.tld'} 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(/^ */, '') original_etc_hosts = <<-ETC_HOSTS.gsub(/^ */, '')
127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6 ::1 localhost6.localdomain6 localhost6