From b3bee732aab00265358049fcc12b2aca07fe9aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Wed, 30 Mar 2022 22:52:58 +0200 Subject: [PATCH 1/3] add .vagrant.d/Vagrantfile to configure vbguest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/test_vagrant.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index c9788cc..1fcf8ed 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -269,7 +269,8 @@ def test_vm_status(vm_dir): def test_vm_lifecycle(vm_dir): - """Test methods controlling the VM - init(), up(), halt(), destroy().""" + """Test methods controlling the VM - init(), up(), suspend(), halt(), destroy().""" + VAGRANT_DIR = f"{os.environ['HOME']}/.vagrant.d" v = vagrant.Vagrant(vm_dir) # Test init by removing Vagrantfile, since v.init() will create one. @@ -278,9 +279,23 @@ def test_vm_lifecycle(vm_dir): except FileNotFoundError: pass + try: + os.mkdir(VAGRANT_DIR, mode=0o755) + except FileExistsError: + pass + + if not os.path.isfile(f"{VAGRANT_DIR}/Vagrantfile"): + with open(f"{VAGRANT_DIR}/Vagrantfile", "w", encoding="UTF-8") as config: + config.write( + 'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false\nend\n' + ) + v.init(TEST_BOX_NAME) assert v.NOT_CREATED == v.status()[0].state + validation = v.validate(vm_dir) + assert validation.returncode == 0 + v.up() assert v.RUNNING == v.status()[0].state @@ -298,7 +313,6 @@ def test_valid_config(vm_dir): v = vagrant.Vagrant(vm_dir) v.up() validation = v.validate(vm_dir) - assert validation.returncode == 0 From f896588adfb4b5ab2ced027ff6d54e787f3f8828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Wed, 30 Mar 2022 23:54:27 +0200 Subject: [PATCH 2/3] unlink Vagrantfile if created MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/test_vagrant.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index 1fcf8ed..9fdfd73 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -271,6 +271,8 @@ def test_vm_status(vm_dir): def test_vm_lifecycle(vm_dir): """Test methods controlling the VM - init(), up(), suspend(), halt(), destroy().""" VAGRANT_DIR = f"{os.environ['HOME']}/.vagrant.d" + VAGRANTFILE_CREATED = False + v = vagrant.Vagrant(vm_dir) # Test init by removing Vagrantfile, since v.init() will create one. @@ -289,6 +291,7 @@ def test_vm_lifecycle(vm_dir): config.write( 'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false\nend\n' ) + VAGRANTFILE_CREATED = True v.init(TEST_BOX_NAME) assert v.NOT_CREATED == v.status()[0].state @@ -308,6 +311,9 @@ def test_vm_lifecycle(vm_dir): v.destroy() assert v.NOT_CREATED == v.status()[0].state + if VAGRANTFILE_CREATED: + os.unlink(f"{VAGRANT_DIR}/Vagrantfile") + def test_valid_config(vm_dir): v = vagrant.Vagrant(vm_dir) From a26e10a09884d6586e2f7e7deeac99df7f62718a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Thu, 31 Mar 2022 00:06:38 +0200 Subject: [PATCH 3/3] dont assume vbguest is installed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/test_vagrant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index 9fdfd73..55c563b 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -289,7 +289,7 @@ def test_vm_lifecycle(vm_dir): if not os.path.isfile(f"{VAGRANT_DIR}/Vagrantfile"): with open(f"{VAGRANT_DIR}/Vagrantfile", "w", encoding="UTF-8") as config: config.write( - 'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false\nend\n' + 'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")\nend\n' ) VAGRANTFILE_CREATED = True