From a9b8139755b748c7fad81133414440d343f3bf8d Mon Sep 17 00:00:00 2001 From: Tiago Mendes-Costa Date: Tue, 21 Apr 2015 20:48:34 +0200 Subject: [PATCH 1/3] Added change_host_name capability for tinycore. --- plugins/guests/tinycore/plugin.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/guests/tinycore/plugin.rb b/plugins/guests/tinycore/plugin.rb index b7553fa0a..3febbb16f 100644 --- a/plugins/guests/tinycore/plugin.rb +++ b/plugins/guests/tinycore/plugin.rb @@ -16,6 +16,11 @@ module VagrantPlugins Cap::ConfigureNetworks end + guest_capability("tinycore", "change_host_name") do + require_relative "cap/change_host_name" + Cap::ChangeHostName + end + guest_capability("tinycore", "halt") do require_relative "cap/halt" Cap::Halt From 0b588e365675570e5206ece2290b7ad1cf4284f9 Mon Sep 17 00:00:00 2001 From: bmx0r Date: Tue, 21 Apr 2015 21:04:40 +0200 Subject: [PATCH 2/3] Remove useless line /usr/bin/sethostname will change /etc/hostname, useless to do it twice --- plugins/guests/tinycore/cap/change_host_name.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/guests/tinycore/cap/change_host_name.rb b/plugins/guests/tinycore/cap/change_host_name.rb index 2c16af362..1c4ec8590 100644 --- a/plugins/guests/tinycore/cap/change_host_name.rb +++ b/plugins/guests/tinycore/cap/change_host_name.rb @@ -4,7 +4,6 @@ module VagrantPlugins class ChangeHostName def self.change_host_name(machine, name) if !machine.communicate.test("hostname | grep '^#{name}$'") - machine.communicate.sudo("sh -c 'echo \"#{name}\" > /etc/hostname'") machine.communicate.sudo("/usr/bin/sethostname #{name}") end end From 36f89afbdf1e64d13d560d82bfa65661a1e10820 Mon Sep 17 00:00:00 2001 From: Tiago Mendes-Costa Date: Wed, 22 Apr 2015 16:12:46 +0200 Subject: [PATCH 3/3] Added unit test for tinycore change_host_name. --- .../tinycore/cap/change_host_name_test.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/unit/plugins/guests/tinycore/cap/change_host_name_test.rb diff --git a/test/unit/plugins/guests/tinycore/cap/change_host_name_test.rb b/test/unit/plugins/guests/tinycore/cap/change_host_name_test.rb new file mode 100644 index 000000000..ba258261f --- /dev/null +++ b/test/unit/plugins/guests/tinycore/cap/change_host_name_test.rb @@ -0,0 +1,26 @@ +require File.expand_path("../../../../../base", __FILE__) + +describe "VagrantPlugins::GuestTinyCore::Cap::ChangeHostName" do + let(:described_class) do + VagrantPlugins::GuestTinyCore::Plugin.components.guest_capabilities[:tinycore].get(:change_host_name) + end + let(:machine) { double("machine") } + let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + let(:old_hostname) { 'boot2docker' } + + before do + allow(machine).to receive(:communicate).and_return(communicator) + communicator.stub_command('hostname -f', stdout: old_hostname) + end + + after do + communicator.verify_expectations! + end + + describe ".change_host_name" do + it "refreshes the hostname service with the sethostname command" do + communicator.expect_command(%q(/usr/bin/sethostname newhostname.newdomain.tld)) + described_class.change_host_name(machine, 'newhostname.newdomain.tld') + end + end +end