Merge pull request #11100 from chkpnt/suse-hostname
Use hostnamectl instead of hostname to set the hostname under SUSE
This commit is contained in:
commit
ea550289a9
|
@ -5,11 +5,10 @@ module VagrantPlugins
|
||||||
def self.change_host_name(machine, name)
|
def self.change_host_name(machine, name)
|
||||||
comm = machine.communicate
|
comm = machine.communicate
|
||||||
|
|
||||||
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
|
if !comm.test("getent hosts '#{name}'", sudo: false)
|
||||||
basename = name.split(".", 2)[0]
|
basename = name.split(".", 2)[0]
|
||||||
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
comm.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||||
echo '#{basename}' > /etc/HOSTNAME
|
hostnamectl set-hostname '#{basename}'
|
||||||
hostname '#{basename}'
|
|
||||||
|
|
||||||
# Prepend ourselves to /etc/hosts
|
# Prepend ourselves to /etc/hosts
|
||||||
grep -w '#{name}' /etc/hosts || {
|
grep -w '#{name}' /etc/hosts || {
|
||||||
|
|
|
@ -25,15 +25,15 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
|
||||||
let(:basename) { "banana-rama" }
|
let(:basename) { "banana-rama" }
|
||||||
|
|
||||||
it "sets the hostname" do
|
it "sets the hostname" do
|
||||||
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
|
comm.stub_command("getent hosts '#{name}'", exit_code: 1)
|
||||||
|
|
||||||
cap.change_host_name(machine, name)
|
cap.change_host_name(machine, name)
|
||||||
expect(comm.received_commands[1]).to match(/echo '#{basename}' > \/etc\/HOSTNAME/)
|
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{basename}'/)
|
||||||
expect(comm.received_commands[1]).to match(/hostname '#{basename}'/)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not change the hostname if already set" do
|
it "does not change the hostname if already set" do
|
||||||
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
|
comm.stub_command("getent hosts '#{name}'", exit_code: 0)
|
||||||
|
|
||||||
cap.change_host_name(machine, name)
|
cap.change_host_name(machine, name)
|
||||||
expect(comm.received_commands.size).to eq(1)
|
expect(comm.received_commands.size).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue