Add unit tests for smartos compatibility
This commit is contained in:
parent
edb4efa10a
commit
31da3860e5
|
@ -6,7 +6,7 @@ module VagrantPlugins
|
|||
su_cmd = machine.config.smartos.suexec_cmd
|
||||
|
||||
# Only do this if the hostname is not already set
|
||||
if !machine.communicate.test("#{su_cmd} hostname | grep '#{name}'")
|
||||
if !machine.communicate.test("hostname | grep '#{name}'")
|
||||
machine.communicate.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"")
|
||||
machine.communicate.execute("#{su_cmd} hostname #{name}")
|
||||
end
|
||||
|
|
|
@ -3,9 +3,10 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ConfigureNetworks
|
||||
def self.configure_networks(machine, networks)
|
||||
su_cmd = machine.config.smartos.suexec_cmd
|
||||
|
||||
networks.each do |network|
|
||||
device = "#{machine.config.smartos.device}#{network[:interface]}"
|
||||
su_cmd = machine.config.smartos.suexec_cmd
|
||||
ifconfig_cmd = "#{su_cmd} /sbin/ifconfig #{device}"
|
||||
|
||||
machine.communicate.execute("#{ifconfig_cmd} plumb")
|
||||
|
|
|
@ -6,7 +6,7 @@ module VagrantPlugins
|
|||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
def self.rsync_install(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
sudo = machine.config.smartos.suexec_cmd
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ module VagrantPlugins
|
|||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("smartos", "rsync_pre") do
|
||||
guest_capability("smartos", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
describe "VagrantPlugins::VagrantPlugins::Cap::ChangeHostName" do
|
||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:change_host_name) }
|
||||
let(:machine) { double("machine") }
|
||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
let(:old_hostname) { 'oldhostname.olddomain.tld' }
|
||||
let(:new_hostname) { 'newhostname.olddomain.tld' }
|
||||
|
||||
before do
|
||||
machine.stub(:communicate).and_return(communicator)
|
||||
machine.stub(:config).and_return(config)
|
||||
communicator.stub_command("hostname | grep '#{old_hostname}'", stdout: old_hostname)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".change_host_name" do
|
||||
it "refreshes the hostname service with the hostname command" do
|
||||
communicator.expect_command(%Q(pfexec hostname #{new_hostname}))
|
||||
plugin.change_host_name(machine, new_hostname)
|
||||
end
|
||||
|
||||
it "writes the hostname into /etc/nodename" do
|
||||
communicator.expect_command(%Q(pfexec sh -c "echo '#{new_hostname}' > /etc/nodename"))
|
||||
plugin.change_host_name(machine, new_hostname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
describe "VagrantPlugins::VagrantPlugins::Cap::ConfigureNetworks" do
|
||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:configure_networks) }
|
||||
let(:machine) { double("machine") }
|
||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
machine.stub(:communicate).and_return(communicator)
|
||||
machine.stub(:config).and_return(config)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".configure_networks" do
|
||||
let(:interface) { "eth0" }
|
||||
let(:device) { "e1000g#{interface}" }
|
||||
|
||||
describe 'dhcp' do
|
||||
let(:network) { {:interface => interface, :type => :dhcp} }
|
||||
|
||||
it "plumbs the device" do
|
||||
communicator.expect_command(%Q(pfexec /sbin/ifconfig #{device} plumb))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
|
||||
it "starts dhcp for the device" do
|
||||
communicator.expect_command(%Q(pfexec /sbin/ifconfig #{device} dhcp start))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'static' do
|
||||
let(:network) { {:interface => interface, :type => :static, :ip => '1.1.1.1', :netmask => '255.255.255.0'} }
|
||||
|
||||
it "plumbs the network" do
|
||||
communicator.expect_command(%Q(pfexec /sbin/ifconfig #{device} plumb))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
|
||||
it "starts sets netmask and IP for the device" do
|
||||
communicator.expect_command(%Q(pfexec /sbin/ifconfig #{device} inet 1.1.1.1 netmask 255.255.255.0))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
|
||||
it "starts enables the device" do
|
||||
communicator.expect_command(%Q(pfexec /sbin/ifconfig #{device} up))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
|
||||
it "starts writes out a hostname file" do
|
||||
communicator.expect_command(%Q(pfexec sh -c "echo '1.1.1.1' > /etc/hostname.#{device}"))
|
||||
plugin.configure_networks(machine, [network])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
describe "VagrantPlugins::VagrantPlugins::Cap::Halt" do
|
||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:halt) }
|
||||
let(:machine) { double("machine") }
|
||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
machine.stub(:communicate).and_return(communicator)
|
||||
machine.stub(:config).and_return(config)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".halt" do
|
||||
it "sends a shutdown signal" do
|
||||
communicator.expect_command(%Q(pfexec /usr/sbin/shutdown -y -i5 -g0))
|
||||
plugin.halt(machine)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
describe "VagrantPlugins::VagrantPlugins::Cap::MountNFS" do
|
||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:mount_nfs_folder) }
|
||||
let(:machine) { double("machine") }
|
||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
machine.stub(:communicate).and_return(communicator)
|
||||
machine.stub(:config).and_return(config)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".mount_nfs_folder" do
|
||||
it "creates the directory mount point" do
|
||||
communicator.expect_command(%Q(pfexec mkdir -p /mountpoint))
|
||||
plugin.mount_nfs_folder(machine, '1.1.1.1', {'nfs' => {:guestpath => '/mountpoint'}})
|
||||
end
|
||||
|
||||
it "mounts the NFS share" do
|
||||
communicator.expect_command(%Q(pfexec /usr/sbin/mount -F nfs '1.1.1.1:/some/share' '/mountpoint'))
|
||||
plugin.mount_nfs_folder(machine, '1.1.1.1', {'nfs' => {:guestpath => '/mountpoint', :hostpath => '/some/share'}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
require File.expand_path("../../../../../base", __FILE__)
|
||||
|
||||
describe "VagrantPlugins::VagrantPlugins::Cap::Rsync" do
|
||||
let(:plugin) { VagrantPlugins::GuestSmartos::Plugin.components.guest_capabilities[:smartos].get(:rsync_install) }
|
||||
let(:machine) { double("machine") }
|
||||
let(:config) { double("config", smartos: VagrantPlugins::GuestSmartos::Config.new) }
|
||||
let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
|
||||
|
||||
before do
|
||||
machine.stub(:communicate).and_return(communicator)
|
||||
machine.stub(:config).and_return(config)
|
||||
end
|
||||
|
||||
after do
|
||||
communicator.verify_expectations!
|
||||
end
|
||||
|
||||
describe ".rsync_installed" do
|
||||
describe "when rsync is in the path" do
|
||||
it "is true" do
|
||||
communicator.stub_command("which rsync", stdout: '/usr/bin/rsync', exit_code: 0)
|
||||
expect(plugin.rsync_installed(machine)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe "when rsync is not in the path" do
|
||||
it "is false" do
|
||||
communicator.stub_command("which rsync", stdout: '', exit_code: 1)
|
||||
expect(plugin.rsync_installed(machine)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".rsync_install" do
|
||||
let(:username) { "some_user" }
|
||||
|
||||
before do
|
||||
machine.stub(:ssh_info).and_return({username: username})
|
||||
end
|
||||
|
||||
it "creates a local directory" do
|
||||
communicator.expect_command(%Q(pfexec mkdir -p '/mountpoint'))
|
||||
plugin.rsync_install(machine, {guestpath: '/mountpoint'})
|
||||
end
|
||||
|
||||
it "chowns local directory to ssh user" do
|
||||
communicator.expect_command(%Q(pfexec chown -R #{username} '/mountpoint'))
|
||||
plugin.rsync_install(machine, {guestpath: '/mountpoint'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue