Skip to content

Commit

Permalink
guests/redhat: set hostname on EL7 [GH-4352]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Aug 31, 2014
1 parent a54f2dc commit 41f4ec1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 10 additions & 1 deletion plugins/guests/redhat/cap/change_host_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ module GuestRedHat
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}")

This comment has been minimized.

Copy link
@cdenneen

cdenneen Sep 2, 2014

Typo... hostnamectl not homenamectl, 1.6.5 please :)

This comment has been minimized.

Copy link
@mitchellh

mitchellh Sep 2, 2014

Author Contributor

Blah! Thanks.

This comment has been minimized.

Copy link
@cdenneen

cdenneen Sep 2, 2014

Tried changing the rb file and get "wrong number of arguments" error... so not sure if that's the only fix...

Using the following vagrant basebox:
config.vm.box_url = "https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box"

/Applications/Vagrant/embedded/gems/gems/vagrant-1.6.4/plugins/guests/redhat/cap/configure_networks.rb:23:in `configure_networks_rhel7': wrong number of arguments (1 for 2) (ArgumentError)
#4438 fixes this issue

So only remaining fix is PR for the typo above which I just did in #4440

end

attr_reader :machine, :new_hostname
Expand Down
7 changes: 5 additions & 2 deletions test/unit/plugins/guests/redhat/cap/change_host_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
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

after do
communicator.verify_expectations!
end

context 'when oldhostname is qualified' do
let(:old_hostname) { 'oldhostname.olddomain.tld' }
let(:similar_hostname) {'oldhostname'}
Expand All @@ -26,7 +29,7 @@

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
Expand Down

0 comments on commit 41f4ec1

Please sign in to comment.