Merge pull request #9212 from mahaag/master

Use basename for setting hostname on Suse
This commit is contained in:
Chris Roberts 2018-01-16 20:08:05 -08:00 committed by GitHub
commit 0bf589861c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -8,8 +8,8 @@ module VagrantPlugins
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
echo '#{name}' > /etc/HOSTNAME
hostname '#{name}'
echo '#{basename}' > /etc/HOSTNAME
hostname '#{basename}'
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {

View File

@ -22,13 +22,14 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
let(:cap) { caps.get(:change_host_name) }
let(:name) { "banana-rama.example.com" }
let(:basename) { "banana-rama" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/HOSTNAME/)
expect(comm.received_commands[1]).to match(/hostname '#{name}'/)
expect(comm.received_commands[1]).to match(/echo '#{basename}' > \/etc\/HOSTNAME/)
expect(comm.received_commands[1]).to match(/hostname '#{basename}'/)
end
it "does not change the hostname if already set" do