Style tweaks and tests added for changing host name
This commit is contained in:
parent
60ef9e482b
commit
8d55bdcae5
|
@ -13,6 +13,7 @@
|
|||
- New `shell` provisioner which simply uploads and executes a script as
|
||||
root on the VM.
|
||||
- Gentoo host only networking no longer fails if alrady setup. [GH-286]
|
||||
- Set the host name of your guest OS with `config.vm.host_name` [GH-273]
|
||||
|
||||
## 0.7.0 (January 19, 2011)
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ module Vagrant
|
|||
class Action
|
||||
module VM
|
||||
class HostName
|
||||
def initialize(app, env, options=nil)
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
env.merge!(options || {})
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@app.call(env)
|
||||
|
||||
host_name = env["config"].vm.host_name
|
||||
if !host_name.nil?
|
||||
env.ui.info I18n.t("vagrant.actions.vm.host_name.setting")
|
||||
|
@ -18,4 +18,4 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,7 +82,6 @@ module Vagrant
|
|||
def change_host_name(name)
|
||||
raise BaseError, :_key => :unsupported_host_name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,12 +24,12 @@ module Vagrant
|
|||
|
||||
def change_host_name(name)
|
||||
vm.ssh.execute do |ssh|
|
||||
host_name_already_set = ssh.test?("sudo hostname | grep '#{name}'")
|
||||
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname") unless host_name_already_set
|
||||
ssh.exec!("sudo service hostname start") unless host_name_already_set
|
||||
if !ssh.test?("sudo hostname | grep '#{name}'")
|
||||
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
|
||||
ssh.exec!("sudo service hostname start")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -507,7 +507,9 @@ en:
|
|||
back the SSH commands necessary to set this up. Please report a bug and this
|
||||
will be fixed for your distro.
|
||||
unsupported_host_name: |-
|
||||
Setting host name is currently only supported on Debian, Ubuntu and RedHat
|
||||
Setting host name is currently only supported on Debian, Ubuntu and RedHat.
|
||||
If you'd like your guest OS to be supported, please open a ticket on the
|
||||
project.
|
||||
linux:
|
||||
attempting_halt: "Attempting graceful shutdown of linux..."
|
||||
mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
require "test_helper"
|
||||
|
||||
class HostNameVMActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::HostName
|
||||
@app, @env = action_env
|
||||
@instance = @klass.new(@app, @env)
|
||||
|
||||
@vm = mock("vm")
|
||||
@env["vm"] = @vm
|
||||
|
||||
@internal_vm = mock("internal")
|
||||
@vm.stubs(:vm).returns(@internal_vm)
|
||||
end
|
||||
|
||||
should "not run anything if no host name is set" do
|
||||
@env["config"].vm.host_name = nil
|
||||
@env["vm"].expects(:system).never
|
||||
@app.expects(:call).with(@env).once
|
||||
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
||||
should "change host name if set" do
|
||||
@env["config"].vm.host_name = "foo"
|
||||
|
||||
system = mock("system")
|
||||
@vm.stubs(:system).returns(system)
|
||||
|
||||
seq = sequence("host_seq")
|
||||
@app.expects(:call).with(@env).in_sequence(seq)
|
||||
system.expects(:change_host_name).with(@env["config"].vm.host_name).in_sequence(seq)
|
||||
|
||||
@instance.call(@env)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue