Update photon cap for setting hostname

sqash
This commit is contained in:
sophia 2020-07-20 13:25:41 -05:00
parent 5afd7fdd73
commit 169d7b4011
2 changed files with 25 additions and 18 deletions

View File

@ -1,11 +1,11 @@
require 'vagrant/util/guest_hosts'
require_relative '../../linux/cap/change_host_name'
module VagrantPlugins
module GuestPhoton
module Cap
class ChangeHostName
extend Vagrant::Util::GuestHosts::Linux
extend VagrantPlugins::GuestLinux::Cap::ChangeHostName
def self.change_name_command(name)
return <<-EOH.gsub(/^ {14}/, "")
# Set the hostname

View File

@ -1,16 +1,17 @@
# Copyright (c) 2015 VMware, Inc. All Rights Reserved.
require_relative "../../../../base"
describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
let(:caps) do
let(:described_class) do
VagrantPlugins::GuestPhoton::Plugin
.components
.guest_capabilities[:photon]
.get(:change_host_name)
end
let(:machine) { double("machine") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
let(:name) { "banana-rama.example.com" }
let(:basename) { "banana-rama" }
before do
allow(machine).to receive(:communicate).and_return(comm)
@ -21,22 +22,28 @@ describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:cap) { caps.get(:change_host_name) }
context "minimal network config" do
let(:networks) { [
[:forwarded_port, {:guest=>22, :host=>2222, :host_ip=>"127.0.0.1", :id=>"ssh", :auto_correct=>true, :protocol=>"tcp"}]
] }
let(:name) { "banana-rama.example.com" }
before do
allow(machine).to receive_message_chain(:config, :vm, :networks).and_return(networks)
end
it "sets the hostname" do
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
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}'/)
end
described_class.change_host_name(machine, name)
expect(comm.received_commands[2]).to match(/hostname '#{name}'/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm).to_not receive(:sudo).with(/hostname '#{name}'/)
end
end
end
end