Skip to content

Commit

Permalink
Implement rsync
Browse files Browse the repository at this point in the history
Introduce rsync function executing "vagrant rsync".

Signed-off-by: Georg Pfuetzenreuter <[email protected]>
  • Loading branch information
tacerus committed Jun 6, 2023
1 parent 7528af6 commit 3b06f1e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
TOX_PARALLEL_NO_SPINNER: 1
TOXENV: ${{ matrix.tox_env }}
FORCE_COLOR: 1
PYTEST_REQPASS: 25
PYTEST_REQPASS: 26

steps:
- name: Check vagrant presence
Expand Down
7 changes: 7 additions & 0 deletions src/vagrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ def provision(self, vm_name=None, provision_with=None) -> None:
providers_arg = None if provision_with is None else ",".join(provision_with)
self._call_vagrant_command(["provision", vm_name, prov_with_arg, providers_arg])

def rsync(self, vm_name=None) -> None:
"""
Re-syncs data directories.
vm_name: optional VM name string.
"""
self._call_vagrant_command(["rsync", vm_name])

def reload(
self, vm_name=None, provision=None, provision_with=None, stream_output=False
) -> Optional[Iterator[str]]:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,29 @@ def test_provisioning(vm_dir):
assert test_file_contents == "foo", "The test file should contain 'foo'"


@pytest.mark.parametrize("vm_dir", (VM_VAGRANTFILE,), indirect=True)
def test_rsync(vm_dir, test_dir):
"""
Test whether rsync updates a synchronized file from containing
'I like hats' to 'I like turtles'.
"""
testfile = "python_vagrant_rsync_test_file"
testfile_path = "{}/{}".format(test_dir, testfile)
ilike1 = "hats"
ilike2 = "turtles"
with open(testfile_path, "w", encoding="UTF-8") as fh:
fh.write("I like {}".format(ilike1))
v = vagrant.Vagrant(vm_dir, quiet_stdout=False, quiet_stderr=False)
v.up()
output = v.ssh(command="cat /vagrant/{}".format(testfile))
assert output.strip() == "I like {}".format(ilike1)
with open(testfile_path, "w", encoding="UTF-8") as fh:
fh.write("I like {}".format(ilike2))
v.rsync()
output = v.ssh(command="cat /vagrant/{}".format(testfile))
assert output.strip() == "I like {}".format(ilike2)


@pytest.mark.parametrize("vm_dir", (MULTIVM_VAGRANTFILE,), indirect=True)
def test_multivm_lifecycle(vm_dir):
v = vagrant.Vagrant(vm_dir)
Expand Down
1 change: 1 addition & 0 deletions tests/vagrantfiles/vm_Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Vagrant.configure("2") do |config|
config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")
config.vm.box = "generic/alpine315"
config.vm.synced_folder ".", "/vagrant", type: "rsync"
end

0 comments on commit 3b06f1e

Please sign in to comment.