Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rsync #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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