guests/redhat: set hostname on EL7 [GH-4352]

This commit is contained in:
Mitchell Hashimoto 2014-08-31 09:58:12 -07:00
parent a54f2dc539
commit 41f4ec1e4d
3 changed files with 16 additions and 3 deletions

View File

@ -71,6 +71,7 @@ BUG FIXES:
- guests/redhat: NFS setup should use systemd for RH7+ [GH-4228]
- guests/redhat: Detect RHEL 7 (and CentOS) and install Docker properly. [GH-4402]
- guests/redhat: Configuring networks on EL7 works. [GH-4195]
- guests/redhat: Setting hostname on EL7 works. [GH-4352]
- guests/smartos: Use `pfexec` for rsync. [GH-4274]
- guests/windows: Reboot after hostname change. [GH-3987]
- hosts/arch: NFS works with latest versions. [GH-4224]

View File

@ -3,7 +3,16 @@ module VagrantPlugins
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
new(machine, name).change!
case machine.guest.capability("flavor")
when :rhel_7
change_host_name_rhel7(machine, name)
else
new(machine, name).change!
end
end
def self.change_host_name_rhel7(machine, name)
machine.communicate.sudo("homenamectl set-hostname #{name}")
end
attr_reader :machine, :new_hostname

View File

@ -7,9 +7,12 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do
end
let(:machine) { double("machine") }
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:guest) { double("guest") }
before do
allow(guest).to receive(:capability).and_return(nil)
allow(machine).to receive(:communicate).and_return(communicator)
allow(machine).to receive(:guest).and_return(guest)
communicator.stub_command('hostname -f', stdout: old_hostname)
communicator.expect_command('hostname -f')
end
@ -17,7 +20,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do
after do
communicator.verify_expectations!
end
context 'when oldhostname is qualified' do
let(:old_hostname) { 'oldhostname.olddomain.tld' }
let(:similar_hostname) {'oldhostname'}
@ -26,7 +29,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do
include_examples 'inserting hostname in /etc/hosts'
include_examples 'swapping simple hostname in /etc/hosts'
include_examples 'swapping qualified hostname in /etc/hosts'
include_examples 'swapping qualified hostname in /etc/hosts'
end
context 'when oldhostname is simple' do