synced_folders/rsync: `vagrant rsync` syncs the folders
This commit is contained in:
parent
59218ded68
commit
309d12a16b
|
@ -1,11 +1,15 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
|
require "vagrant/action/builtin/mixin_synced_folders"
|
||||||
|
|
||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module SyncedFolderRSync
|
module SyncedFolderRSync
|
||||||
module Command
|
module Command
|
||||||
class Rsync < Vagrant.plugin("2", :command)
|
class Rsync < Vagrant.plugin("2", :command)
|
||||||
|
include Vagrant::Action::Builtin::MixinSyncedFolders
|
||||||
|
|
||||||
def self.synopsis
|
def self.synopsis
|
||||||
"syncs rsync synced folders to remote machine"
|
"syncs rsync synced folders to remote machine"
|
||||||
end
|
end
|
||||||
|
@ -28,6 +32,18 @@ module VagrantPlugins
|
||||||
error = true
|
error = true
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determine the rsync synced folders for this machine
|
||||||
|
folders = synced_folders(machine)[:rsync]
|
||||||
|
next if !folders || folders.empty?
|
||||||
|
|
||||||
|
# Get the SSH info for this machine so we can access it
|
||||||
|
ssh_info = machine.ssh_info
|
||||||
|
|
||||||
|
# Sync them!
|
||||||
|
folders.each do |id, folder_opts|
|
||||||
|
RsyncHelper.rsync_single(machine, ssh_info, folder_opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return error ? 1 : 0
|
return error ? 1 : 0
|
||||||
|
|
|
@ -31,6 +31,9 @@ end
|
||||||
# Vagrantfile anywhere, or at least this minimizes those chances.
|
# Vagrantfile anywhere, or at least this minimizes those chances.
|
||||||
ENV["VAGRANT_CWD"] = Tempdir.new.path
|
ENV["VAGRANT_CWD"] = Tempdir.new.path
|
||||||
|
|
||||||
|
# Set the dummy provider to the default for tests
|
||||||
|
ENV["VAGRANT_DEFAULT_PROVIDER"] = "dummy"
|
||||||
|
|
||||||
# Unset all host plugins so that we aren't executing subprocess things
|
# Unset all host plugins so that we aren't executing subprocess things
|
||||||
# to detect a host for every test.
|
# to detect a host for every test.
|
||||||
Vagrant.plugin("2").manager.registered.dup.each do |plugin|
|
Vagrant.plugin("2").manager.registered.dup.each do |plugin|
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
require_relative "../../../../base"
|
||||||
|
|
||||||
|
require Vagrant.source_root.join("plugins/synced_folders/rsync/command/rsync")
|
||||||
|
|
||||||
|
describe VagrantPlugins::SyncedFolderRSync::Command::Rsync do
|
||||||
|
include_context "unit"
|
||||||
|
|
||||||
|
let(:argv) { [] }
|
||||||
|
let(:iso_env) do
|
||||||
|
# We have to create a Vagrantfile so there is a root path
|
||||||
|
env = isolated_environment
|
||||||
|
env.vagrantfile("")
|
||||||
|
env.create_vagrant_env
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:communicator) { double("comm") }
|
||||||
|
|
||||||
|
let(:synced_folders) { {} }
|
||||||
|
|
||||||
|
let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper }
|
||||||
|
|
||||||
|
subject do
|
||||||
|
described_class.new(argv, iso_env).tap do |s|
|
||||||
|
s.stub(synced_folders: synced_folders)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
iso_env.machine_names.each do |name|
|
||||||
|
m = iso_env.machine(name, iso_env.default_provider)
|
||||||
|
m.stub(communicate: communicator)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#execute" do
|
||||||
|
context "with a single machine" do
|
||||||
|
let(:ssh_info) {{
|
||||||
|
private_key_path: [],
|
||||||
|
}}
|
||||||
|
|
||||||
|
let(:machine) { iso_env.machine(iso_env.machine_names[0], iso_env.default_provider) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
communicator.stub(ready?: true)
|
||||||
|
machine.stub(ssh_info: ssh_info)
|
||||||
|
|
||||||
|
synced_folders[:rsync] = [
|
||||||
|
[:one, {}],
|
||||||
|
[:two, {}],
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't sync if communicator isn't ready and exits with 1" do
|
||||||
|
communicator.stub(ready?: false)
|
||||||
|
|
||||||
|
helper_class.should_receive(:rsync_single).never
|
||||||
|
|
||||||
|
expect(subject.execute).to eql(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "rsyncs each folder and exits successfully" do
|
||||||
|
synced_folders[:rsync].each do |_, opts|
|
||||||
|
helper_class.should_receive(:rsync_single).
|
||||||
|
with(machine, ssh_info, opts).
|
||||||
|
ordered
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(subject.execute).to eql(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue