From a139dd2b59e05b9e159d9f3f6fbc232d505256a6 Mon Sep 17 00:00:00 2001 From: Matthias Haag Date: Wed, 22 Nov 2017 11:09:51 +0100 Subject: [PATCH 1/2] use basename for setting hostname --- plugins/guests/suse/cap/change_host_name.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/guests/suse/cap/change_host_name.rb b/plugins/guests/suse/cap/change_host_name.rb index c168885f3..8371f6fff 100644 --- a/plugins/guests/suse/cap/change_host_name.rb +++ b/plugins/guests/suse/cap/change_host_name.rb @@ -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 || { From 9807abe49809774e912a478d2be12a46285e9da2 Mon Sep 17 00:00:00 2001 From: Matthias Haag Date: Wed, 22 Nov 2017 11:28:30 +0100 Subject: [PATCH 2/2] Adjusted test to work with new implementation --- test/unit/plugins/guests/suse/cap/change_host_name_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/plugins/guests/suse/cap/change_host_name_test.rb b/test/unit/plugins/guests/suse/cap/change_host_name_test.rb index 1ff565006..b669f615e 100644 --- a/test/unit/plugins/guests/suse/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/suse/cap/change_host_name_test.rb @@ -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