Merge pull request #11170 from moench-tegeder/suse_hostname_vs_getent

explicitly test the hostname we'll be setting
This commit is contained in:
Brian Cain 2019-11-05 09:30:28 -08:00 committed by GitHub
commit d4f83ca4a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -5,8 +5,8 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("getent hosts '#{name}'", sudo: false)
basename = name.split(".", 2)[0]
basename = name.split(".", 2)[0]
if !comm.test('test "$(hostnamectl --static status)" = "#{basename}"', sudo: false)
comm.sudo <<-EOH.gsub(/^ {14}/, '')
hostnamectl set-hostname '#{basename}'

View File

@ -25,14 +25,14 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
let(:basename) { "banana-rama" }
it "sets the hostname" do
comm.stub_command("getent hosts '#{name}'", exit_code: 1)
comm.stub_command('test "$(hostnamectl --static status)" = "#{basename}"', exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{basename}'/)
end
it "does not change the hostname if already set" do
comm.stub_command("getent hosts '#{name}'", exit_code: 0)
comm.stub_command('test "$(hostnamectl --static status)" = "#{basename}"', exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)